Skip to content

Commit

Permalink
Fix eslint error propagation (#2654)
Browse files Browse the repository at this point in the history
* Fix eslint error propagation

* Address feedback
  • Loading branch information
stephl3 authored Jan 23, 2025
1 parent 2eb308f commit 23f6bc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-rules-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lg-tools/lint': patch
---

Fix eslint so errors properly propagate during CI lint check
17 changes: 12 additions & 5 deletions tools/lint/src/eslint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */
import chalk from 'chalk';
import { ESLint } from 'eslint';
import path from 'path';

Expand Down Expand Up @@ -26,9 +28,9 @@ interface ESLintRunnerOptions extends BaseLintRunnerOptions {
/**
* Creates and runs an ESLint instance
*/
export async function eslint(
options?: ESLintRunnerOptions,
): Promise<Array<ESLint.LintResult>> {
export async function eslint(options?: ESLintRunnerOptions): Promise<boolean> {
console.log(chalk.blue('Running ESLint...'));

const filePaths = options?.filePaths || allFilePaths;
const fix = options?.fix || false;

Expand All @@ -41,8 +43,13 @@ export async function eslint(

const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
// eslint-disable-next-line no-console
console.log(resultText);

return results;
const totalErrors = results.reduce(
(acc, result) => acc + result.errorCount,
0,
);
const hasErrors = totalErrors > 0;

return !hasErrors;
}

0 comments on commit 23f6bc7

Please sign in to comment.