ESLint Plugin Switch Case

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

An ESLint plugin providing switch-case-specific linting rules, including no-default-case, no-case-curly, and newline-between-switch-case. Current stable version is 4.0.0, released with support for ESLint ^9.8.0 or ^10.0.0 and Node.js ^20.19.0 || ^22.13.0 || >= 24. The plugin enforces stylistic and logic rules for switch statements, filling a niche not covered by ESLint core rules. It is maintained by lukeapage and is in active development.

error Cannot find module 'eslint-plugin-switch-case'
cause ELSINT plugin not installed or misconfigured in plugins array.
fix
Run 'npm install eslint-plugin-switch-case --save-dev' and add 'switch-case' to plugins.
error Failed to load config "plugin:switch-case/recommended"
cause Plugin not specified in plugins array before using config.
fix
Ensure plugins: ['switch-case'] is set in your ESLint config.
error ESLint configuration error: The "switch-case" plugin does not support CommonJS. Use import() or ensure your project is ESM.
cause Using require() to load the plugin in a CommonJS context with v4.0.0.
fix
Switch to ESM or use dynamic import().
breaking v4.0.0 drops support for ESLint <9.8.0 and Node <20.19.0.
fix Upgrade ESLint to ^9.8.0 || ^10.0.0 and Node to ^20.19.0 || ^22.13.0 || >= 24.
breaking v4.0.0 is ESM-only; CommonJS require('eslint-plugin-switch-case') may fail.
fix Use import statements or ensure your project is configured for ESM.
deprecated The plugin previously exported a default object; v4 uses named exports.
fix Use import { rules, configs } from 'eslint-plugin-switch-case' instead of importing default.
gotcha The 'recommended' config enables all rules, which may be too strict for some projects.
fix Manually select rules instead of extending recommended.
npm install eslint-plugin-switch-case
yarn add eslint-plugin-switch-case
pnpm add eslint-plugin-switch-case

Sets up ESLint with the switch-case plugin using recommended config and custom rule overrides.

// .eslintrc.js
module.exports = {
  plugins: ['switch-case'],
  extends: ['plugin:switch-case/recommended'],
  rules: {
    'switch-case/no-case-curly': 'error',
    'switch-case/newline-between-switch-case': ['error', 'always'],
    'switch-case/no-default-case': 'error'
  }
};