From 43622f567f0f3471c9f05f1429ab8d2d9379bc77 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 3 Apr 2025 15:22:14 -0700 Subject: [PATCH] chore: remove unused eslint-disable directives (#35482) --- eslint.config.mjs | 73 +++++++++++-------- packages/playwright-core/src/utils/DEPS.list | 6 -- .../src/utils/isomorphic/DEPS.list | 0 .../src/utils/isomorphic/builtins.ts | 2 - .../isomorphic/utilityScriptSerializers.ts | 3 - 5 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 packages/playwright-core/src/utils/DEPS.list create mode 100644 packages/playwright-core/src/utils/isomorphic/DEPS.list diff --git a/eslint.config.mjs b/eslint.config.mjs index 841ad483bb..f6eae0b86e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -217,32 +217,27 @@ const noBooleanCompareRules = { "@typescript-eslint/no-unnecessary-boolean-literal-compare": 2, }; -const noWebGlobalsRules = { - // This should contain every bulitin from builtins.ts. - "no-restricted-globals": [ - "error", - { "name": "window", "message": "Use InjectedScript.window instead" }, - { "name": "document", "message": "Use InjectedScript.document instead" }, - { "name": "globalThis", "message": "Use InjectedScript.window instead" }, - { "name": "setTimeout", "message": "Use InjectedScript.builtins.setTimeout instead" }, - { "name": "clearTimeout", "message": "Use InjectedScript.builtins.clearTimeout instead" }, - { "name": "setInterval", "message": "Use InjectedScript.builtins.setInterval instead" }, - { "name": "clearInterval", "message": "Use InjectedScript.builtins.clearInterval instead" }, - { "name": "requestAnimationFrame", "message": "Use InjectedScript.builtins.requestAnimationFrame instead" }, - { "name": "cancelAnimationFrame", "message": "Use InjectedScript.builtins.cancelAnimationFrame instead" }, - { "name": "requestIdleCallback", "message": "Use InjectedScript.builtins.requestIdleCallback instead" }, - { "name": "cancelIdleCallback", "message": "Use InjectedScript.builtins.cancelIdleCallback instead" }, - { "name": "performance", "message": "Use InjectedScript.builtins.performance instead" }, - { "name": "eval", "message": "Use InjectedScript.builtins.eval instead" }, - { "name": "Date", "message": "Use InjectedScript.builtins.Date instead" }, - { "name": "Map", "message": "Use InjectedScript.builtins.Map instead" }, - { "name": "Set", "message": "Use InjectedScript.builtins.Set instead" }, - ], -}; +// This should contain every builtin from builtins.ts. +const noWebGlobalsRuleList = [ + { name: "window", message: "Use InjectedScript.window instead" }, + { name: "document", message: "Use InjectedScript.document instead" }, + { name: "globalThis", message: "Use InjectedScript.window instead" }, + { name: "setTimeout", message: "Use InjectedScript.builtins.setTimeout instead" }, + { name: "clearTimeout", message: "Use InjectedScript.builtins.clearTimeout instead" }, + { name: "setInterval", message: "Use InjectedScript.builtins.setInterval instead" }, + { name: "clearInterval", message: "Use InjectedScript.builtins.clearInterval instead" }, + { name: "requestAnimationFrame", message: "Use InjectedScript.builtins.requestAnimationFrame instead" }, + { name: "cancelAnimationFrame", message: "Use InjectedScript.builtins.cancelAnimationFrame instead" }, + { name: "requestIdleCallback", message: "Use InjectedScript.builtins.requestIdleCallback instead" }, + { name: "cancelIdleCallback", message: "Use InjectedScript.builtins.cancelIdleCallback instead" }, + { name: "performance", message: "Use InjectedScript.builtins.performance instead" }, + { name: "eval", message: "Use InjectedScript.builtins.eval instead" }, + { name: "Date", message: "Use InjectedScript.builtins.Date instead" }, + { name: "Map", message: "Use InjectedScript.builtins.Map instead" }, + { name: "Set", message: "Use InjectedScript.builtins.Set instead" }, +]; -const noNodeGlobalsRules = { - "no-restricted-globals": ["error", { name: "process" }], -}; +const noNodeGlobalsRuleList = [{ name: "process" }]; const importOrderRules = { "import/order": [ @@ -367,16 +362,34 @@ export default [ "no-console": "off", }, }, + { + files: [ + "packages/playwright-core/src/utils/**/*.ts", + ], + languageOptions: languageOptionsWithTsConfig, + rules: { + "no-restricted-globals": [ + "error", + ...noNodeGlobalsRuleList, + // TODO: reenable once the violations are fixed is utils/isomorphic/*. + // ...noWebGlobalsRules, + ], + ...noFloatingPromisesRules, + ...noBooleanCompareRules, + }, + }, { files: [ "packages/playwright-core/src/server/injected/**/*.ts", - "packages/playwright-core/src/utils/isomorphic/**/*.ts", "packages/playwright-core/src/server/pageBinding.ts", "packages/playwright-core/src/server/storageScript.ts", ], languageOptions: languageOptionsWithTsConfig, rules: { - ...noWebGlobalsRules, + "no-restricted-globals": [ + "error", + ...noWebGlobalsRuleList, + ], ...noFloatingPromisesRules, ...noBooleanCompareRules, }, @@ -385,11 +398,13 @@ export default [ files: [ "packages/playwright-core/src/client/**/*.ts", "packages/playwright-core/src/protocol/**/*.ts", - "packages/playwright-core/src/utils/**/*.ts", ], languageOptions: languageOptionsWithTsConfig, rules: { - ...noNodeGlobalsRules, + "no-restricted-globals": [ + "error", + ...noNodeGlobalsRuleList, + ], ...noFloatingPromisesRules, ...noBooleanCompareRules, }, diff --git a/packages/playwright-core/src/utils/DEPS.list b/packages/playwright-core/src/utils/DEPS.list deleted file mode 100644 index 8a14701d4d..0000000000 --- a/packages/playwright-core/src/utils/DEPS.list +++ /dev/null @@ -1,6 +0,0 @@ -[*] -./ -./isomorphic -../utilsBundle.ts -../zipBundle.ts -../utils/isomorphic \ No newline at end of file diff --git a/packages/playwright-core/src/utils/isomorphic/DEPS.list b/packages/playwright-core/src/utils/isomorphic/DEPS.list new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/playwright-core/src/utils/isomorphic/builtins.ts b/packages/playwright-core/src/utils/isomorphic/builtins.ts index 5bde0b4ac3..5126a988f8 100644 --- a/packages/playwright-core/src/utils/isomorphic/builtins.ts +++ b/packages/playwright-core/src/utils/isomorphic/builtins.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -/* eslint-disable no-restricted-globals */ - // Make sure to update eslint.config.mjs when changing the list of builitins. export type Builtins = { setTimeout: Window['setTimeout'], diff --git a/packages/playwright-core/src/utils/isomorphic/utilityScriptSerializers.ts b/packages/playwright-core/src/utils/isomorphic/utilityScriptSerializers.ts index d419c65f24..8e8a714f05 100644 --- a/packages/playwright-core/src/utils/isomorphic/utilityScriptSerializers.ts +++ b/packages/playwright-core/src/utils/isomorphic/utilityScriptSerializers.ts @@ -178,13 +178,10 @@ export function source(builtins: Builtins) { function serialize(value: any, handleSerializer: (value: any) => HandleOrValue, visitorInfo: VisitorInfo): SerializedValue { if (value && typeof value === 'object') { - // eslint-disable-next-line no-restricted-globals if (typeof globalThis.Window === 'function' && value instanceof globalThis.Window) return 'ref: '; - // eslint-disable-next-line no-restricted-globals if (typeof globalThis.Document === 'function' && value instanceof globalThis.Document) return 'ref: '; - // eslint-disable-next-line no-restricted-globals if (typeof globalThis.Node === 'function' && value instanceof globalThis.Node) return 'ref: '; }