require-jsdoc â
âšī¸ This rule is not included in the recommended rules.
This rule requires JSDoc comments for interface properties and, public properties in Construct classes.
Adding JSDoc comments to properties makes the code more maintainable and easier to understand by providing clear documentation of what each property represents.
đ§ How to use â
js
// eslint.config.mjs
export default [
{
// ... some configs
rules: {
"cdk/require-jsdoc": "error",
},
},
];
â Correct Examples â
ts
import { IBucket } from "aws-cdk-lib/aws-s3";
interface MyConstructProps {
// â
JSDoc comment for interface property
/** S3 bucket to be specified for the resource */
readonly bucket: IBucket;
}
ts
import { Construct } from "constructs";
import { IBucket } from "aws-cdk-lib/aws-s3";
class MyConstruct extends Construct {
// â
JSDoc comment for public property
/** The S3 bucket created by this construct */
public readonly bucket: IBucket;
// â
When the property is not public, this rule is not applied
private readonly bucketName: string;
}
â Incorrect Examples â
ts
import { IBucket } from "aws-cdk-lib/aws-s3";
interface MyConstructProps {
// â Must write JSDoc comment
readonly bucket: IBucket;
}
ts
import { Construct } from "constructs";
import { IBucket } from "aws-cdk-lib/aws-s3";
class MyConstruct extends Construct {
// â Must write JSDoc comment
public readonly bucket: IBucket;
}