---
url: /rules/construct-constructor-property.md
---

# construct-constructor-property

This rule enforces that CDK Construct `constructor` follows standard property patterns.

All Construct constructors should follow a consistent property pattern to maintain uniformity across the codebase.

Note: Additional parameters are allowed after the first three, as long as the initial parameters follow the prescribed pattern.

#### Enforced Property Patterns

* Naming: `scope, id` or `scope, id, props`
* Types:
  * `scope`: Construct type
  * `id`: string type

***

#### 🔧 How to use

::: code-group

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

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

:::

#### ✅ Correct Example

```ts
import { Construct } from "constructs";

// ✅ Constructor with "scope, id" parameter names
export class MyConstruct extends Construct {
  constructor(scope: Construct, id: string) {
    super(scope, id);
  }
}
```

```ts
import { Construct } from "constructs";

export interface MyConstructProps {
  bucketName: string;
}

// ✅ Constructor with "scope, id, props" parameter names
export class MyConstruct extends Construct {
  constructor(scope: Construct, id: string, props: MyConstructProps) {
    super(scope, id);
  }
}
```

```ts
import { Construct } from "constructs";

export interface MyConstructProps {
  bucketName?: string;
}

// ✅ Constructor with "scope, id, props?" parameter names (optional props)
export class MyConstruct extends Construct {
  constructor(scope: Construct, id: string, props?: MyConstructProps) {
    super(scope, id);
  }
}
```

```ts
import { Construct } from "constructs";

export interface MyConstructProps {
  bucketName: string;
}

// ✅ Constructor with additional parameters after "scope, id, props"
export class MyConstruct extends Construct {
  constructor(scope: Construct, id: string, props: MyConstructProps, resourceName: string) {
    super(scope, id);
  }
}
```

#### ❌ Incorrect Example

```ts
import { Construct } from "constructs";

// ❌ First parameter is not named "scope"
export class MyConstruct extends Construct {
  constructor(myScope: Construct, id: string) {
    super(myScope, id);
  }
}
```

```ts
import { Construct } from "constructs";

// ❌ Second parameter is not named "id"
export class MyConstruct extends Construct {
  constructor(scope: Construct, myId: string) {
    super(scope, myId);
  }
}
```

```ts
import { Construct } from "constructs";

export interface MyConstructProps {
  bucketName: string;
}

// ❌ Third parameter is not named "props"
export class MyConstruct extends Construct {
  constructor(scope: Construct, id: string, myProps: MyConstructProps) {
    super(scope, id);
  }
}
```
