Skip to content

Commit 4f1d29d

Browse files
committed
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
1 parent 5ee6fc5 commit 4f1d29d

File tree

18 files changed

+68
-28
lines changed

18 files changed

+68
-28
lines changed

.eslintrc.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,60 @@ module.exports = {
450450
],
451451
rules: { "no-constant-condition": "warn" },
452452
},
453+
{
454+
files: [
455+
"browser/actors/AboutPocketParent.sys.mjs",
456+
"browser/actors/SpeechDispatcherParent.sys.mjs",
457+
"browser/base/content/browser-sync.js",
458+
"browser/base/content/tabbrowser.js",
459+
"browser/components/BrowserContentHandler.sys.mjs",
460+
"browser/components/enterprisepolicies/Policies.sys.mjs",
461+
"browser/components/messagepreview/actors/AboutMessagePreviewChild.sys.mjs",
462+
"browser/components/messagepreview/actors/AboutMessagePreviewParent.sys.mjs",
463+
"browser/components/migration/ChromeMigrationUtils.sys.mjs",
464+
"browser/components/migration/SafariProfileMigrator.sys.mjs",
465+
"browser/components/places/content/places-tree.js",
466+
"browser/components/places/content/treeView.js",
467+
"browser/extensions/screenshots/build/shot.js",
468+
"browser/extensions/webcompat/**",
469+
"browser/modules/BackgroundTask_*.sys.mjs",
470+
"browser/themes/BuiltInThemes.sys.mjs",
471+
"browser/tools/mozscreenshots/mozscreenshots/extension/lib/mozscreenshots-script.js",
472+
"browser/tools/mozscreenshots/mozscreenshots/extension/lib/mozscreenshots.html",
473+
"devtools/client/**",
474+
"devtools/server/actors/inspector/css-logic.js",
475+
"devtools/shared/compatibility/bin/update.js",
476+
"devtools/shared/discovery/discovery.js",
477+
"devtools/shared/protocol/Front.js",
478+
"dom/media/webvtt/update-webvtt.js",
479+
"gfx/layers/layerviewer/layerTreeView.js",
480+
"layout/tools/reftest/reftest-analyzer.xhtml",
481+
"mobile/android/geckoview/src/androidTest/**",
482+
"services/automation/ServicesAutomation.sys.mjs",
483+
"services/settings/RemoteSettings.worker.mjs",
484+
"services/sync/modules/SyncDisconnect.sys.mjs",
485+
"taskcluster/docker/index-task/insert-indexes.js",
486+
"testing/**",
487+
"toolkit/actors/NetErrorParent.sys.mjs",
488+
"toolkit/components/aboutcheckerboard/content/aboutCheckerboard.js",
489+
"toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs",
490+
"toolkit/components/backgroundtasks/BackgroundTasksTestUtils.sys.mjs",
491+
"toolkit/components/credentialmanagement/IdentityCredentialPromptService.sys.mjs",
492+
"toolkit/components/ml/content/MLEngine.worker.mjs",
493+
"toolkit/components/telemetry/pings/BackgroundTask_pingsender.sys.mjs",
494+
"toolkit/components/translations/actors/TranslationsParent.sys.mjs",
495+
"toolkit/components/translations/content/translations-engine.worker.js",
496+
"toolkit/components/xulstore/XULStore.sys.mjs",
497+
"toolkit/content/aboutTelemetry.js",
498+
"toolkit/content/customElements.js",
499+
"toolkit/content/widgets/dialog.js",
500+
"toolkit/content/widgets/menu.js",
501+
"toolkit/mozapps/update/BackgroundUpdate.sys.mjs",
502+
],
503+
rules: {
504+
"no-console": "off",
505+
},
506+
},
453507
{
454508
// Bug 877389 - Gradually migrate from Cu.reportError to console.error.
455509
// Enable these as we fix more areas.

browser/components/aboutwelcome/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ module.exports = {
130130
"max-statements": ["error", 50],
131131
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
132132
"no-alert": "error",
133-
"no-console": ["error", { allow: ["error"] }],
134133
"no-div-regex": "error",
135134
"no-duplicate-imports": "error",
136135
"no-eq-null": "error",

browser/components/asrouter/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ module.exports = {
100100
"max-statements": ["error", 50],
101101
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
102102
"no-alert": "error",
103-
"no-console": ["error", { allow: ["error"] }],
104103
"no-div-regex": "error",
105104
"no-duplicate-imports": "error",
106105
"no-eq-null": "error",

browser/components/newtab/.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ module.exports = {
129129
"max-statements": ["error", 50],
130130
"new-cap": ["error", { newIsCap: true, capIsNew: false }],
131131
"no-alert": "error",
132-
"no-console": ["error", { allow: ["error"] }],
133132
"no-div-regex": "error",
134133
"no-duplicate-imports": "error",
135134
"no-eq-null": "error",

browser/extensions/report-site-issue/.eslintrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ module.exports = {
2727
// Maximum depth callbacks can be nested.
2828
"max-nested-callbacks": ["error", 4],
2929

30-
// Allow the console API aside from console.log.
31-
"no-console": ["error", { allow: ["error", "info", "trace", "warn"] }],
32-
3330
// Disallow use of multiline strings (use template strings instead).
3431
"no-multi-str": "error",
3532

browser/extensions/report-site-issue/test/browser/test.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8">
33
<script>
4-
/* eslint-disable no-console */
54
/* eslint-disable no-unused-expressions */
65
"use strict";
76
console.log(null);

devtools/client/debugger/src/.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ module.exports = {
130130
"no-catch-shadow": 2,
131131
// Disallow assignment in conditional expressions.
132132
"no-cond-assign": 2,
133-
// Allow using the console API.
134-
"no-console": 0,
135133
// Allow use of the continue statement.
136134
"no-continue": 0,
137135
// Disallow control characters in regular expressions.

security/.eslintrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ module.exports = {
1919
// case/default clauses.
2020
"no-case-declarations": "error",
2121

22-
// Disallow use of the console API.
23-
"no-console": ["error", { allow: ["error"] }],
24-
2522
// Disallow constant expressions in conditions (except for loops).
2623
"no-constant-condition": ["error", { checkLoops: false }],
2724

taskcluster/docker/periodic-updates/.eslintrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ module.exports = {
2424
// case/default clauses.
2525
"no-case-declarations": "error",
2626

27-
// Disallow use of the console API.
28-
"no-console": "error",
29-
3027
// Disallow constant expressions in conditions (except for loops).
3128
"no-constant-condition": ["error", { checkLoops: false }],
3229

toolkit/components/extensions/.eslintrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ module.exports = {
120120
// Allow use of bitwise operators.
121121
"no-bitwise": "off",
122122

123-
// Disallow using the console API.
124-
"no-console": "error",
125-
126123
// Allow use of the continue statement.
127124
"no-continue": "off",
128125

toolkit/modules/subprocess/.eslintrc.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@
66

77
module.exports = {
88
extends: "../../components/extensions/.eslintrc.js",
9-
10-
rules: {
11-
"no-console": "off",
12-
},
139
};

tools/esmify/is-esmified.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function generateESMURIMap(jsm_map) {
3434

3535
function isESMifiedSlow(resourceURI) {
3636
if (!(resourceURI in uri_map)) {
37-
console.log(`WARNING: Unknown module: ${resourceURI}`);
37+
console.warn(`WARNING: Unknown module: ${resourceURI}`);
3838
return { result: false, jsms: [] };
3939
}
4040

tools/esmify/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
function warnForPath(inputFile, path, message) {
1010
const loc = path.node.loc;
11-
console.log(
11+
console.warn(
1212
`WARNING: ${inputFile}:${loc.start.line}:${loc.start.column} : ${message}`
1313
);
1414
}

tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = {
77
"mozilla/mark-test-function-used": "error",
88
"mozilla/no-arbitrary-setTimeout": "error",
99

10+
// Bug 1883707 - Turn off no-console in tests at the moment.
11+
"no-console": "off",
1012
// Turn off no-unsanitized for tests, as we do want to be able to use
1113
// these for testing.
1214
"no-unsanitized/method": "off",

tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ module.exports = {
208208
// Disallow use of arguments.caller or arguments.callee.
209209
"no-caller": "error",
210210

211-
// XXX Bug 1487642 - decide if we want to enable this or not.
212-
// Disallow the use of console
213-
"no-console": "off",
211+
// Disallow the use of console, except for errors and warnings.
212+
"no-console": ["error", { allow: ["createInstance", "error", "warn"] }],
214213

215214
// Disallows expressions where the operation doesn't affect the value.
216215
// TODO: This is enabled by default in ESLint's v9 recommended configuration.

tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ module.exports = {
511511
manifest,
512512
});
513513
} catch (e) {
514-
console.log(
514+
console.error(
515515
"TOML ERROR: " +
516516
e.message +
517517
" @line: " +

tools/lint/eslint/eslint-plugin-mozilla/reporters/mozilla-format.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* mach itself.
99
*/
1010

11+
// This is a non-production file that needs to log.
12+
/* eslint-disable no-console */
13+
1114
"use strict";
1215

1316
var mocha = require("mocha");

tools/lint/eslint/eslint-plugin-mozilla/scripts/createExports.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7+
8+
// This is a non-production script.
9+
/* eslint-disable no-console */
10+
711
"use strict";
812

913
var fs = require("fs");

0 commit comments

Comments
 (0)