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.
Common errors
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"] }]
Warnings
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.
Install
npm install eslint-plugin-cdk yarn add eslint-plugin-cdk pnpm add eslint-plugin-cdk Imports
- plugins.cdk wrong
"plugins": ["eslint-plugin-cdk"]correct"plugins": ["cdk"] - rules.* wrong
"ban-lambda-runtimes": "error"correct"cdk/ban-lambda-runtimes": "error" - module.exports.plugins wrong
const cdkPlugin = require('eslint-plugin-cdk'); module.exports = { plugins: { cdk: cdkPlugin } }correctmodule.exports = { plugins: ['cdk'] }
Quickstart
// 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"
}
}