From 5e43c0f16b5dd976e00627f326bde855c59ecae1 Mon Sep 17 00:00:00 2001 From: Maxim Mazurok Date: Mon, 24 Jan 2022 18:40:24 +1100 Subject: [PATCH 1/3] fail-fast --- cspell.schema.json | 4 ++++ packages/cspell-lib/src/__snapshots__/index.test.ts.snap | 1 + packages/cspell-types/cspell.schema.json | 4 ++++ packages/cspell-types/src/CSpellSettingsDef.ts | 4 ++++ packages/cspell-types/src/configFields.ts | 1 + packages/cspell/samples/fail-fast/cspell.json | 8 ++++++++ packages/cspell/samples/fail-fast/fail-fast-cspell.json | 9 +++++++++ packages/cspell/samples/fail-fast/first-fail.txt | 1 + packages/cspell/samples/fail-fast/second-fail.txt | 1 + packages/cspell/src/lint/lint.test.ts | 3 +++ packages/cspell/src/lint/lint.ts | 3 +++ 11 files changed, 39 insertions(+) create mode 100644 packages/cspell/samples/fail-fast/cspell.json create mode 100644 packages/cspell/samples/fail-fast/fail-fast-cspell.json create mode 100644 packages/cspell/samples/fail-fast/first-fail.txt create mode 100644 packages/cspell/samples/fail-fast/second-fail.txt diff --git a/cspell.schema.json b/cspell.schema.json index c4a236b83900..c60634737987 100644 --- a/cspell.schema.json +++ b/cspell.schema.json @@ -1126,6 +1126,10 @@ }, "type": "array" }, + "failFast": { + "description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks); false by default", + "type": "boolean" + }, "features": { "$ref": "#/definitions/Features", "description": "Configure CSpell features.\n\n- Added with `v5.16.0`." diff --git a/packages/cspell-lib/src/__snapshots__/index.test.ts.snap b/packages/cspell-lib/src/__snapshots__/index.test.ts.snap index 7836ce5d2527..44897515f304 100644 --- a/packages/cspell-lib/src/__snapshots__/index.test.ts.snap +++ b/packages/cspell-lib/src/__snapshots__/index.test.ts.snap @@ -21,6 +21,7 @@ Object { "enableGlobDot": "enableGlobDot", "enabled": "enabled", "enabledLanguageIds": "enabledLanguageIds", + "failFast": "failFast", "features": "features", "files": "files", "flagWords": "flagWords", diff --git a/packages/cspell-types/cspell.schema.json b/packages/cspell-types/cspell.schema.json index c4a236b83900..c60634737987 100644 --- a/packages/cspell-types/cspell.schema.json +++ b/packages/cspell-types/cspell.schema.json @@ -1126,6 +1126,10 @@ }, "type": "array" }, + "failFast": { + "description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks); false by default", + "type": "boolean" + }, "features": { "$ref": "#/definitions/Features", "description": "Configure CSpell features.\n\n- Added with `v5.16.0`." diff --git a/packages/cspell-types/src/CSpellSettingsDef.ts b/packages/cspell-types/src/CSpellSettingsDef.ts index 0727194e9681..e4c42ffc48a3 100644 --- a/packages/cspell-types/src/CSpellSettingsDef.ts +++ b/packages/cspell-types/src/CSpellSettingsDef.ts @@ -266,6 +266,10 @@ 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); false by default + */ + failFast?: boolean; } /** diff --git a/packages/cspell-types/src/configFields.ts b/packages/cspell-types/src/configFields.ts index 5b449056bd0d..cd8085aa2b8b 100644 --- a/packages/cspell-types/src/configFields.ts +++ b/packages/cspell-types/src/configFields.ts @@ -17,6 +17,7 @@ export const ConfigFields: CSpellUserSettingsFields = { enabledLanguageIds: 'enabledLanguageIds', enableFiletypes: 'enableFiletypes', enableGlobDot: 'enableGlobDot', + failFast: 'failFast', features: 'features', files: 'files', flagWords: 'flagWords', diff --git a/packages/cspell/samples/fail-fast/cspell.json b/packages/cspell/samples/fail-fast/cspell.json new file mode 100644 index 000000000000..5c7596ffb4c6 --- /dev/null +++ b/packages/cspell/samples/fail-fast/cspell.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", + // Version of the setting file. Always 0.1 + "version": "0.2", + // language - current active spelling language + "language": "en", + "files": ["**/*.txt"] +} diff --git a/packages/cspell/samples/fail-fast/fail-fast-cspell.json b/packages/cspell/samples/fail-fast/fail-fast-cspell.json new file mode 100644 index 000000000000..41b691620332 --- /dev/null +++ b/packages/cspell/samples/fail-fast/fail-fast-cspell.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", + // Version of the setting file. Always 0.1 + "version": "0.2", + // language - current active spelling language + "language": "en", + "files": ["**/*.txt"], + "failFast": true +} diff --git a/packages/cspell/samples/fail-fast/first-fail.txt b/packages/cspell/samples/fail-fast/first-fail.txt new file mode 100644 index 000000000000..e44a66c2115a --- /dev/null +++ b/packages/cspell/samples/fail-fast/first-fail.txt @@ -0,0 +1 @@ +iamtypo diff --git a/packages/cspell/samples/fail-fast/second-fail.txt b/packages/cspell/samples/fail-fast/second-fail.txt new file mode 100644 index 000000000000..963891671617 --- /dev/null +++ b/packages/cspell/samples/fail-fast/second-fail.txt @@ -0,0 +1 @@ +iamtypotoo diff --git a/packages/cspell/src/lint/lint.test.ts b/packages/cspell/src/lint/lint.test.ts index 04e1682590f6..9e4d0335e6dd 100644 --- a/packages/cspell/src/lint/lint.test.ts +++ b/packages/cspell/src/lint/lint.test.ts @@ -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'); @@ -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: [] })} diff --git a/packages/cspell/src/lint/lint.ts b/packages/cspell/src/lint/lint.ts index 362e8c3c9e5c..02beb3e2be97 100644 --- a/packages/cspell/src/lint/lint.ts +++ b/packages/cspell/src/lint/lint.ts @@ -160,6 +160,9 @@ export async function runLint(cfg: LintRequest): Promise { status.filesWithIssues.add(filename); status.issues += result.issues.length; status.errors += result.errors; + if (configInfo.config.failFast === true) { + return status; + } } status.errors += result.configErrors; } From fd0b41e96a665d220fd6eea2fbf673efb3880425 Mon Sep 17 00:00:00 2001 From: Maxim Mazurok Date: Mon, 24 Jan 2022 23:27:32 +1100 Subject: [PATCH 2/3] address comments --- packages/cspell-types/src/CSpellSettingsDef.ts | 3 ++- packages/cspell/samples/fail-fast/cspell.json | 2 -- packages/cspell/samples/fail-fast/fail-fast-cspell.json | 6 +----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/cspell-types/src/CSpellSettingsDef.ts b/packages/cspell-types/src/CSpellSettingsDef.ts index e4c42ffc48a3..9faa9a8af55d 100644 --- a/packages/cspell-types/src/CSpellSettingsDef.ts +++ b/packages/cspell-types/src/CSpellSettingsDef.ts @@ -267,7 +267,8 @@ export interface CommandLineSettings { */ cache?: CacheSettings; /** - * Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks); false by default + * Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks) + * @default */ failFast?: boolean; } diff --git a/packages/cspell/samples/fail-fast/cspell.json b/packages/cspell/samples/fail-fast/cspell.json index 5c7596ffb4c6..9c4337806c60 100644 --- a/packages/cspell/samples/fail-fast/cspell.json +++ b/packages/cspell/samples/fail-fast/cspell.json @@ -1,8 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", - // Version of the setting file. Always 0.1 "version": "0.2", - // language - current active spelling language "language": "en", "files": ["**/*.txt"] } diff --git a/packages/cspell/samples/fail-fast/fail-fast-cspell.json b/packages/cspell/samples/fail-fast/fail-fast-cspell.json index 41b691620332..0429921995e3 100644 --- a/packages/cspell/samples/fail-fast/fail-fast-cspell.json +++ b/packages/cspell/samples/fail-fast/fail-fast-cspell.json @@ -1,9 +1,5 @@ { "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", - // Version of the setting file. Always 0.1 - "version": "0.2", - // language - current active spelling language - "language": "en", - "files": ["**/*.txt"], + "import": "./cspell.json", "failFast": true } From 58af3dd6bb3f1d429c194302911e5be1370f7ddb Mon Sep 17 00:00:00 2001 From: Maxim Mazurok Date: Mon, 24 Jan 2022 23:32:51 +1100 Subject: [PATCH 3/3] update schema --- cspell.schema.json | 3 ++- packages/cspell-types/cspell.schema.json | 3 ++- packages/cspell-types/src/CSpellSettingsDef.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cspell.schema.json b/cspell.schema.json index c60634737987..d118f113ecc3 100644 --- a/cspell.schema.json +++ b/cspell.schema.json @@ -1127,7 +1127,8 @@ "type": "array" }, "failFast": { - "description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks); false by default", + "default": false, + "description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks)", "type": "boolean" }, "features": { diff --git a/packages/cspell-types/cspell.schema.json b/packages/cspell-types/cspell.schema.json index c60634737987..d118f113ecc3 100644 --- a/packages/cspell-types/cspell.schema.json +++ b/packages/cspell-types/cspell.schema.json @@ -1127,7 +1127,8 @@ "type": "array" }, "failFast": { - "description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks); false by default", + "default": false, + "description": "Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks)", "type": "boolean" }, "features": { diff --git a/packages/cspell-types/src/CSpellSettingsDef.ts b/packages/cspell-types/src/CSpellSettingsDef.ts index 9faa9a8af55d..2a1debe158cd 100644 --- a/packages/cspell-types/src/CSpellSettingsDef.ts +++ b/packages/cspell-types/src/CSpellSettingsDef.ts @@ -268,7 +268,7 @@ export interface CommandLineSettings { cache?: CacheSettings; /** * Exit with non-zero code as soon as an issue/error encountered (useful for CI or git hooks) - * @default + * @default false */ failFast?: boolean; }