Skip to content

eslint-cdk-plugin

Install

Just run this:

sh
npm install -D eslint-cdk-plugin
sh
yarn add -D eslint-cdk-plugin
sh
pnpm install -D eslint-cdk-plugin

Setting eslint config

Write eslint.config.mjs as follows:

🚨 This plugin only supports FlatConfig.
What's FlatConfig?
🚨 This plugin uses typescript type information and must be used in conjunction with typescript-eslint

When using ESM

js
// eslint.config.mjs
import cdkPlugin from "eslint-cdk-plugin";
import tsEslint from "typescript-eslint";

export default [
  ...tsEslint.configs.recommended,
  // ✅ Add plugins
  cdkPlugin.configs.recommended,
  {
    files: ["lib/**/*.ts", "bin/*.ts"],
    // ... some configs
  },
];

When using CJS

js
// eslint.config.cjs
const cdkPlugin = require("eslint-cdk-plugin");
const tsEslint = require("typescript-eslint");

module.exports = [
  ...tsEslint.configs.recommended,
  // ✅ Add plugins
  cdkPlugin.configs.recommended,
  {
    files: ["lib/**/*.ts", "bin/*.ts"],
    // ... some configs
  },
];

Customize rules

If you want to customize the rules, write eslint.config.mjs as follows:
(For CJS, use eslint.config.cjs and use CommonJS notation)

js
// eslint.config.mjs
import tsEslint from "typescript-eslint";
import cdkPlugin from "eslint-cdk-plugin";

export default [
  ...tsEslint.configs.recommended,
  {
    files: ["lib/**/*.ts", "bin/*.ts"],
    languageOptions: {
      parserOptions: {
        projectService: true,
        project: "./tsconfig.json",
      },
    },
    // ✅ Add plugins
    plugins: {
      cdk: cdkPlugin,
    },
    // ✅ Add rules (use custom rules)
    rules: {
      "cdk/no-class-in-interface": "error",
      "cdk/no-construct-stack-suffix": "error",
      "cdk/no-parent-name-construct-id-match": "error",
    },
  },
];