Skip to content

Commit

Permalink
ci(lint): exit with error when issues are found (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter authored Dec 28, 2023
1 parent 2064cb8 commit d520b24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 10 additions & 3 deletions scripts/lint/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 },
Expand All @@ -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);
}
10 changes: 4 additions & 6 deletions scripts/lint/stylelint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -24,14 +22,14 @@ 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,
endColumn: warning.endColumn,
content,
}, warning.severity);
});
if (result.warnings.length > 0) throw new Error("stylelint error");
});
});
};

0 comments on commit d520b24

Please sign in to comment.