Skip to content

Commit 6df63fb

Browse files
fughillikbanlkJason3S
authored
fix: Add --no-exit-code option to prevent spelling issues from impacting the exit code. (#4809)
Co-authored-by: Kevin Balke <kbalke@neuralink.com> Co-authored-by: Jason Dent <jason@streetsidesoftware.nl>
1 parent 611e0a8 commit 6df63fb

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

packages/cspell/src/app/__snapshots__/app.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ exports[`Validate cli > app 'check help' Expect Error: 'outputHelp' 1`] = `
183183
" --no-validate-directives Do not validate in-document CSpell directives.",
184184
" --no-color Turn off color.",
185185
" --color Force color",
186+
" --no-exit-code Do not return an exit code if issues are found.",
186187
" --no-default-configuration Do not load the default configuration and",
187188
" dictionaries.",
188189
" -h, --help display help for command",
@@ -513,6 +514,7 @@ exports[`Validate cli > app 'no-args' Expect Error: 'outputHelp' 1`] = `
513514
" --no-progress Turn off progress messages",
514515
" --no-summary Turn off summary message in console.",
515516
" -s, --silent Silent mode, suppress error messages.",
517+
" --no-exit-code Do not return an exit code if issues are found.",
516518
" --quiet Only show spelling issues or errors.",
517519
" --fail-fast Exit after first file with an issue or error.",
518520
" -r, --root <root folder> Root directory, defaults to current directory.",

packages/cspell/src/app/commandCheck.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function commandCheck(prog: Command): Command {
2121
.option('--no-validate-directives', 'Do not validate in-document CSpell directives.')
2222
.option('--no-color', 'Turn off color.')
2323
.option('--color', 'Force color')
24+
.option('--no-exit-code', 'Do not return an exit code if issues are found.')
2425
.addOption(
2526
new CommanderOption(
2627
'--default-configuration',
@@ -34,6 +35,7 @@ export function commandCheck(prog: Command): Command {
3435
),
3536
)
3637
.action(async (files: string[], options: CheckCommandOptions) => {
38+
const useExitCode = options.exitCode ?? true;
3739
App.parseApplicationFeatureFlags(options.flag);
3840
let issueCount = 0;
3941
for (const filename of files) {
@@ -60,7 +62,8 @@ export function commandCheck(prog: Command): Command {
6062
console.log();
6163
}
6264
if (issueCount) {
63-
throw new CheckFailed('Issues found', 1);
65+
const exitCode = useExitCode ?? true ? 1 : 0;
66+
throw new CheckFailed('Issues found', exitCode);
6467
}
6568
});
6669
}

packages/cspell/src/app/commandLint.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function commandLint(prog: Command): Command {
9696
.option('--no-progress', 'Turn off progress messages')
9797
.option('--no-summary', 'Turn off summary message in console.')
9898
.option('-s, --silent', 'Silent mode, suppress error messages.')
99+
.option('--no-exit-code', 'Do not return an exit code if issues are found.')
99100
.addOption(
100101
new CommanderOption('--quiet', 'Only show spelling issues or errors.').implies({
101102
summary: false,
@@ -162,16 +163,21 @@ export function commandLint(prog: Command): Command {
162163
.addHelpText('after', advanced)
163164
.arguments('[globs...]')
164165
.action((fileGlobs: string[], options: LinterCliOptions) => {
166+
const useExitCode = options.exitCode ?? true;
165167
App.parseApplicationFeatureFlags(options.flag);
166168
const { mustFindFiles, fileList } = options;
167169
return App.lint(fileGlobs, options).then((result) => {
168170
if (!fileGlobs.length && !result.files && !result.errors && !fileList) {
169171
spellCheckCommand.outputHelp();
170172
throw new CheckFailed('outputHelp', 1);
171173
}
172-
if (result.issues || result.errors || (mustFindFiles && !result.files)) {
174+
if (result.errors || (mustFindFiles && !result.files)) {
173175
throw new CheckFailed('check failed', 1);
174176
}
177+
if (result.issues) {
178+
const exitCode = useExitCode ? 1 : 0;
179+
throw new CheckFailed('check failed', exitCode);
180+
}
175181
return;
176182
});
177183
});

packages/cspell/src/app/options.ts

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ export interface BaseOptions {
155155
*/
156156
validateDirectives?: boolean;
157157

158+
/**
159+
* Return an exit code if there are issues found.
160+
* @default true
161+
*/
162+
exitCode?: boolean;
163+
158164
/**
159165
* Execution flags.
160166
* Used primarily for releasing experimental features.

0 commit comments

Comments
 (0)