From 14567b566a09f99d28987626d63cf524ca25ca83 Mon Sep 17 00:00:00 2001 From: solufa Date: Fri, 12 Jul 2024 23:52:34 +0900 Subject: [PATCH] chore: support eslint flat config --- .eslintrc.js | 75 ------ .gitignore | 13 + client/.gitignore | 12 - client/package.json | 9 +- eslint.config.mjs | 78 ++++++ package-lock.json | 227 ++++++++++++++++-- package.json | 14 +- server/.gitignore | 7 - .../.well-known/jwks.json/index.ts | 2 +- server/package.json | 6 +- 10 files changed, 311 insertions(+), 132 deletions(-) delete mode 100644 .eslintrc.js delete mode 100644 client/.gitignore create mode 100644 eslint.config.mjs delete mode 100644 server/.gitignore diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index e9e3782..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,75 +0,0 @@ -module.exports = { - root: true, - extends: [ - 'eslint:recommended', - 'plugin:react/recommended', - 'plugin:react-hooks/recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'prettier', - ], - plugins: ['@typescript-eslint', 'react'], - parser: '@typescript-eslint/parser', - env: { - browser: true, - node: true, - es6: true, - }, - settings: { - react: { version: 'detect' }, - }, - parserOptions: { - sourceType: 'module', - ecmaFeatures: { jsx: true }, - }, - rules: { - 'no-restricted-syntax': [ - 'error', - { - selector: - "TSAsExpression[typeAnnotation.type='TSTypeReference'] > TSAsExpression[typeAnnotation.type='TSUnknownKeyword']", - message: 'No type assertion by unknown', - }, - ], - 'react/react-in-jsx-scope': 'off', - 'react/prop-types': 'off', - 'react/self-closing-comp': 'error', - 'react-hooks/rules-of-hooks': 'error', - 'react-hooks/exhaustive-deps': 'error', - eqeqeq: 'error', - 'no-param-reassign': 'error', - 'object-shorthand': ['error', 'always'], - 'prefer-template': 'error', - '@typescript-eslint/consistent-type-imports': 'error', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/no-non-null-assertion': 'error', - '@typescript-eslint/no-explicit-any': 'error', - complexity: ['error', 5], - 'max-depth': ['error', 2], - 'max-nested-callbacks': ['error', 3], - 'max-lines': ['error', 200], - '@typescript-eslint/no-unused-vars': [ - 'warn', - { - argsIgnorePattern: '^_', - varsIgnorePattern: '^_', - caughtErrorsIgnorePattern: '^_', - destructuredArrayIgnorePattern: '^_', - }, - ], - }, - overrides: [ - { - files: ['*.js'], - rules: { '@typescript-eslint/no-var-requires': ['off'] }, - }, - { - files: ['server/**/*.ts'], - rules: { '@typescript-eslint/explicit-function-return-type': ['error'] }, - }, - { - files: ['server/api/**/controller.ts', 'server/api/**/hooks.ts'], - rules: { '@typescript-eslint/explicit-function-return-type': ['off'] }, - }, - ], -}; diff --git a/.gitignore b/.gitignore index 1cd324b..2608a0e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,19 @@ tsconfig.tsbuildinfo data/* !data/.gitkeep .env +**/$*.ts # debug npm-debug.log* + +# client +client/.next/ +client/out/ +client/api/* +**/*.css.d.ts +**/*.css.d.ts.map + +# server +server/index.js +server/index.js.map +server/coverage/ diff --git a/client/.gitignore b/client/.gitignore deleted file mode 100644 index ae6290c..0000000 --- a/client/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# dependencies -node_modules/ - -# next.js -.next/ -out/ - -# misc -api/* -*.css.d.ts -*.css.d.ts.map -$*.ts diff --git a/client/package.json b/client/package.json index 9d21e92..df44680 100644 --- a/client/package.json +++ b/client/package.json @@ -5,16 +5,11 @@ "dev:client": "next dev -p 5051", "dev:hcm": "hcm '**/*.module.css' -w", "dev:aspida": "aspida --watch", - "dev:path": "pathpida --ignorePath .gitignore -s -w", + "dev:path": "pathpida --ignorePath ../.gitignore -s -w", "build": "npm run generate && next build", - "lint": "run-p lint:js lint:prettier lint:style", - "lint:js": "eslint --ext .ts,.tsx,.js --ignore-path .gitignore .", - "lint:prettier": "prettier --check \"./**/*.{ts,tsx,js}\" --ignore-path .gitignore", - "lint:style": "stylelint \"**/*.css\" --ignore-path .gitignore", - "lint:fix": "npm run lint:js -- --fix && prettier --write \"./**/*.{ts,tsx,js}\" --ignore-path .gitignore && npm run lint:style -- --fix", "generate": "run-p generate:*", "generate:aspida": "aspida", - "generate:path": "pathpida --ignorePath .gitignore -s", + "generate:path": "pathpida --ignorePath ../.gitignore -s", "hcm": "hcm '**/*.module.css'", "test": "vitest run", "test:watch": "vitest", diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..b4122cb --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,78 @@ +import js from '@eslint/js'; +import gitignore from 'eslint-config-flat-gitignore'; +import prettierConfig from 'eslint-config-prettier'; +import importPlugin from 'eslint-plugin-import'; +import reactPlugin from 'eslint-plugin-react'; +import globals from 'globals'; +import tseslint from 'typescript-eslint'; + +export default tseslint.config( + { files: ['**/*.(ts,js,tsx)'] }, + gitignore(), + js.configs.recommended, + ...tseslint.configs.recommended, + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + ...globals.es2020, + }, + }, + plugins: { + react: reactPlugin, + import: importPlugin, + }, + settings: { + react: { + version: 'detect', + }, + }, + rules: { + eqeqeq: 'error', + 'no-param-reassign': 'error', + 'object-shorthand': ['error', 'always'], + 'prefer-template': 'error', + '@typescript-eslint/consistent-type-imports': 'error', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-non-null-assertion': 'error', + '@typescript-eslint/no-explicit-any': 'error', + complexity: ['error', 5], + 'max-depth': ['error', 2], + 'max-nested-callbacks': ['error', 3], + 'max-lines': ['error', 200], + '@typescript-eslint/no-unused-vars': [ + 'warn', + { + argsIgnorePattern: '^_', + varsIgnorePattern: '^_', + caughtErrorsIgnorePattern: '^_', + destructuredArrayIgnorePattern: '^_', + }, + ], + }, + }, + { + files: ['*.tsx'], + rules: { + 'react/react-in-jsx-scope': 'off', + 'react/prop-types': 'off', + 'react/self-closing-comp': 'error', + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'error', + }, + }, + { + files: ['server/**/*.ts'], + rules: { '@typescript-eslint/explicit-function-return-type': ['error'] }, + }, + { + files: ['server/api/**/controller.ts', 'server/api/**/hooks.ts'], + rules: { '@typescript-eslint/explicit-function-return-type': ['off'] }, + }, + { + files: ['**/*.js'], + rules: { '@typescript-eslint/no-var-requires': ['off'] }, + }, + prettierConfig, +); diff --git a/package-lock.json b/package-lock.json index c3fa6d4..2d24961 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,14 @@ "version": "0.0.0", "license": "MIT", "devDependencies": { - "@typescript-eslint/eslint-plugin": "^7.16.0", - "@typescript-eslint/parser": "^7.16.0", "@vitest/coverage-v8": "^2.0.2", "eslint": "^8.57.0", + "eslint-config-flat-gitignore": "^0.1.7", "eslint-config-next": "^14.2.5", "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-react": "^7.34.3", + "globals": "^15.8.0", "notios": "^0.5.3", "prettier": "^3.3.2", "prettier-plugin-organize-imports": "^4.0.0", @@ -23,6 +25,7 @@ "stylelint-config-recess-order": "^5.0.1", "stylelint-config-standard": "^36.0.1", "typescript": "^5.5.3", + "typescript-eslint": "^7.16.0", "vite-tsconfig-paths": "^4.3.2", "vitest": "^2.0.2" }, @@ -317,6 +320,33 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@eslint/eslintrc/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/js": { "version": "8.57.0", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", @@ -2522,6 +2552,102 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-flat-gitignore": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/eslint-config-flat-gitignore/-/eslint-config-flat-gitignore-0.1.7.tgz", + "integrity": "sha512-K4UcPriNg6IvNozipPVnLRxuhxys9vRkxYoLLdMPgPDngtWEP/xBT946oUYQHUWLoz4jvX5k+AF/MWh3VN5Lrg==", + "dev": true, + "dependencies": { + "find-up": "^7.0.0", + "parse-gitignore": "^2.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/eslint-config-flat-gitignore/node_modules/find-up": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-7.0.0.tgz", + "integrity": "sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==", + "dev": true, + "dependencies": { + "locate-path": "^7.2.0", + "path-exists": "^5.0.0", + "unicorn-magic": "^0.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-config-flat-gitignore/node_modules/locate-path": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-7.2.0.tgz", + "integrity": "sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==", + "dev": true, + "dependencies": { + "p-locate": "^6.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-config-flat-gitignore/node_modules/p-limit": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-4.0.0.tgz", + "integrity": "sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^1.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-config-flat-gitignore/node_modules/p-locate": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-6.0.0.tgz", + "integrity": "sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==", + "dev": true, + "dependencies": { + "p-limit": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-config-flat-gitignore/node_modules/path-exists": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", + "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, + "node_modules/eslint-config-flat-gitignore/node_modules/yocto-queue": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", + "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", + "dev": true, + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eslint-config-next": { "version": "14.2.5", "resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-14.2.5.tgz", @@ -3047,6 +3173,21 @@ "node": ">=10.13.0" } }, + "node_modules/eslint/node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eslint/node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -3068,6 +3209,18 @@ "node": ">=8" } }, + "node_modules/eslint/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", @@ -3586,27 +3739,12 @@ } }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "version": "15.8.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.8.0.tgz", + "integrity": "sha512-VZAJ4cewHTExBWDHR6yptdIBlx9YSSZuwojj9Nt5mBRXQzrKakDsVKQ1J63sklLvzAJm0X5+RpO4i3Y2hcOnFw==", "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/globals/node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "engines": { - "node": ">=10" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -5466,6 +5604,15 @@ "node": ">=6" } }, + "node_modules/parse-gitignore": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/parse-gitignore/-/parse-gitignore-2.0.0.tgz", + "integrity": "sha512-RmVuCHWsfu0QPNW+mraxh/xjQVw/lhUCUru8Zni3Ctq3AoMhpDTq0OVdKS6iesd6Kqb7viCV3isAL43dciOSog==", + "dev": true, + "engines": { + "node": ">=14" + } + }, "node_modules/parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", @@ -7390,6 +7537,32 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "7.16.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.16.0.tgz", + "integrity": "sha512-kaVRivQjOzuoCXU6+hLnjo3/baxyzWVO5GrnExkFzETRYJKVHYkrJglOu2OCm8Hi9RPDWX1PTNNTpU5KRV0+RA==", + "dev": true, + "dependencies": { + "@typescript-eslint/eslint-plugin": "7.16.0", + "@typescript-eslint/parser": "7.16.0", + "@typescript-eslint/utils": "7.16.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -7413,6 +7586,18 @@ "optional": true, "peer": true }, + "node_modules/unicorn-magic": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", + "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/untildify": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", diff --git a/package.json b/package.json index 8a5b2d2..c005514 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,11 @@ "generate:server": "npm run generate --prefix server", "batch:writeVersion": "node batches/writeVersion.js", "lint": "run-p lint:*", - "lint:client": "npm run lint:fix --prefix client", - "lint:server": "npm run lint:fix --prefix server", + "lint:js": "eslint .", + "lint:style": "stylelint \"**/*.css\" --ignore-path .gitignore", + "lint:prettier": "prettier --check \"./**/*.{ts,tsx,js}\" --ignore-path .gitignore", + "lint:server": "npm run lint --prefix server", + "fix:lint": "npm run lint:js -- --fix && npm run lint:style -- --fix && npm run lint:prettier -- --write", "test": "run-p test:*", "test:client": "npm run test --prefix client", "test:server": "npm run test --prefix server", @@ -27,12 +30,14 @@ "typecheck:server": "npm run typecheck --prefix server" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^7.16.0", - "@typescript-eslint/parser": "^7.16.0", "@vitest/coverage-v8": "^2.0.2", "eslint": "^8.57.0", + "eslint-config-flat-gitignore": "^0.1.7", "eslint-config-next": "^14.2.5", "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-react": "^7.34.3", + "globals": "^15.8.0", "notios": "^0.5.3", "prettier": "^3.3.2", "prettier-plugin-organize-imports": "^4.0.0", @@ -41,6 +46,7 @@ "stylelint-config-recess-order": "^5.0.1", "stylelint-config-standard": "^36.0.1", "typescript": "^5.5.3", + "typescript-eslint": "^7.16.0", "vite-tsconfig-paths": "^4.3.2", "vitest": "^2.0.2" }, diff --git a/server/.gitignore b/server/.gitignore deleted file mode 100644 index e6af376..0000000 --- a/server/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# dependencies -node_modules/ - -index.js -index.js.map -coverage/ -$*.ts diff --git a/server/api/_userPoolId/.well-known/jwks.json/index.ts b/server/api/_userPoolId/.well-known/jwks.json/index.ts index 9746e02..fca1025 100644 --- a/server/api/_userPoolId/.well-known/jwks.json/index.ts +++ b/server/api/_userPoolId/.well-known/jwks.json/index.ts @@ -1,4 +1,4 @@ -import { Jwks } from 'api/@types/auth'; +import type { Jwks } from 'api/@types/auth'; import type { DefineMethods } from 'aspida'; export type Methods = DefineMethods<{ diff --git a/server/package.json b/server/package.json index b13cd15..c3073a0 100644 --- a/server/package.json +++ b/server/package.json @@ -9,11 +9,7 @@ "dev:prisma": "prisma generate --watch", "prebuild": "run-p generate migrate:deploy", "build": "node ./scripts/build.prod.js", - "lint": "run-p lint:js lint:prettier lint:prisma", - "lint:js": "eslint --ext .ts,.js --ignore-path .gitignore .", - "lint:prettier": "prettier --check \"./**/*.{ts,js}\" --ignore-path .gitignore", - "lint:prisma": "prisma format", - "lint:fix": "npm run lint:prisma && npm run lint:js -- --fix && prettier --write \"./**/*.{ts,js}\" --ignore-path .gitignore", + "lint": "prisma format", "generate": "run-s generate:prisma generate:frourio", "generate:prisma": "prisma generate", "generate:frourio": "frourio",