Rules
Rules Reference
Rules enabled when using the recommended configuration.
Rules that can be automatically fixed using the --fix option.
We currently support the following rules:
- construct-constructor-propertyEnforces that constructors of CDK Constructs have parameter names 'scope, id' or 'scope, id, props'.
- no-construct-in-interfaceDisallows specifying CDK Construct types (e.g., Bucket) for interface properties.
- no-construct-in-public-property-of-constructDisallows specifying Construct types (e.g., Bucket) for public properties of CDK Constructs.
- no-construct-stack-suffixDisallows 'Construct' or 'Stack' strings in Construct and Stack IDs.
- no-import-privateDisallows importing modules from private directories at different hierarchy levels.
- no-mutable-property-of-props-interfaceEnforces that properties of Props(interface) are specified with readonly.
- no-mutable-public-property-of-constructEnforces that public properties of Constructs are specified with readonly.
- no-parent-name-construct-id-matchDisallows specifying the parent class name in Construct IDs.
- no-variable-construct-idDisallows using variables for Construct IDs.
- pascal-case-construct-idEnforces PascalCase for Construct IDs.
- props-name-conventionEnforces that Props(interface) names follow the ${ConstructName}Props format.
- require-jsdocRequires JSDoc comments for interface properties and public properties of Constructs.
- require-passing-thisEnforces passing 'this' to the constructor of Constructs.
- require-props-default-docRequires '@default' JSDoc for optional properties of Props(interface).
Recommended Rules
The recommended
rules are suggested for maintaining correct code.
To use these rules, configure as follows:
js
// eslint.config.mjs
import cdkPlugin from "eslint-cdk-plugin";
import tsEslint from "typescript-eslint";
export default [
...tsEslint.configs.recommended,
// ✅ Add plugins
cdkPlugin.configs.recommended,
{
files: ["lib/**/*.ts", "bin/*.ts"],
// ... some configs
},
];
Strict Rules
The strict
rules provide all available rules. To use these rules, configure as follows:
js
// eslint.config.mjs
import cdkPlugin from "eslint-cdk-plugin";
import tsEslint from "typescript-eslint";
export default [
...tsEslint.configs.recommended,
// ✅ Add plugins
cdkPlugin.configs.strict,
{
files: ["lib/**/*.ts", "bin/*.ts"],
// ... some configs
},
];