From 6eb6c48c0e3496c50f76734d44ba8de177a2f250 Mon Sep 17 00:00:00 2001 From: mainframev Date: Thu, 22 Aug 2024 17:19:41 +0200 Subject: [PATCH 01/16] chore: upgrade typescript-eslint to v8 --- package.json | 12 +- packages/eslint-plugin/package.json | 12 +- .../rules/consistent-callback-type.spec.ts | 2 + .../rules/no-missing-jsx-pragma.spec.ts | 5 +- .../rules/no-restricted-globals.spec.ts | 9 +- .../rules/no-restricted-globals.ts | 11 +- .../generators/eslint-rule/generator.spec.ts | 1 + yarn.lock | 177 ++++++++---------- 8 files changed, 115 insertions(+), 114 deletions(-) diff --git a/package.json b/package.json index 529e8bb606a79..18cdbba8782a4 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "@phenomnomnominal/tsquery": "6.1.3", "@playwright/test": "1.44.0", "@react-native/babel-preset": "0.73.21", - "@rnx-kit/eslint-plugin": "0.7.2", + "@rnx-kit/eslint-plugin": "0.8.2", "@rollup/plugin-node-resolve": "13.3.0", "@storybook/addon-a11y": "7.6.20", "@storybook/addon-actions": "7.6.20", @@ -173,10 +173,10 @@ "@types/webpack-hot-middleware": "2.25.9", "@types/yargs": "13.0.11", "@types/yargs-unparser": "2.0.1", - "@typescript-eslint/eslint-plugin": "7.18.0", - "@typescript-eslint/parser": "7.18.0", - "@typescript-eslint/rule-tester": "7.18.0", - "@typescript-eslint/utils": "7.18.0", + "@typescript-eslint/eslint-plugin": "8.8.1", + "@typescript-eslint/parser": "8.8.1", + "@typescript-eslint/rule-tester": "8.8.1", + "@typescript-eslint/utils": "8.8.1", "@wojtekmaj/enzyme-adapter-react-17": "0.6.7", "ajv": "8.4.0", "autoprefixer": "10.2.1", @@ -233,7 +233,7 @@ "eslint-plugin-deprecation": "3.0.0", "eslint-plugin-es": "4.1.0", "eslint-plugin-import": "2.29.1", - "eslint-plugin-jest": "28.6.0", + "eslint-plugin-jest": "28.8.0", "eslint-plugin-jsdoc": "48.7.0", "eslint-plugin-jsx-a11y": "6.9.0", "eslint-plugin-playwright": "0.15.3", diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index cccec7da25786..d7d39c67dc2c2 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -15,12 +15,12 @@ }, "dependencies": { "@griffel/eslint-plugin": "^1.6.4", - "@rnx-kit/eslint-plugin": "^0.7.2", - "@typescript-eslint/eslint-plugin": "^7.18.0", - "@typescript-eslint/utils": "^7.18.0", - "@typescript-eslint/rule-tester": "7.18.0", - "@typescript-eslint/parser": "^7.18.0", - "@typescript-eslint/type-utils": "^7.18.0", + "@rnx-kit/eslint-plugin": "^0.8.2", + "@typescript-eslint/eslint-plugin": "^8.8.1", + "@typescript-eslint/utils": "^8.8.1", + "@typescript-eslint/rule-tester": "8.8.1", + "@typescript-eslint/parser": "^8.8.1", + "@typescript-eslint/type-utils": "^8.8.1", "eslint-config-airbnb": "^18.2.1", "eslint-config-prettier": "^8.3.0", "eslint-import-resolver-typescript": "^3.6.1", diff --git a/tools/eslint-rules/rules/consistent-callback-type.spec.ts b/tools/eslint-rules/rules/consistent-callback-type.spec.ts index b3601fb2a7835..1bac268fee9d1 100644 --- a/tools/eslint-rules/rules/consistent-callback-type.spec.ts +++ b/tools/eslint-rules/rules/consistent-callback-type.spec.ts @@ -3,6 +3,8 @@ import { rule, RULE_NAME } from './consistent-callback-type'; const ruleTester = new RuleTester(); +global.structuredClone = val => JSON.parse(JSON.stringify(val)); + ruleTester.run(RULE_NAME, rule, { valid: [ // Valid when prop is TSTypeAliasDeclaration and the callback uses EventHandler diff --git a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts index 610325520ea17..9a6d78790f1c7 100644 --- a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts +++ b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts @@ -2,10 +2,11 @@ import { RuleTester } from '@typescript-eslint/rule-tester'; import { rule, RULE_NAME } from './no-missing-jsx-pragma'; const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', - parserOptions: { ecmaFeatures: { jsx: true } }, + languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, }); +global.structuredClone = val => JSON.parse(JSON.stringify(val)); + ruleTester.run(RULE_NAME, rule, { valid: [ // no slot api used case diff --git a/tools/eslint-rules/rules/no-restricted-globals.spec.ts b/tools/eslint-rules/rules/no-restricted-globals.spec.ts index f6360f09e1d30..62f2892cbb9fd 100644 --- a/tools/eslint-rules/rules/no-restricted-globals.spec.ts +++ b/tools/eslint-rules/rules/no-restricted-globals.spec.ts @@ -4,6 +4,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import { rule, RULE_NAME } from './no-restricted-globals'; const ruleTester = new RuleTester(); +global.structuredClone = val => JSON.parse(JSON.stringify(val)); ruleTester.run(RULE_NAME, rule, { valid: [ @@ -18,7 +19,9 @@ ruleTester.run(RULE_NAME, rule, { { code: 'event', options: ['foo'], - globals: globals.browser, + languageOptions: { + globals: globals.browser, + }, }, { options: ['KeyboardEvent'], code: `let ev: KeyboardEvent;` }, { @@ -44,7 +47,9 @@ ruleTester.run(RULE_NAME, rule, { { code: 'event', options: ['foo', 'event'], - globals: globals.browser, + languageOptions: { + globals: globals.browser, + }, errors: [ { messageId: 'defaultMessage', diff --git a/tools/eslint-rules/rules/no-restricted-globals.ts b/tools/eslint-rules/rules/no-restricted-globals.ts index 25e265209820f..154dd6e0cab03 100644 --- a/tools/eslint-rules/rules/no-restricted-globals.ts +++ b/tools/eslint-rules/rules/no-restricted-globals.ts @@ -15,8 +15,7 @@ */ import { Reference } from '@typescript-eslint/scope-manager'; -import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils'; - +import { ESLintUtils, AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils'; // NOTE: The rule will be available in ESLint configs as "@nx/workspace-no-restricted-globals" export const RULE_NAME = 'no-restricted-globals'; @@ -24,7 +23,11 @@ type MessageIds = 'defaultMessage' | 'customMessage'; type Options = Array<{ name: string; message?: string } | string>; -export const rule = ESLintUtils.RuleCreator(() => __filename)({ +type Docs = { + recommended: TSESLint.RuleRecommendation; +}; + +export const rule = ESLintUtils.RuleCreator(() => __filename)({ name: RULE_NAME, meta: { type: 'problem', @@ -60,7 +63,7 @@ export const rule = ESLintUtils.RuleCreator(() => __filename) { type: 'problem', docs: { description: \`\`, + recommended: 'recommended', }, schema: [], messages: {}, diff --git a/yarn.lock b/yarn.lock index f249382627024..abf6381e4c79d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1867,7 +1867,7 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" -"@eslint/js@8.57.0", "@eslint/js@^8.56.0": +"@eslint/js@8.57.0": version "8.57.0" resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== @@ -3583,23 +3583,22 @@ mkdirp "^0.5.1" nullthrows "^1.1.1" -"@react-native/eslint-plugin@^0.74.0": - version "0.74.85" - resolved "https://registry.yarnpkg.com/@react-native/eslint-plugin/-/eslint-plugin-0.74.85.tgz#9e028ccf97ad6d3d661d796eb614951343be5a1f" - integrity sha512-FtyfgL8EOTddxm+DyjfsInqMtjmU0PWQIRdyET/uob8i6sCxS+HmBzhbtEVZUKwld2kNG1JGgdNLndcEejC81Q== +"@react-native/eslint-plugin@^0.75.0": + version "0.75.4" + resolved "https://registry.yarnpkg.com/@react-native/eslint-plugin/-/eslint-plugin-0.75.4.tgz#41fa462206e2fd4aea6a27fb0d7660161c6af6b3" + integrity sha512-1kEZzC8UKi3baHnH7tBVCNpF4aoAmT7g7hEa5/rtZ+Z7vcpaxeY6wjNYt3j02Z9n310yX0NKDJox30CqvzEvsg== -"@rnx-kit/eslint-plugin@0.7.2", "@rnx-kit/eslint-plugin@^0.7.2": - version "0.7.2" - resolved "https://registry.yarnpkg.com/@rnx-kit/eslint-plugin/-/eslint-plugin-0.7.2.tgz#be6164db3ca5b8b1782700c8b1d085cb8008e0bc" - integrity sha512-vOwLddSi4lJuGHOQf88iGub44wRFlwmpScx/G6mWoJ/MdWcuN142x6PPyZNIsB2bHQxdbhTnWqXE5JZgfXiSvQ== +"@rnx-kit/eslint-plugin@0.8.2", "@rnx-kit/eslint-plugin@^0.8.2": + version "0.8.2" + resolved "https://registry.yarnpkg.com/@rnx-kit/eslint-plugin/-/eslint-plugin-0.8.2.tgz#693cb08b4b483f2992c31a9cd6fac86f9f32969c" + integrity sha512-WRBS3U9vkZfhJayglotH+4YKj5mBfMMwVDIJmDeGvOm12KtwN/Q9epriKQyY5P40m/OByChw2UriLYngn/u/MQ== dependencies: "@eslint/eslintrc" "^2.1.4" - "@eslint/js" "^8.56.0" - "@react-native/eslint-plugin" "^0.74.0" + "@react-native/eslint-plugin" "^0.75.0" enhanced-resolve "^5.8.3" eslint-plugin-react "^7.33.0" eslint-plugin-react-hooks "^4.6.0" - typescript-eslint "^7.5.0" + typescript-eslint "^8.0.0" "@rollup/plugin-node-resolve@13.3.0": version "13.3.0" @@ -5961,39 +5960,39 @@ dependencies: "@types/node" "*" -"@typescript-eslint/eslint-plugin@7.18.0", "@typescript-eslint/eslint-plugin@^7.18.0": - version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.18.0.tgz#b16d3cf3ee76bf572fdf511e79c248bdec619ea3" - integrity sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw== +"@typescript-eslint/eslint-plugin@8.8.1", "@typescript-eslint/eslint-plugin@^8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.1.tgz#9364b756d4d78bcbdf6fd3e9345e6924c68ad371" + integrity sha512-xfvdgA8AP/vxHgtgU310+WBnLB4uJQ9XdyP17RebG26rLtDrQJV3ZYrcopX91GrHmMoH8bdSwMRh2a//TiJ1jQ== dependencies: "@eslint-community/regexpp" "^4.10.0" - "@typescript-eslint/scope-manager" "7.18.0" - "@typescript-eslint/type-utils" "7.18.0" - "@typescript-eslint/utils" "7.18.0" - "@typescript-eslint/visitor-keys" "7.18.0" + "@typescript-eslint/scope-manager" "8.8.1" + "@typescript-eslint/type-utils" "8.8.1" + "@typescript-eslint/utils" "8.8.1" + "@typescript-eslint/visitor-keys" "8.8.1" graphemer "^1.4.0" ignore "^5.3.1" natural-compare "^1.4.0" ts-api-utils "^1.3.0" -"@typescript-eslint/parser@7.18.0", "@typescript-eslint/parser@^7.18.0": - version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.18.0.tgz#83928d0f1b7f4afa974098c64b5ce6f9051f96a0" - integrity sha512-4Z+L8I2OqhZV8qA132M4wNL30ypZGYOQVBfMgxDH/K5UX0PNqTu1c6za9ST5r9+tavvHiTWmBnKzpCJ/GlVFtg== +"@typescript-eslint/parser@8.8.1", "@typescript-eslint/parser@^8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.8.1.tgz#5952ba2a83bd52024b872f3fdc8ed2d3636073b8" + integrity sha512-hQUVn2Lij2NAxVFEdvIGxT9gP1tq2yM83m+by3whWFsWC+1y8pxxxHUFE1UqDu2VsGi2i6RLcv4QvouM84U+ow== dependencies: - "@typescript-eslint/scope-manager" "7.18.0" - "@typescript-eslint/types" "7.18.0" - "@typescript-eslint/typescript-estree" "7.18.0" - "@typescript-eslint/visitor-keys" "7.18.0" + "@typescript-eslint/scope-manager" "8.8.1" + "@typescript-eslint/types" "8.8.1" + "@typescript-eslint/typescript-estree" "8.8.1" + "@typescript-eslint/visitor-keys" "8.8.1" debug "^4.3.4" -"@typescript-eslint/rule-tester@7.18.0": - version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/rule-tester/-/rule-tester-7.18.0.tgz#1326101d6169dece15d91c0e96dc52e350d8c714" - integrity sha512-ClrFQlwen9pJcYPIBLuarzBpONQAwjmJ0+YUjAo1TGzoZFJPyUK/A7bb4Mps0u+SMJJnFXbfMN8I9feQDf0O5A== +"@typescript-eslint/rule-tester@8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/rule-tester/-/rule-tester-8.8.1.tgz#9be928091917294f260a80178e1141f3acc13a38" + integrity sha512-79TdrU55nz5zroDIumNOpMC5I3fJkmzxAEkstz3nZ8P/xhcvwD35PUuk50l/cfvkdkYS4d4xZwf8iIamfoOzlg== dependencies: - "@typescript-eslint/typescript-estree" "7.18.0" - "@typescript-eslint/utils" "7.18.0" + "@typescript-eslint/typescript-estree" "8.8.1" + "@typescript-eslint/utils" "8.8.1" ajv "^6.12.6" json-stable-stringify-without-jsonify "^1.0.1" lodash.merge "4.6.2" @@ -6007,31 +6006,21 @@ "@typescript-eslint/types" "7.18.0" "@typescript-eslint/visitor-keys" "7.18.0" -"@typescript-eslint/scope-manager@8.7.0": - version "8.7.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.7.0.tgz#90ee7bf9bc982b9260b93347c01a8bc2b595e0b8" - integrity sha512-87rC0k3ZlDOuz82zzXRtQ7Akv3GKhHs0ti4YcbAJtaomllXoSO8hi7Ix3ccEvCd824dy9aIX+j3d2UMAfCtVpg== - dependencies: - "@typescript-eslint/types" "8.7.0" - "@typescript-eslint/visitor-keys" "8.7.0" - -"@typescript-eslint/type-utils@7.18.0", "@typescript-eslint/type-utils@^7.18.0": - version "7.18.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.18.0.tgz#2165ffaee00b1fbbdd2d40aa85232dab6998f53b" - integrity sha512-XL0FJXuCLaDuX2sYqZUUSOJ2sG5/i1AAze+axqmLnSkNEVMVYLF+cbwlB2w8D1tinFuSikHmFta+P+HOofrLeA== +"@typescript-eslint/scope-manager@8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.8.1.tgz#b4bea1c0785aaebfe3c4ab059edaea1c4977e7ff" + integrity sha512-X4JdU+66Mazev/J0gfXlcC/dV6JI37h+93W9BRYXrSn0hrE64IoWgVkO9MSJgEzoWkxONgaQpICWg8vAN74wlA== dependencies: - "@typescript-eslint/typescript-estree" "7.18.0" - "@typescript-eslint/utils" "7.18.0" - debug "^4.3.4" - ts-api-utils "^1.3.0" + "@typescript-eslint/types" "8.8.1" + "@typescript-eslint/visitor-keys" "8.8.1" -"@typescript-eslint/type-utils@^8.0.0": - version "8.7.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.7.0.tgz#d56b104183bdcffcc434a23d1ce26cde5e42df93" - integrity sha512-tl0N0Mj3hMSkEYhLkjREp54OSb/FI6qyCzfiiclvJvOqre6hsZTGSnHtmFLDU8TIM62G7ygEa1bI08lcuRwEnQ== +"@typescript-eslint/type-utils@8.8.1", "@typescript-eslint/type-utils@^8.0.0", "@typescript-eslint/type-utils@^8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.8.1.tgz#31f59ec46e93a02b409fb4d406a368a59fad306e" + integrity sha512-qSVnpcbLP8CALORf0za+vjLYj1Wp8HSoiI8zYU5tHxRVj30702Z1Yw4cLwfNKhTPWp5+P+k1pjmD5Zd1nhxiZA== dependencies: - "@typescript-eslint/typescript-estree" "8.7.0" - "@typescript-eslint/utils" "8.7.0" + "@typescript-eslint/typescript-estree" "8.8.1" + "@typescript-eslint/utils" "8.8.1" debug "^4.3.4" ts-api-utils "^1.3.0" @@ -6040,10 +6029,10 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.18.0.tgz#b90a57ccdea71797ffffa0321e744f379ec838c9" integrity sha512-iZqi+Ds1y4EDYUtlOOC+aUmxnE9xS/yCigkjA7XpTKV6nCBd3Hp/PRGGmdwnfkV2ThMyYldP1wRpm/id99spTQ== -"@typescript-eslint/types@8.7.0": - version "8.7.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.7.0.tgz#21d987201c07b69ce7ddc03451d7196e5445ad19" - integrity sha512-LLt4BLHFwSfASHSF2K29SZ+ZCsbQOM+LuarPjRUuHm+Qd09hSe3GCeaQbcCr+Mik+0QFRmep/FyZBO6fJ64U3w== +"@typescript-eslint/types@8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.8.1.tgz#ebe85e0fa4a8e32a24a56adadf060103bef13bd1" + integrity sha512-WCcTP4SDXzMd23N27u66zTKMuEevH4uzU8C9jf0RO4E04yVHgQgW+r+TeVTNnO1KIfrL8ebgVVYYMMO3+jC55Q== "@typescript-eslint/typescript-estree@7.18.0": version "7.18.0" @@ -6059,13 +6048,13 @@ semver "^7.6.0" ts-api-utils "^1.3.0" -"@typescript-eslint/typescript-estree@8.7.0": - version "8.7.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.7.0.tgz#6c7db6baa4380b937fa81466c546d052f362d0e8" - integrity sha512-MC8nmcGHsmfAKxwnluTQpNqceniT8SteVwd2voYlmiSWGOtjvGXdPl17dYu2797GVscK30Z04WRM28CrKS9WOg== +"@typescript-eslint/typescript-estree@8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.1.tgz#34649f4e28d32ee49152193bc7dedc0e78e5d1ec" + integrity sha512-A5d1R9p+X+1js4JogdNilDuuq+EHZdsH9MjTVxXOdVFfTJXunKJR/v+fNNyO4TnoOn5HqobzfRlc70NC6HTcdg== dependencies: - "@typescript-eslint/types" "8.7.0" - "@typescript-eslint/visitor-keys" "8.7.0" + "@typescript-eslint/types" "8.8.1" + "@typescript-eslint/visitor-keys" "8.8.1" debug "^4.3.4" fast-glob "^3.3.2" is-glob "^4.0.3" @@ -6073,7 +6062,17 @@ semver "^7.6.0" ts-api-utils "^1.3.0" -"@typescript-eslint/utils@7.18.0", "@typescript-eslint/utils@^6.0.0 || ^7.0.0", "@typescript-eslint/utils@^7.0.0", "@typescript-eslint/utils@^7.18.0", "@typescript-eslint/utils@^7.9.0": +"@typescript-eslint/utils@8.8.1", "@typescript-eslint/utils@^6.0.0 || ^7.0.0 || ^8.0.0", "@typescript-eslint/utils@^8.0.0", "@typescript-eslint/utils@^8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.8.1.tgz#9e29480fbfa264c26946253daa72181f9f053c9d" + integrity sha512-/QkNJDbV0bdL7H7d0/y0qBbV2HTtf0TIyjSDTvvmQEzeVx8jEImEbLuOA4EsvE8gIgqMitns0ifb5uQhMj8d9w== + dependencies: + "@eslint-community/eslint-utils" "^4.4.0" + "@typescript-eslint/scope-manager" "8.8.1" + "@typescript-eslint/types" "8.8.1" + "@typescript-eslint/typescript-estree" "8.8.1" + +"@typescript-eslint/utils@^7.0.0", "@typescript-eslint/utils@^7.9.0": version "7.18.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.18.0.tgz#bca01cde77f95fc6a8d5b0dbcbfb3d6ca4be451f" integrity sha512-kK0/rNa2j74XuHVcoCZxdFBMF+aq/vH83CXAOHieC+2Gis4mF8jJXT5eAfyD3K0sAxtPuwxaIOIOvhwzVDt/kw== @@ -6083,16 +6082,6 @@ "@typescript-eslint/types" "7.18.0" "@typescript-eslint/typescript-estree" "7.18.0" -"@typescript-eslint/utils@8.7.0", "@typescript-eslint/utils@^8.0.0": - version "8.7.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.7.0.tgz#cef3f70708b5b5fd7ed8672fc14714472bd8a011" - integrity sha512-ZbdUdwsl2X/s3CiyAu3gOlfQzpbuG3nTWKPoIvAu1pu5r8viiJvv2NPN2AqArL35NCYtw/lrPPfM4gxrMLNLPw== - dependencies: - "@eslint-community/eslint-utils" "^4.4.0" - "@typescript-eslint/scope-manager" "8.7.0" - "@typescript-eslint/types" "8.7.0" - "@typescript-eslint/typescript-estree" "8.7.0" - "@typescript-eslint/visitor-keys@7.18.0": version "7.18.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.18.0.tgz#0564629b6124d67607378d0f0332a0495b25e7d7" @@ -6101,12 +6090,12 @@ "@typescript-eslint/types" "7.18.0" eslint-visitor-keys "^3.4.3" -"@typescript-eslint/visitor-keys@8.7.0": - version "8.7.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.7.0.tgz#5e46f1777f9d69360a883c1a56ac3c511c9659a8" - integrity sha512-b1tx0orFCCh/THWPQa2ZwWzvOeyzzp36vkJYOpVg0u8UVOIsfVrnuC9FqAw9gRKn+rG2VmWQ/zDJZzkxUnj/XQ== +"@typescript-eslint/visitor-keys@8.8.1": + version "8.8.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.1.tgz#0fb1280f381149fc345dfde29f7542ff4e587fc5" + integrity sha512-0/TdC3aeRAsW7MDvYRwEc1Uwm0TIBfzjPFgg60UU2Haj5qsCs9cc3zNgY71edqE3LbWfF/WoZQd3lJoDXFQpag== dependencies: - "@typescript-eslint/types" "8.7.0" + "@typescript-eslint/types" "8.8.1" eslint-visitor-keys "^3.4.3" "@uifabric/set-version@^7.0.23": @@ -10824,12 +10813,12 @@ eslint-plugin-import@2.29.1, eslint-plugin-import@^2.29.1: semver "^6.3.1" tsconfig-paths "^3.15.0" -eslint-plugin-jest@28.6.0, eslint-plugin-jest@^28.6.0: - version "28.6.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-28.6.0.tgz#8410588d60bcafa68a91b6ec272e4a415502302a" - integrity sha512-YG28E1/MIKwnz+e2H7VwYPzHUYU4aMa19w0yGcwXnnmJH6EfgHahTJ2un3IyraUxNfnz/KUhJAFXNNwWPo12tg== +eslint-plugin-jest@28.8.0, eslint-plugin-jest@^28.6.0: + version "28.8.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-28.8.0.tgz#54f597b5a3295ad04ec946baa245ad02b9b2bca0" + integrity sha512-Tubj1hooFxCl52G4qQu0edzV/+EZzPUeN8p2NnW5uu4fbDs+Yo7+qDVDc4/oG3FbCqEBmu/OC3LSsyiU22oghw== dependencies: - "@typescript-eslint/utils" "^6.0.0 || ^7.0.0" + "@typescript-eslint/utils" "^6.0.0 || ^7.0.0 || ^8.0.0" eslint-plugin-jsdoc@48.7.0, eslint-plugin-jsdoc@^48.7.0: version "48.7.0" @@ -22744,14 +22733,14 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript-eslint@^7.5.0: - version "7.18.0" - resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-7.18.0.tgz#e90d57649b2ad37a7475875fa3e834a6d9f61eb2" - integrity sha512-PonBkP603E3tt05lDkbOMyaxJjvKqQrXsnow72sVeOFINDE/qNmnnd+f9b4N+U7W6MXnnYyrhtmF2t08QWwUbA== +typescript-eslint@^8.0.0: + version "8.8.1" + resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-8.8.1.tgz#b375c877b2184d883b6228170bc66f0fca847c9a" + integrity sha512-R0dsXFt6t4SAFjUSKFjMh4pXDtq04SsFKCVGDP3ZOzNP7itF0jBcZYU4fMsZr4y7O7V7Nc751dDeESbe4PbQMQ== dependencies: - "@typescript-eslint/eslint-plugin" "7.18.0" - "@typescript-eslint/parser" "7.18.0" - "@typescript-eslint/utils" "7.18.0" + "@typescript-eslint/eslint-plugin" "8.8.1" + "@typescript-eslint/parser" "8.8.1" + "@typescript-eslint/utils" "8.8.1" typescript@5.0.4, typescript@~5.0.4: version "5.0.4" From 6da01cc76551d0b79d55d0ae952be56515846a3b Mon Sep 17 00:00:00 2001 From: mainframev Date: Thu, 22 Aug 2024 17:20:12 +0200 Subject: [PATCH 02/16] chore: remove unused-vars --- .../ComponentSourceManager/ComponentSourceManager.ts | 3 +-- .../ComponentSourceManager/getExampleModule.ts | 2 +- .../src/context-selector/useContextSelector.ts | 2 +- .../src/context-selector/useContextSelectors.ts | 2 +- .../fluentui/react-bindings/src/utils/getWindow.ts | 2 +- packages/fluentui/react-builder/src/utils/treeStore.ts | 2 +- .../react-northstar/src/utils/fontSizeUtility.ts | 2 +- .../test/specs/commonTests/isConformant.tsx | 10 +++++----- .../react-northstar/test/utils/assertNodeContains.ts | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/ComponentSourceManager.ts b/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/ComponentSourceManager.ts index b25f857f499f1..a45c9a584c5ef 100644 --- a/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/ComponentSourceManager.ts +++ b/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/ComponentSourceManager.ts @@ -121,9 +121,8 @@ export default class ComponentSourceManager extends React.Component< try { const formattedCode = prettifyCode(currentCode, prettierParser); - this.setState({ currentCode: formattedCode, formattedCode }); - } catch (e) {} + } catch {} }; handleCodeReset = (): void => { diff --git a/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/getExampleModule.ts b/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/getExampleModule.ts index 018cf7ae0bdc7..a62e91fd47d83 100644 --- a/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/getExampleModule.ts +++ b/packages/fluentui/docs/src/components/ComponentDoc/ComponentSourceManager/getExampleModule.ts @@ -26,7 +26,7 @@ const getExampleModule = ( namedExports: examplesContext(modulePath), source: exampleSourcesContext(sourcePath), }; - } catch (e) { + } catch { return null; } }; diff --git a/packages/fluentui/react-bindings/src/context-selector/useContextSelector.ts b/packages/fluentui/react-bindings/src/context-selector/useContextSelector.ts index d20bc546c182b..bb385c359d6ea 100644 --- a/packages/fluentui/react-bindings/src/context-selector/useContextSelector.ts +++ b/packages/fluentui/react-bindings/src/context-selector/useContextSelector.ts @@ -53,7 +53,7 @@ export const useContextSelector = ( } return [payload[1], nextSelected] as const; - } catch (e) { + } catch { // ignored (stale props or some other reason) } return [...prevState] as const; // schedule update diff --git a/packages/fluentui/react-bindings/src/context-selector/useContextSelectors.ts b/packages/fluentui/react-bindings/src/context-selector/useContextSelectors.ts index 1dc7139df1c1f..73ee8d428621d 100644 --- a/packages/fluentui/react-bindings/src/context-selector/useContextSelectors.ts +++ b/packages/fluentui/react-bindings/src/context-selector/useContextSelectors.ts @@ -79,7 +79,7 @@ export const useContextSelectors = < } return [payload[1], nextSelected] as const; - } catch (e) { + } catch { // ignored (stale props or some other reason) } return [...prevState] as const; // schedule update diff --git a/packages/fluentui/react-bindings/src/utils/getWindow.ts b/packages/fluentui/react-bindings/src/utils/getWindow.ts index 62ce6b0438ee0..209e62c241d77 100644 --- a/packages/fluentui/react-bindings/src/utils/getWindow.ts +++ b/packages/fluentui/react-bindings/src/utils/getWindow.ts @@ -5,7 +5,7 @@ let _window: Window | undefined = undefined; // Caching the window value at the file scope lets us minimize the impact. try { _window = window; -} catch (e) { +} catch { /* no-op */ } diff --git a/packages/fluentui/react-builder/src/utils/treeStore.ts b/packages/fluentui/react-builder/src/utils/treeStore.ts index 44e05a8e335f5..3efd73fb0c86e 100644 --- a/packages/fluentui/react-builder/src/utils/treeStore.ts +++ b/packages/fluentui/react-builder/src/utils/treeStore.ts @@ -37,7 +37,7 @@ export const readTreeFromURL = (url: string): JSONTreeElement | null => { } try { return treeParse(treeString); - } catch (e) { + } catch { // TODO: client should know it failed return null; } diff --git a/packages/fluentui/react-northstar/src/utils/fontSizeUtility.ts b/packages/fluentui/react-northstar/src/utils/fontSizeUtility.ts index 73b3de0f5b29f..931181647884a 100644 --- a/packages/fluentui/react-northstar/src/utils/fontSizeUtility.ts +++ b/packages/fluentui/react-northstar/src/utils/fontSizeUtility.ts @@ -9,7 +9,7 @@ export const getDocumentRemSize = (): number => { try { // eslint-disable-next-line no-undef return getFontSizeValue(getComputedStyle(document.documentElement).fontSize) || DEFAULT_REM_SIZE_IN_PX; - } catch (e) { + } catch { return DEFAULT_REM_SIZE_IN_PX; } } diff --git a/packages/fluentui/react-northstar/test/specs/commonTests/isConformant.tsx b/packages/fluentui/react-northstar/test/specs/commonTests/isConformant.tsx index 02166f50b9b9c..b7849d6e416fe 100644 --- a/packages/fluentui/react-northstar/test/specs/commonTests/isConformant.tsx +++ b/packages/fluentui/react-northstar/test/specs/commonTests/isConformant.tsx @@ -153,7 +153,7 @@ export function isConformant( const component = getComponent(wrapper); try { expect(component.is(tag)).toEqual(true); - } catch (err) { + } catch { expect(component.type()).not.toEqual(Component); expect(component.prop('as')).toEqual(tag); } @@ -169,7 +169,7 @@ export function isConformant( try { expect(component.type()).toEqual(MyComponent); - } catch (err) { + } catch { expect(component.type()).not.toEqual(Component); expect(component.find('[as]').last().prop('as')).toEqual(MyComponent); } @@ -187,7 +187,7 @@ export function isConformant( try { expect(component.type()).toEqual(MyComponent); - } catch (err) { + } catch { expect(component.type()).not.toEqual(Component); expect(component.prop('as')).toEqual(MyComponent); } @@ -390,7 +390,7 @@ export function isConformant( try { expect(handlerSpy).toHaveBeenCalled(); - } catch (err) { + } catch { throw new Error( [ `<${constructorName} ${listenerName}={${handlerName}} />\n`, @@ -422,7 +422,7 @@ export function isConformant( expectedArgs.forEach((expectedArg, argI) => { expect(lastHandlerCall[argI]).toEqual(expectedArg); }); - } catch (err) { + } catch { throw new Error( [ `<${constructorName} ${listenerName}={${handlerName}} />\n`, diff --git a/packages/fluentui/react-northstar/test/utils/assertNodeContains.ts b/packages/fluentui/react-northstar/test/utils/assertNodeContains.ts index a885ab133c3bc..29613c5723e81 100644 --- a/packages/fluentui/react-northstar/test/utils/assertNodeContains.ts +++ b/packages/fluentui/react-northstar/test/utils/assertNodeContains.ts @@ -9,7 +9,7 @@ export const assertNodeContains = (parentNode: Element, childSelector: string, i const didFind = parentNode.querySelector(childSelector) !== null; try { expect(didFind).toEqual(isPresent); - } catch (err) { + } catch { throw new Error(`${didFind ? 'Found' : 'Did not find'} "${childSelector}" in the ${parentNode}.`); } }; From 67853b1fdad9655f7ba8f9506cbc72dc23e5857d Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 23 Aug 2024 14:40:51 +0200 Subject: [PATCH 03/16] chore: update RuleTester config in tests --- .../src/rules/ban-context-export/index.js | 6 ++-- .../rules/ban-context-export/index.test.js | 31 +++++++++---------- .../ban-instanceof-html-element/index.js | 7 +++-- .../ban-instanceof-html-element/index.test.js | 4 +-- .../rules/deprecated-keyboard-event-props.js | 9 ++++-- .../no-context-default-value/index.test.js | 4 +-- .../src/rules/no-global-react.js | 9 ++++-- .../rules/no-restricted-imports/index.test.js | 4 +-- .../src/rules/no-tslint-comments.js | 9 ++++-- .../rules/no-missing-jsx-pragma.ts | 8 +++-- 10 files changed, 52 insertions(+), 39 deletions(-) diff --git a/packages/eslint-plugin/src/rules/ban-context-export/index.js b/packages/eslint-plugin/src/rules/ban-context-export/index.js index 81cde74b5fa5a..6b239a07abb76 100644 --- a/packages/eslint-plugin/src/rules/ban-context-export/index.js +++ b/packages/eslint-plugin/src/rules/ban-context-export/index.js @@ -7,6 +7,8 @@ const { getTypeServices } = require('../../utils/type-services'); /** @typedef { import('@typescript-eslint/utils').TSESTree.VariableDeclarator } VariableDeclarator*/ /** @typedef { import('@typescript-eslint/utils').TSESTree.ExportSpecifier} ExportSpecifier */ +/** @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs*/ +/** @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation */ /** * @typedef {{ * exclude?: string[]; @@ -33,10 +35,10 @@ module.exports = createRule({ }, ], type: 'problem', - docs: { + docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ description: 'Ban export of React context or context selector objects', recommended: 'recommended', - }, + }), messages: { nativeContext: '{{exportName}} should not be exported directly', contextSelector: '{{exportName}} should not be exported directly', diff --git a/packages/eslint-plugin/src/rules/ban-context-export/index.test.js b/packages/eslint-plugin/src/rules/ban-context-export/index.test.js index 099eec01b1fa5..244122b9f9d23 100644 --- a/packages/eslint-plugin/src/rules/ban-context-export/index.test.js +++ b/packages/eslint-plugin/src/rules/ban-context-export/index.test.js @@ -3,35 +3,32 @@ const { RuleTester } = require('@typescript-eslint/rule-tester'); const path = require('path'); const rule = require('./index'); -const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', - parserOptions: { - project: path.resolve(__dirname, './fixtures/ban-context-export/tsconfig.json'), - tsconfigRootDir: path.resolve(__dirname, './fixtures/ban-context-export'), - }, -}); +const ruleTester = new RuleTester(); /** * @param {string} fixtureName */ function getParserOptions(fixtureName) { return { - project: path.resolve(__dirname, `./fixtures/${fixtureName}/tsconfig.json`), - tsconfigRootDir: path.resolve(__dirname, `./fixtures/${fixtureName}`), + parserOptions: { + parser: '@typescript-eslint/parser', + project: path.resolve(__dirname, `./fixtures/${fixtureName}/tsconfig.json`), + tsconfigRootDir: path.resolve(__dirname, `./fixtures/${fixtureName}`), + }, }; } ruleTester.run('ban-context-export', rule, { valid: [ { - parserOptions: getParserOptions('internal-export'), + languageOptions: getParserOptions('internal-export'), code: ` export { MyContext } from './context' `, filename: 'src/internal/index.ts', }, { - parserOptions: getParserOptions('not-a-context'), + languageOptions: getParserOptions('not-a-context'), code: ` export { MyContext } from './context' `, @@ -39,7 +36,7 @@ ruleTester.run('ban-context-export', rule, { }, { options: [{ exclude: ['**/special-path/**/*'] }], - parserOptions: getParserOptions('exclude'), + languageOptions: getParserOptions('exclude'), code: ` import * as React from 'react'; export const MyContext = React.createContext({}); @@ -50,7 +47,7 @@ ruleTester.run('ban-context-export', rule, { invalid: [ { errors: [{ messageId: 'nativeContext' }], - parserOptions: getParserOptions('export-specifier'), + languageOptions: getParserOptions('export-specifier'), code: ` export { MyContext } from './context' `, @@ -58,7 +55,7 @@ ruleTester.run('ban-context-export', rule, { }, { errors: [{ messageId: 'contextSelector' }], - parserOptions: getParserOptions('context-selector'), + languageOptions: getParserOptions('context-selector'), code: ` export { MyContext } from './context' `, @@ -66,7 +63,7 @@ ruleTester.run('ban-context-export', rule, { }, { errors: [{ messageId: 'nativeContext' }], - parserOptions: getParserOptions('named-export'), + languageOptions: getParserOptions('named-export'), code: ` import * as React from 'react'; export const MyContext = React.createContext({}); @@ -75,7 +72,7 @@ ruleTester.run('ban-context-export', rule, { }, { errors: [{ messageId: 'contextSelector' }], - parserOptions: getParserOptions('named-export'), + languageOptions: getParserOptions('named-export'), code: ` import { createContext } from '@proj/react-context-selector'; export const MyContext = createContext({}); @@ -85,7 +82,7 @@ ruleTester.run('ban-context-export', rule, { { errors: [{ messageId: 'nativeContext' }], options: [{ exclude: ['**/wrong-path/**/*'] }], - parserOptions: getParserOptions('exclude'), + languageOptions: getParserOptions('exclude'), code: ` import * as React from 'react'; export const MyContext = React.createContext({}); diff --git a/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js b/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js index 49277fb01e1ef..d0cb27b1b7ec8 100644 --- a/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js +++ b/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js @@ -4,17 +4,18 @@ const createRule = require('../../utils/createRule'); /** * @typedef {import('./types').HTMLElementConstructorName} HTMLElementConstructorName - * + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation */ module.exports = createRule({ name: 'ban-instanceof-html-element', meta: { type: 'problem', - docs: { + docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ description: 'Ban usage of instanceof HTMLElement comparison', recommended: 'recommended', - }, + }), messages: { invalidBinaryExpression: 'instanceof {{right}} should be avoided, use isHTMLElement instead.', }, diff --git a/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.test.js b/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.test.js index 64bd9f936ace7..aaf940a64751f 100644 --- a/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.test.js +++ b/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.test.js @@ -1,9 +1,7 @@ const { RuleTester } = require('@typescript-eslint/rule-tester'); const rule = require('./index'); -const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', -}); +const ruleTester = new RuleTester(); ruleTester.run('ban-instanceof-htmlelement', rule, { valid: [ diff --git a/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js b/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js index 5cc050c109de4..0db57b9545e7e 100644 --- a/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js +++ b/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js @@ -2,15 +2,20 @@ const createRule = require('../utils/createRule'); const { ESLintUtils } = require('@typescript-eslint/utils'); +/** + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation + */ + module.exports = createRule({ name: 'deprecated-keyboard-event-props', meta: { type: 'problem', - docs: { + docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ description: 'Forbid use of deprecated KeyboardEvent props "which" and "keyCode".', recommended: 'recommended', requiresTypeChecking: true, - }, + }), messages: { deprecatedProp: 'KeyboardEvent prop "{{name}}" is deprecated (consider using @fluentui/keyboard-key instead)', }, diff --git a/packages/eslint-plugin/src/rules/no-context-default-value/index.test.js b/packages/eslint-plugin/src/rules/no-context-default-value/index.test.js index 3181028e03381..47ee4b7103b93 100644 --- a/packages/eslint-plugin/src/rules/no-context-default-value/index.test.js +++ b/packages/eslint-plugin/src/rules/no-context-default-value/index.test.js @@ -1,9 +1,7 @@ const { RuleTester } = require('@typescript-eslint/rule-tester'); const rule = require('./index'); -const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', -}); +const ruleTester = new RuleTester(); ruleTester.run('no-context-default-value', rule, { valid: [ diff --git a/packages/eslint-plugin/src/rules/no-global-react.js b/packages/eslint-plugin/src/rules/no-global-react.js index c32c564569876..948e074191007 100644 --- a/packages/eslint-plugin/src/rules/no-global-react.js +++ b/packages/eslint-plugin/src/rules/no-global-react.js @@ -2,14 +2,19 @@ const { AST_NODE_TYPES } = require('@typescript-eslint/utils'); const createRule = require('../utils/createRule'); +/** + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation + */ + module.exports = createRule({ name: 'no-global-react', meta: { type: 'problem', - docs: { + docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ description: 'Prevent accidental references to the global React namespace', recommended: 'recommended', - }, + }), messages: { missingImport: 'You must explicitly import React to reference it', }, diff --git a/packages/eslint-plugin/src/rules/no-restricted-imports/index.test.js b/packages/eslint-plugin/src/rules/no-restricted-imports/index.test.js index 5d07ee450f1e6..ce4abf4a2c08d 100644 --- a/packages/eslint-plugin/src/rules/no-restricted-imports/index.test.js +++ b/packages/eslint-plugin/src/rules/no-restricted-imports/index.test.js @@ -1,9 +1,7 @@ const { RuleTester } = require('@typescript-eslint/rule-tester'); const rule = require('./index'); -const ruleTester = new RuleTester({ - parser: '@typescript-eslint/parser', -}); +const ruleTester = new RuleTester(); ruleTester.run('no-restricted-imports', rule, { valid: [ diff --git a/packages/eslint-plugin/src/rules/no-tslint-comments.js b/packages/eslint-plugin/src/rules/no-tslint-comments.js index 4e943f8bcf361..96d659bb2512f 100644 --- a/packages/eslint-plugin/src/rules/no-tslint-comments.js +++ b/packages/eslint-plugin/src/rules/no-tslint-comments.js @@ -1,14 +1,19 @@ // @ts-check const createRule = require('../utils/createRule'); +/** + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs + * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation + */ + module.exports = createRule({ name: 'no-tslint-comments', meta: { type: 'problem', - docs: { + docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ description: 'Forbid tslint:disable/tslint:enable comments after ESLint migration.', recommended: 'recommended', - }, + }), messages: { tslint: 'tslint:{{verb}} comments are unnecessary with ESLint', }, diff --git a/tools/eslint-rules/rules/no-missing-jsx-pragma.ts b/tools/eslint-rules/rules/no-missing-jsx-pragma.ts index da0c14195c7a6..60b45546b9842 100644 --- a/tools/eslint-rules/rules/no-missing-jsx-pragma.ts +++ b/tools/eslint-rules/rules/no-missing-jsx-pragma.ts @@ -14,7 +14,7 @@ * https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/rules */ -import { ESLintUtils, AST_NODE_TYPES, AST_TOKEN_TYPES, ASTUtils, TSESTree } from '@typescript-eslint/utils'; +import { ESLintUtils, AST_NODE_TYPES, AST_TOKEN_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils'; // NOTE: The rule will be available in ESLint configs as "@nx/workspace-no-missing-jsx-pragma" export const RULE_NAME = 'no-missing-jsx-pragma'; @@ -28,7 +28,11 @@ type MessageIds = | 'invalidJSXPragmaForClassic' | 'redundantPragma'; -export const rule = ESLintUtils.RuleCreator(() => __filename)({ +type Docs = { + recommended: TSESLint.RuleRecommendation; +}; + +export const rule = ESLintUtils.RuleCreator(() => __filename)({ name: RULE_NAME, meta: { type: 'problem', From 57652a386a84676fd16510d8f43dc82dd12e3147 Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 23 Aug 2024 14:41:57 +0200 Subject: [PATCH 04/16] chore(eslint-plugin): update minimal typescript version --- packages/eslint-plugin/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index d7d39c67dc2c2..ba621af46a4ca 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -37,7 +37,7 @@ }, "peerDependencies": { "eslint": "^8.0.0", - "typescript": "^4.7.5" + "typescript": "^4.8.4" }, "files": [ "src" From d9ce53c4f800f830082739403c090e7dfa1b1c3b Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 23 Aug 2024 14:42:14 +0200 Subject: [PATCH 05/16] chore: update change files --- ...eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json | 7 +++++++ ...eb-components-ad9feaa2-0083-4a09-a62c-4f26d54356c6.json | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json create mode 100644 change/@fluentui-web-components-ad9feaa2-0083-4a09-a62c-4f26d54356c6.json diff --git a/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json b/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json new file mode 100644 index 0000000000000..f40bdb1fde93d --- /dev/null +++ b/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "update minimal typescript version to 4.8.4", + "packageName": "@fluentui/eslint-plugin", + "email": "vgenaev@gmail.com", + "dependentChangeType": "patch" +} diff --git a/change/@fluentui-web-components-ad9feaa2-0083-4a09-a62c-4f26d54356c6.json b/change/@fluentui-web-components-ad9feaa2-0083-4a09-a62c-4f26d54356c6.json new file mode 100644 index 0000000000000..c53be7ff1e939 --- /dev/null +++ b/change/@fluentui-web-components-ad9feaa2-0083-4a09-a62c-4f26d54356c6.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "resolve eslint errors after upgrade to typescript-eslint v8", + "packageName": "@fluentui/web-components", + "email": "vgenaev@gmail.com", + "dependentChangeType": "none" +} From 276fb6886ac024d5702abe3323fbe673bdd00968 Mon Sep 17 00:00:00 2001 From: mainframev Date: Tue, 27 Aug 2024 12:20:38 +0200 Subject: [PATCH 06/16] chore(tools): update consistent-callback-type --- .../rules/consistent-callback-type.spec.ts | 2 -- tools/eslint-rules/rules/consistent-callback-type.ts | 10 +++++++--- tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts | 2 -- tools/eslint-rules/rules/no-restricted-globals.spec.ts | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/eslint-rules/rules/consistent-callback-type.spec.ts b/tools/eslint-rules/rules/consistent-callback-type.spec.ts index 1bac268fee9d1..b3601fb2a7835 100644 --- a/tools/eslint-rules/rules/consistent-callback-type.spec.ts +++ b/tools/eslint-rules/rules/consistent-callback-type.spec.ts @@ -3,8 +3,6 @@ import { rule, RULE_NAME } from './consistent-callback-type'; const ruleTester = new RuleTester(); -global.structuredClone = val => JSON.parse(JSON.stringify(val)); - ruleTester.run(RULE_NAME, rule, { valid: [ // Valid when prop is TSTypeAliasDeclaration and the callback uses EventHandler diff --git a/tools/eslint-rules/rules/consistent-callback-type.ts b/tools/eslint-rules/rules/consistent-callback-type.ts index 963924de5ffcd..56aad41168ffc 100644 --- a/tools/eslint-rules/rules/consistent-callback-type.ts +++ b/tools/eslint-rules/rules/consistent-callback-type.ts @@ -1,9 +1,13 @@ -import { ESLintUtils, AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; +import { ESLintUtils, AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils'; // NOTE: The rule will be available in ESLint configs as "@nx/workspace-consistent-callback-type" export const RULE_NAME = 'consistent-callback-type'; -export const rule = ESLintUtils.RuleCreator(() => __filename)({ +type Docs = { + recommended: TSESLint.RuleRecommendation; +}; + +export const rule = ESLintUtils.RuleCreator(() => __filename)({ name: RULE_NAME, meta: { type: 'problem', @@ -41,7 +45,7 @@ export const rule = ESLintUtils.RuleCreator(() => __filename)({ typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && typeAnnotation.typeName.name === 'EventHandler' && - typeAnnotation.typeParameters + typeAnnotation.typeArguments ) ) { context.report({ diff --git a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts index 9a6d78790f1c7..5c2aa48891013 100644 --- a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts +++ b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts @@ -5,8 +5,6 @@ const ruleTester = new RuleTester({ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, }); -global.structuredClone = val => JSON.parse(JSON.stringify(val)); - ruleTester.run(RULE_NAME, rule, { valid: [ // no slot api used case diff --git a/tools/eslint-rules/rules/no-restricted-globals.spec.ts b/tools/eslint-rules/rules/no-restricted-globals.spec.ts index 62f2892cbb9fd..7523db381e44c 100644 --- a/tools/eslint-rules/rules/no-restricted-globals.spec.ts +++ b/tools/eslint-rules/rules/no-restricted-globals.spec.ts @@ -4,7 +4,6 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import { rule, RULE_NAME } from './no-restricted-globals'; const ruleTester = new RuleTester(); -global.structuredClone = val => JSON.parse(JSON.stringify(val)); ruleTester.run(RULE_NAME, rule, { valid: [ From b7d33494534fc205f243fa1bc94c57980c134ff0 Mon Sep 17 00:00:00 2001 From: mainframev Date: Tue, 27 Aug 2024 12:21:52 +0200 Subject: [PATCH 07/16] chore(web-components): add rules to config to keep current eslint behavior --- packages/web-components/.eslintrc.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/web-components/.eslintrc.json b/packages/web-components/.eslintrc.json index c96b794360cfd..3d5876196e9ba 100644 --- a/packages/web-components/.eslintrc.json +++ b/packages/web-components/.eslintrc.json @@ -38,6 +38,7 @@ "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-empty-interface": "error", + "@typescript-eslint/no-empty-object-type": "off", "@typescript-eslint/no-unsafe-declaration-merging": "off", "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/explicit-function-return-type": "off", @@ -49,6 +50,7 @@ "args": "none" } ], + "@typescript-eslint/no-unused-expressions": "warn", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/naming-convention": [ "error", From 5295b13c1cf5c47140261a13576d286f7915d7fc Mon Sep 17 00:00:00 2001 From: mainframev Date: Tue, 15 Oct 2024 14:10:49 +0200 Subject: [PATCH 08/16] fixup! chore: update RuleTester config in tests --- .../src/generators/eslint-rule/generator.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/workspace-plugin/src/generators/eslint-rule/generator.spec.ts b/tools/workspace-plugin/src/generators/eslint-rule/generator.spec.ts index 27036f82d9889..0e1ce9e8a9d43 100644 --- a/tools/workspace-plugin/src/generators/eslint-rule/generator.spec.ts +++ b/tools/workspace-plugin/src/generators/eslint-rule/generator.spec.ts @@ -54,7 +54,6 @@ describe('eslint-rule generator', () => { type: 'problem', docs: { description: \`\`, - recommended: 'recommended', }, schema: [], messages: {}, From 2297e2b67ffce87c6c78bbf2d4ee88dc55dbe870 Mon Sep 17 00:00:00 2001 From: mainframev Date: Tue, 15 Oct 2024 16:36:42 +0200 Subject: [PATCH 09/16] fixup! chore: update RuleTester config in tests --- tools/eslint-rules/rules/consistent-callback-type.spec.ts | 4 ++++ tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts | 4 ++++ tools/eslint-rules/rules/no-restricted-globals.spec.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/tools/eslint-rules/rules/consistent-callback-type.spec.ts b/tools/eslint-rules/rules/consistent-callback-type.spec.ts index b3601fb2a7835..9cea897a39ccb 100644 --- a/tools/eslint-rules/rules/consistent-callback-type.spec.ts +++ b/tools/eslint-rules/rules/consistent-callback-type.spec.ts @@ -3,6 +3,10 @@ import { rule, RULE_NAME } from './consistent-callback-type'; const ruleTester = new RuleTester(); +global.structuredClone = jest.fn(val => { + return JSON.parse(JSON.stringify(val)); +}); + ruleTester.run(RULE_NAME, rule, { valid: [ // Valid when prop is TSTypeAliasDeclaration and the callback uses EventHandler diff --git a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts index 5c2aa48891013..bbd72aa56423f 100644 --- a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts +++ b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts @@ -5,6 +5,10 @@ const ruleTester = new RuleTester({ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, }); +global.structuredClone = jest.fn(val => { + return JSON.parse(JSON.stringify(val)); +}); + ruleTester.run(RULE_NAME, rule, { valid: [ // no slot api used case diff --git a/tools/eslint-rules/rules/no-restricted-globals.spec.ts b/tools/eslint-rules/rules/no-restricted-globals.spec.ts index 7523db381e44c..c2aade09c09c8 100644 --- a/tools/eslint-rules/rules/no-restricted-globals.spec.ts +++ b/tools/eslint-rules/rules/no-restricted-globals.spec.ts @@ -5,6 +5,10 @@ import { rule, RULE_NAME } from './no-restricted-globals'; const ruleTester = new RuleTester(); +global.structuredClone = jest.fn(val => { + return JSON.parse(JSON.stringify(val)); +}); + ruleTester.run(RULE_NAME, rule, { valid: [ { From ceb3415771295d2a6bd93f013bcc553c7a17e7a1 Mon Sep 17 00:00:00 2001 From: Victor Genaev Date: Fri, 18 Oct 2024 15:59:52 +0200 Subject: [PATCH 10/16] Update change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json Co-authored-by: Martin Hochel --- ...ntui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json b/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json index f40bdb1fde93d..8fd0ec90c6f91 100644 --- a/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json +++ b/change/@fluentui-eslint-plugin-9708d729-ebb2-44cd-8fe1-30cf46fc403d.json @@ -1,6 +1,6 @@ { "type": "patch", - "comment": "update minimal typescript version to 4.8.4", + "comment": "fix: bump minimal typescript version to 4.8.4", "packageName": "@fluentui/eslint-plugin", "email": "vgenaev@gmail.com", "dependentChangeType": "patch" From 78745aa36605a8867f8fc850673ae58fb0c0e5e0 Mon Sep 17 00:00:00 2001 From: Victor Genaev Date: Fri, 18 Oct 2024 16:00:06 +0200 Subject: [PATCH 11/16] Update packages/eslint-plugin/src/rules/ban-context-export/index.test.js Co-authored-by: Martin Hochel --- .../eslint-plugin/src/rules/ban-context-export/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/ban-context-export/index.test.js b/packages/eslint-plugin/src/rules/ban-context-export/index.test.js index 244122b9f9d23..5df8ec8742318 100644 --- a/packages/eslint-plugin/src/rules/ban-context-export/index.test.js +++ b/packages/eslint-plugin/src/rules/ban-context-export/index.test.js @@ -8,7 +8,7 @@ const ruleTester = new RuleTester(); /** * @param {string} fixtureName */ -function getParserOptions(fixtureName) { +function getLanguageOptions(fixtureName) { return { parserOptions: { parser: '@typescript-eslint/parser', From 2ea5df0a0e62d461e1cf15a9db74b906086c7d7b Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 18 Oct 2024 16:02:27 +0200 Subject: [PATCH 12/16] fixup! Update packages/eslint-plugin/src/rules/ban-context-export/index.test.js --- .../src/rules/ban-context-export/index.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/eslint-plugin/src/rules/ban-context-export/index.test.js b/packages/eslint-plugin/src/rules/ban-context-export/index.test.js index 5df8ec8742318..9f0f3273acd58 100644 --- a/packages/eslint-plugin/src/rules/ban-context-export/index.test.js +++ b/packages/eslint-plugin/src/rules/ban-context-export/index.test.js @@ -21,14 +21,14 @@ function getLanguageOptions(fixtureName) { ruleTester.run('ban-context-export', rule, { valid: [ { - languageOptions: getParserOptions('internal-export'), + languageOptions: getLanguageOptions('internal-export'), code: ` export { MyContext } from './context' `, filename: 'src/internal/index.ts', }, { - languageOptions: getParserOptions('not-a-context'), + languageOptions: getLanguageOptions('not-a-context'), code: ` export { MyContext } from './context' `, @@ -36,7 +36,7 @@ ruleTester.run('ban-context-export', rule, { }, { options: [{ exclude: ['**/special-path/**/*'] }], - languageOptions: getParserOptions('exclude'), + languageOptions: getLanguageOptions('exclude'), code: ` import * as React from 'react'; export const MyContext = React.createContext({}); @@ -47,7 +47,7 @@ ruleTester.run('ban-context-export', rule, { invalid: [ { errors: [{ messageId: 'nativeContext' }], - languageOptions: getParserOptions('export-specifier'), + languageOptions: getLanguageOptions('export-specifier'), code: ` export { MyContext } from './context' `, @@ -55,7 +55,7 @@ ruleTester.run('ban-context-export', rule, { }, { errors: [{ messageId: 'contextSelector' }], - languageOptions: getParserOptions('context-selector'), + languageOptions: getLanguageOptions('context-selector'), code: ` export { MyContext } from './context' `, @@ -63,7 +63,7 @@ ruleTester.run('ban-context-export', rule, { }, { errors: [{ messageId: 'nativeContext' }], - languageOptions: getParserOptions('named-export'), + languageOptions: getLanguageOptions('named-export'), code: ` import * as React from 'react'; export const MyContext = React.createContext({}); @@ -72,7 +72,7 @@ ruleTester.run('ban-context-export', rule, { }, { errors: [{ messageId: 'contextSelector' }], - languageOptions: getParserOptions('named-export'), + languageOptions: getLanguageOptions('named-export'), code: ` import { createContext } from '@proj/react-context-selector'; export const MyContext = createContext({}); @@ -82,7 +82,7 @@ ruleTester.run('ban-context-export', rule, { { errors: [{ messageId: 'nativeContext' }], options: [{ exclude: ['**/wrong-path/**/*'] }], - languageOptions: getParserOptions('exclude'), + languageOptions: getLanguageOptions('exclude'), code: ` import * as React from 'react'; export const MyContext = React.createContext({}); From 43af5e4289fb8920e7439a665c252096ddd91dbf Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 18 Oct 2024 16:06:48 +0200 Subject: [PATCH 13/16] fixup! chore: update RuleTester config in tests --- tools/eslint-rules/rules/consistent-callback-type.ts | 9 ++------- tools/eslint-rules/rules/no-missing-jsx-pragma.ts | 9 ++------- tools/eslint-rules/rules/no-restricted-globals.ts | 9 ++------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/tools/eslint-rules/rules/consistent-callback-type.ts b/tools/eslint-rules/rules/consistent-callback-type.ts index 56aad41168ffc..20f012ef6d3ea 100644 --- a/tools/eslint-rules/rules/consistent-callback-type.ts +++ b/tools/eslint-rules/rules/consistent-callback-type.ts @@ -1,19 +1,14 @@ -import { ESLintUtils, AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils'; +import { ESLintUtils, AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; // NOTE: The rule will be available in ESLint configs as "@nx/workspace-consistent-callback-type" export const RULE_NAME = 'consistent-callback-type'; -type Docs = { - recommended: TSESLint.RuleRecommendation; -}; - -export const rule = ESLintUtils.RuleCreator(() => __filename)({ +export const rule = ESLintUtils.RuleCreator(() => __filename)({ name: RULE_NAME, meta: { type: 'problem', docs: { description: 'Enforce callback props to be typed with `EventHandler`', - recommended: 'recommended', }, messages: { invalidType: 'callback props should be typed with @fluentui/react-utilities#EventHandler', diff --git a/tools/eslint-rules/rules/no-missing-jsx-pragma.ts b/tools/eslint-rules/rules/no-missing-jsx-pragma.ts index 60b45546b9842..64425000c74dc 100644 --- a/tools/eslint-rules/rules/no-missing-jsx-pragma.ts +++ b/tools/eslint-rules/rules/no-missing-jsx-pragma.ts @@ -14,7 +14,7 @@ * https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/src/rules */ -import { ESLintUtils, AST_NODE_TYPES, AST_TOKEN_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils'; +import { ESLintUtils, AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from '@typescript-eslint/utils'; // NOTE: The rule will be available in ESLint configs as "@nx/workspace-no-missing-jsx-pragma" export const RULE_NAME = 'no-missing-jsx-pragma'; @@ -28,17 +28,12 @@ type MessageIds = | 'invalidJSXPragmaForClassic' | 'redundantPragma'; -type Docs = { - recommended: TSESLint.RuleRecommendation; -}; - -export const rule = ESLintUtils.RuleCreator(() => __filename)({ +export const rule = ESLintUtils.RuleCreator(() => __filename)({ name: RULE_NAME, meta: { type: 'problem', docs: { description: 'Enforce properly configured of @jsx or @jsxImportSource pragma for files using Fluent slot API', - recommended: 'recommended', }, schema: [ { diff --git a/tools/eslint-rules/rules/no-restricted-globals.ts b/tools/eslint-rules/rules/no-restricted-globals.ts index 154dd6e0cab03..1c06e332c18b3 100644 --- a/tools/eslint-rules/rules/no-restricted-globals.ts +++ b/tools/eslint-rules/rules/no-restricted-globals.ts @@ -15,7 +15,7 @@ */ import { Reference } from '@typescript-eslint/scope-manager'; -import { ESLintUtils, AST_NODE_TYPES, TSESTree, TSESLint } from '@typescript-eslint/utils'; +import { ESLintUtils, AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; // NOTE: The rule will be available in ESLint configs as "@nx/workspace-no-restricted-globals" export const RULE_NAME = 'no-restricted-globals'; @@ -23,17 +23,12 @@ type MessageIds = 'defaultMessage' | 'customMessage'; type Options = Array<{ name: string; message?: string } | string>; -type Docs = { - recommended: TSESLint.RuleRecommendation; -}; - -export const rule = ESLintUtils.RuleCreator(() => __filename)({ +export const rule = ESLintUtils.RuleCreator(() => __filename)({ name: RULE_NAME, meta: { type: 'problem', docs: { description: ``, - recommended: 'recommended', }, schema: { type: 'array', From d6a3be42c00177710766ca4d20ef804382499a29 Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 18 Oct 2024 16:11:11 +0200 Subject: [PATCH 14/16] chore(eslint-rules): set testEnvironment to node, prevent failing on structuredClone --- tools/eslint-rules/jest.config.ts | 1 + tools/eslint-rules/rules/consistent-callback-type.spec.ts | 4 ---- tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts | 4 ---- tools/eslint-rules/rules/no-restricted-globals.spec.ts | 4 ---- 4 files changed, 1 insertion(+), 12 deletions(-) diff --git a/tools/eslint-rules/jest.config.ts b/tools/eslint-rules/jest.config.ts index 7b931b87d5b9a..413d6be004292 100644 --- a/tools/eslint-rules/jest.config.ts +++ b/tools/eslint-rules/jest.config.ts @@ -2,6 +2,7 @@ export default { displayName: 'eslint-rules', preset: '../../jest.preset.js', + testEnvironment: 'node', transform: { '^.+\\.[tj]s$': ['@swc/jest', {}], }, diff --git a/tools/eslint-rules/rules/consistent-callback-type.spec.ts b/tools/eslint-rules/rules/consistent-callback-type.spec.ts index 9cea897a39ccb..b3601fb2a7835 100644 --- a/tools/eslint-rules/rules/consistent-callback-type.spec.ts +++ b/tools/eslint-rules/rules/consistent-callback-type.spec.ts @@ -3,10 +3,6 @@ import { rule, RULE_NAME } from './consistent-callback-type'; const ruleTester = new RuleTester(); -global.structuredClone = jest.fn(val => { - return JSON.parse(JSON.stringify(val)); -}); - ruleTester.run(RULE_NAME, rule, { valid: [ // Valid when prop is TSTypeAliasDeclaration and the callback uses EventHandler diff --git a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts index bbd72aa56423f..5c2aa48891013 100644 --- a/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts +++ b/tools/eslint-rules/rules/no-missing-jsx-pragma.spec.ts @@ -5,10 +5,6 @@ const ruleTester = new RuleTester({ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } }, }); -global.structuredClone = jest.fn(val => { - return JSON.parse(JSON.stringify(val)); -}); - ruleTester.run(RULE_NAME, rule, { valid: [ // no slot api used case diff --git a/tools/eslint-rules/rules/no-restricted-globals.spec.ts b/tools/eslint-rules/rules/no-restricted-globals.spec.ts index c2aade09c09c8..7523db381e44c 100644 --- a/tools/eslint-rules/rules/no-restricted-globals.spec.ts +++ b/tools/eslint-rules/rules/no-restricted-globals.spec.ts @@ -5,10 +5,6 @@ import { rule, RULE_NAME } from './no-restricted-globals'; const ruleTester = new RuleTester(); -global.structuredClone = jest.fn(val => { - return JSON.parse(JSON.stringify(val)); -}); - ruleTester.run(RULE_NAME, rule, { valid: [ { From 66a26832e8ee9367dfde9c8d2c28503626d7c8cd Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 18 Oct 2024 16:12:52 +0200 Subject: [PATCH 15/16] chore(workspace-plugin): set testEnvironment to node in jest.config --- tools/workspace-plugin/jest.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/workspace-plugin/jest.config.ts b/tools/workspace-plugin/jest.config.ts index 9fc6c42f824ef..c65c10bf45685 100644 --- a/tools/workspace-plugin/jest.config.ts +++ b/tools/workspace-plugin/jest.config.ts @@ -15,4 +15,5 @@ export default { watchPathIgnorePatterns: ['/node_modules/', '/__fixtures__/'], coverageDirectory: '../../coverage/tools/workspace-plugin', setupFiles: ['/jest-setup.js'], + testEnvironment: 'node', } as import('@jest/types').Config.InitialOptions; From 23df01038245bf2625e4ebf023a16a9a6d22fd0c Mon Sep 17 00:00:00 2001 From: mainframev Date: Fri, 18 Oct 2024 16:37:58 +0200 Subject: [PATCH 16/16] chore(eslint-plugin): remove redundant recommended property --- .../src/rules/ban-context-export/index.js | 7 ++----- .../src/rules/ban-instanceof-html-element/index.js | 7 ++----- .../src/rules/deprecated-keyboard-event-props.js | 4 +--- packages/eslint-plugin/src/rules/no-global-react.js | 10 ++-------- packages/eslint-plugin/src/rules/no-tslint-comments.js | 10 ++-------- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/packages/eslint-plugin/src/rules/ban-context-export/index.js b/packages/eslint-plugin/src/rules/ban-context-export/index.js index 6b239a07abb76..a81dda19c9b7d 100644 --- a/packages/eslint-plugin/src/rules/ban-context-export/index.js +++ b/packages/eslint-plugin/src/rules/ban-context-export/index.js @@ -7,8 +7,6 @@ const { getTypeServices } = require('../../utils/type-services'); /** @typedef { import('@typescript-eslint/utils').TSESTree.VariableDeclarator } VariableDeclarator*/ /** @typedef { import('@typescript-eslint/utils').TSESTree.ExportSpecifier} ExportSpecifier */ -/** @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs*/ -/** @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation */ /** * @typedef {{ * exclude?: string[]; @@ -35,10 +33,9 @@ module.exports = createRule({ }, ], type: 'problem', - docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ + docs: { description: 'Ban export of React context or context selector objects', - recommended: 'recommended', - }), + }, messages: { nativeContext: '{{exportName}} should not be exported directly', contextSelector: '{{exportName}} should not be exported directly', diff --git a/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js b/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js index d0cb27b1b7ec8..ca22c6f9cda71 100644 --- a/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js +++ b/packages/eslint-plugin/src/rules/ban-instanceof-html-element/index.js @@ -4,18 +4,15 @@ const createRule = require('../../utils/createRule'); /** * @typedef {import('./types').HTMLElementConstructorName} HTMLElementConstructorName - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation */ module.exports = createRule({ name: 'ban-instanceof-html-element', meta: { type: 'problem', - docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ + docs: { description: 'Ban usage of instanceof HTMLElement comparison', - recommended: 'recommended', - }), + }, messages: { invalidBinaryExpression: 'instanceof {{right}} should be avoided, use isHTMLElement instead.', }, diff --git a/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js b/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js index 0db57b9545e7e..30fa88473a873 100644 --- a/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js +++ b/packages/eslint-plugin/src/rules/deprecated-keyboard-event-props.js @@ -4,16 +4,14 @@ const { ESLintUtils } = require('@typescript-eslint/utils'); /** * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation */ module.exports = createRule({ name: 'deprecated-keyboard-event-props', meta: { type: 'problem', - docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ + docs: /** @type {RuleMetaDataDocs} */ ({ description: 'Forbid use of deprecated KeyboardEvent props "which" and "keyCode".', - recommended: 'recommended', requiresTypeChecking: true, }), messages: { diff --git a/packages/eslint-plugin/src/rules/no-global-react.js b/packages/eslint-plugin/src/rules/no-global-react.js index 948e074191007..9fcec153bed0a 100644 --- a/packages/eslint-plugin/src/rules/no-global-react.js +++ b/packages/eslint-plugin/src/rules/no-global-react.js @@ -2,19 +2,13 @@ const { AST_NODE_TYPES } = require('@typescript-eslint/utils'); const createRule = require('../utils/createRule'); -/** - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation - */ - module.exports = createRule({ name: 'no-global-react', meta: { type: 'problem', - docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ + docs: { description: 'Prevent accidental references to the global React namespace', - recommended: 'recommended', - }), + }, messages: { missingImport: 'You must explicitly import React to reference it', }, diff --git a/packages/eslint-plugin/src/rules/no-tslint-comments.js b/packages/eslint-plugin/src/rules/no-tslint-comments.js index 96d659bb2512f..d0afa2877e86d 100644 --- a/packages/eslint-plugin/src/rules/no-tslint-comments.js +++ b/packages/eslint-plugin/src/rules/no-tslint-comments.js @@ -1,19 +1,13 @@ // @ts-check const createRule = require('../utils/createRule'); -/** - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleMetaDataDocs} RuleMetaDataDocs - * @typedef { import('@typescript-eslint/utils').TSESLint.RuleRecommendation} RuleRecommendation - */ - module.exports = createRule({ name: 'no-tslint-comments', meta: { type: 'problem', - docs: /** @type {RuleMetaDataDocs & { recommended: RuleRecommendation }} */ ({ + docs: { description: 'Forbid tslint:disable/tslint:enable comments after ESLint migration.', - recommended: 'recommended', - }), + }, messages: { tslint: 'tslint:{{verb}} comments are unnecessary with ESLint', },