Skip to content

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"],
},
};

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",
});
FieldTypeDescription
idstringUnique rule identifier
severity"error" | "warning" | "info"Default severity level
messagestringDiagnostic message
matchselectorStructural selector for AST nodes
FieldTypeDescription
patternstringRegex pattern the matched value must satisfy
requirestringComma-separated list of required property names
maxnumberNumeric threshold
SelectorMatches
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"))

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).