ESLint config for ECMAScript Next that you can import, extend and override
PluggableESNext: 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:
- @nazarkulyk/esnext
Alternatively, in your .eslintrc.js
or .eslintrc.json
:
{
"extends": ["@nazarkulyk/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-parser
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
- plugin:import/errors
- plugin:import/warnings
includes the following rules:
-
constructor-super
: requiresuper()
calls in constructors -
for-direction
: enforce that a for loop update clause moves the counter in the right direction -
getter-return
: enforce that a return statement is present in property getters -
no-case-declarations
: disallowlet
,const
,function
andclass
declarations incase
/default
clauses insideswitch
blocks -
no-class-assign
: disallow reassigning variables declared as classes -
no-compare-neg-zero
: disallow comparing against -0 -
no-cond-assign
: disallow assignment operators in conditional expressions -
no-console
: disallow the use ofconsole
-
no-const-assign
: disallow reassigningconst
variables -
no-constant-condition
: disallow constant expressions in conditions -
no-control-regex
: disallow control characters in regular expressions -
no-debugger
: disallow the use ofdebugger
-
no-delete-var
: disallow deleting variables -
no-dupe-args
: disallow duplicate arguments infunction
definitions -
no-dupe-class-members
: disallow duplicate class members -
no-dupe-keys
: disallow duplicate keys in object literals -
no-duplicate-case
: disallow duplicate case labels -
no-empty
: disallow empty block statements -
no-empty-character-class
: disallow empty character classes in regular expressions -
no-empty-pattern
: disallow empty destructuring patterns -
no-ex-assign
: disallow reassigning exceptions incatch
clauses -
no-extra-boolean-cast
: disallow unnecessary boolean casts -
no-extra-semi
: disallow unnecessary semicolons -
no-fallthrough
: disallow fallthrough ofcase
statements -
no-func-assign
: disallow reassigningfunction
declarations -
no-inner-declarations
: disallowfunction
orvar
declarations in nested blocks -
no-invalid-regexp
: disallow invalid regular expression strings inRegExp
constructors -
no-irregular-whitespace
: disallow irregular whitespace outside of strings and comments -
no-mixed-spaces-and-tabs
: disallow mixed spaces and tabs for indentation -
no-new-symbol
: disallownew
operators with theSymbol
object -
no-obj-calls
: disallow calling global object properties as functions -
no-octal
: disallow octal literals -
no-redeclare
: disallowvar
redeclaration -
no-regex-spaces
: disallow multiple spaces in regular expression literals -
no-self-assign
: disallow assignments where both sides are exactly the same -
no-sparse-arrays
: disallow sparse arrays -
no-this-before-super
: disallowthis
/super
before callingsuper()
in constructors -
no-undef
: disallow the use of undeclared variables unless mentioned in/-global -/
comments -
no-unexpected-multiline
: disallow multiline expressions likely to cause ASI errors -
no-unreachable
: disallow unreachable code afterreturn
,throw
,continue
, andbreak
statements -
no-unsafe-finally
: disallow control flow statements infinally
blocks -
no-unused-labels
: disallow unused labels -
no-unused-vars
: disallow unused variables -
no-useless-escape
: disallow unnecessary escape characters -
require-yield
: require generator functions to containyield
-
use-isnan
: disallow comparisons withNaN
, requiring calls toisNaN()
instead -
valid-typeof
: enforce comparingtypeof
expressions against valid type strings -
import/no-unresolved
: ensure imports point to a file/module that can be resolved -
import/named
: ensure named imports correspond to a named export in the remote file -
import/namespace
: ensure imported namespaces contain dereferenced properties as they are dereferenced -
import/default
: ensure a default export is present, given a default import -
import/export
: report any invalid exports, i.e. re-export of the same name -
import/no-named-as-default
: report use of exported name as identifier of default export; set to warn only -
import/no-named-as-default-member
: report use of exported name as property of default export; set to warn only
rules:
selected from here, configured to:
-
array-callback-return
: enforcereturn
statements in callbacks to array prototype methods such asmap
,reduce
,find
etc. -
arrow-body-style
: require braces around arrow function bodies,as-needed
-
class-methods-use-this
: disallow class methods that don't usethis
-
dot-notation
: enforce dot notation for accessing object properties whenever possible -
eqeqeq
: prefer===
and!==
over==
and!=
-
import/no-amd
: report AMDrequire
anddefine
calls -
import/no-commonjs
: report CommonJSrequire
calls andmodule.exports
orexports.*
-
import/no-duplicates
: report repeated import of the same module in multiple places -
import/no-extraneous-dependencies
: forbid the use of extraneous packages -
import/no-mutable-exports
: forbid the use of mutable exports withvar
orlet
-
import/no-namespace
: report namespace imports -
import/no-nodejs-modules
: disallow node.js builtin modules -
import/prefer-default-export
: prefer a default export if module exports a single name -
no-alert
: disallow the use ofalert
,confirm
, andprompt
-
no-constant-condition
: overrideeslint:recommended
withcheckLoops: false
to avoid errors in infinite generators -
no-duplicate-imports
: disallow duplicate module imports -
no-empty-function
: disallow empty functions -
no-else-return
: disallowelse
blocks afterreturn
statements inif
blocks -
no-eval
: disallow the use ofeval()
-
no-extend-native
: disallow extending built-in or native objects -
no-extra-bind
: disallow binding functions that don't usethis
-
no-global-assign
: disallow assignments to native objects or read-only global variables -
no-implicit-globals
: disallowvar
and namedfunction
declarations in the global scope, doesn't apply to modules -
no-implied-eval
: disallow the use of eval()-like methods -
no-invalid-this
: disallowthis
outside of constructors, classes or methods -
no-lonely-if
: disallowif
statements as the only statement inelse
blocks -
no-loop-func
: disallowfunction
s inside loops -
no-new
: disallownew
operators outside of assignments or comparisons -
no-new-func
: disallow creating functions with theFunction
constructor -
no-new-wrappers
: disallow creating objects with theString
,Number
, andBoolean
constructors -
no-proto
: disallow use of the__proto__
property -
no-script-url
: disallowjavascript:
urls -
no-self-compare
: disallow comparisons where both sides are exactly the same -
no-throw-literal
: disallow throwing literals as exceptions -
no-unmodified-loop-condition
: enforce updating the loop condition in each iteration -
no-unneeded-ternary
: disallow ternary operators when simpler alternatives exist;defaultAssignment: false
prefers||
for default assignments -
no-unsafe-negation
: disallow negating the left operand of relational operators likein
andinstanceof
-
no-unused-expressions
: disallow expressions that have no effect on the state of the program, withallowShortCircuit: true
andallowTernary: true
allowing&&
,||
and the ternary operator as shorthands forif
andelse
-
no-use-before-define
: disallow the use of variables before they are defined;nofunc
ignoresfunction
declarations since they're hoisted -
no-useless-call
: disallow unnecessary.call()
and.apply()
-
no-useless-computed-key
: disallow unnecessary computed property keys in object literals -
no-useless-concat
: disallow unnecessary concatenation of literals or template literals -
no-useless-constructor
: disallow unnecessary constructors -
no-useless-rename
: disallow renamingimport
,export
, and destructured assignments to the same name -
no-var
: requirelet
orconst
instead ofvar
-
no-with
: disallowwith
statements -
object-shorthand
: require method and property shorthand syntax for object literals -
operator-assignment
: require assignment operator shorthand where possible -
prefer-arrow-callback
: require callbacks to be arrow functions -
prefer-const
: requireconst
declarations for variables that are never reassigned after declared -
prefer-rest-params
: require rest parameters instead ofarguments
-
prefer-spread
: require spread operator instead of.apply()