Custom Rules
You can define project-specific lint rules using the declarative rule({...}) format.
Add your rule files to the plugins array in chant.config.ts:
export default { lint: { plugins: ["./lint-rules/org-standards.ts"], },};Rule Format
Section titled “Rule Format”Each rule is a top-level rule({...}) call:
rule({ id: "ORG001", severity: "warning", message: "Storage resources must have versioning enabled", match: match.property("versioning").on(match.anyResource()), pattern: "true",});Required Fields
Section titled “Required Fields”| Field | Type | Description |
|---|---|---|
id | string | Unique rule identifier |
severity | "error" | "warning" | "info" | Default severity level |
message | string | Diagnostic message |
match | selector | Structural selector for AST nodes |
Optional Fields
Section titled “Optional Fields”| Field | Type | Description |
|---|---|---|
pattern | string | Regex pattern the matched value must satisfy |
require | string | Comma-separated list of required property names |
max | number | Numeric threshold |
Match Selectors
Section titled “Match Selectors”| Selector | Matches |
|---|---|
match.resource("ClassName") | new ClassName({...}) expressions |
match.anyResource() | Any new expression |
match.stringLiteral() | String literal values |
match.exportName() | Exported declaration names |
match.importSource() | Import module specifiers |
match.property("name") | Object property with given key |
match.exportedConst() | export const declarations |
Narrow a selector with .on():
match.property("tags").on(match.resource("StorageType"))Duplicate Detection
Section titled “Duplicate Detection”If a custom rule ID collides with a built-in rule, the linter reports an error at startup. Choose IDs namespaced to your organization (e.g., ORG001, ACME001).