Skip to content

Commit

Permalink
Merge pull request #19042 from Snuffleupagus/eslint-no-console
Browse files Browse the repository at this point in the history
Enable the ESLint `no-console` rule in parts of the code-base
  • Loading branch information
timvandermeij authored Nov 17, 2024
2 parents a719c3c + af3c1f2 commit 15a5e47
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ export default [
"template-curly-spacing": ["error", "never"],
},
},
{
files: jsFiles("src"),
rules: {
"no-console": "error",
},
},

/* ======================================================================== *\
Test-specific rules
Expand Down Expand Up @@ -354,11 +360,13 @@ export default [
files: jsFiles("test/unit"),
rules: {
"import/no-unresolved": ["error", { ignore: ["pdfjs/"] }],
"no-console": ["error", { allow: ["warn", "error"] }],
},
},
{
files: jsFiles("test/integration"),
rules: {
"no-console": ["error", { allow: ["warn", "error"] }],
"no-restricted-syntax": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ function noContextMenu(e) {

// Deprecated API function -- display regardless of the `verbosity` setting.
function deprecated(details) {
// eslint-disable-next-line no-console
console.log("Deprecated API usage: " + details);
}

Expand Down
2 changes: 1 addition & 1 deletion src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ImageManager {
}
data.refCounter = 1;
} catch (e) {
console.error(e);
warn(e);
data = null;
}
this.#cache.set(key, data);
Expand Down
1 change: 1 addition & 0 deletions src/pdf.sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Sandbox {
[buf, this._alertOnError]
);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
} finally {
if (buf) {
Expand Down
2 changes: 2 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,15 @@ function getVerbosityLevel() {
// end users.
function info(msg) {
if (verbosity >= VerbosityLevel.INFOS) {
// eslint-disable-next-line no-console
console.log(`Info: ${msg}`);
}
}

// Non-fatal warnings.
function warn(msg) {
if (verbosity >= VerbosityLevel.WARNINGS) {
// eslint-disable-next-line no-console
console.log(`Warning: ${msg}`);
}
}
Expand Down
6 changes: 4 additions & 2 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ async function waitForEvent({

const success = await awaitPromise(handle);
if (success === null) {
console.log(`waitForEvent: ${eventName} didn't trigger within the timeout`);
console.warn(
`waitForEvent: ${eventName} didn't trigger within the timeout`
);
} else if (!success) {
console.log(`waitForEvent: ${eventName} triggered, but validation failed`);
console.warn(`waitForEvent: ${eventName} triggered, but validation failed`);
}
}

Expand Down

0 comments on commit 15a5e47

Please sign in to comment.