Skip to content

eslint-plugin-awscdk ​

Install ​

Just run this:

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

Setting eslint config ​

Write eslint.config.mjs as follows:

🚨 This plugin uses typescript type information and must be used in conjunction with typescript-eslint

When using ESM ​

js
// eslint.config.mjs
import eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import cdkPlugin from "eslint-plugin-awscdk";

export default defineConfig([
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  {
    files: ["lib/**/*.ts", "bin/*.ts"],
    // βœ… Add plugins
    extends: [cdkPlugin.configs.recommended],
    // ... some configs
  },
]);

When using CJS ​

js
// eslint.config.cjs
const eslint = require("@eslint/js");
const { defineConfig } = require("eslint/config");
const tseslint = require("typescript-eslint");
const cdkPlugin = require("eslint-plugin-awscdk");

module.exports = defineConfig([
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  {
    files: ["lib/**/*.ts", "bin/*.ts"],
    // βœ… Add plugins
    extends: [cdkPlugin.configs.recommended],
    // ... 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 eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import cdkPlugin from "eslint-plugin-awscdk";

export default defineConfig([
  eslint.configs.recommended,
  ...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-construct-in-interface": "error",
      "cdk/no-construct-stack-suffix": "error",
      "cdk/no-parent-name-construct-id-match": "error",
    },
  },
]);