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.
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
eval
- Disallow archaic language features like
with
- Disallow obvious bad practices like
new Number(13)
- Point out places the code could be made shorter. For example:
The
if (someCondition) return someValue; else { // Do something else }
else
block is unneeded, since theif
block contains areturn
statement.eslint-config-problems
will point this out to you (or auto-fix with the--fix
option).
By default eslint-config-problems
forces the use of ES2015+ features supported by Node.js versions 6 and higher. Here are the rules enforced:
no-var
- Uselet
/const
instead.object-shorthand
- Use object shorthand where possible.prefer-arrow-callback
- Use arrow functions as callbacks where possible.prefer-numeric-literals
- Don't useparseInt()
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.apply
where possible.prefer-rest-params
- Use rest parameters instead ofarguments
.prefer-const
- I realize this is very opinionated; if you don't like it, addprefer-const: off
to your config.
There is a sub-config, accessible at problems/node8
, which forces ES features supported by Node.js 8+. Specifically, it enforces the use of the exponentiation operator instead of Math.pow()
.
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.
eslint-config-problems
doesn't set any environments by default, other than the es6
environment (to turn on the ES2015 parser, allow Promise
, etc.) So you'll have to manually set your environment in your ESLint config. Here's a list of environments.
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: true
plugins:
- prettier
rules:
- prettier/prettier: error