From 589c48bedac0cf11267734a5b003db1fdfa959c2 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 1 Nov 2021 22:07:38 -0700 Subject: [PATCH] [WIP] Fix eslint for Next.js Tweaked some of the default Next.js rules, fixed lint-staged for `next lint`, made a few small easy lint fixes. Feels good! Note that using the `dirs` option in `next.config.js` was causing `lint-staged` to lint _everything_. That's why I edited `yarn lint` to specify the dirs instead: that way, that command will lint all those dirs, but they won't get included in invocations with `--file`. There are still a few lint errors left after this commit, because our tags aren't working (@next/next/no-img-element). I'll fix those when we figure out what's wrong with images! --- .eslintrc.json | 12 ++- lint-staged.config.js | 6 ++ next.config.js | 3 - package.json | 12 +-- src/app/ModelingPage.js | 2 +- src/app/UserItemListPage.js | 2 +- .../WardrobePage/support/PosePickerSupport.js | 2 +- src/index.js | 1 - yarn.lock | 100 ++++++++++++++++-- 9 files changed, 113 insertions(+), 27 deletions(-) create mode 100644 lint-staged.config.js diff --git a/.eslintrc.json b/.eslintrc.json index 3da87ea..24b3ebe 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,7 @@ { - "extends": "next/core-web-vitals", + "extends": ["next/core-web-vitals"], + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], "rules": { "no-console": [ "warn", @@ -9,12 +11,16 @@ ], "import/first": "off", "import/no-webpack-loader-syntax": "off", - "no-unused-vars": [ + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ "warn", { "varsIgnorePattern": "^unused", "argsIgnorePattern": "^_+$|^e$" } - ] + ], + "react/no-unescaped-entities": ["error", { "forbid": [">", "}"] }], + // We have some React.forwardRefs that trigger this, not sure how to improve + "react/display-name": "off" } } diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000..580d288 --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,6 @@ +module.exports = { + "*.{js,ts,tsx}": (filenames) => + `next lint --max-warnings=0 --fix --file ${filenames + .map((file) => file.split(process.cwd())[1]) + .join(" --file ")}`, +}; diff --git a/next.config.js b/next.config.js index d7cf568..1c289bd 100644 --- a/next.config.js +++ b/next.config.js @@ -2,7 +2,4 @@ module.exports = { env: { PUBLIC_URL: "", }, - eslint: { - dirs: ["src"], - }, }; diff --git a/package.json b/package.json index 11784fa..cc86398 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "build": "yarn build-cached-data && next build", "vercel-build": "yum install libuuid-devel libmount-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/", "test": "jest test --env=jsdom", - "lint": "next lint", + "lint": "next lint --dir src --dir pages", "cypress": "cypress open", "mysql": "mysql --host=impress.openneo.net --user=$(dotenv -p IMPRESS_MYSQL_USER) --password=$(dotenv -p IMPRESS_MYSQL_PASSWORD) --database=openneo_impress", "mysql-dev": "mysql --host=localhost --user=impress_2020_dev --password=impress_2020_dev --database=impress_2020_dev", @@ -78,11 +78,6 @@ "delete-user": "ts-node --compiler=typescript-cached-transpile --transpile-only -r dotenv/config scripts/delete-user.js", "export-users-to-auth0": "ts-node --compiler=typescript-cached-transpile --transpile-only -r dotenv/config scripts/export-users-to-auth0.js" }, - "lint-staged": { - "*.{js,ts,tsx}": [ - "next lint --max-warnings=0 --fix" - ] - }, "browserslist": { "production": [ ">0.2%", @@ -97,6 +92,8 @@ }, "devDependencies": { "5to6-codemod": "^1.8.0", + "@typescript-eslint/eslint-plugin": "^5.3.0", + "@typescript-eslint/parser": "^5.3.0", "apollo-server-testing": "^2.12.0", "auth0": "^2.28.0", "cypress": "^7.2.0", @@ -115,7 +112,6 @@ "prettier": "^2.0.5", "react-is": "^16.13.1", "ts-node": "^9.1.1", - "typescript-cached-transpile": "^0.0.6", - "typescript-eslint": "^0.0.1-alpha.0" + "typescript-cached-transpile": "^0.0.6" } } diff --git a/src/app/ModelingPage.js b/src/app/ModelingPage.js index bda99cd..93e0bac 100644 --- a/src/app/ModelingPage.js +++ b/src/app/ModelingPage.js @@ -188,7 +188,7 @@ function ItemModelBadges({ item, currentUserOwnsItem }) { {item.isNc && } {currentUserOwnsItem && } {item.speciesThatNeedModels.map((species) => ( - {species.name} + {species.name} ))} ); diff --git a/src/app/UserItemListPage.js b/src/app/UserItemListPage.js index 7ed2ba5..50c7b64 100644 --- a/src/app/UserItemListPage.js +++ b/src/app/UserItemListPage.js @@ -609,7 +609,7 @@ export function NeopetsStarIcon(props) { > diff --git a/src/app/WardrobePage/support/PosePickerSupport.js b/src/app/WardrobePage/support/PosePickerSupport.js index 749b587..7bd377b 100644 --- a/src/app/WardrobePage/support/PosePickerSupport.js +++ b/src/app/WardrobePage/support/PosePickerSupport.js @@ -212,7 +212,7 @@ function PosePickerSupport({ .map((zone) => `${zone.label} (${zone.id})`) .sort((a, b) => a[0].localeCompare(b[0])) .map((zoneText) => ( - {zoneText} + {zoneText} ))} ) : ( diff --git a/src/index.js b/src/index.js index 3c35380..64301aa 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,4 @@ import React from "react"; -import ReactDOM from "react-dom"; import App from "./app/App"; export default function NextIndexWrapper() { diff --git a/yarn.lock b/yarn.lock index 6d37149..d2834f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3074,6 +3074,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0" integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw== +"@types/json-schema@^7.0.9": + version "7.0.9" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" + integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" @@ -3331,6 +3336,32 @@ resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.3.tgz#781d360c282436494b32fe7d9f7f8e64b3118aa3" integrity sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw== +"@typescript-eslint/eslint-plugin@^5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.3.0.tgz#a55ae72d28ffeb6badd817fe4566c9cced1f5e29" + integrity sha512-ARUEJHJrq85aaiCqez7SANeahDsJTD3AEua34EoQN9pHS6S5Bq9emcIaGGySt/4X2zSi+vF5hAH52sEen7IO7g== + dependencies: + "@typescript-eslint/experimental-utils" "5.3.0" + "@typescript-eslint/scope-manager" "5.3.0" + debug "^4.3.2" + functional-red-black-tree "^1.0.1" + ignore "^5.1.8" + regexpp "^3.2.0" + semver "^7.3.5" + tsutils "^3.21.0" + +"@typescript-eslint/experimental-utils@5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.3.0.tgz#ee56b4957547ed2b0fc7451205e41502e664f546" + integrity sha512-NFVxYTjKj69qB0FM+piah1x3G/63WB8vCBMnlnEHUsiLzXSTWb9FmFn36FD9Zb4APKBLY3xRArOGSMQkuzTF1w== + dependencies: + "@types/json-schema" "^7.0.9" + "@typescript-eslint/scope-manager" "5.3.0" + "@typescript-eslint/types" "5.3.0" + "@typescript-eslint/typescript-estree" "5.3.0" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + "@typescript-eslint/parser@^4.20.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.33.0.tgz#dfe797570d9694e560528d18eecad86c8c744899" @@ -3341,6 +3372,16 @@ "@typescript-eslint/typescript-estree" "4.33.0" debug "^4.3.1" +"@typescript-eslint/parser@^5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.3.0.tgz#7879f15e26d370ed3f653fb7dd06479531ed3ab9" + integrity sha512-rKu/yAReip7ovx8UwOAszJVO5MgBquo8WjIQcp1gx4pYQCwYzag+I5nVNHO4MqyMkAo0gWt2gWUi+36gWAVKcw== + dependencies: + "@typescript-eslint/scope-manager" "5.3.0" + "@typescript-eslint/types" "5.3.0" + "@typescript-eslint/typescript-estree" "5.3.0" + debug "^4.3.2" + "@typescript-eslint/scope-manager@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.33.0.tgz#d38e49280d983e8772e29121cf8c6e9221f280a3" @@ -3349,11 +3390,24 @@ "@typescript-eslint/types" "4.33.0" "@typescript-eslint/visitor-keys" "4.33.0" +"@typescript-eslint/scope-manager@5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.3.0.tgz#97d0ccc7c9158e89e202d5e24ce6ba49052d432e" + integrity sha512-22Uic9oRlTsPppy5Tcwfj+QET5RWEnZ5414Prby465XxQrQFZ6nnm5KnXgnsAJefG4hEgMnaxTB3kNEyjdjj6A== + dependencies: + "@typescript-eslint/types" "5.3.0" + "@typescript-eslint/visitor-keys" "5.3.0" + "@typescript-eslint/types@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.33.0.tgz#a1e59036a3b53ae8430ceebf2a919dc7f9af6d72" integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ== +"@typescript-eslint/types@5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.3.0.tgz#af29fd53867c2df0028c57c36a655bd7e9e05416" + integrity sha512-fce5pG41/w8O6ahQEhXmMV+xuh4+GayzqEogN24EK+vECA3I6pUwKuLi5QbXO721EMitpQne5VKXofPonYlAQg== + "@typescript-eslint/typescript-estree@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz#0dfb51c2908f68c5c08d82aefeaf166a17c24609" @@ -3367,6 +3421,19 @@ semver "^7.3.5" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.3.0.tgz#4f68ddd46dc2983182402d2ab21fb44ad94988cf" + integrity sha512-FJ0nqcaUOpn/6Z4Jwbtf+o0valjBLkqc3MWkMvrhA2TvzFXtcclIM8F4MBEmYa2kgcI8EZeSAzwoSrIC8JYkug== + dependencies: + "@typescript-eslint/types" "5.3.0" + "@typescript-eslint/visitor-keys" "5.3.0" + debug "^4.3.2" + globby "^11.0.4" + is-glob "^4.0.3" + semver "^7.3.5" + tsutils "^3.21.0" + "@typescript-eslint/visitor-keys@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.33.0.tgz#2a22f77a41604289b7a186586e9ec48ca92ef1dd" @@ -3375,6 +3442,14 @@ "@typescript-eslint/types" "4.33.0" eslint-visitor-keys "^2.0.0" +"@typescript-eslint/visitor-keys@5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.3.0.tgz#a6258790f3b7b2547f70ed8d4a1e0c3499994523" + integrity sha512-oVIAfIQuq0x2TFDNLVavUn548WL+7hdhxYn+9j3YdJJXB7mH9dAmZNJsPDa7Jc+B9WGqoiex7GUDbyMxV0a/aw== + dependencies: + "@typescript-eslint/types" "5.3.0" + eslint-visitor-keys "^3.0.0" + "@wry/context@^0.6.0": version "0.6.1" resolved "https://registry.yarnpkg.com/@wry/context/-/context-0.6.1.tgz#c3c29c0ad622adb00f6a53303c4f965ee06ebeb2" @@ -5313,7 +5388,7 @@ debug@4, debug@^4.1.0, debug@^4.1.1, debug@~4.1.0: dependencies: ms "^2.1.1" -debug@4.3.2, debug@^4.0.1, debug@^4.3.1: +debug@4.3.2, debug@^4.0.1, debug@^4.3.1, debug@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw== @@ -5987,6 +6062,13 @@ eslint-utils@^2.1.0: dependencies: eslint-visitor-keys "^1.1.0" +eslint-utils@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672" + integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA== + dependencies: + eslint-visitor-keys "^2.0.0" + eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" @@ -5997,6 +6079,11 @@ eslint-visitor-keys@^2.0.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== +eslint-visitor-keys@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.0.0.tgz#e32e99c6cdc2eb063f204eda5db67bfe58bb4186" + integrity sha512-mJOZa35trBTb3IyRmo8xmKBZlxf+N7OnUl4+ZhJHs/r+0770Wh/LEACE2pqMGMe27G/4y8P2bYGk4J70IC5k1Q== + eslint@<8.0.0: version "7.32.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d" @@ -6844,7 +6931,7 @@ globals@^13.6.0, globals@^13.9.0: dependencies: type-fest "^0.20.2" -globby@^11.0.3: +globby@^11.0.3, globby@^11.0.4: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg== @@ -7246,7 +7333,7 @@ ignore@^4.0.6: resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== -ignore@^5.1.4: +ignore@^5.1.4, ignore@^5.1.8: version "5.1.8" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57" integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw== @@ -10179,7 +10266,7 @@ regexp.prototype.flags@^1.3.1: call-bind "^1.0.2" define-properties "^1.1.3" -regexpp@^3.1.0: +regexpp@^3.1.0, regexpp@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg== @@ -11555,11 +11642,6 @@ typescript-cached-transpile@^0.0.6: fs-extra "^8.1.0" tslib "^1.10.0" -typescript-eslint@^0.0.1-alpha.0: - version "0.0.1-alpha.0" - resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-0.0.1-alpha.0.tgz#285d68a4e96588295cd436278801bcb6a6b916c1" - integrity sha512-1hNKM37dAWML/2ltRXupOq2uqcdRQyDFphl+341NTPXFLLLiDhErXx8VtaSLh3xP7SyHZdcCgpt9boYYVb3fQg== - typescript@^4.4.4: version "4.4.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"