From 88121424fa64173634d5104002d073d0afd1a42f Mon Sep 17 00:00:00 2001 From: Yoichiro Tanaka Date: Wed, 5 Jun 2024 14:18:50 +0900 Subject: [PATCH] Migrate the ESLint configuration file as the Flat Config format. --- .eslintrc.json | 41 ----------------------------- eslint.config.mjs | 67 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 6 ++++- yarn.lock | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 42 deletions(-) delete mode 100644 .eslintrc.json create mode 100644 eslint.config.mjs diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index c7479f91..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "env": { - "es6": true, - "node": true, - "browser": true - }, - "parser": "@typescript-eslint/parser", - "plugins": ["react", "prettier"], - "parserOptions": { - "version": 2018, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:prettier/recommended", - "prettier/react" - ], - "rules": { - "prettier/prettier": [ - "warn", - {}, - { - "usePrettierrc": true - } - ], - "no-unused-vars": "warn", - "react/prop-types": "warn" - }, - "globals": { - "HIDDevice": "readonly", - "describe": "readonly", - "test": "readonly", - "expect": "readonly", - "fail": "readonly", - "assert": "readonly" - } -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..2d6e4bcd --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,67 @@ +// This file was generated automatically by `npx @eslint/migrate-config .eslintrc.json`. +// https://www.npmjs.com/package/@eslint/migrate-config + +import { fixupConfigRules, fixupPluginRules } from "@eslint/compat"; +import react from "eslint-plugin-react"; +import prettier from "eslint-plugin-prettier"; +import globals from "globals"; +import tsParser from "@typescript-eslint/parser"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import js from "@eslint/js"; +import { FlatCompat } from "@eslint/eslintrc"; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all +}); + +export default [...fixupConfigRules(compat.extends( + "eslint:recommended", + "plugin:react/recommended", + "plugin:prettier/recommended", + "prettier/react", +)), { + files: ["**/*.ts", "**/*.tsx"], + plugins: { + react: fixupPluginRules(react), + prettier: fixupPluginRules(prettier), + }, + + languageOptions: { + globals: { + ...globals.node, + ...globals.browser, + HIDDevice: "readonly", + describe: "readonly", + test: "readonly", + expect: "readonly", + fail: "readonly", + assert: "readonly", + }, + + parser: tsParser, + ecmaVersion: 5, + sourceType: "module", + + parserOptions: { + version: 2018, + + ecmaFeatures: { + jsx: true, + }, + }, + }, + + rules: { + "prettier/prettier": ["warn", {}, { + usePrettierrc: true, + }], + + "no-unused-vars": "warn", + "react/prop-types": "warn", + }, +}]; \ No newline at end of file diff --git a/package.json b/package.json index 96ec73a7..4a787ced 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "scripts": { "start": "vite", "type-check": "tsc --noEmit", - "lint": "eslint src --ext .ts,.tsx", + "lint": "eslint src", "build": "yarn type-check && yarn lint && vite build", "test": "vitest", "format": "prettier --write './src/**/*.{ts,tsx}'", @@ -67,6 +67,9 @@ ] }, "devDependencies": { + "@eslint/compat": "^1.0.3", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.4.0", "@storybook/addon-actions": "^6.1.14", "@storybook/addon-essentials": "^6.1.15", "@storybook/addon-links": "^6.1.14", @@ -98,6 +101,7 @@ "eslint-config-prettier": "^7.0.0", "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-react": "^7.21.5", + "globals": "^15.3.0", "happy-dom": "^14.12.0", "husky": "^4.3.6", "json-schema-to-typescript": "^10.1.2", diff --git a/yarn.lock b/yarn.lock index a6eea5d0..0b954a8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2083,6 +2083,13 @@ __metadata: languageName: node linkType: hard +"@eslint/compat@npm:^1.0.3": + version: 1.0.3 + resolution: "@eslint/compat@npm:1.0.3" + checksum: 10c0/7d8392949c07e518dc487fb745379b08fbc22680039d52f1f370472154fb3e98197e21c4b692479b965739d7ec0c84523b376b43e03360ffbfde65b628788acf + languageName: node + linkType: hard + "@eslint/eslintrc@npm:^2.1.4": version: 2.1.4 resolution: "@eslint/eslintrc@npm:2.1.4" @@ -2100,6 +2107,23 @@ __metadata: languageName: node linkType: hard +"@eslint/eslintrc@npm:^3.1.0": + version: 3.1.0 + resolution: "@eslint/eslintrc@npm:3.1.0" + dependencies: + ajv: "npm:^6.12.4" + debug: "npm:^4.3.2" + espree: "npm:^10.0.1" + globals: "npm:^14.0.0" + ignore: "npm:^5.2.0" + import-fresh: "npm:^3.2.1" + js-yaml: "npm:^4.1.0" + minimatch: "npm:^3.1.2" + strip-json-comments: "npm:^3.1.1" + checksum: 10c0/5b7332ed781edcfc98caa8dedbbb843abfb9bda2e86538529c843473f580e40c69eb894410eddc6702f487e9ee8f8cfa8df83213d43a8fdb549f23ce06699167 + languageName: node + linkType: hard + "@eslint/js@npm:8.57.0": version: 8.57.0 resolution: "@eslint/js@npm:8.57.0" @@ -2107,6 +2131,13 @@ __metadata: languageName: node linkType: hard +"@eslint/js@npm:^9.4.0": + version: 9.4.0 + resolution: "@eslint/js@npm:9.4.0" + checksum: 10c0/7ffc508d3e9cd496cab7f08c5ba8f97851c8adaea3ebff8804b1c3b4662aa7aac7e9c3b597f7e47fdc29319a107bcf892865070a6b113c2e4d19f8fa1f99f569 + languageName: node + linkType: hard + "@firebase/analytics-types@npm:0.6.0": version: 0.6.0 resolution: "@firebase/analytics-types@npm:0.6.0" @@ -5840,6 +5871,9 @@ __metadata: dependencies: "@emotion/react": "npm:^11.11.4" "@emotion/styled": "npm:^11.11.5" + "@eslint/compat": "npm:^1.0.3" + "@eslint/eslintrc": "npm:^3.1.0" + "@eslint/js": "npm:^9.4.0" "@mui/icons-material": "npm:^5.15.19" "@mui/material": "npm:^5.15.19" "@mui/styles": "npm:^5.15.19" @@ -5880,6 +5914,7 @@ __metadata: eslint-plugin-prettier: "npm:^5.1.3" eslint-plugin-react: "npm:^7.21.5" firebase: "npm:^8.2.1" + globals: "npm:^15.3.0" happy-dom: "npm:^14.12.0" husky: "npm:^4.3.6" immer: "npm:^8.0.0" @@ -9308,6 +9343,13 @@ __metadata: languageName: node linkType: hard +"eslint-visitor-keys@npm:^4.0.0": + version: 4.0.0 + resolution: "eslint-visitor-keys@npm:4.0.0" + checksum: 10c0/76619f42cf162705a1515a6868e6fc7567e185c7063a05621a8ac4c3b850d022661262c21d9f1fc1d144ecf0d5d64d70a3f43c15c3fc969a61ace0fb25698cf5 + languageName: node + linkType: hard + "eslint@npm:8.57.0": version: 8.57.0 resolution: "eslint@npm:8.57.0" @@ -9368,6 +9410,17 @@ __metadata: languageName: node linkType: hard +"espree@npm:^10.0.1": + version: 10.0.1 + resolution: "espree@npm:10.0.1" + dependencies: + acorn: "npm:^8.11.3" + acorn-jsx: "npm:^5.3.2" + eslint-visitor-keys: "npm:^4.0.0" + checksum: 10c0/7c0f84afa0f9db7bb899619e6364ed832ef13fe8943691757ddde9a1805ae68b826ed66803323015f707a629a5507d0d290edda2276c25131fe0ad883b8b5636 + languageName: node + linkType: hard + "espree@npm:^9.6.0, espree@npm:^9.6.1": version: 9.6.1 resolution: "espree@npm:9.6.1" @@ -10500,6 +10553,20 @@ __metadata: languageName: node linkType: hard +"globals@npm:^14.0.0": + version: 14.0.0 + resolution: "globals@npm:14.0.0" + checksum: 10c0/b96ff42620c9231ad468d4c58ff42afee7777ee1c963013ff8aabe095a451d0ceeb8dcd8ef4cbd64d2538cef45f787a78ba3a9574f4a634438963e334471302d + languageName: node + linkType: hard + +"globals@npm:^15.3.0": + version: 15.3.0 + resolution: "globals@npm:15.3.0" + checksum: 10c0/edbef1c528185d02636ed6d72a1688168b922d6176031904386214f8b59d893f1d0a28da519b95665f557d366b17ea1affb9f433ea451e7372e2808fb31079d7 + languageName: node + linkType: hard + "globalthis@npm:^1.0.0, globalthis@npm:^1.0.3": version: 1.0.4 resolution: "globalthis@npm:1.0.4"