Thanks for taking the time to contribute! 😄
- Fork and clone this repository
- Branch from the default
master
branch using a descriptive new branch name - Install dependencies with
npm ci
- Refer to the ESLint documentation and the Custom Rules page
To add a new rule:
- Follow the instructions in the ESLint generator-eslint documentation to install Yeoman and the generator
- Run the new rule generator
yo eslint:rule
and answer the questions- select "ESLint Plugin"
- for "Type a short description of this rule" provide text which starts with one of "enforce", "require" or "disallow" (all lower case)
- Yeoman creates three boilerplate files:
docs/rules/<rule-id>.md
lib/rules/<rule-id>.js
test/rules/<rule-id>.js
- Run
npm run lint-fix
- Address the linting errors by editing
lib/rules/<rule-id>.js
- Add a
meta.messages
property (see MessageIds) - Select the appropriate
meta.type
property usingproblem
,suggestion
, orlayout
- Add a
- Complete the new rule by adding content to the three files previously created
- Run
eslint-doc-generator
to generate automated documentation sections (see Document generation below) - Review documentation changes
- Run
npm run lint
- Run
npm test
to run Jest (or runnpm start
to run Jest in watchAll mode where it remains active and reruns when source changes are made) - Make sure all tests are passing
- Add the rule to legacy.js and to flat.js
- Create a git commit with a commit message similar to:
feat: add rule <description>
(see commit message conventions) - Create a PR from your branch
This plugin uses the ESLint eslint-doc-generator to generate consistent documentation.
- Install with
npm install eslint-doc-generator -g
- Run
eslint-doc-generator
in the root directory of the plugin
- The directory tests-legacy contains tests which are compatible with the legacy ESLint v8 RuleTester utility. It is not expected to add new rules to this set of tests.
- The directory tests is for tests compatible with the current ESLint RuleTester.