From d520b24b534f1e733272f8da678d7b37144627e3 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:38:10 -0500 Subject: [PATCH] ci(lint): exit with error when issues are found (#419) --- scripts/lint/main.ts | 13 ++++++++++--- scripts/lint/stylelint.ts | 10 ++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/lint/main.ts b/scripts/lint/main.ts index 0a6ac2b383..b6cc65b51e 100755 --- a/scripts/lint/main.ts +++ b/scripts/lint/main.ts @@ -20,6 +20,8 @@ const stylesheets = walk(join(REPO_ROOT, "styles", subDir), { match: [/\.user.css$/], }); +let failed = false; + for await (const entry of stylesheets) { const repodir = dirname(entry.path); const repo = basename(repodir); @@ -33,8 +35,9 @@ for await (const entry of stylesheets) { if (!isLess) continue; // try to compile the less file, report any errors - less.render(content, { lint: true, globalVars }).then().catch( - (err) => { + less.render(content, { lint: true, globalVars }).catch( + (err: Less.RenderError) => { + failed = true; log( err.message, { file, startLine: err.line, endLine: err.line, content }, @@ -44,10 +47,14 @@ for await (const entry of stylesheets) { ); // advanced linting with stylelint - await lint(entry, content, flags.fix); + await lint(entry, content, flags.fix).catch(() => failed = true); } // if any files are missing, cause the workflow to fail if (await checkForMissingFiles() === false) { + failed = true; +} + +if (failed) { Deno.exit(1); } diff --git a/scripts/lint/stylelint.ts b/scripts/lint/stylelint.ts index 81138ee047..96ab17401d 100644 --- a/scripts/lint/stylelint.ts +++ b/scripts/lint/stylelint.ts @@ -10,10 +10,8 @@ import "npm:stylelint-config-recommended"; import { REPO_ROOT } from "@/deps.ts"; import { log } from "@/lint/logger.ts"; -export const lint = async (entry: WalkEntry, content: string, fix: boolean) => { - const file = relative(REPO_ROOT, entry.path); - - await stylelint.lint({ files: entry.path, fix }) +export const lint = (entry: WalkEntry, content: string, fix: boolean) => + stylelint.lint({ files: entry.path, fix }) .then(({ results }) => { results.map((result) => { result.warnings.map((warning) => { @@ -24,7 +22,7 @@ export const lint = async (entry: WalkEntry, content: string, fix: boolean) => { ) ?? "unspecified stylelint error"; log(message, { - file, + file: relative(REPO_ROOT, entry.path), startLine: warning.line, endLine: warning.endLine, startColumn: warning.column, @@ -32,6 +30,6 @@ export const lint = async (entry: WalkEntry, content: string, fix: boolean) => { content, }, warning.severity); }); + if (result.warnings.length > 0) throw new Error("stylelint error"); }); }); -};