Add `no-console` eslint rule (#293)
This commit is contained in:
Родитель
8787c828f0
Коммит
aea92c72b1
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@cadl-lang/compiler",
|
||||
"comment": "",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "@cadl-lang/compiler"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@cadl-lang/eslint-config-cadl",
|
||||
"comment": "Add `no-console` eslint rule as warning.",
|
||||
"type": "minor"
|
||||
}
|
||||
],
|
||||
"packageName": "@cadl-lang/eslint-config-cadl"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "tmlanguage-generator",
|
||||
"comment": "",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "tmlanguage-generator"
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable no-console */
|
||||
import { spawnSync, SpawnSyncOptionsWithStringEncoding } from "child_process";
|
||||
import { mkdtemp, readdir, rmdir } from "fs/promises";
|
||||
import mkdirp from "mkdirp";
|
||||
|
|
|
@ -238,8 +238,10 @@ export function logVerboseTestOutput(
|
|||
) {
|
||||
if (process.env.CADL_VERBOSE_TEST_OUTPUT) {
|
||||
if (typeof messageOrCallback === "string") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(messageOrCallback);
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
messageOrCallback(console.log);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ export async function formatCadlFiles(patterns: string[], { debug }: { debug?: b
|
|||
} catch (e) {
|
||||
if (e instanceof PrettierParserError) {
|
||||
const details = debug ? e.message : "";
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`File '${file}' failed to fromat. ${details}`);
|
||||
} else {
|
||||
throw e;
|
||||
|
@ -67,6 +68,7 @@ export async function findUnformattedCadlFiles(
|
|||
} catch (e) {
|
||||
if (e instanceof PrettierParserError) {
|
||||
const details = debug ? e.message : "";
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`File '${file}' failed to fromat. ${details}`);
|
||||
unformatted.push(file);
|
||||
} else {
|
||||
|
|
|
@ -19,10 +19,12 @@ export async function installCadlDependencies(directory: string): Promise<void>
|
|||
return new Promise(() => {
|
||||
child.on("error", (error: SpawnError) => {
|
||||
if (error.code === "ENOENT") {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(
|
||||
"Cannot find `npm` executable. Make sure to have npm installed in your path."
|
||||
);
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error("Error", error);
|
||||
}
|
||||
process.exit(error.errno);
|
||||
|
|
|
@ -48,6 +48,7 @@ function processLog(log: LogInfo): ProcessedLog {
|
|||
|
||||
export function createConsoleSink(): LogSink {
|
||||
function log(data: ProcessedLog) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(formatLog(data));
|
||||
}
|
||||
|
||||
|
|
|
@ -203,6 +203,7 @@ export async function scaffoldNewProject(host: CompilerHost, config: Scaffolding
|
|||
await writeMain(host, config);
|
||||
await writeFiles(host, config);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("Cadl init completed. You can run `cadl install` now to install dependencies.");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { inspect } from "util";
|
||||
import {
|
||||
validateDecoratorParamType,
|
||||
validateDecoratorTarget,
|
||||
|
@ -81,13 +82,17 @@ export function getDoc(program: Program, target: Type): string | undefined {
|
|||
}
|
||||
|
||||
export function inspectType(program: Program, target: Type, text: string) {
|
||||
if (text) console.log(text);
|
||||
console.dir(target, { depth: 3 });
|
||||
// eslint-disable-next-line no-console
|
||||
if (text) console.error(text);
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(inspect(target, { depth: 3 }));
|
||||
}
|
||||
|
||||
export function inspectTypeName(program: Program, target: Type, text: string) {
|
||||
if (text) console.log(text);
|
||||
console.log(program.checker!.getTypeName(target));
|
||||
// eslint-disable-next-line no-console
|
||||
if (text) console.error(text);
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(program.checker!.getTypeName(target));
|
||||
}
|
||||
|
||||
const intrinsicsKey = Symbol();
|
||||
|
|
|
@ -71,8 +71,10 @@ function fatalError(e: any) {
|
|||
// If we failed to send any log messages over LSP pipe, send them to
|
||||
// stderr before exiting.
|
||||
for (const pending of server?.pendingMessages ?? []) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(pending);
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable no-console */
|
||||
import { logVerboseTestOutput } from "../../core/diagnostics.js";
|
||||
import { parse } from "../../core/parser.js";
|
||||
|
||||
|
|
|
@ -34,6 +34,9 @@ module.exports = {
|
|||
destructuring: "all",
|
||||
},
|
||||
],
|
||||
|
||||
// Do not want console.log left from debugging or using console.log for logging. Use the program logger.
|
||||
"no-console": "warn",
|
||||
},
|
||||
ignorePatterns: ["dist/**/*", "dist-dev/**/*"],
|
||||
overrides: [
|
||||
|
|
|
@ -184,7 +184,9 @@ async function processGrammar(grammar: Grammar, options: EmitOptions): Promise<a
|
|||
}
|
||||
const sourceFile = options.errorSourceFilePath ?? "unknown_file";
|
||||
//prettier-ignore
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`${sourceFile}(1,1): error TM0001: Bad regex: ${JSON.stringify({[prop]: regexp})}: ${err.message}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(node);
|
||||
throw err;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче