eslint-plugin-cdk

raw JSON →
1.8.0 verified Sat Apr 25 auth: no javascript

ESLint plugin with rules for AWS CDK projects. Version 1.8.0, experimental and subject to breaking changes. Offers rules like banning deprecated Lambda runtimes, enforcing construct patterns, and preventing static imports. Differentiates from other CDK linters by focusing on CDK-specific conventions and JSII compliance. Requires peer dependency @typescript-eslint/eslint-plugin >=3.9.0 and Node >=10.

error ESLint couldn't find the plugin "eslint-plugin-cdk".
cause Missing npm install or incorrect plugin name.
fix
Run 'yarn add -D eslint-plugin-cdk' and ensure plugins array uses 'cdk' not 'eslint-plugin-cdk'.
error Definition for rule 'cdk/ban-lambda-runtimes' was not found.
cause ESLint not configured to use plugin 'cdk'.
fix
Add '"plugins": ["cdk"]' to your ESLint config.
error Cannot read property 'bannedRuntimes' of undefined
cause Rule options not passed as second element of array.
fix
Use array syntax: ["error", { "bannedRuntimes": ["NODEJS_10_X"] }]
breaking Plugin is experimental and subject to breaking changes at any time.
fix Pin to exact version or review changelog before upgrading.
deprecated Rule 'no-static-import' may be removed in future major versions; recommended to use 'no-static-imports' (plural) instead.
fix Use rule 'cdk/no-static-imports' instead.
gotcha Rules like 'ban-reserved-words' require 'jsiiOnly: true' to activate; without it, rule does nothing.
fix Set 'jsiiOnly: true' in rule options if using JSII.
npm install eslint-plugin-cdk
yarn add eslint-plugin-cdk
pnpm add eslint-plugin-cdk

Configures ESLint with cdk/ban-lambda-runtimes, cdk/construct-ctor, and cdk/no-static-import rules.

// Install: yarn add -D eslint-plugin-cdk @typescript-eslint/eslint-plugin
// .eslintrc.json
{
  "plugins": ["cdk"],
  "rules": {
    "cdk/ban-lambda-runtimes": ["error", {
      "bannedRuntimes": [
        "NODEJS",
        "NODEJS_4_3",
        "NODEJS_6_10",
        "NODEJS_8_10",
        "NODEJS_10_X",
        "NODEJS_12_X"
      ]
    }],
    "cdk/construct-ctor": "error",
    "cdk/no-static-import": "error"
  }
}