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);
}
}