Rules
Rules Reference
Using the recommended settings will enables this rule
Problems reported by this rule can be fixed automatically with the --fix command line option
Currently we support the following rules:
- pascal-case-construct-idEnforce PascalCase for Construct IDs
- require-passing-thisRequire passing
this
in Construct constructors - no-variable-construct-idDisallow variables in Construct IDs
- no-parent-name-construct-id-matchDisallow matching parent name in Construct IDs
- no-construct-stack-suffixDisallow Construct and Stack names not to use the "Construct" or "Stack" suffix
- no-class-in-interfaceDisallow
Class
type in interface properties - no-public-class-fieldsDisallow specifying the
Class
type in the public variable of the Construct or Stack - no-mutable-public-fieldsEnforces specifying
readonly
in the public variables of the Construct or Stack - no-mutable-props-interfaceEnforces specifying
readonly
in the properties of the Props(interface) - require-jsdocRequire JSDoc comments for interface properties and Construct's public properties
- require-props-default-docRequire
@default
JSDoc for optional properties of Props(interface) - props-name-conventionEnforce Props(interface) name to follow
${ConstructName}Props
format - no-import-privateDisallow importing private modules
Recommended Rules
Recommended rules for code correctness that you can drop in without additional configuration.
when use recommended rules, configure as follows.
js
// eslint.config.mjs
import tsEslint from "typescript-eslint";
import eslintCdkPlugin from "eslint-cdk-plugin";
export default tsEslint.config({
files: ["lib/**/*.ts", "bin/*.ts"],
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
projectService: true,
project: "./tsconfig.json",
},
},
extends: [...tsEslint.configs.recommended],
// ✅ Add plugins
plugins: {
cdk: eslintCdkPlugin,
},
// ✅ Add rules (use recommended rules)
rules: {
...eslintCdkPlugin.configs.recommended.rules,
},
});
Strict Rules
Strict Rules provides all available rules to improve code quality and consistency.
When using strict rules, configure as follows.
js
// eslint.config.mjs
import tsEslint from "typescript-eslint";
import eslintCdkPlugin from "eslint-cdk-plugin";
export default tsEslint.config({
files: ["lib/**/*.ts", "bin/*.ts"],
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
projectService: true,
project: "./tsconfig.json",
},
},
extends: [...tsEslint.configs.recommended],
// ✅ Add plugins
plugins: {
cdk: eslintCdkPlugin,
},
// ✅ Add rules (use strict rules)
rules: {
...eslintCdkPlugin.configs.strict.rules,
},
});