Pluggable ESLint config for ECMAScript Next that you can import, extend and override
ESNext: Safety Checks and Best Practices with a bias toward code concision / brevity
Usage
In your js project directory:
npm install --save-dev eslint-config-esnext
And in your .eslintrc.yaml
:
---
extends:
- esnext
Alternatively, in your .eslintrc.js
or .eslintrc.json
:
{
"extends": ["esnext"]
}
To add a git-hook to your commits, consider using husky
npm install --save-dev husky
And in your package.json
:
"scripts": {
"precommit": "eslint ."
}
Config
This config is biased and opinionated, and errs on the side of too many rules instead of too few. Think of this as a superset of your repo's lint config, and discard what you don't like in it. It's easy to override and disable the rules you find inconvenient.
env:
es6: true
commonjs: true
enables ES6 features and CommonJS modules
parser: babel-eslint
enables parsing all babel supported code
parserOptions:
ecmaVersion: 7
sourceType: module
ecmaFeatures:
impliedStrict: true
modules: true
experimentalObjectRestSpread: true
allows es2015 modules and es2016 object rest and spread to be parsed, and applies strict mode to all js code
extends: eslint:recommended
includes the following rules:
rules:
selected from here, configured to:
array-callback-return
: enforce return
statements in callbacks to array prototype methods such as map
, reduce
, find
etc.arrow-body-style
: require braces around arrow function bodies, as-needed
dot-notation
: enforce dot notation for accessing object properties whenever possibleeqeqeq
: prefer ===
and !==
over ==
and !=
no-alert
: disallow the use of alert
, confirm
, and prompt
no-constant-condition
: override eslint:recommended
with checkLoops: false
to avoid errors in infinite generatorsno-duplicate-imports
: disallow duplicate module importsno-empty-function
: disallow empty functionsno-else-return
: disallow else
blocks after return
statements in if
blocksno-eval
: disallow the use of eval()
no-extend-native
: disallow extending built-in or native objectsno-extra-bind
: disallow binding functions that don't use this
no-implicit-globals
: disallow var
and named function
declarations in the global scope, doesn't apply to modulesno-implied-eval
: disallow the use of eval()-like methodsno-invalid-this
: disallow this
outside of constructors, classes or methodsno-lonely-if
: disallow if
statements as the only statement in else
blocksno-loop-func
: disallow function
s inside loopsno-new
: disallow new
operators outside of assignments or comparisonsno-new-func
: disallow creating functions with the Function
constructorno-new-wrappers
: disallow creating objects with the String
, Number
, and Boolean
constructorsno-proto
: disallow use of the __proto__
propertyno-script-url
: disallow javascript:
urlsno-self-compare
: disallow comparisons where both sides are exactly the sameno-throw-literal
: disallow throwing literals as exceptionsno-unmodified-loop-condition
: enforce updating the loop condition in each iterationno-unneeded-ternary
: disallow ternary operators when simpler alternatives exist; defaultAssignment: false
prefers ||
for default assignmentsno-unused-expressions
: disallow expressions that have no effect on the state of the program, with allowShortCircuit: true
and allowTernary: true
allowing &&
, ||
and the ternary operator as shorthands for if
and else
no-use-before-define
: disallow the use of variables before they are defined; nofunc
ignores function
declarations since they're hoistedno-useless-call
: disallow unnecessary .call()
and .apply()
no-useless-computed-key
: disallow unnecessary computed property keys in object literalsno-useless-concat
: disallow unnecessary concatenation of literals or template literalsno-useless-constructor
: disallow unnecessary constructorsno-useless-escape
: disallow unnecessary escape charactersno-useless-rename
: disallow renaming import
, export
, and destructured assignments to the same nameno-var
: require let
or const
instead of var
no-with
: disallow with
statementsobject-shorthand
: require method and property shorthand syntax for object literalsoperator-assignment
: require assignment operator shorthand where possibleprefer-arrow-callback
: require callbacks to be arrow functionsprefer-const
: require const
declarations for variables that are never reassigned after declaredprefer-rest-params
: require rest parameters instead of arguments
prefer-spread
: require spread operator instead of .apply()