eslint-config-atomix-base
This package provides Atomix's base .eslintrc config for ECMAScript 2017.
Usage
Our config bases on Airbnb's eslint config and Unicorn by Sindre Sorhus.
Installation:
npm install --save-dev eslint babel-eslint eslint-config-atomix-base
Create .eslintrc
:
Add test
script to your package.json "test": "eslint src lib bin"
If you don't want es2017 features:
npm install --save-dev eslint eslint-config-atomix-base
Rules
Config extends airbnb-base
and plugin:unicorn/recommended
.
strict: off
https://eslint.org/docs/rules/strict
Disable strict mode. You can manually enable it if required.
warn
no-unused-vars: ignoreRestSiblings: false
https://eslint.org/docs/rules/no-unused-vars
Unused variables/functions/classes should be removed or commented.
error, never
semi: https://eslint.org/docs/rules/semi
We don't write semicolons at each line. Only when needed.
off
no-confusing-arrow: https://eslint.org/docs/rules/no-confusing-arrow
Really? You can be confused with?
const x = 1 ? 2 : 3
off
object-property-newline: off
object-curly-newline: off
object-curly-spacing: https://eslint.org/docs/rules/object-property-newline https://eslint.org/docs/rules/object-curly-newline https://eslint.org/docs/rules/object-curly-spacing
Disabled because broken
warn
, always
arrow-parens: https://eslint.org/docs/rules/arrow-parens
As defined in Airbnb JS CodeStyle arrow parens should only for block body.
But when you add more params for lambda, you should add parens. Example:
-.map(value => rotate(value, 1))+.map((value, index) => rotate(value, 1 - index))
It provides inconsistency.
// Good {}; {}; a; {'\n'}a;a;const foo = bar: baz const bar = barbazconst baz = { return 1}
// Bad {}; {}; a; {'\n'}a;a;const foo = bar: baz const bar = barbazconst baz = { return 1}
error
, ^([a-z]([A-Za-z0-9]+){2,})|([A-Z][A-Z_0-9]+$
id-match: properties: false onlyDeclarations: true
https://eslint.org/docs/rules/id-match
All identifiers should be camelCased and more that 2 symbols length. Constants can be SCREAMING_UNDERSCORED
// Good let value = 1const functionDummy = {}const CONSTANT_NAME = 123 {}
// Badconst Value = 1const function_dummy = {}const constant_NAME = 1 {}
warn
no-magic-numbers: ignore: 1 0 -1 ignoreArrayIndexes: true enforceConst: true detectObjects: false
https://eslint.org/docs/rules/no-magic-numbers
Magic numbers is not descriptive. Please name it.
Exclude: 1, 0, -1, array indexes, object of numbers.
// Good const TAX = 128const Coeff = A: 0924 B: 0759 C: 0552 V: 0308 Z: 0116const val = myList5const prev = myListvalnext - 1
error
comma-dangle: arrays: 'always-multiline' objects: 'always-multiline' imports: 'always-multiline' functions: 'ignore'
https://eslint.org/docs/rules/comma-dangle
Not all environments supports comma dangle in function call/definition.
error, after
operator-linebreak: overrides: '?': 'before' ':': 'before' '&&': 'before' '+': 'before' '||': 'before'
https://eslint.org/docs/rules/operator-linebreak
We like write idented code and readable code in any line width.
// Goodconst foo = condition ? firstResult : second + result const demo = Foofirst || Foosecond || 'default value' // Badconst foo = condition ? firstResult : second + result const demo = Foofirst || Foosecond || 'default value'
error, stroustrup
brace-style: https://eslint.org/docs/rules/brace-style
Because, 1tbs is so dirty.
// Good { if argument && argumentchained try const result = Target while !resultactive resultstatus return result catch error return Target else if argument const value = Target try return value catch error const rawValue = value return Target else const defaultValue = Target return defaultValue } // Bad { if argument && argumentchained try const result = Target while !resultactive resultstatus return result catch error return Target else if argument const value = Target try return value catch error const rawValue = value return Target else const defaultValue = Target return defaultValue }
error, as-needed
quote-props: https://eslint.org/docs/rules/quote-props
Use quotes only if needed.
// Goodconst foo = demo: 1 'foo-bar': 2 bar: lock: 4 baz: 3 // Badconst baz = 'demo': 1 'foo-bar': 2 'bar': 'lock': 4 'baz': 3
off
no-plusplus: https://eslint.org/docs/rules/no-plusplus
We use it, because it good shorthand for some cases.
[error, always]
lines-between-class-members: exceptAfterSingleLine: true
https://eslint.org/docs/rules/lines-between-class-members
Add lines between class methods/properties.
Example:
id = 1 name = 'Foo' { // code } { /* single line */ } { // code }
[error, beside]
implicit-arrow-linebreak: https://eslint.org/docs/rules/implicit-arrow-linebreak
Implicit return in arrow function should be on same line.
Correct:
const foo = 1const bar = 2const baz = { const val = 3 return 3}
Incorrect:
const foo = 1const bar = 2 const baz = 3
error
padding-line-between-statements: blankLine: 'always' prev: 'const' 'let' 'var' next: '*' blankLine: 'any' prev: 'const' 'let' 'var' next: 'const' 'let' 'var'
https://eslint.org/docs/rules/padding-line-between-statements
Add padding line after let
, const
definitions.
Correct:
const foo = 1const bar = 2
Incorrect:
const foo = 1const bar = 2
off
no-await-in-loop: https://eslint.org/docs/rules/no-await-in-loop
In Node.js LTS await in loop is native and optimized.
Enabled in react
off
no-restricted-syntax: https://eslint.org/docs/rules/no-restricted-syntax
In node.js we want to use "await in for" without Futures.
https://github.com/airbnb/javascript#iterators--nope
Enabled in react
off
import/no-unresolved: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
Because some projects use aliases or module resolvers.
But you can configure module resolver for eslint and enable it rule in your config.
error, never
import/extensions: always for: json, json5, less, css, scss, sass, styl, jpeg, jpg, png, svg, bmp, gif
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
Node, webpack, rollup not require .js
in file path by default.
warn
import/order: groups: 'builtin' 'external' 'internal' 'parent' 'sibling' 'index' 'newlines-between': 'ignore'
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
Prefer order of your imports. To correct resolving internal
and external
modules configure module resolver.
warn
import/newline-after-import: count: 2
https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
We separate our imports with main code with 2 empty lines.
off
import/prefer-default-export: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
Use named exports to resolve naming problem.
With default export you can implicitly rename import binding. And your import not found in search by project.
// foo.js {} // bar.js
With named import you explicitly rename import binding.
// foo.js {} // bar.js
off
import/no-named-as-default: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
Rule is not resolving param-case
naming of the files.
error
unicorn/catch-error-name: name: 'error'
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/catch-error-name.md
Variable names like e
, err
, er
is so short. Name should be comprehensive like error
.
off
unicorn/no-fn-reference-in-iterator:
Disabled, because we like functional programming and we check all changelogs before update dependencies.
off
unicorn/import-index: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/import-index.md
Disabled, because we like more descriptive paths.