Bug 1883371 - Enable ESLint rule no-console on production code. r=mossop,webcompat-reviewers,devtools-reviewers,omc-reviewers,twisniewski,nchevobbe,aminomancer

Allow for console.error, console.warn and console.createInstance, but fail for everything else.

Differential Revision: https://phabricator.services.mozilla.com/D203456
This commit is contained in:
Mark Banner 2024-03-05 16:56:57 +00:00
parent 5ee6fc544c
commit 4f1d29d324
18 changed files with 68 additions and 28 deletions

View File

@ -450,6 +450,60 @@ module.exports = {
],
rules: { "no-constant-condition": "warn" },
},
{
files: [
"browser/actors/AboutPocketParent.sys.mjs",
"browser/actors/SpeechDispatcherParent.sys.mjs",
"browser/base/content/browser-sync.js",
"browser/base/content/tabbrowser.js",
"browser/components/BrowserContentHandler.sys.mjs",
"browser/components/enterprisepolicies/Policies.sys.mjs",
"browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs",
"browser/components/messagepreview/actors/AboutMessagePreviewParent.sys.mjs",
"browser/components/migration/ChromeMigrationUtils.sys.mjs",
"browser/components/migration/SafariProfileMigrator.sys.mjs",
"browser/components/places/content/places-tree.js",
"browser/components/places/content/treeView.js",
"browser/extensions/screenshots/build/shot.js",
"browser/extensions/webcompat/**",
"browser/modules/BackgroundTask_*.sys.mjs",
"browser/themes/BuiltInThemes.sys.mjs",
"browser/tools/mozscreenshots/mozscreenshots/extension/lib/mozscreenshots-script.js",
"browser/tools/mozscreenshots/mozscreenshots/extension/lib/mozscreenshots.html",
"devtools/client/**",
"devtools/server/actors/inspector/css-logic.js",
"devtools/shared/compatibility/bin/update.js",
"devtools/shared/discovery/discovery.js",
"devtools/shared/protocol/Front.js",
"dom/media/webvtt/update-webvtt.js",
"gfx/layers/layerviewer/layerTreeView.js",
"layout/tools/reftest/reftest-analyzer.xhtml",
"mobile/android/geckoview/src/androidTest/**",
"services/automation/ServicesAutomation.sys.mjs",
"services/settings/RemoteSettings.worker.mjs",
"services/sync/modules/SyncDisconnect.sys.mjs",
"taskcluster/docker/index-task/insert-indexes.js",
"testing/**",
"toolkit/actors/NetErrorParent.sys.mjs",
"toolkit/components/aboutcheckerboard/content/aboutCheckerboard.js",
"toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs",
"toolkit/components/backgroundtasks/BackgroundTasksTestUtils.sys.mjs",
"toolkit/components/credentialmanagement/IdentityCredentialPromptService.sys.mjs",
"toolkit/components/ml/content/MLEngine.worker.mjs",
"toolkit/components/telemetry/pings/BackgroundTask_pingsender.sys.mjs",
"toolkit/components/translations/actors/TranslationsParent.sys.mjs",
"toolkit/components/translations/content/translations-engine.worker.js",
"toolkit/components/xulstore/XULStore.sys.mjs",
"toolkit/content/aboutTelemetry.js",
"toolkit/content/customElements.js",
"toolkit/content/widgets/dialog.js",
"toolkit/content/widgets/menu.js",
"toolkit/mozapps/update/BackgroundUpdate.sys.mjs",
],
rules: {
"no-console": "off",
},
},
{
// Bug 877389 - Gradually migrate from Cu.reportError to console.error.
// Enable these as we fix more areas.

View File

@ -130,7 +130,6 @@ module.exports = {
"max-statements": ["error", 50],
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
"no-alert": "error",
"no-console": ["error", { allow: ["error"] }],
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-eq-null": "error",

View File

@ -100,7 +100,6 @@ module.exports = {
"max-statements": ["error", 50],
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
"no-alert": "error",
"no-console": ["error", { allow: ["error"] }],
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-eq-null": "error",

View File

@ -129,7 +129,6 @@ module.exports = {
"max-statements": ["error", 50],
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
"no-alert": "error",
"no-console": ["error", { allow: ["error"] }],
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-eq-null": "error",

View File

@ -27,9 +27,6 @@ module.exports = {
// Maximum depth callbacks can be nested.
"max-nested-callbacks": ["error", 4],
// Allow the console API aside from console.log.
"no-console": ["error", { allow: ["error", "info", "trace", "warn"] }],
// Disallow use of multiline strings (use template strings instead).
"no-multi-str": "error",

View File

@ -1,7 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
/* eslint-disable no-console */
/* eslint-disable no-unused-expressions */
"use strict";
console.log(null);

View File

@ -130,8 +130,6 @@ module.exports = {
"no-catch-shadow": 2,
// Disallow assignment in conditional expressions.
"no-cond-assign": 2,
// Allow using the console API.
"no-console": 0,
// Allow use of the continue statement.
"no-continue": 0,
// Disallow control characters in regular expressions.

View File

@ -19,9 +19,6 @@ module.exports = {
// case/default clauses.
"no-case-declarations": "error",
// Disallow use of the console API.
"no-console": ["error", { allow: ["error"] }],
// Disallow constant expressions in conditions (except for loops).
"no-constant-condition": ["error", { checkLoops: false }],

View File

@ -24,9 +24,6 @@ module.exports = {
// case/default clauses.
"no-case-declarations": "error",
// Disallow use of the console API.
"no-console": "error",
// Disallow constant expressions in conditions (except for loops).
"no-constant-condition": ["error", { checkLoops: false }],

View File

@ -120,9 +120,6 @@ module.exports = {
// Allow use of bitwise operators.
"no-bitwise": "off",
// Disallow using the console API.
"no-console": "error",
// Allow use of the continue statement.
"no-continue": "off",

View File

@ -6,8 +6,4 @@
module.exports = {
extends: "../../components/extensions/.eslintrc.js",
rules: {
"no-console": "off",
},
};

View File

@ -34,7 +34,7 @@ function generateESMURIMap(jsm_map) {
function isESMifiedSlow(resourceURI) {
if (!(resourceURI in uri_map)) {
console.log(`WARNING: Unknown module: ${resourceURI}`);
console.warn(`WARNING: Unknown module: ${resourceURI}`);
return { result: false, jsms: [] };
}

View File

@ -8,7 +8,7 @@
function warnForPath(inputFile, path, message) {
const loc = path.node.loc;
console.log(
console.warn(
`WARNING: ${inputFile}:${loc.start.line}:${loc.start.column} : ${message}`
);
}

View File

@ -7,6 +7,8 @@ module.exports = {
"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",

View File

@ -208,9 +208,8 @@ 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 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.

View File

@ -511,7 +511,7 @@ module.exports = {
manifest,
});
} catch (e) {
console.log(
console.error(
"TOML ERROR: " +
e.message +
" @line: " +

View File

@ -8,6 +8,9 @@
* mach itself.
*/
// This is a non-production file that needs to log.
/* eslint-disable no-console */
"use strict";
var mocha = require("mocha");

View File

@ -4,6 +4,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// This is a non-production script.
/* eslint-disable no-console */
"use strict";
var fs = require("fs");