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 is recommended to be used with typescript-eslint because it uses type information.

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

export default [
  eslint.configs.recommended,
  ...tsEslint.configs.recommended,
  ...tsEslint.configs.stylistic,
  {
    plugins: {
      cdk: eslintCdkPlugin,
    },
    rules: {
      ...eslintCdkPlugin.configs.recommended.rules,
    },
  },
];

Customize rules

If you want to customize the rules, write eslint.config.mjs as follows:

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

export default [
  eslint.configs.recommended,
  ...tsEslint.configs.recommended,
  ...tsEslint.configs.stylistic,
  {
    plugins: {
      cdk: eslintCdkPlugin,
    },
    rules: {
      ...eslintCdkPlugin.configs.recommended.rules,
      "cdk/no-public-class-fields": "warn",
    },
  },
];