---
url: /ja/rules/no-mutable-public-property-of-construct.md
---

# no-mutable-public-property-of-construct

このルールは、CDK Construct の `public` プロパティに `readonly` 修飾子を指定することを強制します

CDK Construct は多くの場合、状態を持つ AWS リソースを表します。\
これらの `public` プロパティを `readonly` にすることで、Construct のインスタンス化後に意図しない変更が加えられることを防ぎます。

***

#### 🔧 使用方法

::: code-group

```ts [Oxlint]
// oxlint.config.ts
export default defineConfig({
  // ... some configs
  rules: {
    "awscdk/no-mutable-public-property-of-construct": "error",
  },
});
```

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

:::

#### ✅ 適切な例

```ts
import { Construct } from "constructs";
import { IBucket } from "aws-cdk-lib/aws-s3";
import { Topic } from "aws-cdk-lib/aws-sns";

export class MyConstruct extends Construct {
  // ✅ public プロパティに `readonly` 修飾子が指定されている
  public readonly bucket: IBucket;
  // ✅ public でないプロパティには、このルールは適用されない
  private topic: Topic;
}
```

#### ❌ 不適切な例

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

export class MyConstruct extends Construct {
  // ❌ public プロパティに `readonly` 修飾子が指定されていない
  public bucket: IBucket;
}
```
