最低限、セミコロンやクウォートなどを整理したいケースが多いのでメモ。
yarn add -D eslint eslint-plugin-react
.eslintrc.js
を作成
module.exports = { root: true, env: { node: true, es6: true, }, parserOptions: { // Parsing error: 'import' and 'export' may appear only with 'sourceType: module' 対策 sourceType: 'module', // eslint Parsing error: Unexpected token function with async 対策 ecmaVersion: 8 }, plugins: [ 'react' ], ignorePatterns: [ 'node_modules/*', '.next/*', 'out/*', ], extends: [ 'eslint:recommended', 'plugin:react/recommended' ], // https://eslint.org/docs/rules/ を参照 rules: { 'semi': ['error', 'never'], 'react/react-in-jsx-scope': 'off', // めっちゃエラー出るので 'react/prop-types': 'off' // めっちゃエラー出るので } }
package.json
"scripts": { "lint": "eslint --ext js,jsx --fix ." }
実行
yarn lint
// .vscode/settings.json { "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }