{"id":1327,"date":"2021-05-17T19:00:00","date_gmt":"2021-05-17T10:00:00","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1327"},"modified":"2021-05-17T16:28:29","modified_gmt":"2021-05-17T07:28:29","slug":"react-eslint-setup","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1327","title":{"rendered":"[React.js]create-react-app\u306elint\u304b\u3089ESLint\u3078\u79fb\u884c\u3059\u308b"},"content":{"rendered":"\n<p>create-react-app\u306b\u3082\u30c7\u30d5\u30a9\u30eb\u30c8\u3067eslint\u304c\u5165\u3063\u3066\u3044\u3066\u3001eslint\u30b3\u30de\u30f3\u30c9\u3082\u4f7f\u3048\u308b\u306e\u3067\u3059\u304c\u3001<br>react-scripts\u3067\u306e\u8d77\u52d5\u304b\u3089\u5909\u3048\u308b\u6642\u306bESLint\u3092\u6539\u3081\u3066\u5c0e\u5165\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u305f\u306e\u3067\u305d\u306e\u307e\u3068\u3081\u3067\u3059\u3002<\/p>\n\n\n\n<p>monorepo\u74b0\u5883\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u5b9f\u884c\u65b9\u6cd5\u3092react-app-rewired\u306b\u5909\u3048\u305f\u308a\u3001<br>\u30c6\u30b9\u30c8\u306e\u5b9f\u884c\u65b9\u6cd5\u3092jest\u306b\u5909\u3048\u305f\u308a\u3057\u3066\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u305f\u4e00\u74b0\u3067\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nyarn add --dev eslint @typescript-eslint\/eslint-plugin @typescript-eslint\/parser eslint-config-prettier eslint-plugin-jest eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks prettier\n<\/pre><\/div>\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">eslint \u3067\u89e3\u6790\u5bfe\u8c61\u304b\u3089\u9664\u5916\u3057\u305f\u3044\u3082\u306e\u3092\u6307\u5b9a<\/h2>\n\n\n\n<p>package.json\u306beslintIgnore\u9805\u76ee\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n  ...\n  &quot;eslintIgnore&quot;: &#x5B;\n    &quot;**\/build\/**\/*.js&quot;,\n    &quot;**\/coverage\/**\/*.js&quot;,\n    &quot;**\/*.test.ts&quot;,\n    &quot;**\/*.test.tsx&quot;,\n    &quot;**\/*.stories.tsx&quot;\n  ]\n  ...\n}\n<\/pre><\/div>\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">script \u306e\u8ffd\u52a0<\/h2>\n\n\n\n<p>package.json\u306bESLint\u306e\u5b9f\u884c\u30b3\u30de\u30f3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n  ...\n  &quot;script&quot;: {\n    &quot;lint_check&quot;: &quot;yarn eslint --ext .js,.jsx,.ts,.tsx .&quot;,\n    &quot;lint&quot;: &quot;yarn eslint --ext .js,.jsx,.ts,.tsx -f json -o .\/report\/eslint-report.json&quot;\n  }\n  ...\n}\n<\/pre><\/div>\n\n\n<p>\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f\u3001\u305f\u3060\u306eeslint\u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c\u3060\u3068\u89e3\u6790\u5bfe\u8c61\u306e\u30d5\u30a1\u30a4\u30eb\u306fjs\u3060\u3051\u3068\u306a\u308a\u3001typescript\u3092\u8a8d\u8b58\u3057\u3066\u304f\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p>\u306a\u306e\u3067\u3001<code> --ext<\/code> \u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4f7f\u3063\u3066typescript\u306e\u30d5\u30a1\u30a4\u30eb\u3082lint\u5bfe\u8c61\u306b\u8a2d\u5b9a\u3057\u3066\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3057\u3066<code>-f<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3068<code>-o<\/code>\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4f7f\u3044\u3001json\u5f62\u5f0f\u3067\u30ec\u30dd\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\"><code>.eslintrc.yml <\/code>\u306e\u4f5c\u6210<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\nenv:\n  es2020: true\n  jest\/globals: true\nparser: '@typescript-eslint\/parser'\nparserOptions:\n  project: .\/tsconfig.json\n  ecmaFeatures:\n    jsx: true\nplugins:\n  - react\n  - jest\n  - '@typescript-eslint'\nsettings:\n  react:\n    version: detect\n  jest:\n    version: 26\nextends:\n  - eslint:recommended\n  - plugin:@typescript-eslint\/eslint-recommended\n  - plugin:@typescript-eslint\/recommended\n  - plugin:jest\/recommended\n  - prettier\nrules:\n  '@typescript-eslint\/explicit-function-return-type': off\n  '@typescript-eslint\/ban-types': off\n  '@typescript-eslint\/explicit-module-boundary-types': off\n  '@typescript-eslint\/no-explicit-any': off\n  'jest\/no-conditional-expect': off\n  'jest\/no-try-expect': off\n  'jest\/no-jasmine-globals': off\n<\/pre><\/div>\n\n\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u30d7\u30e9\u30b0\u30a4\u30f3\u3068\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u30de\u30c3\u30d4\u30f3\u30b0<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>yarn add\u3057\u305f\u30d1\u30c3\u30b1\u30fc\u30b8<\/th><th>.eslintrc.yml\u306e\u8a2d\u5b9a<\/th><\/tr><\/thead><tbody><tr><td>eslint<\/td><td><\/td><\/tr><tr><td>@typescript-eslint\/eslint-plugin<\/td><td>extends<br>    &#8211; plugin:@typescript-eslint\/eslint-recommended<\/td><\/tr><tr><td>@typescript-eslint\/parser<\/td><td>parser: &#8216;@typescript-eslint\/parser&#8217;<\/td><\/tr><tr><td>eslint-config-prettier<\/td><td>extends<br>    &#8211; prettier<\/td><\/tr><tr><td>eslint-plugin-jest<\/td><td>plugins<br>    &#8211; &#8216;jest&#8217;<\/td><\/tr><tr><td>eslint-plugin-jsx-a11y<\/td><td>plugins<br>    &#8211; &#8216;jsx-a11y&#8217;<\/td><\/tr><tr><td>eslint-plugin-react<\/td><td><code>extends:<\/code><br>    <code>- eslint:recommended<\/code><br>    <code>- plugin:react\/recommended<\/code><\/td><\/tr><tr><td>eslint-plugin-react-hooks<\/td><td>extends<br>    &#8211; plugin:react-hooks\/recommended<\/td><\/tr><tr><td>prettier<\/td><td><\/td><\/tr><tr><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 id=\"outline__4_1\" class=\"wp-block-heading\">jest\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u6307\u5b9a\u306b\u3064\u3044\u3066<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n  jest:\n    version: 26\n<\/pre><\/div>\n\n\n<p>vscode\u3067\u958b\u767a\u3057\u3066\u3044\u308b\u5834\u5408\u3001vscode\u306elint\u6a5f\u80fd\u3068project\u306eESLint\u304c\u565b\u307f\u5408\u308f\u305avscode\u4e0a\u3067\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u983b\u7e41\u306b\u8868\u793a\u3055\u308c\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u969b\u306e\u56de\u907f\u7b56\u3068\u3057\u3066ESLint\u306e\u8a2d\u5b9a\u4e0a\u3067jest\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3059\u308b\u3068\u89e3\u6d88\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/github.com\/microsoft\/vscode-eslint\/issues\/1145\">Unable to detect Jest version in create-react-app project<\/a><\/p>\n\n\n\n<h2 id=\"outline__5\" class=\"wp-block-heading\">(Option) vscode \u306e settings.json \u3092\u4f5c\u6210<\/h2>\n\n\n\n<p>vscode\u3067\u958b\u767a\u3057\u3066\u3044\u308b\u5834\u5408\u3001vscode\u4e0a\u3067\u306e\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>[rootProject]\/.vscode\/settings.json<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n  &quot;files.autoSave&quot;: &quot;afterDelay&quot;,\n  &quot;prettier.jsxBracketSameLine&quot;: true,\n  &quot;prettier.jsxSingleQuote&quot;: true,\n  &quot;prettier.packageManager&quot;: &quot;yarn&quot;,\n  &quot;prettier.printWidth&quot;: 140,\n  &quot;prettier.singleQuote&quot;: true,\n  &quot;eslint.packageManager&quot;: &quot;yarn&quot;,\n  &quot;eslint.validate&quot;: &#x5B;&quot;typescript&quot;, &quot;typescriptreact&quot;],\n  &quot;eslint.enable&quot;: true\n}\n<\/pre><\/div>\n\n\n<h2 id=\"outline__6\" class=\"wp-block-heading\">\u95a2\u9023<\/h2>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/react-monorepo\/\">[React.js]monorepo\u74b0\u5883\u3092\u69cb\u7bc9\u3059\u308b+typescript<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/react-dotenv\/\">[React.js]dotenv\u3092\u5229\u7528\u3057\u3066\u74b0\u5883\u5dee\u5206\u3092\u5438\u53ce\u3059\u308b<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/react-jest-html-reporters\/\">[React.js]jest\u3068jest-html-reporters\u306e\u5c0e\u5165<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>create-react-app\u306b\u3082\u30c7\u30d5\u30a9\u30eb\u30c8\u3067eslint\u304c\u5165\u3063\u3066\u3044\u3066\u3001eslint\u30b3\u30de\u30f3\u30c9\u3082\u4f7f\u3048 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1314,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[298],"tags":[301,295,296],"class_list":["post-1327","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","tag-eslint","tag-react-js","tag-typescript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1327"}],"version-history":[{"count":2,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1327\/revisions"}],"predecessor-version":[{"id":1330,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1327\/revisions\/1330"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/1314"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}