Skip to content

props-name-convention ​

ℹī¸ This rule is not included in the recommended rules.

Forces the Props(interface) name of the Construct class to follow the form ${ConstructName}Props.
Where ${ConstructName} is the name of the Construct class.

Following a consistent naming pattern clarifies the relationship between Construct and its Props(interface), improving code maintainability and ease of understanding.


🔧 How to use ​

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

✅ Correct Examples ​

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

// ✅ Props(interface) name follows the format of `${ConstructName}Props`
interface MyConstructProps {
  readonly bucket?: IBucket;
}

class MyConstruct extends Construct {
  constructor(scope: Construct, id: string, props: MyConstructProps) {
    super(scope, id);
  }
}
ts
import { IBucket } from "aws-cdk-lib/aws-s3";

// ✅ This rule does not apply to interfaces that are not Construct classes
interface Props {
  readonly bucket?: string;
}

class NotConstruct {
  constructor(props: Props) {}
}

❌ Incorrect Examples ​

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

// ❌ Props interface name must follow ${ConstructName}Props format
interface Props {
  readonly bucket?: string;
}

class MyConstruct extends Construct {
  constructor(scope: Construct, id: string, props: Props) {
    super(scope, id);
  }
}