Skip to content
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

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

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
2 changes: 1 addition & 1 deletion scripts/lint/file-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const checkForMissingFiles = async () => {
.write();
} else {
missingFiles.map((f) => {
log(color.red(`Missing file:`) + ` ${f}`, { file: f }, "error");
log.error(color.red(`Missing file:`) + ` ${f}`, { file: f });
});
}

Expand Down
48 changes: 32 additions & 16 deletions scripts/lint/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,37 @@ const prettyPrint = (
);
};

export const log = (
message: string,
props: LoggerProps,
severity: "error" | "warning" = "warning",
) => {
if (Deno.env.has("CI")) {
switch (severity) {
case "error":
core.error(message, props);
break;
case "warning":
core.warning(message, props);
break;
export const log = {
log: (
message: string,
props: LoggerProps,
severity: "error" | "warning",
) => {
if (Deno.env.has("CI")) {
switch (severity) {
case "error":
core.error(message, props);
break;
case "warning":
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");
},
};
3 changes: 1 addition & 2 deletions scripts/lint/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ for await (const entry of stylesheets) {
less.render(content, { lint: true, globalVars: globalVars }).catch(
(err: Less.RenderError) => {
failed = true;
log(
log.error(
err.message,
{ file, startLine: err.line, endLine: err.line, content },
"error",
);
},
);
Expand Down
17 changes: 8 additions & 9 deletions scripts/lint/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const verifyMetadata = async (
e.index -= line.length + 1;
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)) {
Expand All @@ -58,11 +58,11 @@ export const verifyMetadata = async (
color.red(String(current)),
);

log(message, {
log.error(message, {
file,
startLine: line !== 0 ? line : undefined,
content,
}, "warning");
});
}
}

Expand All @@ -84,7 +84,7 @@ export const verifyMetadata = async (
.findLastIndex((line: string) => line.includes("==/UserStyle== */")) +
1;

log(
log.error(
sprintf(
"Metadata variable `%s` should exist",
color.bold(variable),
Expand All @@ -94,7 +94,6 @@ export const verifyMetadata = async (
startLine: line !== 0 ? line : undefined,
content,
},
"warning",
);
} else if (expected.trim() !== lines[current - 1].trim()) {
const message = sprintf(
Expand All @@ -103,11 +102,11 @@ export const verifyMetadata = async (
(/\[[^\]]+\]/.exec(expected) as RegExpExecArray)[0],
);

log(message, {
log.error(message, {
file,
startLine: current,
content,
}, "warning");
});

if (fix) {
content = content.replace(lines[current - 1], expected);
Expand Down Expand Up @@ -135,9 +134,9 @@ const assertions = (userstyle: string, userstyles: Userstyles) => {
const prefix = "https://github.com/catppuccin/userstyles";

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",
}, "error");
});
Deno.exit(1);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/lint/stylelint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const lint = (
color.dim(`(${warning.rule})`),
) ?? "unspecified stylelint error";

log(message, {
log.log(message, {
file: relative(REPO_ROOT, entry.path),
startLine: warning.line,
endLine: warning.endLine,
Expand Down
3 changes: 1 addition & 2 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ export const getUserstylesData = (): Userstyles => {
const groups =
/(?<message>.*) at line (?<line>\d+), column (?<column>\d+):[\S\s]*/
.exec(err.message)?.groups;
log(
log.error(
groups!.message,
{
file: "scripts/userstyles.yml",
startLine: Number(groups!.line),
content: content,
},
"error",
);
} else {
console.log(err);
Expand Down
Loading