⚠️ This article was posted over 2 years ago. The information might be outdated. ⚠️
Table of Contents
- Introduction
- Install packages
- Create your .eslintrc.json file
- Add shortcut commands
- How to use lint commands
- References
Introduction
This is just a quick guideline to install ESLint
in your JS applications.
Install packages
Follow the steps below and install all the necessary packages.
$ npm install --save-dev eslint
$ npm add --save-dev eslint-plugin-import eslint-plugin-jsx-a11y
$ npm install --save-dev prettier eslint-plugin-prettier
$ npm install --save-dev eslint-config-prettier
$ npm installl --save-dev eslint-plugin-react-hooks
Or just run
$ npm install --save-dev eslint eslint-plugin-import eslint-plugin-jsx-a11y prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-react-hooks
FYI, Difference between ESLint and Prettier.
Create your .eslintrc.json file
{
"extends": [
"react-app",
"plugin:jsx-a11y/recommended",
"prettier",
"react-hooks"
],
"plugins": ["jsx-a11y", "prettier"],
"rules": {
"prettier/prettier": "error"
}
}
Add shortcut commands
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint . --ext .js,.jsx; exit 0",
"lint-fix": "eslint --fix . --ext .js,.jsx; exit 0"
}
How to use lint commands
Simply run the commands below to use ESLint
.
// Run the command to check a specific file.
$ ./node_modules/.bin/eslint yourfile.js
// Run the command to fix errors.
// Each file
$ ./node_modules/.bin/eslint --fix yourfile.js
// Each Folder
$ ./node_modules/.bin/eslint --fix src/actions/
If you are also using Codeclimate
$ touch .codeclimate.yml
// .codeclimate.yml
eslint:
enabled: true
config:
config: /vfhd-development-kit/projects/vf_helpdesk_frontend/.eslintrc.json
References
References
- Integrating with ESLint · Prettier
- ESLint で ES6 で書かれた React のコードを検証する - Qiita
- ESLint の推奨設定(eslint:recommended)のチェック内容 | Tips Note by TAM
- ESLint ルール 一覧 (日本語) - galife
- Prettier と Linter を併用する - Qiita
- GitHub - prettier/eslint-config-prettier: Turns off all rules that are unnecessary or might conflict with Prettier.
- Prettier + ESLint + Facebook Code Quality: The Auto-magical React Styling Tutorial
- Prettier + ESLint + Facebook Code Quality: The Auto-magical React Styling Tutorial
- Command Line Interface - ESLint - Pluggable JavaScript linter
- Running eslint as an npm script results in ELIFECYCLE error. · Issue #2409 · eslint/eslint · GitHub
- ESLint をグローバルにインストールせずに使う - Qiita
- Streamline JavaScript Development with ESLint - NodeSource