eslint-config-problems is an ESLint config that doesn't regulate your code style. It only catches actual problems with your code.
It's designed for use with Prettier, the opinionated code formatter; but you could also use this as a solid base config to add stylistic rules on top of.
- Installation & Usage
Rules were chosen based on the following criteria:
- No stylistic rules; nothing that Prettier can fix
- Prevent guaranteed runtime errors (i.e. no undefined variables)
- Disallow "evil" things like
- Disallow archaic language features like
- Disallow obvious bad practices like
- Point out places the code could be made shorter. For example:Theif someCondition return someValue;else// Do something else
elseblock is unneeded, since the
ifblock contains a
eslint-config-problemswill point this out to you (or auto-fix with the
eslint-config-problems forces the use of ES2015+ features supported by Node.js versions 10 and higher. Here are the rules enforced:
object-shorthand- Use object shorthand where possible.
prefer-arrow-callback- Use arrow functions as callbacks where possible.
prefer-numeric-literals- Don't use
parseInt()to write binary, octal, and hexadecimal numbers, use the literal form instead.
prefer-template- Use template strings instead of string concatenation.
prefer-spread- Use the spread operator instead of
prefer-rest-params- Use rest parameters instead of
- Use the exponentiation operator (
**) instead of
prefer-object-spread- Use object spread where possible, instead of
- Use optional catch bindings when not using the error variable in the catch block (enforced by
prefer-const- I realize this is very opinionated; if you don't like it, add
prefer-const: offto your config.
It also sets
ecmaVersion: 2020 in the
parserOptions, so that ESLint can parse modern code (including
BigInt in Node 10.8+) with no additional setup.
I disagree with rule X; you missed rule Y
If you disagree; feel free to open an issue. I'm open to changing rules if you have a good reason.
If I missed a rule that prevents an actual problem or is otherwise in keeping with the general guidelines above, please open an issue as well; I just might add it.
Installation & Usage
eslint-config-problems doesn't set any environments by default, other than the
es6 environment. So you'll have to manually set your environment in your ESLint config. Here's a list of environments.
If you're using ES Modules, you will need to set
sourceType: module in the
parserOptions, like this:
npm install -D eslint eslint-config-problems
In your eslintrc.yaml:
extends: 'problems'env:# Set your environments here; for example:node: true
npm install -D eslint prettier eslint-config-problems eslint-plugin-prettier
In your eslintrc.yaml:
extends: 'problems'env:# Set your environments here; for example:node: trueplugins:- prettierrules:- prettier/prettier: error