'How do you run eslint for only a specific rule or set of rules - command line only

I know you can define rules in an .eslintrc file, but what if I just want to run eslint and check for one specific rule?

E.g. $ eslint helpme.js --rule some-important-rule



Solution 1:[1]

I don't know if this is the best way, but I was able to get this working:

$ eslint helpme.js --no-eslintrc --env "es6" --env "node" --parser-options "{ecmaVersion: 2018}" --rule "{some-important-rule: error}"

Note: With this method (ignoring .eslintrc completeley) you still have to add some stuff from .eslintrc like your environment and parser options.

Solution 2:[2]

If you want to use your .eslintrc file to keep your configuration (parser, plugin settings, etc), you can use eslint-nibble with the --rule=some-important-rule flag. This will respect your normal configuration, but only show you errors from that rule. There are some other flags as well like --no-interactive if you want to run this in something like a CI environment.

Disclaimer: I'm the creator of eslint-nibble.

Solution 3:[3]

Simple way to see single rule output while still using .eslintrc is to use grep:

$ eslint helpme.js | egrep "(^/|some\-important\-rule$)"

Solution 4:[4]

Expanding on @matrik answer, this doesn't require me to define all eslint config again and also shows the file name.

eslint helpme.js | egrep "react/jsx-no-literals" -B 1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JBaczuk
Solution 2 IanVS
Solution 3 matrik
Solution 4 Borjante