fix(lint): use errors instead of warnings, refactor log impl (#1170)

This commit is contained in:
uncenter authored and GitHub committed 2024-08-07 08:47:13 -04:00
1 parent 1a18410a1f
commit fd457b15f7
6 files changed
+44 -31

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@ export const checkForMissingFiles = async () => {
.write(); .write();
} else { } else {
missingFiles.map((f) => { missingFiles.map((f) => {
log(color.red(`Missing file:`) + ` ${f}`, { file: f }, "error"); log.error(color.red(`Missing file:`) + ` ${f}`, { file: f });
}); });
} }
+32 -16
View File
@@ -65,21 +65,37 @@ const prettyPrint = (
); );
}; };
export const log = ( export const log = {
message: string, log: (
props: LoggerProps, message: string,
severity: "error" | "warning" = "warning", props: LoggerProps,
) => { severity: "error" | "warning",
if (Deno.env.has("CI")) { ) => {
switch (severity) { if (Deno.env.has("CI")) {
case "error": switch (severity) {
core.error(message, props); case "error":
break; core.error(message, props);
case "warning": break;
core.warning(message, props); case "warning":
break; core.warning(message, props);
break;
}
} else {
prettyPrint(message, props, severity);
} }
} else { },
prettyPrint(message, props, severity);
} warn: function (
message: string,
props: LoggerProps,
) {
this.log(message, props, "warning");
},
error: function (
message: string,
props: LoggerProps,
) {
this.log(message, props, "error");
},
}; };
+1 -2
View File
@@ -49,10 +49,9 @@ for await (const entry of stylesheets) {
less.render(content, { lint: true, globalVars: globalVars }).catch( less.render(content, { lint: true, globalVars: globalVars }).catch(
(err: Less.RenderError) => { (err: Less.RenderError) => {
failed = true; failed = true;
log( log.error(
err.message, err.message,
{ file, startLine: err.line, endLine: err.line, content }, { file, startLine: err.line, endLine: err.line, content },
"error",
); );
}, },
); );
+8 -9
View File
@@ -36,7 +36,7 @@ export const verifyMetadata = async (
e.index -= line.length + 1; e.index -= line.length + 1;
if (e.index < 0) break; if (e.index < 0) break;
} }
log(e.message, { file, startLine, content }); log.error(e.message, { file, startLine, content });
}); });
for (const [key, expected] of Object.entries(assert)) { for (const [key, expected] of Object.entries(assert)) {
@@ -58,11 +58,11 @@ export const verifyMetadata = async (
color.red(String(current)), color.red(String(current)),
); );
log(message, { log.error(message, {
file, file,
startLine: line !== 0 ? line : undefined, startLine: line !== 0 ? line : undefined,
content, content,
}, "warning"); });
} }
} }
@@ -84,7 +84,7 @@ export const verifyMetadata = async (
.findLastIndex((line: string) => line.includes("==/UserStyle== */")) + .findLastIndex((line: string) => line.includes("==/UserStyle== */")) +
1; 1;
log( log.error(
sprintf( sprintf(
"Metadata variable `%s` should exist", "Metadata variable `%s` should exist",
color.bold(variable), color.bold(variable),
@@ -94,7 +94,6 @@ export const verifyMetadata = async (
startLine: line !== 0 ? line : undefined, startLine: line !== 0 ? line : undefined,
content, content,
}, },
"warning",
); );
} else if (expected.trim() !== lines[current - 1].trim()) { } else if (expected.trim() !== lines[current - 1].trim()) {
const message = sprintf( const message = sprintf(
@@ -103,11 +102,11 @@ export const verifyMetadata = async (
(/\[[^\]]+\]/.exec(expected) as RegExpExecArray)[0], (/\[[^\]]+\]/.exec(expected) as RegExpExecArray)[0],
); );
log(message, { log.error(message, {
file, file,
startLine: current, startLine: current,
content, content,
}, "warning"); });
if (fix) { if (fix) {
content = content.replace(lines[current - 1], expected); content = content.replace(lines[current - 1], expected);
@@ -135,9 +134,9 @@ const assertions = (userstyle: string, userstyles: Userstyles) => {
const prefix = "https://github.com/catppuccin/userstyles"; const prefix = "https://github.com/catppuccin/userstyles";
if (!userstyles[userstyle]) { if (!userstyles[userstyle]) {
log("Metadata section for this userstyle has not been added", { log.error("Metadata section for this userstyle has not been added", {
file: "scripts/userstyles.yml", file: "scripts/userstyles.yml",
}, "error"); });
Deno.exit(1); Deno.exit(1);
} }
+1 -1
View File
@@ -29,7 +29,7 @@ export const lint = (
color.dim(`(${warning.rule})`), color.dim(`(${warning.rule})`),
) ?? "unspecified stylelint error"; ) ?? "unspecified stylelint error";
log(message, { log.log(message, {
file: relative(REPO_ROOT, entry.path), file: relative(REPO_ROOT, entry.path),
startLine: warning.line, startLine: warning.line,
endLine: warning.endLine, endLine: warning.endLine,
+1 -2
View File
@@ -67,14 +67,13 @@ export const getUserstylesData = (): Userstyles => {
const groups = const groups =
/(?<message>.*) at line (?<line>\d+), column (?<column>\d+):[\S\s]*/ /(?<message>.*) at line (?<line>\d+), column (?<column>\d+):[\S\s]*/
.exec(err.message)?.groups; .exec(err.message)?.groups;
log( log.error(
groups!.message, groups!.message,
{ {
file: "scripts/userstyles.yml", file: "scripts/userstyles.yml",
startLine: Number(groups!.line), startLine: Number(groups!.line),
content: content, content: content,
}, },
"error",
); );
} else { } else {
console.log(err); console.log(err);