Skip to content

Commit 5f1844b

Browse files
committed
feat: made the lint script actually exit with a fail if eslint found errors
1 parent 9182396 commit 5f1844b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/bin/lint.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ async function main(argv = process.argv) {
6666
}
6767

6868
try {
69-
await utils.runESLint({
69+
const hadLintingErrors = await utils.runESLint({
7070
fix,
7171
configPath: chosenConfig,
7272
explicitGlobs: eslintPatterns,
7373
});
74+
75+
if (hadLintingErrors) {
76+
hadFailure = true;
77+
}
7478
} catch (err) {
7579
console.error(`ESLint failed: \n${err}`);
7680
hadFailure = true;
@@ -182,7 +186,10 @@ async function main(argv = process.argv) {
182186
}
183187

184188
if (hadFailure) {
189+
console.error('[matrixai-lint] ✖ Linting failed.');
185190
process.exit(1);
191+
} else {
192+
console.error('[matrixai-lint] ✔ Linting passed.');
186193
}
187194
}
188195

src/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function runESLint({
1616
fix: boolean;
1717
configPath?: string;
1818
explicitGlobs?: string[];
19-
}) {
19+
}): Promise<boolean> {
2020
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
2121
const defaultConfigPath = path.resolve(dirname, './configs/js.js');
2222

@@ -33,8 +33,7 @@ async function runESLint({
3333
ignorePatterns: [], // Trust caller entirely
3434
});
3535

36-
await lintAndReport(eslint, explicitGlobs, fix);
37-
return;
36+
return await lintAndReport(eslint, explicitGlobs, fix);
3837
}
3938

4039
// PATH B – default behaviour (tsconfig + matrix config)
@@ -63,10 +62,14 @@ async function runESLint({
6362
ignorePatterns: ignorePats,
6463
});
6564

66-
await lintAndReport(eslint, patterns, fix);
65+
return await lintAndReport(eslint, patterns, fix);
6766
}
6867

69-
async function lintAndReport(eslint: ESLint, patterns: string[], fix: boolean) {
68+
async function lintAndReport(
69+
eslint: ESLint,
70+
patterns: string[],
71+
fix: boolean,
72+
): Promise<boolean> {
7073
const results = await eslint.lintFiles(patterns);
7174

7275
if (fix) {
@@ -75,6 +78,9 @@ async function lintAndReport(eslint: ESLint, patterns: string[], fix: boolean) {
7578

7679
const formatter = await eslint.loadFormatter('stylish');
7780
console.log(formatter.format(results));
81+
const hasErrors = results.some((r) => r.errorCount > 0);
82+
83+
return hasErrors;
7884
}
7985
/* eslint-enable no-console */
8086

0 commit comments

Comments
 (0)