no-mutable-property-of-props-interface β
β
Using recommended in an ESLint configuration enables this rule.
π§ Some problems reported by this rule are automatically fixable by the --fix ESLint command line option
This rule disallows mutable properties in Props interfaces for CDK Constructs or Stacks. (It prohibits defining properties in an interface whose name ends with "Props" without the readonly modifier.)
Specifying mutable properties in Props interfaces is not recommended as it can lead to unintended side effects.
π§ How to use β
js
// eslint.config.mjs
export default defineConfig([
{
// ... some configs
rules: {
"cdk/no-mutable-property-of-props-interface": "error",
},
},
]);β Correct Example β
ts
import { IBucket } from "aws-cdk-lib/aws-s3";
interface MyConstructProps {
// β
readonly properties are allowed
readonly bucket: IBucket;
}ts
import { IBucket } from "aws-cdk-lib/aws-s3";
// β
This rule does not apply to interfaces not ending with "Props"
interface MyInterface {
bucket: IBucket;
}β Incorrect Example β
ts
import { IBucket } from "aws-cdk-lib/aws-s3";
interface MyConstructProps {
// β Properties in "Props" interfaces should be readonly
bucket: IBucket;
}