Skip to content

Commit 4c3c3f4

Browse files
feat(scripts): Add max-warnings arg for ESLint
1 parent fe60de4 commit 4c3c3f4

File tree

7 files changed

+18
-2
lines changed

7 files changed

+18
-2
lines changed

.changeset/salty-pianos-write.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tcd-devkit/scripts': patch
3+
---
4+
5+
Add max-warnings arg for ESLint

packages/scripts/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ Runs ESLint, Prettier (check mode), and TypeScript type checking.
6464
- `--refresh-cache`: Force refresh of the cache.
6565
- `--ignore-path <path>`: Path to a custom ignore file (e.g., `.myignore`).
6666
- `--project <path>`: Path to your `tsconfig.json` or equivalent TypeScript project file. (e.g., `tcd-scripts lint --project ./tsconfig.build.json`)
67+
- `--max-warnings <number>`: Maximum number of warnings allowed before failing. (Default: 0)
6768

6869
**Example:**
6970

7071
```bash
71-
tcd-scripts lint ./src ./tests --only eslint --project ./tsconfig.lint.json
72+
tcd-scripts lint ./src ./tests --only eslint --project ./tsconfig.lint.json --max-warnings 10
7273
```
7374

7475
#### `tcd-scripts format [files...]` (alias: `tcd-scripts f`)

packages/scripts/src/commands/format.command.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const registerFormatCommand = (program: Command) => {
2626
.addOption(noCacheOption)
2727
.addOption(refreshCacheOption)
2828
.addOption(ignorePathOption)
29-
3029
.action(async (files: string[], options: FormatCommandOptions) => {
3130
const toolsToRun = getToolsToRun(FORMAT_TOOLS, options);
3231
let overallSuccess = true;

packages/scripts/src/commands/lint.command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ignorePathOption,
66
lintOnlyOption,
77
lintSkipOption,
8+
maxWarningsOption,
89
noCacheOption,
910
projectOption,
1011
refreshCacheOption,
@@ -31,6 +32,7 @@ export const registerLintCommand = (program: Command) => {
3132
.addOption(refreshCacheOption)
3233
.addOption(ignorePathOption)
3334
.addOption(projectOption)
35+
.addOption(maxWarningsOption)
3436
.action(async (files, options: LintCommandOptions) => {
3537
const toolsToRun = getToolsToRun(LINT_TOOLS, options);
3638
let overallSuccess = true;

packages/scripts/src/constants/option.constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export const ignorePathOption = new Option(
5454
'Path to ignore file for Prettier',
5555
);
5656

57+
export const maxWarningsOption = new Option(
58+
'--max-warnings <number>',
59+
'Maximum number of warnings allowed before failing',
60+
).default('0');
61+
5762
export const projectOption = new Option(
5863
'--project <path>',
5964
'Path to TS config for TSC',

packages/scripts/src/types/option.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface BaseCommandOptions {
99
refreshCache?: boolean;
1010
cacheLocation?: string;
1111
ignorePath?: string;
12+
maxWarnings?: string;
1213
}
1314

1415
export interface ToolSelectionOptions<TTool extends string> {

packages/scripts/src/utils/cli.utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export const runEslint = async (
157157
const eslintArgs = [];
158158

159159
if (isFix) eslintArgs.push('--fix');
160+
if (options.maxWarnings !== undefined) {
161+
eslintArgs.push('--max-warnings', options.maxWarnings.toString());
162+
}
160163

161164
await handleCache(options, eslintArgs, './.eslintcache');
162165

0 commit comments

Comments
 (0)