ci(lint): exit with error when issues are found (#419)
This commit is contained in:
1 parent
2064cb869e
commit
d520b24b53
2 files changed
+14
-9
No files matched your search
+10
-3
@@ -20,6 +20,8 @@ const stylesheets = walk(join(REPO_ROOT, "styles", subDir), {
|
|||||||
match: [/\.user.css$/],
|
match: [/\.user.css$/],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let failed = false;
|
||||||
|
|
||||||
for await (const entry of stylesheets) {
|
for await (const entry of stylesheets) {
|
||||||
const repodir = dirname(entry.path);
|
const repodir = dirname(entry.path);
|
||||||
const repo = basename(repodir);
|
const repo = basename(repodir);
|
||||||
@@ -33,8 +35,9 @@ for await (const entry of stylesheets) {
|
|||||||
if (!isLess) continue;
|
if (!isLess) continue;
|
||||||
|
|
||||||
// try to compile the less file, report any errors
|
// try to compile the less file, report any errors
|
||||||
less.render(content, { lint: true, globalVars }).then().catch(
|
less.render(content, { lint: true, globalVars }).catch(
|
||||||
(err) => {
|
(err: Less.RenderError) => {
|
||||||
|
failed = true;
|
||||||
log(
|
log(
|
||||||
err.message,
|
err.message,
|
||||||
{ file, startLine: err.line, endLine: err.line, content },
|
{ file, startLine: err.line, endLine: err.line, content },
|
||||||
@@ -44,10 +47,14 @@ for await (const entry of stylesheets) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// advanced linting with stylelint
|
// 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 any files are missing, cause the workflow to fail
|
||||||
if (await checkForMissingFiles() === false) {
|
if (await checkForMissingFiles() === false) {
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,8 @@ import "npm:stylelint-config-recommended";
|
|||||||
import { REPO_ROOT } from "@/deps.ts";
|
import { REPO_ROOT } from "@/deps.ts";
|
||||||
import { log } from "@/lint/logger.ts";
|
import { log } from "@/lint/logger.ts";
|
||||||
|
|
||||||
export const lint = async (entry: WalkEntry, content: string, fix: boolean) => {
|
export const lint = (entry: WalkEntry, content: string, fix: boolean) =>
|
||||||
const file = relative(REPO_ROOT, entry.path);
|
stylelint.lint({ files: entry.path, fix })
|
||||||
|
|
||||||
await stylelint.lint({ files: entry.path, fix })
|
|
||||||
.then(({ results }) => {
|
.then(({ results }) => {
|
||||||
results.map((result) => {
|
results.map((result) => {
|
||||||
result.warnings.map((warning) => {
|
result.warnings.map((warning) => {
|
||||||
@@ -24,7 +22,7 @@ export const lint = async (entry: WalkEntry, content: string, fix: boolean) => {
|
|||||||
) ?? "unspecified stylelint error";
|
) ?? "unspecified stylelint error";
|
||||||
|
|
||||||
log(message, {
|
log(message, {
|
||||||
file,
|
file: relative(REPO_ROOT, entry.path),
|
||||||
startLine: warning.line,
|
startLine: warning.line,
|
||||||
endLine: warning.endLine,
|
endLine: warning.endLine,
|
||||||
startColumn: warning.column,
|
startColumn: warning.column,
|
||||||
@@ -32,6 +30,6 @@ export const lint = async (entry: WalkEntry, content: string, fix: boolean) => {
|
|||||||
content,
|
content,
|
||||||
}, warning.severity);
|
}, warning.severity);
|
||||||
});
|
});
|
||||||
|
if (result.warnings.length > 0) throw new Error("stylelint error");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
|
||||||
Reference in new issue
Block a user