feat: improve scripts/lint logging (#1305)

This commit is contained in:
uncenter authored and GitHub committed 2024-09-13 17:10:03 -04:00
1 parent 4de6cc6071
commit c5d639d694
6 files changed
+106 -75

No files matched your search

+24 -18
View File
@@ -5,7 +5,7 @@ import { SetRequired } from "type-fest/source/set-required.d.ts";
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
import { UserstylesSchema } from "@/types/userstyles.d.ts";
import { log } from "@/lint/logger.ts";
import { log } from "@/logger.ts";
import { sprintf } from "@std/fmt/printf";
/**
@@ -22,18 +22,20 @@ export const validateYaml = <T>(
const data = parse(content);
if (!validate(data)) {
console.log(
"Found schema errors in scripts/userstyles.yml: " +
validate.errors?.map((err) =>
sprintf(
"%s %s%s",
err.instancePath.slice(1).replaceAll("/", "."),
err.message,
err.params.allowedValues
? ` (${JSON.stringify(err.params.allowedValues, undefined)})`
: "",
)
).join(" and "),
log.error(
validate.errors!.map((err) =>
sprintf(
"%s %s%s",
err.instancePath.slice(1).replaceAll("/", "."),
err.message,
err.params.allowedValues
? ` (${JSON.stringify(err.params.allowedValues, undefined)})`
: "",
)
).join(" and "),
{
file: "scripts/userstyles.yml",
},
);
Deno.exit(1);
}
@@ -56,14 +58,18 @@ export const getUserstylesData = (): Userstyles => {
userStylesSchema,
);
if (data.userstyles === undefined || data.collaborators === undefined) {
console.log("userstyles.yml is missing required fields");
Deno.exit(1);
for (const field of ["userstyles", "collaborators"] as const) {
if (data[field] === undefined) {
log.error(`Missing required field \`${field}\``, {
file: "scripts/userstyles.yml",
});
Deno.exit(1);
}
}
return data as Userstyles;
} catch (err) {
if (err.name === "YAMLError") {
if (err.name === "SyntaxError") {
const groups =
/(?<message>.*) at line (?<line>\d+), column (?<column>\d+):[\S\s]*/
.exec(err.message)?.groups;
@@ -76,7 +82,7 @@ export const getUserstylesData = (): Userstyles => {
},
);
} else {
console.log(err);
throw err;
}
Deno.exit(1);