ESLint - izudon/izudon.github.io GitHub Wiki
- See also Prettier
10.1 節に詳しい。
インストール
$ npm install --save-dev eslint
$ yarn add --dev eslint
設定
$ yarn run eslint --init
- 対話形式で設定。結果は
.eslint.[js|yml|json]
に保存。
微調整設定
1.Jest 環境の追加
- JavaScript の テスト環境である Jest の 設定がないために、
Jest のグローバル変数であるtest
やexpect
が、
定義されていないといってエラーになってしまっている;。
./src/App.test.js
5:1 error 'test' is not defined no-undef
8:3 error 'expect' is not defined no-undef
.eslint.[js|yml|json]
に以下のように設定を追加する。
{
"env": {
"browser": true,
"es2021": true,
"jest": true // これを追加
},
// 他の設定
}
2.prop-type の無視
./src/XxxProvider.js
6:40 error 'children' is missing in props validation react/prop-types
{
"rules": {
"react/prop-types": "off"
}
}
利用
$ npx eslint 〈ファイルまたはフォルダ〉
$ yarn run -s eslint 〈ファイルまたはフォルダ〉
スクリプトに登録
package.json
"scripts": { "eslint": "eslint 'src/**/*.js'" },
$ npm run eslint
$ yarn run eslint