eslint-plugin-no-dupe-class-fields
This project is an ESLint plugin which detects when classes have duplicate fields, including methods and properties.
bar = 5; { console; } let foo = ;foo; // Error because bar is 5. Whoops
This plugin will detect if there are multiple methods or properties with the same name on a single class. This plugin is an upgraded version of the built-in no-dupe-class-members rule, which does not detect class properties. When you use this plugin's recommended config, the built-in no-dupe-class-members rule will be disabled.
Class properties are currently an ECMAScript proposal, and are only supported with a babel plugin. ESLint does not support class properties by default, so you must currently use the babel-eslint parser with ESLint for this plugin to detect class properties.
Configuration
- Install babel-eslint and this plugin:
npm install --save-dev babel-eslint eslint-plugin-no-dupe-class-fields
oryarn add --dev babel-eslint eslint-plugin-no-dupe-class-fields
. - Set the ESLint config's
parser
property tobabel-eslint
. - Add
plugin:no-dupe-class-fields/recommended
to the ESLint config'sextends
list.
Example: