Skip to content

no-mutable-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 disallow making public properties of constructs or stack Props (interfaces) mutable.

It is not a good to specify mutable public properties in props, as this can lead to unintended side effects.


🔧 How to use

js
// eslint.config.mjs
export default [
  {
    // ... some configs
    rules: {
      "cdk/no-mutable-props-interface": "error",
    },
  },
];

✅ Correct Example

ts
import { IBucket } from "aws-cdk-lib/aws-s3";

interface MyConstructProps {
  // ✅ Can use readonly
  readonly bucket: IBucket;
}
ts
import { IBucket } from "aws-cdk-lib/aws-s3";

// ✅ This rule does not apply to interfaces that are not Props
interface MyInterface {
  bucket: IBucket;
}

❌ Incorrect Example

ts
import { IBucket } from "aws-cdk-lib/aws-s3";

interface MyConstructProps {
  // ❌ Shouldn't use mutable
  bucket: IBucket;
}