From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../lib/configs/browser-test.js | 15 ++++++ .../lib/configs/chrome-test.js | 1 + .../lib/configs/general-test.js | 17 ++++++ .../lib/configs/recommended.js | 60 ++++++++++------------ .../lib/configs/xpcshell-test.js | 11 ++++ 5 files changed, 72 insertions(+), 32 deletions(-) create mode 100644 tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.js (limited to 'tools/lint/eslint/eslint-plugin-mozilla/lib/configs') diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js index 08747a3f88..f21cd8d15a 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.js @@ -57,6 +57,19 @@ module.exports = { waitForFocus: false, }, + overrides: [ + { + // Some directories have multiple kinds of tests, and some rules + // don't work well for plain mochitests, so disable those. + files: ["*.html", "*.xhtml"], + // plain/chrome mochitests don't automatically include Assert, so + // autofixing `ok()` to Assert.something is bad. + rules: { + "mozilla/no-comparison-or-assignment-inside-ok": "off", + }, + }, + ], + plugins: ["mozilla", "@microsoft/sdl"], rules: { @@ -66,6 +79,7 @@ module.exports = { { exceptions: [ "^http:\\/\\/mochi\\.test?.*", + "^http:\\/\\/mochi\\.xorigin-test?.*", "^http:\\/\\/localhost?.*", "^http:\\/\\/127\\.0\\.0\\.1?.*", // Exempt xmlns urls @@ -83,6 +97,7 @@ module.exports = { "mozilla/mark-test-function-used": "error", "mozilla/no-addtask-setup": "error", "mozilla/no-arbitrary-setTimeout": "error", + "mozilla/no-comparison-or-assignment-inside-ok": "error", "mozilla/no-redeclare-with-import-autofix": [ "error", { errorForNonImports: false }, diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js index 3b5bbc06e2..a236118909 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.js @@ -39,6 +39,7 @@ module.exports = { { exceptions: [ "^http:\\/\\/mochi\\.test?.*", + "^http:\\/\\/mochi\\.xorigin-test?.*", "^http:\\/\\/localhost?.*", "^http:\\/\\/127\\.0\\.0\\.1?.*", // Exempt xmlns urls diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.js new file mode 100644 index 0000000000..2ed45ff621 --- /dev/null +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.js @@ -0,0 +1,17 @@ +// Parent config file for all xpcshell files. +"use strict"; + +module.exports = { + rules: { + "mozilla/import-headjs-globals": "error", + "mozilla/mark-test-function-used": "error", + "mozilla/no-arbitrary-setTimeout": "error", + + // Bug 1883707 - Turn off no-console in tests at the moment. + "no-console": "off", + // Turn off no-unsanitized for tests, as we do want to be able to use + // these for testing. + "no-unsanitized/method": "off", + "no-unsanitized/property": "off", + }, +}; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js index db7a0dc731..c4d28594b5 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js @@ -18,6 +18,14 @@ * require-atomic-updates - bug 1551829. * - This generates too many false positives that are not easy to work * around, and false positives seem to be inherent in the rule. + * no-inner-declarations - bug 1487642. + * - Would be interested if this could apply to just vars, but at the moment + * it doesn't. + * max-depth + * - Don't enforce the maximum depth that blocks can be nested. The + * complexity rule is a better rule to check this. + * no-useless-escape - bug 1881262. + * - This doesn't reveal any actual errors, and is a lot of work to address. */ module.exports = { env: { @@ -42,7 +50,7 @@ module.exports = { // environment for them. env: { browser: false, - "mozilla/jsm": true, + "mozilla/sysmjs": true, }, files: ["**/*.sys.mjs", "**/*.jsm"], rules: { @@ -149,10 +157,6 @@ module.exports = { // Functions must always return something or nothing "consistent-return": "error", - // XXX This rule line should be removed to enable it. See bug 1487642. - // Require super() calls in constructors - "constructor-super": "off", - // Require braces around blocks that start a new line curly: ["error", "all"], @@ -163,14 +167,6 @@ module.exports = { // No credentials submitted with fetch calls "fetch-options/no-fetch-credentials": "off", - // XXX This rule line should be removed to enable it. See bug 1487642. - // Enforce return statements in getters - "getter-return": "off", - - // Don't enforce the maximum depth that blocks can be nested. The complexity - // rule is a better rule to check this. - "max-depth": "off", - // Maximum depth callbacks can be nested. "max-nested-callbacks": ["error", 10], @@ -212,28 +208,24 @@ module.exports = { // Disallow use of arguments.caller or arguments.callee. "no-caller": "error", - // XXX Bug 1487642 - decide if we want to enable this or not. - // Disallow lexical declarations in case clauses - "no-case-declarations": "off", - - // XXX Bug 1487642 - decide if we want to enable this or not. - // Disallow the use of console - "no-console": "off", + // Disallow the use of console, except for errors and warnings. + "no-console": ["error", { allow: ["createInstance", "error", "warn"] }], // Disallows expressions where the operation doesn't affect the value. // TODO: This is enabled by default in ESLint's v9 recommended configuration. "no-constant-binary-expression": "error", - // XXX Bug 1487642 - decide if we want to enable this or not. - // Disallow constant expressions in conditions - "no-constant-condition": "off", - // If an if block ends with a return no need for an else block "no-else-return": "error", // No empty statements "no-empty": ["error", { allowEmptyCatch: true }], + // Disallow empty static blocks. + // This rule will be a recommended rule in ESLint v9 so may be removed + // when we upgrade to that. + "no-empty-static-block": "error", + // Disallow eval and setInteral/setTimeout with strings "no-eval": "error", @@ -256,8 +248,7 @@ module.exports = { // Disallow eval and setInteral/setTimeout with strings "no-implied-eval": "error", - // This has been superseded since we're using ES6. - // Disallow variable or function declarations in nested blocks + // See explicit decisions at top of file. "no-inner-declarations": "off", // Disallow the use of the __iterator__ property @@ -275,6 +266,11 @@ module.exports = { // Nested ternary statements are confusing "no-nested-ternary": "error", + // Disallow new operators with global non-constructor functions. + // This rule will be a recommended rule in ESLint v9 so may be removed + // when we upgrade to that. + "no-new-native-nonconstructor": "error", + // Disallow use of new wrappers "no-new-wrappers": "error", @@ -312,6 +308,11 @@ module.exports = { "no-unsanitized/method": "error", "no-unsanitized/property": "error", + // Disallow unused private class members. + // This rule will be a recommended rule in ESLint v9 so may be removed + // when we upgrade to that. + "no-unused-private-class-members": "error", + // No declaring variables that are never used "no-unused-vars": [ "error", @@ -331,8 +332,7 @@ module.exports = { // lines) "no-useless-concat": "error", - // XXX Bug 1487642 - decide if we want to enable this or not. - // Disallow unnecessary escape characters + // See explicit decisions at top of file. "no-useless-escape": "off", // Disallow redundant return statements @@ -343,9 +343,5 @@ module.exports = { // This may conflict with prettier, so turn it off. "prefer-arrow-callback": "off", - - // XXX Bug 1487642 - decide if we want to enable this or not. - // Require generator functions to contain yield - "require-yield": "off", }, }; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js index 6a4d572911..d3c983999a 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js @@ -9,6 +9,16 @@ module.exports = { }, overrides: [ + { + // Some directories have multiple kinds of tests, and some rules + // don't work well for plain mochitests, so disable those. + files: ["*.html", "*.xhtml"], + // plain/chrome mochitests don't automatically include Assert, so + // autofixing `ok()` to Assert.something is bad. + rules: { + "mozilla/no-comparison-or-assignment-inside-ok": "off", + }, + }, { // If it is a head file, we turn off global unused variable checks, as it // would require searching the other test files to know if they are used or not. @@ -44,6 +54,7 @@ module.exports = { "mozilla/import-headjs-globals": "error", "mozilla/mark-test-function-used": "error", "mozilla/no-arbitrary-setTimeout": "error", + "mozilla/no-comparison-or-assignment-inside-ok": "error", "mozilla/no-useless-run-test": "error", "no-shadow": "error", // Turn off no-unsanitized for tests, as we do want to be able to use -- cgit v1.2.3