From 9e6ff979dbcbdacbebebd8baf9984c34d856fe2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 12 Nov 2024 13:00:27 +0100 Subject: [PATCH] Migrate to ESLint flat config Flat config is the new config system used by ESLint 9. To make the migration easier, they also added flat config support to ESLint 8. This commit migrates the various ESLint configs in the repository to use the new system, **without** upgrading to ESLint 9 yet. --- .eslintignore | 13 -- .eslintrc | 265 ---------------------- eslint.config.mjs | 436 +++++++++++++++++++++++++++++++++++++ examples/.eslintrc | 11 - examples/node/.eslintrc | 9 - examples/webpack/.eslintrc | 9 - external/.eslintrc | 9 - gulpfile.mjs | 3 - package-lock.json | 18 +- package.json | 3 +- src/core/image_resizer.js | 5 +- src/core/jpeg_stream.js | 5 +- test/.eslintrc | 18 -- test/fuzz/.eslintrc | 9 - test/integration/.eslintrc | 14 -- test/unit/.eslintrc | 10 - 16 files changed, 450 insertions(+), 387 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 eslint.config.mjs delete mode 100644 examples/.eslintrc delete mode 100644 examples/node/.eslintrc delete mode 100644 examples/webpack/.eslintrc delete mode 100644 external/.eslintrc delete mode 100644 test/.eslintrc delete mode 100644 test/fuzz/.eslintrc delete mode 100644 test/integration/.eslintrc delete mode 100644 test/unit/.eslintrc diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index a1279de754437..0000000000000 --- a/.eslintignore +++ /dev/null @@ -1,13 +0,0 @@ -build/ -l10n/ -docs/ -node_modules/ -external/bcmaps/ -external/builder/fixtures/ -external/builder/fixtures_babel/ -external/quickjs/ -external/openjpeg/ -test/tmp/ -test/pdfs/ -web/locale/ -*~/ diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 87715ac69acd0..0000000000000 --- a/.eslintrc +++ /dev/null @@ -1,265 +0,0 @@ -{ - "parserOptions": { - "ecmaVersion": 2022, - "sourceType": "module", - }, - - "plugins": [ - "import", - "json", - "no-unsanitized", - "perfectionist", - "unicorn", - ], - - "extends": [ - "plugin:json/recommended", - "plugin:prettier/recommended" - ], - - "env": { - "browser": true, - "es2022": true, - "worker": true, - }, - - "globals": { - "PDFJSDev": "readonly", - "__non_webpack_import__": "readonly", - }, - - "rules": { - // Plugins - "import/export": "error", - "import/exports-last": "error", - "import/extensions": ["error", "always", { "ignorePackages": true, }], - "import/first": "error", - "import/named": "error", - "import/no-cycle": "error", - "import/no-empty-named-blocks": "error", - "import/no-commonjs": "error", - "import/no-mutable-exports": "error", - "import/no-self-import": "error", - "import/no-unresolved": ["error", { - "ignore": ["display", "pdfjs", "pdfjs-lib", "pdfjs-web", "web", "fluent-bundle", "fluent-dom"], - }], - "no-unsanitized/method": "error", - "no-unsanitized/property": "error", - "perfectionist/sort-exports": "error", - "perfectionist/sort-named-exports": "error", - "unicorn/no-abusive-eslint-disable": "error", - "unicorn/no-array-push-push": "error", - "unicorn/no-instanceof-array": "error", - "unicorn/no-invalid-remove-event-listener": "error", - "unicorn/no-new-buffer": "error", - "unicorn/no-typeof-undefined": ["error", { - "checkGlobalVariables": false, - }], - "unicorn/no-useless-promise-resolve-reject": "error", - "unicorn/no-useless-spread": "error", - "unicorn/prefer-array-find": "error", - "unicorn/prefer-array-flat": "error", - "unicorn/prefer-array-flat-map": "error", - "unicorn/prefer-array-index-of": "error", - "unicorn/prefer-array-some": "error", - "unicorn/prefer-at": "error", - "unicorn/prefer-date-now": "error", - "unicorn/prefer-dom-node-append": "error", - "unicorn/prefer-dom-node-remove": "error", - "unicorn/prefer-includes": "error", - "unicorn/prefer-logical-operator-over-ternary": "error", - "unicorn/prefer-modern-dom-apis": "error", - "unicorn/prefer-modern-math-apis": "error", - "unicorn/prefer-negative-index": "error", - "unicorn/prefer-optional-catch-binding": "error", - "unicorn/prefer-regexp-test": "error", - "unicorn/prefer-string-replace-all": "error", - "unicorn/prefer-string-starts-ends-with": "error", - "unicorn/prefer-ternary": ["error", "only-single-line"], - "unicorn/throw-new-error": "error", - - // Possible errors - "for-direction": "error", - "getter-return": "error", - "no-async-promise-executor": "error", - "no-cond-assign": ["error", "except-parens"], - "no-constant-condition": ["error", { "checkLoops": false, }], - "no-debugger": "error", - "no-dupe-args": "error", - "no-dupe-else-if": "error", - "no-dupe-keys": "error", - "no-duplicate-case": "error", - "no-empty": ["error", { "allowEmptyCatch": true, }], - "no-empty-character-class": "error", - "no-ex-assign": "error", - "no-extra-boolean-cast": "error", - "no-func-assign": "error", - "no-inner-declarations": ["error", "functions"], - "no-invalid-regexp": "error", - "no-irregular-whitespace": "error", - "no-loss-of-precision": "error", - "no-obj-calls": "error", - "no-promise-executor-return": "error", - "no-regex-spaces": "error", - "no-setter-return": "error", - "no-sparse-arrays": "error", - "no-template-curly-in-string": "error", - "no-unexpected-multiline": "error", - "no-unreachable": "error", - "no-unsafe-finally": "error", - "no-unsafe-negation": "error", - "no-unsafe-optional-chaining": ["error", { "disallowArithmeticOperators": true }], - "no-unused-private-class-members": "error", - "use-isnan": ["error", { "enforceForIndexOf": true, }], - "valid-typeof": ["error", { "requireStringLiterals": true, }], - - // Best Practices - "accessor-pairs": ["error", { - "setWithoutGet": true, - "enforceForClassMembers": true, - }], - "consistent-return": "error", - "curly": ["error", "all"], - "default-case-last": "error", - "dot-notation": "error", - "eqeqeq": ["error", "always"], - "grouped-accessor-pairs": ["error", "getBeforeSet"], - "no-alert": "error", - "no-caller": "error", - "no-else-return": "error", - "no-empty-pattern": "error", - "no-eval": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-extra-label": "error", - "no-fallthrough": "error", - "no-floating-decimal": "error", - "no-global-assign": "error", - "no-implied-eval": "error", - "no-iterator": "error", - "no-lone-blocks": "error", - "no-lonely-if": "error", - "no-multi-str": "error", - "no-new": "error", - "no-new-func": "error", - "no-new-symbol": "error", - "no-new-wrappers": "error", - "no-octal-escape": "error", - "no-octal": "error", - "no-redeclare": "error", - "no-return-await": "error", - "no-self-assign": "error", - "no-self-compare": "error", - "no-throw-literal": "error", - "no-unused-expressions": "error", - "no-unused-labels": "error", - "no-useless-call": "error", - "no-useless-catch": "error", - "no-useless-concat": "error", - "no-useless-escape": "error", - "no-useless-return": "error", - "prefer-promise-reject-errors": "error", - "prefer-spread": "error", - "wrap-iife": ["error", "any"], - "yoda": ["error", "never", { - "exceptRange": true, - }], - - // Strict Mode - "strict": ["off", "global"], - - // Variables - "no-delete-var": "error", - "no-label-var": "error", - "no-shadow": "error", - "no-shadow-restricted-names": "error", - "no-undef-init": "error", - "no-undef": ["error", { "typeof": true, }], - "no-unused-vars": ["error", { - "vars": "all", - "args": "none", - }], - "no-use-before-define": ["error", { - "functions": false, - "classes": false, - "variables": false, - }], - - // Stylistic Issues - "lines-between-class-members": ["error", "always"], - "max-len": ["error", { - "code": 1000, - "comments": 80, - "ignoreUrls": true - }], - "new-cap": ["error", { "newIsCap": true, "capIsNew": false, }], - "no-array-constructor": "error", - "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0, "maxBOF": 1, }], - "no-nested-ternary": "error", - "no-new-object": "error", - "no-restricted-syntax": ["error", - { - "selector": "BinaryExpression[operator='instanceof'][right.name='Object']", - "message": "Use `typeof` rather than `instanceof Object`.", - }, - { - "selector": "CallExpression[callee.name='assert'][arguments.length!=2]", - "message": "`assert()` must always be invoked with two arguments.", - }, - { - "selector": "CallExpression[callee.name='isCmd'][arguments.length<2]", - "message": "Use `instanceof Cmd` rather than `isCmd()` with one argument.", - }, - { - "selector": "CallExpression[callee.name='isDict'][arguments.length<2]", - "message": "Use `instanceof Dict` rather than `isDict()` with one argument.", - }, - { - "selector": "CallExpression[callee.name='isName'][arguments.length<2]", - "message": "Use `instanceof Name` rather than `isName()` with one argument.", - }, - { - "selector": "NewExpression[callee.name='Cmd']", - "message": "Use `Cmd.get()` rather than `new Cmd()`.", - }, - { - "selector": "NewExpression[callee.name='Name']", - "message": "Use `Name.get()` rather than `new Name()`.", - }, - { - "selector": "NewExpression[callee.name='Ref']", - "message": "Use `Ref.get()` rather than `new Ref()`.", - }, - ], - "no-unneeded-ternary": "error", - "operator-assignment": "error", - "prefer-exponentiation-operator": "error", - "spaced-comment": ["error", "always", { - "block": { - "balanced": true, - } - }], - - // ECMAScript 6 - "arrow-body-style": ["error", "as-needed"], - "constructor-super": "error", - "no-class-assign": "error", - "no-const-assign": "error", - "no-dupe-class-members": "error", - "no-duplicate-imports": "error", - "no-this-before-super": "error", - "no-useless-computed-key": "error", - "no-useless-constructor": "error", - "no-useless-rename": "error", - "no-var": "error", - "object-shorthand": ["error", "always", { - "avoidQuotes": true, - }], - "prefer-const": "error", - "require-yield": "error", - "sort-imports": ["error", { - "ignoreCase": true, - }], - "template-curly-spacing": ["error", "never"], - }, -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000000000..e0c2b8b014e31 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,436 @@ +import globals from "globals"; + +import import_ from "eslint-plugin-import"; +import jasmine from "eslint-plugin-jasmine"; +import json from "eslint-plugin-json"; +import noUnsanitized from "eslint-plugin-no-unsanitized"; +import perfectionist from "eslint-plugin-perfectionist"; +import prettierRecommended from "eslint-plugin-prettier/recommended"; +import unicorn from "eslint-plugin-unicorn"; + +const jsFiles = folder => { + const prefix = folder === "." ? "" : folder + "/"; + return [prefix + "**/*.js", prefix + "**/*.jsm", prefix + "**/*.mjs"]; +}; + +// Include all files referenced in extensions/chromium/background.js +const chromiumExtensionServiceWorkerFiles = [ + "extensions/chromium/extension-router.js", + "extensions/chromium/options/migration.js", + "extensions/chromium/pdfHandler.js", + "extensions/chromium/preserve-referer.js", + "extensions/chromium/suppress-update.js", + "extensions/chromium/telemetry.js", +]; + +export default [ + { + ignores: [ + "**/build/", + "**/l10n/", + "**/docs/", + "**/node_modules/", + "external/bcmaps/", + "external/builder/fixtures/", + "external/builder/fixtures_babel/", + "external/quickjs/", + "external/openjpeg/", + "test/tmp/", + "test/pdfs/", + "web/locale/", + "**/*~/", + ], + }, + + /* ======================================================================== *\ + Base configuration + \* ======================================================================== */ + + prettierRecommended, + { + files: ["**/*.json"], + ...json.configs.recommended, + }, + { + files: jsFiles("."), + ignores: chromiumExtensionServiceWorkerFiles, + languageOptions: { + globals: globals.browser, + }, + }, + { + files: jsFiles("."), + + plugins: { + import: import_.flatConfigs.recommended.plugins.import, + json, + "no-unsanitized": noUnsanitized, + perfectionist, + unicorn, + }, + + languageOptions: { + globals: { + ...globals.worker, + PDFJSDev: "readonly", + __non_webpack_import__: "readonly", + }, + + ecmaVersion: 2022, + sourceType: "module", + }, + + rules: { + "import/export": "error", + "import/exports-last": "error", + "import/extensions": ["error", "always", { ignorePackages: true }], + "import/first": "error", + "import/named": "error", + "import/no-cycle": "error", + "import/no-empty-named-blocks": "error", + "import/no-commonjs": "error", + "import/no-mutable-exports": "error", + "import/no-self-import": "error", + "import/no-unresolved": [ + "error", + { + ignore: [ + "display", + "pdfjs", + "pdfjs-lib", + "pdfjs-web", + "web", + "fluent-bundle", + "fluent-dom", + ], + }, + ], + "no-unsanitized/method": "error", + "no-unsanitized/property": "error", + "perfectionist/sort-exports": "error", + "perfectionist/sort-named-exports": "error", + "unicorn/no-abusive-eslint-disable": "error", + "unicorn/no-array-push-push": "error", + "unicorn/no-instanceof-array": "error", + "unicorn/no-invalid-remove-event-listener": "error", + "unicorn/no-new-buffer": "error", + "unicorn/no-typeof-undefined": ["error", { checkGlobalVariables: false }], + "unicorn/no-useless-promise-resolve-reject": "error", + "unicorn/no-useless-spread": "error", + "unicorn/prefer-array-find": "error", + "unicorn/prefer-array-flat": "error", + "unicorn/prefer-array-flat-map": "error", + "unicorn/prefer-array-index-of": "error", + "unicorn/prefer-array-some": "error", + "unicorn/prefer-at": "error", + "unicorn/prefer-date-now": "error", + "unicorn/prefer-dom-node-append": "error", + "unicorn/prefer-dom-node-remove": "error", + "unicorn/prefer-includes": "error", + "unicorn/prefer-logical-operator-over-ternary": "error", + "unicorn/prefer-modern-dom-apis": "error", + "unicorn/prefer-modern-math-apis": "error", + "unicorn/prefer-negative-index": "error", + "unicorn/prefer-optional-catch-binding": "error", + "unicorn/prefer-regexp-test": "error", + "unicorn/prefer-string-replace-all": "error", + "unicorn/prefer-string-starts-ends-with": "error", + "unicorn/prefer-ternary": ["error", "only-single-line"], + "unicorn/throw-new-error": "error", + + // Possible errors + "for-direction": "error", + "getter-return": "error", + "no-async-promise-executor": "error", + "no-cond-assign": ["error", "except-parens"], + "no-constant-condition": ["error", { checkLoops: false }], + "no-debugger": "error", + "no-dupe-args": "error", + "no-dupe-else-if": "error", + "no-dupe-keys": "error", + "no-duplicate-case": "error", + "no-empty": ["error", { allowEmptyCatch: true }], + "no-empty-character-class": "error", + "no-ex-assign": "error", + "no-extra-boolean-cast": "error", + "no-func-assign": "error", + "no-inner-declarations": ["error", "functions"], + "no-invalid-regexp": "error", + "no-irregular-whitespace": "error", + "no-loss-of-precision": "error", + "no-obj-calls": "error", + "no-promise-executor-return": "error", + "no-regex-spaces": "error", + "no-setter-return": "error", + "no-sparse-arrays": "error", + "no-template-curly-in-string": "error", + "no-unexpected-multiline": "error", + "no-unreachable": "error", + "no-unsafe-finally": "error", + "no-unsafe-negation": "error", + "no-unsafe-optional-chaining": [ + "error", + { disallowArithmeticOperators: true }, + ], + "no-unused-private-class-members": "error", + "use-isnan": ["error", { enforceForIndexOf: true }], + "valid-typeof": ["error", { requireStringLiterals: true }], + + // Best Practices + "accessor-pairs": [ + "error", + { setWithoutGet: true, enforceForClassMembers: true }, + ], + "consistent-return": "error", + curly: ["error", "all"], + "default-case-last": "error", + "dot-notation": "error", + eqeqeq: ["error", "always"], + "grouped-accessor-pairs": ["error", "getBeforeSet"], + "no-alert": "error", + "no-caller": "error", + "no-else-return": "error", + "no-empty-pattern": "error", + "no-eval": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-fallthrough": "error", + "no-floating-decimal": "error", + "no-global-assign": "error", + "no-implied-eval": "error", + "no-iterator": "error", + "no-lone-blocks": "error", + "no-lonely-if": "error", + "no-multi-str": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-symbol": "error", + "no-new-wrappers": "error", + "no-octal-escape": "error", + "no-octal": "error", + "no-redeclare": "error", + "no-return-await": "error", + "no-self-assign": "error", + "no-self-compare": "error", + "no-throw-literal": "error", + "no-unused-expressions": "error", + "no-unused-labels": "error", + "no-useless-call": "error", + "no-useless-catch": "error", + "no-useless-concat": "error", + "no-useless-escape": "error", + "no-useless-return": "error", + "prefer-promise-reject-errors": "error", + "prefer-spread": "error", + "wrap-iife": ["error", "any"], + yoda: ["error", "never", { exceptRange: true }], + + // Strict Mode + strict: ["off", "global"], + + // Variables + "no-delete-var": "error", + "no-label-var": "error", + "no-shadow": "error", + "no-shadow-restricted-names": "error", + "no-undef-init": "error", + "no-undef": ["error", { typeof: true }], + "no-unused-vars": ["error", { vars: "all", args: "none" }], + "no-use-before-define": [ + "error", + { functions: false, classes: false, variables: false }, + ], + + // Stylistic Issues + "lines-between-class-members": ["error", "always"], + "max-len": ["error", { code: 1000, comments: 80, ignoreUrls: true }], + "new-cap": ["error", { newIsCap: true, capIsNew: false }], + "no-array-constructor": "error", + "no-multiple-empty-lines": ["error", { max: 1, maxEOF: 0, maxBOF: 1 }], + "no-nested-ternary": "error", + "no-new-object": "error", + "no-restricted-syntax": [ + "error", + { + selector: + "BinaryExpression[operator='instanceof'][right.name='Object']", + message: "Use `typeof` rather than `instanceof Object`.", + }, + { + selector: "CallExpression[callee.name='assert'][arguments.length!=2]", + message: "`assert()` must always be invoked with two arguments.", + }, + { + selector: "CallExpression[callee.name='isCmd'][arguments.length<2]", + message: + "Use `instanceof Cmd` rather than `isCmd()` with one argument.", + }, + { + selector: "CallExpression[callee.name='isDict'][arguments.length<2]", + message: + "Use `instanceof Dict` rather than `isDict()` with one argument.", + }, + { + selector: "CallExpression[callee.name='isName'][arguments.length<2]", + message: + "Use `instanceof Name` rather than `isName()` with one argument.", + }, + { + selector: "NewExpression[callee.name='Cmd']", + message: "Use `Cmd.get()` rather than `new Cmd()`.", + }, + { + selector: "NewExpression[callee.name='Name']", + message: "Use `Name.get()` rather than `new Name()`.", + }, + { + selector: "NewExpression[callee.name='Ref']", + message: "Use `Ref.get()` rather than `new Ref()`.", + }, + ], + "no-unneeded-ternary": "error", + "operator-assignment": "error", + "prefer-exponentiation-operator": "error", + "spaced-comment": ["error", "always", { block: { balanced: true } }], + + // ECMAScript 6 + "arrow-body-style": ["error", "as-needed"], + "constructor-super": "error", + "no-class-assign": "error", + "no-const-assign": "error", + "no-dupe-class-members": "error", + "no-duplicate-imports": "error", + "no-this-before-super": "error", + "no-useless-computed-key": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-var": "error", + "object-shorthand": ["error", "always", { avoidQuotes: true }], + "prefer-const": "error", + "require-yield": "error", + "sort-imports": ["error", { ignoreCase: true }], + "template-curly-spacing": ["error", "never"], + }, + }, + + /* ======================================================================== *\ + Test-specific rules + \* ======================================================================== */ + + { + files: jsFiles("test"), + + plugins: { jasmine }, + + languageOptions: { + globals: { + ...globals.node, + ...globals.jasmine, + }, + }, + rules: { + ...jasmine.configs.recommended.rules, + "jasmine/new-line-before-expect": "off", + "jasmine/new-line-between-declarations": "off", + "jasmine/no-focused-tests": "error", + "jasmine/no-pending-tests": "off", + "jasmine/no-spec-dupes": ["error", "branch"], + "jasmine/no-suite-dupes": ["error", "branch"], + "jasmine/prefer-jasmine-matcher": "off", + "jasmine/prefer-toHaveBeenCalledWith": "off", + }, + }, + { + files: jsFiles("test/fuzz"), + rules: { + "import/no-unresolved": [ + "error", + { ignore: [".*/build/image_decoders/.*"] }, + ], + }, + }, + { + files: jsFiles("test/unit"), + rules: { + "import/no-unresolved": ["error", { ignore: ["pdfjs/"] }], + }, + }, + { + files: jsFiles("test/integration"), + rules: { + "no-restricted-syntax": [ + "error", + { + selector: "CallExpression[callee.name='waitForTimeout']", + message: + "`waitForTimeout` can cause intermittent failures and should not be used (see issue #17656 for replacements).", + }, + ], + }, + }, + + /* ======================================================================== *\ + External libraries + \* ======================================================================== */ + + { + files: jsFiles("external"), + + languageOptions: { globals: globals.node }, + }, + + /* ======================================================================== *\ + Examples + \* ======================================================================== */ + + { + files: jsFiles("examples"), + + languageOptions: { + globals: { + pdfjsImageDecoders: false, + pdfjsLib: false, + pdfjsViewer: false, + }, + }, + }, + { + files: [...jsFiles("examples/node"), ...jsFiles("examples/webpack")], + + languageOptions: { globals: globals.node }, + }, + + /* ======================================================================== *\ + Chromium extension + \* ======================================================================== */ + + { + files: jsFiles("extensions/chromium"), + + languageOptions: { + globals: globals.webextensions, + sourceType: "script", + }, + + rules: { + "no-var": "off", + }, + }, + { + files: chromiumExtensionServiceWorkerFiles, + + languageOptions: { + globals: globals.serviceworker, + sourceType: "script", + }, + }, + + /* ======================================================================== *\ + Other + \* ======================================================================== */ + { + files: ["gulpfile.mjs"], + languageOptions: { globals: globals.node }, + }, +]; diff --git a/examples/.eslintrc b/examples/.eslintrc deleted file mode 100644 index 433abdbfab2c4..0000000000000 --- a/examples/.eslintrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": [ - "../.eslintrc" - ], - - "globals": { - "pdfjsImageDecoders": false, - "pdfjsLib": false, - "pdfjsViewer": false, - }, -} diff --git a/examples/node/.eslintrc b/examples/node/.eslintrc deleted file mode 100644 index 46f120c21a4f5..0000000000000 --- a/examples/node/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": [ - "../.eslintrc" - ], - - "env": { - "node": true, - }, -} diff --git a/examples/webpack/.eslintrc b/examples/webpack/.eslintrc deleted file mode 100644 index 46f120c21a4f5..0000000000000 --- a/examples/webpack/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": [ - "../.eslintrc" - ], - - "env": { - "node": true, - }, -} diff --git a/external/.eslintrc b/external/.eslintrc deleted file mode 100644 index e3523dce526ed..0000000000000 --- a/external/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": [ - ../.eslintrc - ], - - "env": { - "node": true, - }, -} diff --git a/gulpfile.mjs b/gulpfile.mjs index ff4802cc1f785..7c0460d0f5c78 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-env node */ import { babelPluginPDFJSPreprocessor, @@ -1956,8 +1955,6 @@ gulp.task("lint", function (done) { // Ensure that we lint the Firefox specific *.jsm files too. const esLintOptions = [ "node_modules/eslint/bin/eslint", - "--ext", - ".js,.jsm,.mjs,.json", ".", "--report-unused-disable-directives", ]; diff --git a/package-lock.json b/package-lock.json index dc1270cb909f1..c059aba741a2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,11 +24,12 @@ "eslint": "^8.57.1", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jasmine": "^4.2.2", - "eslint-plugin-json": "^3.1.0", + "eslint-plugin-json": "^4.0.1", "eslint-plugin-no-unsanitized": "^4.1.2", "eslint-plugin-perfectionist": "^3.9.1", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-unicorn": "^56.0.0", + "globals": "^15.12.0", "gulp": "^5.0.0", "gulp-cli": "^3.0.0", "gulp-postcss": "^10.0.0", @@ -5454,16 +5455,17 @@ } }, "node_modules/eslint-plugin-json": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-json/-/eslint-plugin-json-3.1.0.tgz", - "integrity": "sha512-MrlG2ynFEHe7wDGwbUuFPsaT2b1uhuEFhJ+W1f1u+1C2EkXmTYJp4B1aAdQQ8M+CC3t//N/oRKiIVw14L2HR1g==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-json/-/eslint-plugin-json-4.0.1.tgz", + "integrity": "sha512-3An5ISV5dq/kHfXdNyY5TUe2ONC3yXFSkLX2gu+W8xAhKhfvrRvkSAeKXCxZqZ0KJLX15ojBuLPyj+UikQMkOA==", "dev": true, + "license": "MIT", "dependencies": { "lodash": "^4.17.21", "vscode-json-languageservice": "^4.1.6" }, "engines": { - "node": ">=12.0" + "node": ">=18.0" } }, "node_modules/eslint-plugin-no-unsanitized": { @@ -6967,9 +6969,9 @@ } }, "node_modules/globals": { - "version": "15.10.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-15.10.0.tgz", - "integrity": "sha512-tqFIbz83w4Y5TCbtgjZjApohbuh7K9BxGYFm7ifwDR240tvdb7P9x+/9VvUKlmkPoiknoJtanI8UOrqxS3a7lQ==", + "version": "15.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.12.0.tgz", + "integrity": "sha512-1+gLErljJFhbOVyaetcwJiJ4+eLe45S2E7P5UiZ9xGfeq3ATQf5DOv9G7MH3gGbKQLkzmNh2DxfZwLdw+j6oTQ==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index de2ae98c7ac9e..4a1a069af5e4f 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,12 @@ "eslint": "^8.57.1", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jasmine": "^4.2.2", - "eslint-plugin-json": "^3.1.0", + "eslint-plugin-json": "^4.0.1", "eslint-plugin-no-unsanitized": "^4.1.2", "eslint-plugin-perfectionist": "^3.9.1", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-unicorn": "^56.0.0", + "globals": "^15.12.0", "gulp": "^5.0.0", "gulp-cli": "^3.0.0", "gulp-postcss": "^10.0.0", diff --git a/src/core/image_resizer.js b/src/core/image_resizer.js index 8652a828b60b2..a21e175ebe6f3 100644 --- a/src/core/image_resizer.js +++ b/src/core/image_resizer.js @@ -48,11 +48,9 @@ class ImageResizer { return shadow( this, "canUseImageDecoder", - // eslint-disable-next-line no-undef this.#isChrome || typeof ImageDecoder === "undefined" ? Promise.resolve(false) - : // eslint-disable-next-line no-undef - ImageDecoder.isTypeSupported("image/bmp") + : ImageDecoder.isTypeSupported("image/bmp") ); } @@ -185,7 +183,6 @@ class ImageResizer { let decoder, imagePromise; if (await ImageResizer.canUseImageDecoder) { - // eslint-disable-next-line no-undef decoder = new ImageDecoder({ data, type: "image/bmp", diff --git a/src/core/jpeg_stream.js b/src/core/jpeg_stream.js index 6cf2de2cba764..f25ae4e40b2b7 100644 --- a/src/core/jpeg_stream.js +++ b/src/core/jpeg_stream.js @@ -36,11 +36,9 @@ class JpegStream extends DecodeStream { return shadow( this, "canUseImageDecoder", - // eslint-disable-next-line no-undef typeof ImageDecoder === "undefined" ? Promise.resolve(false) - : // eslint-disable-next-line no-undef - ImageDecoder.isTypeSupported("image/jpeg") + : ImageDecoder.isTypeSupported("image/jpeg") ); } @@ -163,7 +161,6 @@ class JpegStream extends DecodeStream { if (!JpegImage.canUseImageDecoder(data, jpegOptions.colorTransform)) { return null; } - // eslint-disable-next-line no-undef decoder = new ImageDecoder({ data, type: "image/jpeg", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 4f371e4248581..0000000000000 --- a/test/.eslintrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "plugins": ["jasmine"], - "extends": ["../.eslintrc", "plugin:jasmine/recommended"], - "env": { - "node": true, - "jasmine": true - }, - "rules": { - "jasmine/new-line-before-expect": "off", - "jasmine/new-line-between-declarations": "off", - "jasmine/no-focused-tests": "error", - "jasmine/no-pending-tests": "off", - "jasmine/no-spec-dupes": ["error", "branch"], - "jasmine/no-suite-dupes": ["error", "branch"], - "jasmine/prefer-jasmine-matcher": "off", - "jasmine/prefer-toHaveBeenCalledWith": "off" - } -} diff --git a/test/fuzz/.eslintrc b/test/fuzz/.eslintrc deleted file mode 100644 index 7d611b5c61737..0000000000000 --- a/test/fuzz/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": [ - "../.eslintrc" - ], - - "rules": { - "import/no-unresolved": ["error", { "ignore": [".*/build/image_decoders/.*"] }], - }, -} diff --git a/test/integration/.eslintrc b/test/integration/.eslintrc deleted file mode 100644 index 8aedbe37f89f8..0000000000000 --- a/test/integration/.eslintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": [ - "../.eslintrc" - ], - - "rules": { - "no-restricted-syntax": ["error", - { - "selector": "CallExpression[callee.name='waitForTimeout']", - "message": "`waitForTimeout` can cause intermittent failures and should not be used (see issue #17656 for replacements).", - }, - ], - }, -} diff --git a/test/unit/.eslintrc b/test/unit/.eslintrc deleted file mode 100644 index 69af6d92d1199..0000000000000 --- a/test/unit/.eslintrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": [ - "../.eslintrc" - ], - - "rules": { - // Plugins - "import/no-unresolved": ["error", { "ignore": ["pdfjs/"] }], - }, -}