Skip to content

Commit

Permalink
ci(lint): exit with error when issues are found
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed Dec 27, 2023
1 parent 80f0d16 commit bb01400
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 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 errored;

for await (const entry of stylesheets) {
const repodir = dirname(entry.path);
const repo = basename(repodir);
Expand All @@ -35,6 +37,7 @@ for await (const entry of stylesheets) {
// try to compile the less file, report any errors
less.render(content, { lint: true, globalVars }).then().catch(
(err) => {
errored = true;
log(
err.message,
{ file, startLine: err.line, endLine: err.line, content },
Expand All @@ -44,10 +47,16 @@ for await (const entry of stylesheets) {
);

// advanced linting with stylelint
await lint(entry, content, flags.fix);
if (await lint(entry, content, flags.fix) === false) {
errored = true;
}
}

// if any files are missing, cause the workflow to fail
if (await checkForMissingFiles() === false) {
errored = true;
}

if (errored) {
Deno.exit(1);
}
8 changes: 8 additions & 0 deletions scripts/lint/stylelint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ import { log } from "@/lint/logger.ts";
export const lint = async (entry: WalkEntry, content: string, fix: boolean) => {
const file = relative(REPO_ROOT, entry.path);

let success = true;

await stylelint.lint({ files: entry.path, fix })
.then(({ results }) => {
results.map((result) => {
if (result.warnings.length > 0) {
success = false;
}

result.warnings.map((warning) => {
// Some cleanup for fancier logging, dims the rule name
const message = warning.text?.replace(
Expand All @@ -34,4 +40,6 @@ export const lint = async (entry: WalkEntry, content: string, fix: boolean) => {
});
});
});

return success;
};

0 comments on commit bb01400

Please sign in to comment.