chore: enable no-console lint rule (#5975)

This commit is contained in:
Asher Gomez 2024-09-13 15:43:13 +10:00 committed by GitHub
parent 75a50aecf7
commit 58dbbd6bd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 58 additions and 11 deletions

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/** /**

View File

@ -1,4 +1,4 @@
// deno-lint-ignore-file camelcase // deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { import {
createGraph, createGraph,
@ -87,13 +87,13 @@ const ENTRYPOINTS: Record<Mod, string[]> = {
collections: ["mod.ts"], collections: ["mod.ts"],
crypto: ["mod.ts"], crypto: ["mod.ts"],
csv: ["mod.ts"], csv: ["mod.ts"],
data_structures: ["mod.ts"], "data_structures": ["mod.ts"],
datetime: ["mod.ts"], datetime: ["mod.ts"],
dotenv: ["mod.ts"], dotenv: ["mod.ts"],
encoding: ["mod.ts"], encoding: ["mod.ts"],
expect: ["mod.ts"], expect: ["mod.ts"],
fmt: ["bytes.ts", "colors.ts", "duration.ts", "printf.ts"], fmt: ["bytes.ts", "colors.ts", "duration.ts", "printf.ts"],
front_matter: ["mod.ts"], "front_matter": ["mod.ts"],
fs: ["mod.ts"], fs: ["mod.ts"],
html: ["mod.ts"], html: ["mod.ts"],
http: ["mod.ts"], http: ["mod.ts"],
@ -103,7 +103,7 @@ const ENTRYPOINTS: Record<Mod, string[]> = {
json: ["mod.ts"], json: ["mod.ts"],
jsonc: ["mod.ts"], jsonc: ["mod.ts"],
log: ["mod.ts"], log: ["mod.ts"],
media_types: ["mod.ts"], "media_types": ["mod.ts"],
msgpack: ["mod.ts"], msgpack: ["mod.ts"],
net: ["mod.ts"], net: ["mod.ts"],
path: ["mod.ts"], path: ["mod.ts"],

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/** /**
* Checks whether all deprecated tags have a message. * Checks whether all deprecated tags have a message.

View File

@ -215,10 +215,10 @@ async function assertSnippetEvals(
stderr: "piped", stderr: "piped",
}); });
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
// deno-lint-ignore no-console
console.warn( console.warn(
`Snippet at ${document.location.filename}:${document.location.line} has been running for more than 10 seconds...`, `Snippet at ${document.location.filename}:${document.location.line} has been running for more than 10 seconds...\n${snippet}`,
); );
console.warn(snippet);
}, 10_000); }, 10_000);
try { try {
const { success, stderr } = await command.output(); const { success, stderr } = await command.output();
@ -548,6 +548,7 @@ const lintStatus = await new Deno.Command(Deno.execPath(), {
stderr: "inherit", stderr: "inherit",
}).output(); }).output();
if (!lintStatus.success) { if (!lintStatus.success) {
// deno-lint-ignore no-console
console.error( console.error(
`%c[error] %c'deno doc --lint' failed`, `%c[error] %c'deno doc --lint' failed`,
"color: red", "color: red",
@ -568,6 +569,7 @@ for await (const _ of iter) {
} }
if (diagnostics.length > 0) { if (diagnostics.length > 0) {
for (const error of diagnostics) { for (const error of diagnostics) {
// deno-lint-ignore no-console
console.error( console.error(
`%c[error] %c${error.message} %cat ${error.cause}`, `%c[error] %c${error.message} %cat ${error.cause}`,
"color: red", "color: red",
@ -576,6 +578,7 @@ if (diagnostics.length > 0) {
); );
} }
// deno-lint-ignore no-console
console.log(`%c${diagnostics.length} errors found`, "color: red"); console.log(`%c${diagnostics.length} errors found`, "color: red");
Deno.exit(1); Deno.exit(1);
} }

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import denoJson from "../deno.json" with { type: "json" }; import denoJson from "../deno.json" with { type: "json" };

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { walk } from "../fs/walk.ts"; import { walk } from "../fs/walk.ts";
import { globToRegExp } from "../path/glob_to_regexp.ts"; import { globToRegExp } from "../path/glob_to_regexp.ts";

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { walk } from "../fs/walk.ts"; import { walk } from "../fs/walk.ts";

View File

@ -15,6 +15,7 @@ export async function discoverPackages() {
} }
packages.sort(); packages.sort();
// deno-lint-ignore no-console
console.log("Discovered", packages.length, "packages."); console.log("Discovered", packages.length, "packages.");
return packages; return packages;
} }
@ -59,5 +60,6 @@ async function discoverExports(pkg: string) {
if (import.meta.main) { if (import.meta.main) {
const packages = await discoverPackages(); const packages = await discoverPackages();
// deno-lint-ignore no-console
console.log(packages); console.log(packages);
} }

View File

@ -1,4 +1,5 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=git,deno --no-check #!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=git,deno --no-check
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { getReleasesMdFile, loadRepo, VersionFile } from "./repo.ts"; import { getReleasesMdFile, loadRepo, VersionFile } from "./repo.ts";

View File

@ -1,4 +1,5 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run=git --no-check #!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run=git --no-check
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { createOctoKit, getGitHubRepository } from "./deps.ts"; import { createOctoKit, getGitHubRepository } from "./deps.ts";
import { loadRepo, VersionFile } from "./repo.ts"; import { loadRepo, VersionFile } from "./repo.ts";

View File

@ -1,4 +1,5 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run=git --no-check #!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run=git --no-check
// deno-lint-ignore-file no-console
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { containsVersion, createOctoKit, getGitHubRepository } from "./deps.ts"; import { containsVersion, createOctoKit, getGitHubRepository } from "./deps.ts";
import { getReleasesMdFile, loadRepo, VersionFile } from "./repo.ts"; import { getReleasesMdFile, loadRepo, VersionFile } from "./repo.ts";

View File

@ -65,6 +65,7 @@ export function delay(ms: number, options: DelayOptions = {}): Promise<void> {
if (!(error instanceof ReferenceError)) { if (!(error instanceof ReferenceError)) {
throw error; throw error;
} }
// deno-lint-ignore no-console
console.error("`persistent` option is only available in Deno"); console.error("`persistent` option is only available in Deno");
} }
} }

View File

@ -298,6 +298,7 @@ function makeTables(
} }
export async function tables(version: string) { export async function tables(version: string) {
// deno-lint-ignore no-console
console.info(`Generating tables for Unicode ${version}`); console.info(`Generating tables for Unicode ${version}`);
const eawMap = await loadEastAsianWidths(version); const eawMap = await loadEastAsianWidths(version);

View File

@ -20,6 +20,7 @@ const largeDigest = encodeHex(
); );
const heapBytesAfterLarge = memory.buffer.byteLength; const heapBytesAfterLarge = memory.buffer.byteLength;
// deno-lint-ignore no-console
console.log(JSON.stringify({ console.log(JSON.stringify({
heapBytesInitial, heapBytesInitial,
smallDigest, smallDigest,

View File

@ -20,6 +20,7 @@ const heapBytesFinal = memory.buffer.byteLength;
const stateFinal = encodeHex(state); const stateFinal = encodeHex(state);
// deno-lint-ignore no-console
console.log(JSON.stringify({ console.log(JSON.stringify({
heapBytesInitial, heapBytesInitial,
heapBytesFinal, heapBytesFinal,

View File

@ -396,6 +396,8 @@ export class DateTimeFormatter {
case "numeric": { case "numeric": {
value = /^\d{1,2}/.exec(string)?.[0] as string; value = /^\d{1,2}/.exec(string)?.[0] as string;
if (part.hour12 && parseInt(value) > 12) { if (part.hour12 && parseInt(value) > 12) {
// TODO(iuioiua): Replace with throwing an error
// deno-lint-ignore no-console
console.error( console.error(
`Trying to parse hour greater than 12, use 'H' instead of 'h'.`, `Trying to parse hour greater than 12, use 'H' instead of 'h'.`,
); );
@ -405,6 +407,8 @@ export class DateTimeFormatter {
case "2-digit": { case "2-digit": {
value = /^\d{2}/.exec(string)?.[0] as string; value = /^\d{2}/.exec(string)?.[0] as string;
if (part.hour12 && parseInt(value) > 12) { if (part.hour12 && parseInt(value) > 12) {
// TODO(iuioiua): Replace with throwing an error
// deno-lint-ignore no-console
console.error( console.error(
`Trying to parse hour greater than 12, use 'HH' instead of 'hh'.`, `Trying to parse hour greater than 12, use 'HH' instead of 'hh'.`,
); );
@ -412,6 +416,7 @@ export class DateTimeFormatter {
break; break;
} }
default: default:
// TODO(iuioiua): Correct error type and message
throw new Error( throw new Error(
`ParserError: value "${part.value}" is not supported`, `ParserError: value "${part.value}" is not supported`,
); );

View File

@ -43,7 +43,8 @@
"camelcase", "camelcase",
"no-sync-fn-in-async-fn", "no-sync-fn-in-async-fn",
"single-var-declarator", "single-var-declarator",
"verbatim-module-syntax" "verbatim-module-syntax",
"no-console"
] ]
} }
}, },

View File

@ -4,6 +4,7 @@ import { loadSync } from "./mod.ts";
if (!(Deno.readTextFileSync instanceof Function)) { if (!(Deno.readTextFileSync instanceof Function)) {
// Avoid errors that occur in deno deploy: https://github.com/denoland/deno_std/issues/1957 // Avoid errors that occur in deno deploy: https://github.com/denoland/deno_std/issues/1957
// deno-lint-ignore no-console
console.warn( console.warn(
`Deno.readTextFileSync is not a function: No .env data was read.`, `Deno.readTextFileSync is not a function: No .env data was read.`,
); );

View File

@ -84,6 +84,7 @@ export function parse(text: string): Record<string, string> {
?.groups as LineParseResult; ?.groups as LineParseResult;
if (!RE_VALID_KEY.test(key)) { if (!RE_VALID_KEY.test(key)) {
// deno-lint-ignore no-console
console.warn( console.warn(
`Ignored the key "${key}" as it is not a valid identifier: The key need to match the pattern /^[a-zA-Z_][a-zA-Z0-9_]*$/.`, `Ignored the key "${key}" as it is not a valid identifier: The key need to match the pattern /^[a-zA-Z_][a-zA-Z0-9_]*$/.`,
); );

View File

@ -23,6 +23,7 @@ export function stringify(object: Record<string, string>): string {
let escapedValue = value ?? ""; let escapedValue = value ?? "";
if (key.startsWith("#")) { if (key.startsWith("#")) {
// deno-lint-ignore no-console
console.warn( console.warn(
`key starts with a '#' indicates a comment and is ignored: '${key}'`, `key starts with a '#' indicates a comment and is ignored: '${key}'`,
); );

View File

@ -1,4 +1,5 @@
import { load } from "../mod.ts"; import { load } from "../mod.ts";
const conf = await load(); const conf = await load();
// deno-lint-ignore no-console
console.log(JSON.stringify(conf, null, 2)); console.log(JSON.stringify(conf, null, 2));

View File

@ -1,3 +1,4 @@
import "../load.ts"; import "../load.ts";
// deno-lint-ignore no-console
console.log(Deno.env.get("GREETING")); console.log(Deno.env.get("GREETING"));

View File

@ -1,4 +1,5 @@
// test file for https://github.com/denoland/deno_std/issues/1957 // test file for https://github.com/denoland/deno_std/issues/1957
// This file is imported from ./app_load_parent.ts // This file is imported from ./app_load_parent.ts
// deno-lint-ignore no-console
console.log(Deno.env.get("GREETING")); console.log(Deno.env.get("GREETING"));

View File

@ -226,13 +226,12 @@ for (const s of scenes) {
const command = new Deno.Command(Deno.execPath(), { const command = new Deno.Command(Deno.execPath(), {
args, args,
stderr: "inherit",
}); });
const { stdout, stderr } = await command.output(); const { stdout } = await command.output();
assertStringIncludes(new TextDecoder().decode(stdout), s.output); assertStringIncludes(new TextDecoder().decode(stdout), s.output);
if (stderr.length > 0) {
console.log(new TextDecoder().decode(stderr));
}
} catch (err) { } catch (err) {
// deno-lint-ignore no-console
console.log(err); console.log(err);
await Deno.remove(testfolder, { recursive: true }); await Deno.remove(testfolder, { recursive: true });
throw err; throw err;

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
import { emptyDir } from "../empty_dir.ts"; import { emptyDir } from "../empty_dir.ts";
try { try {

View File

@ -1,3 +1,4 @@
// deno-lint-ignore-file no-console
import { emptyDirSync } from "../empty_dir.ts"; import { emptyDirSync } from "../empty_dir.ts";
try { try {

View File

@ -2,5 +2,6 @@ import { expandGlob } from "../expand_glob.ts";
const glob = new URL("*", import.meta.url).pathname; const glob = new URL("*", import.meta.url).pathname;
for await (const { filename } of expandGlob(glob)) { for await (const { filename } of expandGlob(glob)) {
// deno-lint-ignore no-console
console.log(filename); console.log(filename);
} }

View File

@ -365,6 +365,7 @@ function parseSetCookie(value: string): Cookie | null {
case "max-age": case "max-age":
cookie.maxAge = Number(value); cookie.maxAge = Number(value);
if (cookie.maxAge < 0) { if (cookie.maxAge < 0) {
// deno-lint-ignore no-console
console.warn( console.warn(
"Max-Age must be an integer superior or equal to 0. Cookie ignored.", "Max-Age must be an integer superior or equal to 0. Cookie ignored.",
); );
@ -396,6 +397,7 @@ function parseSetCookie(value: string): Cookie | null {
if (cookie.name.startsWith("__Secure-")) { if (cookie.name.startsWith("__Secure-")) {
/** This requirement is mentioned in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie but not the RFC. */ /** This requirement is mentioned in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie but not the RFC. */
if (!cookie.secure) { if (!cookie.secure) {
// deno-lint-ignore no-console
console.warn( console.warn(
"Cookies with names starting with `__Secure-` must be set with the secure flag. Cookie ignored.", "Cookies with names starting with `__Secure-` must be set with the secure flag. Cookie ignored.",
); );
@ -404,18 +406,21 @@ function parseSetCookie(value: string): Cookie | null {
} }
if (cookie.name.startsWith("__Host-")) { if (cookie.name.startsWith("__Host-")) {
if (!cookie.secure) { if (!cookie.secure) {
// deno-lint-ignore no-console
console.warn( console.warn(
"Cookies with names starting with `__Host-` must be set with the secure flag. Cookie ignored.", "Cookies with names starting with `__Host-` must be set with the secure flag. Cookie ignored.",
); );
return null; return null;
} }
if (cookie.domain !== undefined) { if (cookie.domain !== undefined) {
// deno-lint-ignore no-console
console.warn( console.warn(
"Cookies with names starting with `__Host-` must not have a domain specified. Cookie ignored.", "Cookies with names starting with `__Host-` must not have a domain specified. Cookie ignored.",
); );
return null; return null;
} }
if (cookie.path !== "/") { if (cookie.path !== "/") {
// deno-lint-ignore no-console
console.warn( console.warn(
"Cookies with names starting with `__Host-` must have path be `/`. Cookie has been ignored.", "Cookies with names starting with `__Host-` must have path be `/`. Cookie has been ignored.",
); );

View File

@ -408,6 +408,7 @@ function serverLog(req: Request, status: number) {
const url = new URL(req.url); const url = new URL(req.url);
const s = `${dateFmt} [${req.method}] ${url.pathname}${url.search} ${status}`; const s = `${dateFmt} [${req.method}] ${url.pathname}${url.search} ${status}`;
// using console.debug instead of console.log so chrome inspect users can hide request logs // using console.debug instead of console.log so chrome inspect users can hide request logs
// deno-lint-ignore no-console
console.debug(s); console.debug(s);
} }
@ -760,6 +761,7 @@ async function createServeDirResponse(
} }
function logError(error: Error) { function logError(error: Error) {
// deno-lint-ignore no-console
console.error(`%c${error.message}`, "color: red"); console.error(`%c${error.message}`, "color: red");
} }
@ -802,12 +804,14 @@ function main() {
} }
if (serverArgs.version) { if (serverArgs.version) {
// deno-lint-ignore no-console
console.log(`Deno File Server ${denoConfig.version}`); console.log(`Deno File Server ${denoConfig.version}`);
Deno.exit(); Deno.exit();
} }
if (keyFile || certFile) { if (keyFile || certFile) {
if (keyFile === "" || certFile === "") { if (keyFile === "" || certFile === "") {
// deno-lint-ignore no-console
console.log("--key and --cert are required for TLS"); console.log("--key and --cert are required for TLS");
printUsage(); printUsage();
Deno.exit(1); Deno.exit(1);
@ -849,6 +853,7 @@ function main() {
if (networkAddress && !DENO_DEPLOYMENT_ID) { if (networkAddress && !DENO_DEPLOYMENT_ID) {
message += `\n- Network: ${protocol}://${networkAddress}:${port}`; message += `\n- Network: ${protocol}://${networkAddress}:${port}`;
} }
// deno-lint-ignore no-console
console.log(message); console.log(message);
} }
@ -874,6 +879,7 @@ function main() {
} }
function printUsage() { function printUsage() {
// deno-lint-ignore no-console
console.log(`Deno File Server ${denoConfig.version} console.log(`Deno File Server ${denoConfig.version}
Serves a local directory in HTTP. Serves a local directory in HTTP.

View File

@ -1,6 +1,7 @@
import { serveFile } from "../file_server.ts"; import { serveFile } from "../file_server.ts";
Deno.serve( Deno.serve(
// deno-lint-ignore no-console
{ port: 8000, onListen: () => console.log("Server running...") }, { port: 8000, onListen: () => console.log("Server running...") },
(req) => { (req) => {
return serveFile(req, "./testdata/hello.html"); return serveFile(req, "./testdata/hello.html");

View File

@ -53,6 +53,7 @@ export class ConsoleHandler extends BaseHandler {
} }
log(msg: string) { log(msg: string) {
// deno-lint-ignore no-console
console.log(msg); console.log(msg);
} }
} }

View File

@ -358,6 +358,7 @@ class AssertSnapshotContext {
const updated = this.getUpdatedCount(); const updated = this.getUpdatedCount();
if (updated > 0) { if (updated > 0) {
// deno-lint-ignore no-console
console.log( console.log(
`%c\n > ${updated} ${ `%c\n > ${updated} ${
updated === 1 ? "snapshot" : "snapshots" updated === 1 ? "snapshot" : "snapshots"
@ -367,6 +368,7 @@ class AssertSnapshotContext {
} }
const removed = removedSnapshotNames.length; const removed = removedSnapshotNames.length;
if (removed > 0) { if (removed > 0) {
// deno-lint-ignore no-console
console.log( console.log(
`%c\n > ${removed} ${ `%c\n > ${removed} ${
removed === 1 ? "snapshot" : "snapshots" removed === 1 ? "snapshot" : "snapshots"
@ -374,6 +376,7 @@ class AssertSnapshotContext {
"color: red; font-weight: bold;", "color: red; font-weight: bold;",
); );
for (const snapshotName of removedSnapshotNames) { for (const snapshotName of removedSnapshotNames) {
// deno-lint-ignore no-console
console.log(`%c • ${snapshotName}`, "color: red;"); console.log(`%c • ${snapshotName}`, "color: red;");
} }
} }