【りあクト!2】ESLintの設定
タグ:
JavaScript
TypeScript
React
パッケージを最新にしておく
TypeScriptの最新版をインストールする。
$ yarn upgrade-interactive --latest
eslintの初期設定
eslintの初期設定をする。 本にはない項目として「スタイルガイドを使用しますか?」というものがあるが、そこでairbnbを指定しても期待した動作をしていない気がする。
$ yarn eslint --init yarn run v1.22.5 $ /workspaces/React/hello-world/node_modules/.bin/eslint --init ✔ How would you like to use ESLint? · style ✔ What type of modules does your project use? · esm ✔ Which framework does your project use? · react ✔ Does your project use TypeScript? · No / Yes ✔ Where does your code run? · browser ✔ How would you like to define a style for your project? · guide ✔ Which style guide do you want to follow? · airbnb ✔ What format do you want your config file to be in? · JavaScript Checking peerDependencies of eslint-config-airbnb@latest Local ESLint installation not found. The config that you've selected requires the following dependencies: eslint-plugin-react@^7.21.5 @typescript-eslint/eslint-plugin@latest eslint-config-airbnb@latest eslint@^5.16.0 || ^6.8.0 || ^7.2.0 eslint-plugin-import@^2.22.1 eslint-plugin-jsx-a11y@^6.4.1 eslint-plugin-react-hooks@^4 || ^3 || ^2.3.0 || ^1.7.0 @typescript-eslint/parser@latest ✔ Would you like to install them now with npm? · No / Yes Oops! Something went wrong! :( ESLint: 7.20.0 ESLint couldn't find the config "airbnb" to extend from. Please check that the name of the config is correct. The config "airbnb" was referenced from the config file in "". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
拡張ルールセットがプラグインをインストールする
$ yarn add -D eslint-plugin-react@latest @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest $ typesync $ yarn
Airbnb JavaScript Style Guide に準拠するESLintの設定を導入する
結局こっちでスタイルガイドを入れる。
yarn add -D eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react-hooks