Standards for ECMAScript Projects of PALife.
Basically we use AirBnB's ESLint rules, however we make some exceptions.
eslint-config-airbnb
AirBnB's ESLint, it relies on these rules:eslint
Default ESLint ruleseslint-plugin-import
Import ruleseslint-plugin-jsx-a11y
HTML accessibility ruleseslint-plugin-react
React rules
See .eslintrc
file for exceptional rules.
Walk around examples
folder to see explanations for each rules. We try to explain why, how to use a rule and give some correct or wrong example codes.
-
If there is no
package.json
in your project, add it(skip this step if it already exists):npm init
-
Save these libraries to your project's
devDependencies
:npm i babel-eslint eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react --save-dev
-
Copy
.eslintrc
file to your project root directory.Recommended: or put ESLint configuration in your
package.json
file undereslintConfig
:package.json
{ "eslintConfig": { "extends": "airbnb", "installedESLint": true, "parser": "babel-eslint", "plugins": [ "react" ], "env": { "browser": true }, "rules": { "semi": ["error", "never"] } } }
-
Configure your editor to read
.eslintrc
file:-
Atom
Install
linter
andlinter-eslint
packages and Atom will lint automatically. -
WebStorm
Search for 'eslint', then check
Enable
and setESLint package
topath/to/your/project/node_modules/eslint
.
-
Recommended: use git pre-commit
hook to run ESLint before committing.
-
Install pre-commit
npm install --save-dev pre-commit
-
Add ESLint scripts in your
package.json
, like below:package.json
{ "scripts": { "lint": "./node_modules/.bin/eslint --global require,window --ext .js src" }, "pre-commit": [ "lint" ] }
-
Run
git commit
to test ifpre-commit
hook works.