eslint-config-topcoder
This package contains ESLint configs for applications:
- nodejs v7 (backend application)
- nodejs v7 with babel (backend application written in babel)
- react
It contains plugins:
- eslint-plugin-babel - ESLint rules for babel
- eslint-plugin-react - ESLint rules for react
- eslint-plugin-lodash - ESLint rules for lodash (
underscore
is forbidden) - eslint-plugin-import - ESLint plugin with rules that help validate proper imports
Installation
Nodejs
npm install --save-dev eslint-config-topcoder
Configure .eslintrc
{
"extends": "eslint-config-topcoder/nodejs"
}
Nodejs + babel
npm install --save-dev eslint-config-topcoder eslint-plugin-babel@^4.0.0 babel-eslint@^7.1.1
Configure .eslintrc
{
"extends": "eslint-config-topcoder/nodejs-babel"
}
React
npm install --save-dev eslint-config-topcoder eslint-plugin-babel@^4.0.0 eslint-plugin-react@^6.8.0 babel-eslint@^7.1.1
Configure .eslintrc
{
"extends": "eslint-config-topcoder/react"
}
Add scripts to package.json
"scripts": {
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix"
}
Run scripts with -s
flag
npm run lint -s
npm run lint:fix -s
General notes
-
It's not allowed to disable rules. The purpose of this config is to keep consistent styles in all topcoder projects.
However some exception are allowed. -
You can disable rules in configuration/setup files.
Example:app;ExpressJS requires to create a function with 4 parameters for error handling, but it may happen that we don't use some parameters.
Following example is not allowed, becausesocket
can be removed.io; -
magic-numbers
Following magic numbers are allowed:-1
,0
,1
.
In some cases you can disable this rule:
-
Math computations
const avg = foo + bar / 2; // eslint-disable-line magic-numbers -
Unit tests
Unit tests usually contain hard-coded data, andmagic-numbers
can be problematic. -
In following cases it's not allowed to disable magic-numbers
badresstatus400;res;good
;resstatusHttpStatusBAD_REQUEST;res;bad
if foostatus === 1good
const ACTIVE_STATUS = 1;if foostatus === ACTIVE_STATUS
- You should disable only using inline commands:
bad (all rules are disabled)good (only 1 rule is disabled)// eslint-disable-line// eslint-disable-line magic-numbers - Exceptions for
import/no-unresolved
It's allowed to add exceptions if you use aliases (mostly React).
For example:'import/no-unresolved': 2 ignore: '^components/' '^containers/' '^services/' '^layouts/'
Config for unit tests
If test
directory contains unit tests, you should create test/.eslintrc
and extend the base config.
Example:
"extends" : "../.eslintrc" "env" : "mocha" : true "globals": "expect": true "rules": // allow chai asserts like `expect(foo).to.be.true` "no-unused-expressions": 0 "no-magic-numbers": 0 "max-lines": 0
Contributors
- lsentkiewicz - Łukasz Sentkiewicz @Sky_
License
MIT