Skip to content

no-mutable-property-of-props-interface

recommended を使用した場合、このルールが有効になります。
🔧 このルールによってエラーになるコードは ESLint の --fix コマンド で自動修正できます。

このルールは、CDK Construct または Stack の Props (interface) のプロパティに、readonly 修飾子を指定することを強制します

意図しない副作用を防ぐため、Props のプロパティには readonly 修飾子を指定することが推奨されます。


🔧 使用方法

js
// eslint.config.mjs
export default defineConfig([
  {
    // ... some configs
    rules: {
      "awscdk/no-mutable-property-of-props-interface": "error",
    },
  },
]);

✅ 適切な例

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

interface MyConstructProps {
  // ✅ Props のプロパティに readonly 修飾子が指定されている
  readonly bucket: IBucket;
}
ts
import { IBucket } from "aws-cdk-lib/aws-s3";

// ✅ Props ではない interface に対しては、このルールは適用されない
interface MyInterface {
  bucket: IBucket;
}

❌ 不適切な例

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

interface MyConstructProps {
  // ❌ Props のプロパティに readonly 修飾子が指定されていない
  bucket: IBucket;
}