Skip to content

[chore] no console.log anymore in our codebase #12476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/command/render/output-tex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export function texToPdfOutputRecipe(

// Clean the output directory if it is empty
if (pdfOutputDir) {
console.log({ pdfOutputDir });
try {
// Remove the outputDir if it is empty
safeRemoveSync(pdfOutputDir, { recursive: false });
Expand Down
4 changes: 2 additions & 2 deletions src/command/render/pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ async function resolveExtras(
}
} else if (source === "bunny") {
const font = Zod.BrandFontBunny.parse(_font);
console.log(
info(
"Font bunny is not yet supported for Typst, skipping",
font.family,
);
Expand Down Expand Up @@ -1528,7 +1528,7 @@ async function resolveExtras(
}
}
if (!found) {
console.log(
info(
"skipping",
family,
"\nnot currently able to use formats",
Expand Down
10 changes: 7 additions & 3 deletions src/core/deno/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import * as colors from "fmt/colors";
import { warn } from "../../deno_ral/log.ts";

type StackEntry = {
pos: string;
Expand Down Expand Up @@ -47,7 +48,7 @@ export const getStackAsArray = (
/^.*at async (.*)src\/quarto.ts:\d+:\d+$/,
);
if (!m) {
console.log(
warn(
"Could not find quarto.ts in stack trace, is QUARTO_DENO_V8_OPTIONS set with a sufficiently-large stack size?",
);
}
Expand Down Expand Up @@ -184,12 +185,15 @@ export const getStack = (format?: "json" | "raw" | "ansi", offset?: number) => {
getStackAsArray(format, offset ? offset + 1 : 3).join("\n");
};

// use debugPrint instead of console.log so it's easy to find stray print statements
// use debugPrint instead of console["log"] so it's easier to find stray print statements
// on our codebase
//
// deno-lint-ignore no-explicit-any
export const debugPrint = (...data: any[]) => {
console.log(...data);
// use console["log"] here instead of dot notation
// to allow us to lint for the dot notation usage which
// we want to disallow throughout the codebase
console["log"](...data);
};

export const debugLogWithStack = async (...data: unknown[]) => {
Expand Down
22 changes: 11 additions & 11 deletions src/core/handlers/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,21 @@ const dotHandler: LanguageHandler = {
toFileUrl(resourcePath(join("js", "graphviz-wasm.js"))).href
);
let svg;
const oldConsoleLog = console.log;
const oldConsoleWarn = console.warn;
console.log = () => {};
console.warn = () => {};
// use console["log"] here instead of dot notation
// to allow us to lint for the dot notation usage which
// we want to disallow throughout the codebase
const oldConsoleLog = console["log"];
const oldConsoleWarn = console["warn"];
console["log"] = () => {};
console["warn"] = () => {};
try {
svg = await graphvizModule.graphviz().layout(
cellContent.value,
"svg",
options["graph-layout"],
);
console.log = oldConsoleLog;
console.warn = oldConsoleWarn;
} catch (e) {
if (!(e instanceof Error)) throw e;
console.log = oldConsoleLog;
console.warn = oldConsoleWarn;
const m = (e.message as string).match(
/(.*)syntax error in line (\d+)(.*)/,
);
Expand All @@ -94,10 +93,11 @@ const dotHandler: LanguageHandler = {
mapResult!.originalString.fileName
}, line ${line + 1}${m[3]}`,
);
throw e;
} else {
throw e;
}
throw e;
} finally {
console["log"] = oldConsoleLog;
console["warn"] = oldConsoleWarn;
}

const makeFigLink = (
Expand Down
2 changes: 0 additions & 2 deletions src/core/handlers/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
0,
);
warning(error.message);
console.log("");
return await makeDefault();
} else {
if (isRevealjsOutput(handlerContext.options.context.format.pandoc)) {
Expand All @@ -467,7 +466,6 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
0,
);
warning(error.message);
console.log("");
}
return await makeJs();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/external/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* ```ts
* import { bgBlue, red, bold } from "https://deno.land/std@$STD_VERSION/fmt/colors";
* console.log(bgBlue(red(bold("Hello world!"))));
* console["log"](bgBlue(red(bold("Hello world!"))));
* ```
*
* This module supports `NO_COLOR` environmental variable disabling any coloring
Expand Down
6 changes: 3 additions & 3 deletions src/core/lib/yaml-intelligence/yaml-intelligence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ export async function getCompletions(
await init(context);
return await getAutomation("completions", context);
} catch (e) {
console.log("Error found during autocomplete", e);
console["log"]("Error found during autocomplete", e);
exportSmokeTest("completions", context);
return null;
}
Expand All @@ -1245,7 +1245,7 @@ export async function getLint(
await init(context);
return await getAutomation("validation", context);
} catch (e) {
console.log("Error found during linting", e);
console["log"]("Error found during linting", e);
exportSmokeTest("validation", context);
return null;
}
Expand All @@ -1259,7 +1259,7 @@ export async function getHover(
await init(context);
return hover(context);
} catch (e) {
console.log("Error found during hover", e);
console["log"]("Error found during hover", e);
exportSmokeTest("hover", context);
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions src/core/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { makeTimedFunctionAsync } from "./performance/function-times.ts";
import { isWindows } from "../deno_ral/platform.ts";
import { convertCombinedLuaProfileToCSV } from "./performance/perfetto-utils.ts";
import { info } from "../deno_ral/log.ts";

type Runner = (args: Args) => Promise<unknown>;
export async function mainRunner(runner: Runner) {
Expand Down Expand Up @@ -48,8 +49,8 @@ export async function mainRunner(runner: Runner) {

// if profiling, wait for 10 seconds before quitting
if (Deno.env.get("QUARTO_TS_PROFILE") !== undefined) {
console.log("Program finished. Turn off the Chrome profiler now!");
console.log("Waiting for 10 seconds ...");
info("Program finished. Turn off the Chrome profiler now!");
info("Waiting for 10 seconds ...");
await new Promise((resolve) => setTimeout(resolve, 10000));
}

Expand Down
12 changes: 8 additions & 4 deletions src/core/performance/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2020-2023 Posit Software, PBC
*/

import { info } from "../../deno_ral/log.ts";
import { inputTargetIndexCacheMetrics } from "../../project/project-index.ts";
import { functionTimes } from "./function-times.ts";
import { Stats } from "./stats.ts";
Expand Down Expand Up @@ -64,9 +65,12 @@ export function reportPerformanceMetrics(keys?: MetricsKeys[]) {
if (outFile) {
Deno.writeTextFileSync(outFile, content);
} else {
console.log("---");
console.log("Performance metrics");
console.log("Quarto:");
console.log(content);
const msg = [
"---",
"Performance metrics",
"Quarto:",
content,
];
info(msg.join("\n"));
}
}
4 changes: 2 additions & 2 deletions src/core/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export async function withPuppeteerBrowserAndPage<T>(
(allowedErrorMessages.indexOf(error.message) !== -1) &&
(attempts < maxAttempts)
) {
console.log(
error(
`\nEncountered a bad error message from puppeteer: "${error.message}"\n Retrying ${attempts}/${maxAttempts}`,
);
} else {
Expand Down Expand Up @@ -174,7 +174,7 @@ export async function inPuppeteer(
(allowedErrorMessages.indexOf(error.message) !== -1) &&
(attempts < maxAttempts)
) {
console.log(
error(
`\nEncountered a bad error message from puppeteer: "${error.message}"\n Retrying ${attempts}/${maxAttempts}`,
);
} else {
Expand Down
20 changes: 11 additions & 9 deletions src/core/sass/analyzer/declaration-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { warn } from "../../../deno_ral/log.ts";

export const propagateDeclarationTypes = (ast: any) => {
const declarationsToTrack = new Map<string, any>();

Expand Down Expand Up @@ -81,12 +83,12 @@ export const propagateDeclarationTypes = (ast: any) => {
// let's not be this loud
//
// else {
// console.log(Deno.env.get("QUARTO_DEBUG"));
// console.log(
// info(Deno.env.get("QUARTO_DEBUG"));
// info(
// "Warning: variable redeclaration with conflicting default settings",
// );
// console.log("variable: ", varName);
// console.log("lines ", prevDeclaration?.line, node?.line);
// info("variable: ", varName);
// info("lines ", prevDeclaration?.line, node?.line);
// }
}
} else {
Expand Down Expand Up @@ -180,8 +182,8 @@ export const propagateDeclarationTypes = (ast: any) => {
!declarationsToTrack.has(nodeVariableName) &&
!namesToIgnore.has(nodeVariableName)
) {
console.log("Warning: variable used before declaration");
console.log("variable: ", nodeVariableName, valueNode.line);
warn("Warning: variable used before declaration");
warn(`variable: ${nodeVariableName} ${valueNode.line}`);
return undefined;
} else {
const valueType = declarationsToTrack.get(nodeVariableName)?.valueType;
Expand Down Expand Up @@ -213,15 +215,15 @@ export const propagateDeclarationTypes = (ast: any) => {
// // now warn about variables with unknown types
// for (const [name, node] of declarationsToTrack) {
// if (node.valueType === "color") {
// console.log(name, node.line)
// warn(name, node.line)
// }
// if (!node.valueType && node.value.value.length === 1) {
// // ignore unknown types for multi-value declarations, assume they're arrays which we don't care about.
// if (node.value.value[0]?.type === "parentheses") {
// continue;
// }
// console.log("Warning: variable with unknown type");
// console.log("variable: ", name, node);
// warn("Warning: variable with unknown type");
// warn("variable: ", name, node);
// }
// }
};
20 changes: 12 additions & 8 deletions src/core/sass/analyzer/get-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import { error } from "../../../deno_ral/log.ts";
import { walk } from "./ast-utils.ts";
// import { assert } from "jsr:@std/assert";

// deno-lint-ignore no-explicit-any
const assert = (condition: any) => {
if (!condition) {
throw new Error("Assertion failed");
}
}
};

export const getVariableDependencies = (declarations: Map<string, any>) => {
const dependencies = new Map<string, {
node: any,
dependencies: Set<string>
// deno-lint-ignore no-explicit-any
node: any;
dependencies: Set<string>;
}>();
for (const [name, node] of declarations) {
assert(node?.type === "declaration");
const varName = node?.property?.variable?.value;
assert(varName === name);
if (!dependencies.has(varName)) {
dependencies.set(varName, {node: node, dependencies: new Set()});
dependencies.set(varName, { node: node, dependencies: new Set() });
}
const varValue = node?.value;
// deno-lint-ignore no-explicit-any
walk(varValue, (inner: any) => {
if (inner?.type === "variable") {
const innerName = inner?.value;
if (!innerName) {
console.log(inner);
throw new Error("stop")
error(inner);
throw new Error("stop");
}
dependencies.get(varName)!.dependencies.add(innerName);
dependencies.get(varName)!.dependencies.add(innerName);
}
return true;
});
}
return dependencies;
}
};
11 changes: 6 additions & 5 deletions src/core/schema/json-schema-from-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
JsonObject,
SchemaSchema,
} from "../../resources/types/schema-schema-types.ts";
import { error } from "../../deno_ral/log.ts";

// https://json-schema.org/draft/2020-12/json-schema-core#name-json-schema-documents
type JsonSchema = JsonObject | boolean;
Expand Down Expand Up @@ -129,8 +130,8 @@ const convertSchemaToJSONSchema = (_schema: SchemaSchema): JsonSchema => {
};
}
} else {
console.log({ schema });
console.log(typeof schema);
error({ schema });
error(typeof schema);
throw new Error(`fallthrough?`);
}
} else {
Expand All @@ -140,7 +141,7 @@ const convertSchemaToJSONSchema = (_schema: SchemaSchema): JsonSchema => {
};
}
}
console.log(JSON.stringify(schema, null, 2));
error(JSON.stringify(schema, null, 2));
throw new Error("Not implemented");
};

Expand All @@ -152,8 +153,8 @@ export const generateJsonSchemasFromSchemas = async (resourcePath: string) => {
try {
acc[name] = convertSchemaToJSONSchema(schema);
} catch (e) {
console.log("Outermost failing schema:");
console.log(JSON.stringify(schema));
error("Outermost failing schema:");
error(JSON.stringify(schema));
throw e;
}
return acc;
Expand Down
2 changes: 1 addition & 1 deletion src/core/typst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export async function typstWatch(
typstProgressDone();
}
child.status.then((status) => {
console.log(`typst exited with status ${status.code}`);
error(`typst exited with status ${status.code}`);
});
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/deno_ral/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
info,
LogLevels,
setup,
warn,
warn as warning,
} from "log";

Expand Down
Loading
Loading