Skip to content

Commit

Permalink
feat: Add failFast config option to exit as soon as an issue encoun…
Browse files Browse the repository at this point in the history
…tered (#2307)

* add failFast config option
* update schema
  • Loading branch information
Maxim-Mazurok committed Jan 26, 2022
1 parent e9c408b commit 26dd25a
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,11 @@
},
"type": "array"
},
"failFast": {
"default": false,
"description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks)",
"type": "boolean"
},
"features": {
"$ref": "#/definitions/Features",
"description": "Configure CSpell features.\n\n- Added with `v5.16.0`."
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-lib/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Object {
"enableGlobDot": "enableGlobDot",
"enabled": "enabled",
"enabledLanguageIds": "enabledLanguageIds",
"failFast": "failFast",
"features": "features",
"files": "files",
"flagWords": "flagWords",
Expand Down
5 changes: 5 additions & 0 deletions packages/cspell-types/cspell.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,11 @@
},
"type": "array"
},
"failFast": {
"default": false,
"description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks)",
"type": "boolean"
},
"features": {
"$ref": "#/definitions/Features",
"description": "Configure CSpell features.\n\n- Added with `v5.16.0`."
Expand Down
5 changes: 5 additions & 0 deletions packages/cspell-types/src/CSpellSettingsDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ export interface CommandLineSettings {
* Define cache settings.
*/
cache?: CacheSettings;
/**
* Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks)
* @default false
*/
failFast?: boolean;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/cspell-types/src/configFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const ConfigFields: CSpellUserSettingsFields = {
enabledLanguageIds: 'enabledLanguageIds',
enableFiletypes: 'enableFiletypes',
enableGlobDot: 'enableGlobDot',
failFast: 'failFast',
features: 'features',
files: 'files',
flagWords: 'flagWords',
Expand Down
6 changes: 6 additions & 0 deletions packages/cspell/samples/fail-fast/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"language": "en",
"files": ["**/*.txt"]
}
5 changes: 5 additions & 0 deletions packages/cspell/samples/fail-fast/fail-fast-cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"import": "./cspell.json",
"failFast": true
}
1 change: 1 addition & 0 deletions packages/cspell/samples/fail-fast/first-fail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iamtypo
1 change: 1 addition & 0 deletions packages/cspell/samples/fail-fast/second-fail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iamtypotoo
3 changes: 3 additions & 0 deletions packages/cspell/src/lint/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { runLint } from './lint';
const root = path.resolve(__dirname, '../..');
const samples = path.resolve(root, 'samples');
const latexSamples = path.resolve(samples, 'latex');
const failFastSamples = path.resolve(samples, 'fail-fast');
const hiddenSamples = path.resolve(samples, 'hidden-test');
const filesToCheck = path.resolve(root, 'fixtures/features/file-list/files-to-check.txt');
const filesToCheckWithMissing = path.resolve(root, 'fixtures/features/file-list/files-to-check-missing.txt');
Expand All @@ -27,6 +28,8 @@ describe('Linter Validation Tests', () => {
test.each`
files | options | expectedRunResult | expectedReport
${[]} | ${{ root: latexSamples }} | ${oc({ errors: 0, files: 4 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'Tufte' })] })}
${['*.txt']} | ${{ root: failFastSamples }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 2 }) })}
${['*.txt']} | ${{ root: failFastSamples, config: j(samples, 'fail-fast', 'fail-fast-cspell.json') }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 1 }) })}
${['**/ebook.tex']} | ${{ root: latexSamples }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${['**/ebook.tex']} | ${{ root: latexSamples, gitignore: true }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
${['**/hidden.md']} | ${{ root: hiddenSamples }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })}
Expand Down
3 changes: 3 additions & 0 deletions packages/cspell/src/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ export async function runLint(cfg: LintRequest): Promise<RunResult> {
status.filesWithIssues.add(filename);
status.issues += result.issues.length;
status.errors += result.errors;
if (configInfo.config.failFast === true) {
return status;
}
}
status.errors += result.configErrors;
}
Expand Down

0 comments on commit 26dd25a

Please sign in to comment.