From aa4982b5adffa3d81e823fca5fb52048c51917ff Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Thu, 27 Aug 2026 15:10:27 +0200 Subject: [PATCH 1/5] feat: Add `--force-check` cli option --- @internal/tsdown/config.ts | 6 +-- package.json | 1 - .../tsdown.config.ts | 2 +- packages/cspell-lib/api/api.d.ts | 4 ++ .../src/lib/textValidation/docValidator.ts | 7 +++- packages/cspell-trie-lib/tsdown.config.ts | 2 +- packages/cspell/bin.mjs | 1 + .../cspell/src/__snapshots__/app.test.ts.snap | 37 +++++++++++++++++++ packages/cspell/src/app.test.ts | 33 +++++++++++++++++ packages/cspell/src/cli-reporter.ts | 2 +- packages/cspell/src/commandLint.ts | 12 +++++- packages/cspell/src/lint/lint.ts | 23 ++++++++++-- packages/cspell/src/lint/processFile.ts | 8 +++- packages/cspell/src/options.ts | 8 ++++ 14 files changed, 132 insertions(+), 14 deletions(-) diff --git a/@internal/tsdown/config.ts b/@internal/tsdown/config.ts index 5e8ec6e73da3..50bb9c276b3e 100644 --- a/@internal/tsdown/config.ts +++ b/@internal/tsdown/config.ts @@ -6,13 +6,13 @@ export type { UserConfig } from 'tsdown'; export { defineConfig } from 'tsdown'; export const defaultDeps: DepsConfig = { - onlyAllowBundle: [], + onlyBundle: [], }; export const defaultConfig: UserConfig = { outDir: 'dist', format: ['esm'], - target: 'Node20', + target: 'Node22', dts: true, sourcemap: true, clean: true, @@ -39,7 +39,7 @@ export function createConfig(config: UserConfig | UserConfig[]): UserConfig | Us * const config = createConfig({ * entry: ['src/index.ts'], * outDir: 'dist', - * ...deps({ onlyAllowBundle: ['gensequence'] }), + * ...deps({ onlyBundle: ['gensequence'] }), * }); * ``` * @param deps - config to merge diff --git a/package.json b/package.json index 1b74a2dbf97a..f011f5b34cbe 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "clean-build": "pnpm run clean && pnpm -r --stream --workspace-concurrency=2 run build", "clean-dist": "shx rm -rf \"packages/*/dist\"", "clean": "shx rm -rf \"{*,*/*}/{*.tsbuildinfo,*.tsbuildInfo,temp,coverage,*.cpuprofile}\" \"**/dist/**/*.tsbuildInfo\" lcov.info && pnpm -r run clean", - "#coverage-collect": "globcat \"packages/*/coverage/lcov.info\" > lcov.info", "coverage-collect": "shx cat packages/*/coverage/lcov.info > lcov.info", "coverage": "pnpm --stream -r --workspace-concurrency=1 run coverage && pnpm run coverage-collect", "eslint-fix": "eslint . --fix --cache", diff --git a/packages/cspell-dictionary-bundler-plugin/tsdown.config.ts b/packages/cspell-dictionary-bundler-plugin/tsdown.config.ts index bbd5b27f6d8d..9f7bf15d835a 100644 --- a/packages/cspell-dictionary-bundler-plugin/tsdown.config.ts +++ b/packages/cspell-dictionary-bundler-plugin/tsdown.config.ts @@ -6,7 +6,7 @@ const baseConfig: UserConfig = { outDir: 'dist', format: ['esm'], deps: { - onlyAllowBundle: false, + onlyBundle: false, }, }; diff --git a/packages/cspell-lib/api/api.d.ts b/packages/cspell-lib/api/api.d.ts index 3ff1d0312f76..c9720e0a53f2 100644 --- a/packages/cspell-lib/api/api.d.ts +++ b/packages/cspell-lib/api/api.d.ts @@ -838,6 +838,10 @@ interface DocumentValidatorOptions extends ValidateTextOptions { * If not set, the current working directory will be used. */ resolveImportsRelativeTo?: string | URL; + /** + * If true, the document will be checked even if it would normally be excluded. + */ + forceCheck?: boolean; } type PerfTimings = Record; declare class DocumentValidator { diff --git a/packages/cspell-lib/src/lib/textValidation/docValidator.ts b/packages/cspell-lib/src/lib/textValidation/docValidator.ts index f1ee079cf9a2..f08c524207eb 100644 --- a/packages/cspell-lib/src/lib/textValidation/docValidator.ts +++ b/packages/cspell-lib/src/lib/textValidation/docValidator.ts @@ -77,6 +77,11 @@ export interface DocumentValidatorOptions extends ValidateTextOptions { * If not set, the current working directory will be used. */ resolveImportsRelativeTo?: string | URL; + + /** + * If true, the document will be checked even if it would normally be excluded. + */ + forceCheck?: boolean; } const ERROR_NOT_PREPARED = 'Validator Must be prepared before calling this function.'; @@ -188,7 +193,7 @@ export class DocumentValidator { const recShouldCheckTime = recordPerfTime(this.perfTiming, '_shouldCheck'); // eslint-disable-next-line unicorn/prefer-regexp-test - const shouldCheck = !matcher.match(uriToFilePath(uri)) && (docSettings.enabled ?? true); + const shouldCheck = options.forceCheck || (!matcher.match(uriToFilePath(uri)) && (docSettings.enabled ?? true)); recShouldCheckTime(); diff --git a/packages/cspell-trie-lib/tsdown.config.ts b/packages/cspell-trie-lib/tsdown.config.ts index be951b401f7d..28a68a622075 100644 --- a/packages/cspell-trie-lib/tsdown.config.ts +++ b/packages/cspell-trie-lib/tsdown.config.ts @@ -6,7 +6,7 @@ const baseConfig: UserConfig = { outDir: 'dist', fixedExtension: false, platform: 'neutral', - ...deps({ onlyAllowBundle: ['gensequence'] }), + ...deps({ onlyBundle: ['gensequence'] }), }; const config: UserConfig[] = createConfig([baseConfig]); diff --git a/packages/cspell/bin.mjs b/packages/cspell/bin.mjs index a6ae0227ade7..80e676f06d71 100755 --- a/packages/cspell/bin.mjs +++ b/packages/cspell/bin.mjs @@ -6,6 +6,7 @@ import { CommanderError, program } from 'commander'; import { ApplicationError, CheckFailed, run } from './dist/esm/app.js'; run(program, process.argv).catch((e) => { + process.exitCode = process.exitCode || 1; if (!(e instanceof CommanderError) && !(e instanceof CheckFailed)) { const verbose = process.argv.includes('--verbose') || process.argv.includes('-v'); const msg = !verbose && e instanceof ApplicationError ? e.message : format(e); diff --git a/packages/cspell/src/__snapshots__/app.test.ts.snap b/packages/cspell/src/__snapshots__/app.test.ts.snap index 3e7b00f332e9..506d7d10065d 100644 --- a/packages/cspell/src/__snapshots__/app.test.ts.snap +++ b/packages/cspell/src/__snapshots__/app.test.ts.snap @@ -1014,6 +1014,8 @@ exports[`Validate cli > app 'no-args' Expect Error: 'outputHelp' 1`] = ` " line.", " --file [file...] Specify files to spell check. They are filtered", " by the [globs...].", + " --force-check Force the --file or --file-list documents to be", + " checked even if it would normally be excluded.", " --no-issues Do not show the spelling errors.", " --no-progress Turn off progress messages", " --no-summary Turn off summary message in console.", @@ -3823,6 +3825,35 @@ error" exports[`Validate cli > app 'with spelling errors Dutch.txt' Expect Error: [Function CheckFailed] 3`] = `""`; +exports[`Validate cli > app --force-check 'lint --file package.json --force-check' Expect Error: undefined 1`] = `[]`; + +exports[`Validate cli > app --force-check 'lint --file package.json --force-check' Expect Error: undefined 2`] = ` +"error 1/1 package.json 0.00ms +error +error CSpell: Files checked: 1, Issues found: 0 in 0 files. +error" +`; + +exports[`Validate cli > app --force-check 'lint --file package.json --force-check' Expect Error: undefined 3`] = `""`; + +exports[`Validate cli > app --force-check 'lint README.md --file package.json' Expect Error: 'error: mixing globs and --file is not supported' 1`] = `[]`; + +exports[`Validate cli > app --force-check 'lint README.md --file package.json' Expect Error: 'error: mixing globs and --file is not supported' 2`] = `""`; + +exports[`Validate cli > app --force-check 'lint README.md --file package.json' Expect Error: 'error: mixing globs and --file is not supported' 3`] = ` +"error: mixing globs and --file is not supported +" +`; + +exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified.' 1`] = `[]`; + +exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified.' 2`] = `""`; + +exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified.' 3`] = ` +"error: --force-check requires --file, --files, or --file-list to be specified. +" +`; + exports[`Validate cli > app dictionary [ 'dictionaries' ] 1`] = `[]`; exports[`Validate cli > app dictionary [ 'dictionaries' ] 2`] = ` @@ -4328,6 +4359,8 @@ exports[`Validate cli > app help [ 'lint', '--help' ] 1`] = ` " line.", " --file [file...] Specify files to spell check. They are filtered", " by the [globs...].", + " --force-check Force the --file or --file-list documents to be", + " checked even if it would normally be excluded.", " --no-issues Do not show the spelling errors.", " --no-progress Turn off progress messages", " --no-summary Turn off summary message in console.", @@ -4462,6 +4495,8 @@ exports[`Validate cli > app help [ 'lint', '--help', '--issue-template' ] 1`] = " line.", " --file [file...] Specify files to spell check. They are filtered", " by the [globs...].", + " --force-check Force the --file or --file-list documents to be", + " checked even if it would normally be excluded.", " --no-issues Do not show the spelling errors.", " --no-progress Turn off progress messages", " --no-summary Turn off summary message in console.", @@ -4623,6 +4658,8 @@ exports[`Validate cli > app help [ 'lint', '--help', '--verbose' ] 1`] = ` " line.", " --file [file...] Specify files to spell check. They are filtered", " by the [globs...].", + " --force-check Force the --file or --file-list documents to be", + " checked even if it would normally be excluded.", " --no-issues Do not show the spelling errors.", " --no-progress Turn off progress messages", " --no-summary Turn off summary message in console.", diff --git a/packages/cspell/src/app.test.ts b/packages/cspell/src/app.test.ts index da912e783284..9fd25dc1ec98 100644 --- a/packages/cspell/src/app.test.ts +++ b/packages/cspell/src/app.test.ts @@ -106,6 +106,14 @@ interface TestCase { eInfo: boolean; } +interface ArgsTestCase { + args: string | string[]; + errorCheck: ErrorCheck; + eError: boolean; + eLog: boolean; + eInfo: boolean; +} + class RecordStdStream { private static columnWidth = 80; private write = process.stdout.write.bind(process.stdout); @@ -320,6 +328,31 @@ describe('Validate cli', () => { expect(normalizeOutput(captureStderr.text)).toMatchSnapshot(); }); + test.each` + args | errorCheck | eError | eLog | eInfo + ${'lint --file package.json --force-check'} | ${undefined} | ${true} | ${false} | ${false} + ${'lint README.md --file package.json'} | ${'error: mixing globs and --file is not supported'} | ${false} | ${false} | ${false} + ${'lint README.md --force-check'} | ${'error: --force-check requires --file, --files, or --file-list to be specified'} | ${false} | ${false} | ${false} + `( + 'app --force-check $args Expect Error: $errorCheck', + async ({ args: testArgs, errorCheck, eError, eLog, eInfo }: ArgsTestCase) => { + testArgs = typeof testArgs === 'string' ? testArgs.split(' ') : testArgs; + chalk.level = 1; + const commander = getCommander(); + const args = argv(...testArgs); + const result = app.run(commander, args); + await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck)); + + eError ? expect(error).toHaveBeenCalled() : expect(error).not.toHaveBeenCalled(); + eLog ? expect(log).toHaveBeenCalled() : expect(log).not.toHaveBeenCalled(); + eInfo ? expect(info).toHaveBeenCalled() : expect(info).not.toHaveBeenCalled(); + + expect(captureStdout.text).toMatchSnapshot(); + expect(logger.normalizedHistory()).toMatchSnapshot(); + expect(normalizeOutput(captureStderr.text)).toMatchSnapshot(); + }, + ); + test.each` cmdArgs ${['--help']} diff --git a/packages/cspell/src/cli-reporter.ts b/packages/cspell/src/cli-reporter.ts index a82dd91cbf4c..a1e0635c8c9b 100644 --- a/packages/cspell/src/cli-reporter.ts +++ b/packages/cspell/src/cli-reporter.ts @@ -288,7 +288,7 @@ export function getReporter(options: ReporterOptions, config?: CSpellReporterCon } const resultEmitter = (result: RunResult) => { - if (!fileGlobs.length && !result.files) { + if (!fileGlobs.length && !result.files && !result.skippedFiles && !result.errors && !result.issues) { return; } const { files, issues, cachedFiles, filesWithIssues, errors, skippedFiles } = result; diff --git a/packages/cspell/src/commandLint.ts b/packages/cspell/src/commandLint.ts index b7088897f58a..171873292c12 100644 --- a/packages/cspell/src/commandLint.ts +++ b/packages/cspell/src/commandLint.ts @@ -115,6 +115,10 @@ export function commandLint(prog: Command, opts: CommandOptions): Command { ) .option('--file [file...]', 'Specify files to spell check. They are filtered by the [globs...].', collect) .addOption(crOpt('--files [file...]', 'Alias of "--file". Files to spell check.', collect).hideHelp()) + .option( + '--force-check', + 'Force the --file or --file-list documents to be checked even if it would normally be excluded.', + ) .option('--no-issues', 'Do not show the spelling errors.') .option('--no-progress', 'Turn off progress messages') .option('--no-summary', 'Turn off summary message in console.') @@ -213,7 +217,13 @@ async function action(this: Command, fileGlobs: string[], cliOptions: LinterCliC if (maxFileSizeErr) { this.error(`error: invalid option value for --max-file-size: ${maxFileSizeErr}`); } - const { mustFindFiles, fileList, files, file } = options; + const { mustFindFiles, fileList, files, file, forceCheck } = options; + if (forceCheck && !file?.length && !files?.length && !fileList?.length) { + this.error('error: --force-check requires --file, --files, or --file-list to be specified'); + } + if (fileGlobs.length && (file?.length || files?.length)) { + this.error('error: mixing globs and --file is not supported'); + } const result = await App.lint(fileGlobs, options); if (!fileGlobs.length && !result.files && !result.errors && !fileList && !files?.length && !file?.length) { this.outputHelp(); diff --git a/packages/cspell/src/lint/lint.ts b/packages/cspell/src/lint/lint.ts index 84b861aa4171..332b680799cd 100644 --- a/packages/cspell/src/lint/lint.ts +++ b/packages/cspell/src/lint/lint.ts @@ -141,7 +141,7 @@ export async function runLint(cfg: LintRequest): Promise { try { const cacheSettings = await calcCacheSettings(configInfo.config, { ...cfg.options, version }, root); - const files = await determineFilesToCheck(configInfo, cfg, reporter, globInfo); + const { files, skippedFiles } = await determineFilesToCheck(configInfo, cfg, reporter, globInfo); const processFilesOptions: ProcessFilesOptions = { chalk, @@ -159,6 +159,8 @@ export async function runLint(cfg: LintRequest): Promise { if (configErrorCount && cfg.options.exitCode !== false) { result.errors ||= configErrorCount; } + result.files += skippedFiles; + result.skippedFiles = (result.skippedFiles ?? 0) + skippedFiles; debugStats && console.error('stats: %o', getDefaultConfigLoader().getStats()); return result; } catch (e) { @@ -264,12 +266,19 @@ function filesToProcess(files: Iterable): FileToProcess[] { return filenames.map((filename, sequence) => ({ filename, sequence, sequenceSize })); } +interface FilesToCheck { + files: FileToProcess[] | AsyncIterable; + skippedFiles: number; +} + async function determineFilesToCheck( configInfo: ConfigInfo, cfg: LintRequest, reporter: FinalizedReporter, globInfo: AppGlobInfo, -): Promise> { +): Promise { + let skippedFiles = 0; + async function _determineFilesToCheck(): Promise> { const { fileLists } = cfg; const hasFileLists = !!fileLists.length; @@ -317,15 +326,20 @@ async function determineFilesToCheck( function isExcluded(filename: string, globMatcherExclude: GlobMatcher): boolean { if (cspellIsBinaryFile(toFileURL(filename))) { + skippedFiles++; return true; } + if (cfg.options.forceCheck) { + return false; + } const { root } = cfg; const absFilename = path.resolve(root, filename); const r = globMatcherExclude.matchEx(absFilename); if (r.matched) { + skippedFiles++; const { glob, source } = extractGlobSource(r.pattern); - if (calcVerboseLevel(cfg.options) > 1) { + if (calcVerboseLevel(cfg.options) > 0) { reporter.info( `Excluded File: ${path.relative(root, absFilename)}; Excluded by ${glob} from ${source}`, MessageTypes.Info, @@ -349,7 +363,8 @@ async function determineFilesToCheck( return (filename: string): boolean => !isExcluded(filename, globMatcherExclude); } - return _determineFilesToCheck(); + const files = await _determineFilesToCheck(); + return { files, skippedFiles }; } interface GlobAndSource { diff --git a/packages/cspell/src/lint/processFile.ts b/packages/cspell/src/lint/processFile.ts index 0cd0069b257b..0e2daf441301 100644 --- a/packages/cspell/src/lint/processFile.ts +++ b/packages/cspell/src/lint/processFile.ts @@ -97,13 +97,19 @@ export async function processFile( let spellResult: Partial = {}; try { - const { showSuggestions: generateSuggestions, validateDirectives, skipValidation } = cfg.options; + const { + showSuggestions: generateSuggestions, + validateDirectives, + skipValidation, + forceCheck: force, + } = cfg.options; const numSuggestions = configInfo.config.numSuggestions ?? 5; const validateOptions = util.clean({ generateSuggestions, numSuggestions, validateDirectives, skipValidation, + force, }); const r = await spellCheckDocument(doc, validateOptions, userSettings); // console.warn('filename: %o %o', path.relative(process.cwd(), filename), r.perf); diff --git a/packages/cspell/src/options.ts b/packages/cspell/src/options.ts index 1ff606e4a001..aed45d9653e2 100644 --- a/packages/cspell/src/options.ts +++ b/packages/cspell/src/options.ts @@ -400,6 +400,14 @@ export interface LinterCliOptions extends LinterOptions { */ stopConfigSearchAt?: string[]; + /** + * Force the document to be checked even if it would normally be excluded. + */ + forceCheck?: boolean; + + /** + * Which issues to report. If not set, all issues are reported. + */ report?: ReportChoices | undefined; } From fa76c7ca02c0d1ead07cae9ceeb43f4afc72dcb6 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Thu, 27 Aug 2026 16:05:37 +0200 Subject: [PATCH 2/5] fix skip count --- packages/cspell/src/cli-reporter.ts | 4 ++-- packages/cspell/src/lint/lint.ts | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/cspell/src/cli-reporter.ts b/packages/cspell/src/cli-reporter.ts index a1e0635c8c9b..ebd5b587ad6b 100644 --- a/packages/cspell/src/cli-reporter.ts +++ b/packages/cspell/src/cli-reporter.ts @@ -288,10 +288,10 @@ export function getReporter(options: ReporterOptions, config?: CSpellReporterCon } const resultEmitter = (result: RunResult) => { - if (!fileGlobs.length && !result.files && !result.skippedFiles && !result.errors && !result.issues) { + const { files, issues, cachedFiles, filesWithIssues, errors, skippedFiles } = result; + if (!fileGlobs.length && !files && !skippedFiles && !errors && !issues) { return; } - const { files, issues, cachedFiles, filesWithIssues, errors, skippedFiles } = result; const numFilesWithIssues = filesWithIssues.size; const chalk = stderr.chalk; diff --git a/packages/cspell/src/lint/lint.ts b/packages/cspell/src/lint/lint.ts index 332b680799cd..125efbcec835 100644 --- a/packages/cspell/src/lint/lint.ts +++ b/packages/cspell/src/lint/lint.ts @@ -279,6 +279,14 @@ async function determineFilesToCheck( ): Promise { let skippedFiles = 0; + function countSkippedFiles(fn: (file: string) => boolean) { + return (file: string) => { + const skipped = fn(file); + if (skipped) skippedFiles++; + return skipped; + }; + } + async function _determineFilesToCheck(): Promise> { const { fileLists } = cfg; const hasFileLists = !!fileLists.length; @@ -309,12 +317,13 @@ async function determineFilesToCheck( const opFilterExcludedFiles = opFilter(filterOutExcludedFilesFn(globMatcher)); const includeFilter = createIncludeFileFilterFn(allGlobs, root, enableGlobDot); - const rawCliFiles = cfg.files?.map((file) => resolveFilename(file, root)).filter(includeFilter); + const includeFilterCountSkipped = countSkippedFiles(includeFilter); + const rawCliFiles = cfg.files?.map((file) => resolveFilename(file, root)).filter(includeFilterCountSkipped); const cliFiles = cfg.options.mustFindFiles ? rawCliFiles : rawCliFiles && pipeAsync(rawCliFiles, opFilterAsync(isFile)); const foundFiles = hasFileLists - ? concatAsyncIterables(cliFiles, await useFileLists(fileLists, includeFilter)) + ? concatAsyncIterables(cliFiles, await useFileLists(fileLists, includeFilterCountSkipped)) : cliFiles || (await findFiles(fileGlobs, globOptions)); const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles; @@ -326,7 +335,6 @@ async function determineFilesToCheck( function isExcluded(filename: string, globMatcherExclude: GlobMatcher): boolean { if (cspellIsBinaryFile(toFileURL(filename))) { - skippedFiles++; return true; } if (cfg.options.forceCheck) { @@ -337,7 +345,6 @@ async function determineFilesToCheck( const r = globMatcherExclude.matchEx(absFilename); if (r.matched) { - skippedFiles++; const { glob, source } = extractGlobSource(r.pattern); if (calcVerboseLevel(cfg.options) > 0) { reporter.info( From 5b02a63fe7d14cdefbad9d394e961324a3c89e6a Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Fri, 28 Aug 2026 13:37:56 +0200 Subject: [PATCH 3/5] Correct the calculation for skipped. --- .../features/file-list/files-to-check.txt | 2 +- .../cspell/src/__snapshots__/app.test.ts.snap | 12 +-- packages/cspell/src/lint/lint.test.ts | 64 ++++++------- packages/cspell/src/lint/lint.ts | 93 +++++++++++++++---- packages/cspell/src/lint/processFiles.ts | 11 ++- 5 files changed, 123 insertions(+), 59 deletions(-) diff --git a/packages/cspell/fixtures/features/file-list/files-to-check.txt b/packages/cspell/fixtures/features/file-list/files-to-check.txt index e4f38771e1ee..83069ad37404 100644 --- a/packages/cspell/fixtures/features/file-list/files-to-check.txt +++ b/packages/cspell/fixtures/features/file-list/files-to-check.txt @@ -1,2 +1,2 @@ -../../../src/app.ts +../../../src/app.mts ../../../README.md diff --git a/packages/cspell/src/__snapshots__/app.test.ts.snap b/packages/cspell/src/__snapshots__/app.test.ts.snap index 506d7d10065d..8684dc581bae 100644 --- a/packages/cspell/src/__snapshots__/app.test.ts.snap +++ b/packages/cspell/src/__snapshots__/app.test.ts.snap @@ -100,7 +100,7 @@ exports[`Validate cli > app '--fail-fast with config' Expect Error: [Function Ch error log first-fail.txt:1:1 - Unknown word (iamtypo) log -error CSpell: Files checked: 1, Issues found: 1 in 1 file. +error CSpell: Files checked: 1, skipped: 1, Issues found: 1 in 1 file. error" `; @@ -113,7 +113,7 @@ exports[`Validate cli > app '--fail-fast with option' Expect Error: [Function Ch error log first-fail.txt:1:1 - Unknown word (iamtypo) log -error CSpell: Files checked: 1, Issues found: 1 in 1 file. +error CSpell: Files checked: 1, skipped: 1, Issues found: 1 in 1 file. error" `; @@ -3845,12 +3845,12 @@ exports[`Validate cli > app --force-check 'lint README.md --file package.json' E " `; -exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified.' 1`] = `[]`; +exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified' 1`] = `[]`; -exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified.' 2`] = `""`; +exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified' 2`] = `""`; -exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified.' 3`] = ` -"error: --force-check requires --file, --files, or --file-list to be specified. +exports[`Validate cli > app --force-check 'lint README.md --force-check' Expect Error: 'error: --force-check requires --file, --files, or --file-list to be specified' 3`] = ` +"error: --force-check requires --file, --files, or --file-list to be specified " `; diff --git a/packages/cspell/src/lint/lint.test.ts b/packages/cspell/src/lint/lint.test.ts index ed3b243a3691..3cda79043340 100644 --- a/packages/cspell/src/lint/lint.test.ts +++ b/packages/cspell/src/lint/lint.test.ts @@ -80,38 +80,38 @@ describe('Linter Validation Tests', () => { // cspell:ignore Tufte checkedd 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 }) })} - ${['*.txt']} | ${{ root: failFastSamples, failFast: true }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 1 }) })} - ${['*.txt']} | ${{ root: failFastSamples, failFast: false, config: j(samples, 'fail-fast/fail-fast-cspell.json') }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 2 }) })} - ${['**/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: [] })} - ${['**/hidden.md']} | ${{ root: hiddenSamples, dot: true }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/*.md']} | ${{ root: hiddenSamples, dot: false }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/*.md']} | ${{ root: hiddenSamples }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/*.md']} | ${{ root: hiddenSamples, dot: true }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**']} | ${{ root: samples, config: j(samples, 'cspell-not-found.json') }} | ${oc({ errors: 1, files: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} - ${['**']} | ${{ root: samples, config: j(samples, 'linked/cspell-import-missing.json') }} | ${oc({ errors: 1, files: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} - ${['**/ebook.tex']} | ${{ root: samples, config: j(samples, 'cspell-missing-dict.json') }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/ebook.tex']} | ${{ root: samples, config: j(samples, 'linked/cspell-import.json') }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheck], dot: true }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/*.md']} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheck] }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/*.ts']} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheck] }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: ['missing-file.txt'] }} | ${oc({ errors: 1, files: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} - ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheckWithMissing] }} | ${oc({ errors: 0, files: 3 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheckWithMissing], mustFindFiles: true }} | ${oc({ errors: 1, files: 3 })} | ${oc({ errorCount: 1, errors: [expect.anything()], issues: [] })} - ${["'**'"]} | ${{ root, config: j(root, 'cspell.json'), mustFindFiles: true }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(CheckFailed)], issues: [] })} - ${['**']} | ${{ root: j(configSamples, 'yaml-regexp') }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'checkedd' })] })} - ${[]} | ${{ ...optionsRootCSpellJson, files: ['README.md', 'LICENSE'], dot: true }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['*.md']} | ${{ ...optionsRootCSpellJson, files: ['README.md', 'LICENSE'], dot: true }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${[]} | ${{ ...optionsRootCSpellJson, files: ['README.md', 'missing.txt'], dot: true, mustFindFiles: false }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${[]} | ${{ ...optionsRootCSpellJson, files: ['README.md', 'missing.txt'], dot: true, mustFindFiles: true }} | ${oc({ errors: 1, files: 2 })} | ${oc({ errorCount: 1, errors: [expect.anything()], issues: [] })} - ${[]} | ${{ ...optionsRootCSpellJson, files: ['../../README.md'], dot: true }} | ${oc({ errors: 0, files: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${[]} | ${{ ...optionsRootCSpellJson, files: ['../../resources/patreon.png' /* skip binary */], dot: true }} | ${oc({ errors: 0, files: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} - ${['**/*.md']} | ${{ root: './fixtures/issue-6025', config: './fixtures/issue-6025/nested/cspell.config.yaml' }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + files | options | expectedRunResult | expectedReport + ${[]} | ${{ root: latexSamples }} | ${oc({ errors: 0, files: 4, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'Tufte' })] })} + ${['*.txt']} | ${{ root: failFastSamples }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 2 }) })} + ${['*.txt']} | ${{ root: failFastSamples, config: j(samples, 'fail-fast/fail-fast-cspell.json') }} | ${oc({ errors: 0, files: 2 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 1 }) })} + ${['*.txt']} | ${{ root: failFastSamples, failFast: true }} | ${oc({ errors: 0, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 1 }) })} + ${['*.txt']} | ${{ root: failFastSamples, failFast: false, config: j(samples, 'fail-fast/fail-fast-cspell.json') }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: oc({ length: 2 }) })} + ${['**/ebook.tex']} | ${{ root: latexSamples }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/ebook.tex']} | ${{ root: latexSamples, gitignore: true }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/hidden.md']} | ${{ root: hiddenSamples }} | ${oc({ errors: 0, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/hidden.md']} | ${{ root: hiddenSamples, dot: true }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/*.md']} | ${{ root: hiddenSamples, dot: false }} | ${oc({ errors: 0, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/*.md']} | ${{ root: hiddenSamples }} | ${oc({ errors: 0, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/*.md']} | ${{ root: hiddenSamples, dot: true }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**']} | ${{ root: samples, config: j(samples, 'cspell-not-found.json') }} | ${oc({ errors: 1, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} + ${['**']} | ${{ root: samples, config: j(samples, 'linked/cspell-import-missing.json') }} | ${oc({ errors: 1, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} + ${['**/ebook.tex']} | ${{ root: samples, config: j(samples, 'cspell-missing-dict.json') }} | ${oc({ errors: 0, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/ebook.tex']} | ${{ root: samples, config: j(samples, 'linked/cspell-import.json') }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheck], dot: true }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/*.md']} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheck] }} | ${oc({ errors: 0, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/*.mts']} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheck] }} | ${oc({ errors: 0, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: ['missing-file.txt'] }} | ${oc({ errors: 1, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(Error)], issues: [] })} + ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheckWithMissing] }} | ${oc({ errors: 0, files: 3, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${[]} | ${{ root, config: j(root, 'cspell.json'), fileLists: [filesToCheckWithMissing], mustFindFiles: true }} | ${oc({ errors: 1, files: 3, skippedFiles: 1 })} | ${oc({ errorCount: 1, errors: [expect.anything()], issues: [] })} + ${["'**'"]} | ${{ root, config: j(root, 'cspell.json'), mustFindFiles: true }} | ${oc({ errors: 0, files: 0, skippedFiles: 0 })} | ${oc({ errorCount: 1, errors: [expect.any(CheckFailed)], issues: [] })} + ${['**']} | ${{ root: j(configSamples, 'yaml-regexp') }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [oc({ text: 'checkedd' })] })} + ${[]} | ${{ files: ['README.md', 'LICENSE'], dot: true, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['*.md']} | ${{ files: ['README.md', 'LICENSE'], dot: true, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${[]} | ${{ files: ['README.md', 'missing.txt'], dot: true, mustFindFiles: false, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${[]} | ${{ files: ['README.md', 'missing.txt'], dot: true, mustFindFiles: true, ...optionsRootCSpellJson }} | ${oc({ errors: 1, files: 2, skippedFiles: 1 })} | ${oc({ errorCount: 1, errors: [expect.anything()], issues: [] })} + ${[]} | ${{ files: ['../../README.md'], dot: true, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 1, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${[]} | ${{ files: ['../../resources/patreon.png' /* skip binary */], dot: true, ...optionsRootCSpellJson }} | ${oc({ errors: 0, files: 1, skippedFiles: 1 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} + ${['**/*.md']} | ${{ root: './fixtures/issue-6025', config: './fixtures/issue-6025/nested/cspell.config.yaml' }} | ${oc({ errors: 0, files: 2, skippedFiles: 0 })} | ${oc({ errorCount: 0, errors: [], issues: [] })} `('runLint $files $options', async ({ files, options, expectedRunResult, expectedReport }) => { const reporter = new InMemoryReporter(); const runResult = await runLint(new LintRequest(files, options, reporter)); diff --git a/packages/cspell/src/lint/lint.ts b/packages/cspell/src/lint/lint.ts index 125efbcec835..e776679cc954 100644 --- a/packages/cspell/src/lint/lint.ts +++ b/packages/cspell/src/lint/lint.ts @@ -141,7 +141,7 @@ export async function runLint(cfg: LintRequest): Promise { try { const cacheSettings = await calcCacheSettings(configInfo.config, { ...cfg.options, version }, root); - const { files, skippedFiles } = await determineFilesToCheck(configInfo, cfg, reporter, globInfo); + const filesToCheck = await determineFilesToCheck(configInfo, cfg, reporter, globInfo); const processFilesOptions: ProcessFilesOptions = { chalk, @@ -155,12 +155,13 @@ export async function runLint(cfg: LintRequest): Promise { cacheSettings, }; - const result = await processFiles(files, processFilesOptions); + const result = await processFiles(filesToCheck.files, processFilesOptions); if (configErrorCount && cfg.options.exitCode !== false) { result.errors ||= configErrorCount; } + const skippedFiles = Math.max(0, filesToCheck.numFiles - result.files); result.files += skippedFiles; - result.skippedFiles = (result.skippedFiles ?? 0) + skippedFiles; + result.skippedFiles = (result.skippedFiles || 0) + skippedFiles; debugStats && console.error('stats: %o', getDefaultConfigLoader().getStats()); return result; } catch (e) { @@ -268,7 +269,11 @@ function filesToProcess(files: Iterable): FileToProcess[] { interface FilesToCheck { files: FileToProcess[] | AsyncIterable; - skippedFiles: number; + /** + * The total number of files considered for linting. + * This number is ONLY valid after `files` has been consumed. + */ + numFiles: number; } async function determineFilesToCheck( @@ -277,20 +282,34 @@ async function determineFilesToCheck( reporter: FinalizedReporter, globInfo: AppGlobInfo, ): Promise { - let skippedFiles = 0; + const result: FilesToCheck = { + files: [], + numFiles: 0, + }; - function countSkippedFiles(fn: (file: string) => boolean) { - return (file: string) => { - const skipped = fn(file); - if (skipped) skippedFiles++; - return skipped; + function countFiles(fnKeep?: (file: T) => boolean) { + if (!fnKeep) + return () => { + result.numFiles++; + return true; + }; + return (file: T) => { + // console.warn('Counting file: %o', file); + result.numFiles++; + return fnKeep(file); }; } async function _determineFilesToCheck(): Promise> { + return !cfg.fileLists?.length && !cfg.files?.length + ? determineFilesToCheckFromGlobs() + : determineFilesToCheckFromCliFiles(); + } + + async function determineFilesToCheckFromCliFiles(): Promise> { const { fileLists } = cfg; const hasFileLists = !!fileLists.length; - const { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes } = globInfo; + const { allGlobs, excludeGlobs, normalizedExcludes } = globInfo; // Get Exclusions from the config files. const { root } = cfg; @@ -315,21 +334,59 @@ async function determineFilesToCheck( globOptions.dot = enableGlobDot; } - const opFilterExcludedFiles = opFilter(filterOutExcludedFilesFn(globMatcher)); const includeFilter = createIncludeFileFilterFn(allGlobs, root, enableGlobDot); - const includeFilterCountSkipped = countSkippedFiles(includeFilter); + const includeFilterCountSkipped = countFiles(includeFilter); const rawCliFiles = cfg.files?.map((file) => resolveFilename(file, root)).filter(includeFilterCountSkipped); const cliFiles = cfg.options.mustFindFiles ? rawCliFiles : rawCliFiles && pipeAsync(rawCliFiles, opFilterAsync(isFile)); + const foundFiles = hasFileLists ? concatAsyncIterables(cliFiles, await useFileLists(fileLists, includeFilterCountSkipped)) - : cliFiles || (await findFiles(fileGlobs, globOptions)); + : cliFiles || []; + + const opFilterExcludedFiles = opFilter(filterOutExcludedFilesFn(globMatcher)); + const files = isAsyncIterable(foundFiles) + ? pipeAsync(foundFiles, opFilterExcludedFiles, filesToProcessAsync) + : filesToProcess(pipe(foundFiles, opFilterExcludedFiles)); + + return files; + } + + async function determineFilesToCheckFromGlobs(): Promise> { + const { gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes } = globInfo; + + // Get Exclusions from the config files. + const { root } = cfg; + const globsToExcludeRaw = [...(configInfo.config.ignorePaths || []), ...excludeGlobs]; + const globsToExclude = globsToExcludeRaw.filter((g) => !globPattern(g).startsWith('!')); + if (globsToExclude.length !== globsToExcludeRaw.length) { + const globs = globsToExcludeRaw.map((g) => globPattern(g)).filter((g) => g.startsWith('!')); + const msg = `Negative glob exclusions are not supported: ${globs.join(', ')}`; + reporter.info(msg, MessageTypes.Warning); + } + const globMatcher = buildGlobMatcher(globsToExclude, root, true); + const ignoreGlobs = extractGlobsFromMatcher(globMatcher); + // cspell:word nodir + const globOptions: GlobOptions = { + root, + cwd: root, + ignore: [...ignoreGlobs, ...normalizedExcludes], + nodir: true, + }; + const enableGlobDot = cfg.enableGlobDot ?? configInfo.config.enableGlobDot; + if (enableGlobDot !== undefined) { + globOptions.dot = enableGlobDot; + } + + const opFilterExcludedFiles = opFilter(filterOutExcludedFilesFn(globMatcher)); + const foundFiles = await findFiles(fileGlobs, globOptions); const filtered = gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles; const files = isAsyncIterable(filtered) - ? pipeAsync(filtered, opFilterExcludedFiles, filesToProcessAsync) - : filesToProcess(pipe(filtered, opFilterExcludedFiles)); + ? pipeAsync(filtered, opFilterExcludedFiles, filesToProcessAsync, opFilter(countFiles())) + : filesToProcess(pipe(filtered, opFilterExcludedFiles)).filter(countFiles()); + return files; } @@ -370,8 +427,8 @@ async function determineFilesToCheck( return (filename: string): boolean => !isExcluded(filename, globMatcherExclude); } - const files = await _determineFilesToCheck(); - return { files, skippedFiles }; + result.files = await _determineFilesToCheck(); + return result; } interface GlobAndSource { diff --git a/packages/cspell/src/lint/processFiles.ts b/packages/cspell/src/lint/processFiles.ts index a59a9c982a02..e71f1480a0ec 100644 --- a/packages/cspell/src/lint/processFiles.ts +++ b/packages/cspell/src/lint/processFiles.ts @@ -226,6 +226,13 @@ function processMaxFileSize(value: number | string | undefined): number | undefi } export function runResult(init: Partial = {}): RunResult { - const { files = 0, filesWithIssues = new Set(), issues = 0, errors = 0, cachedFiles = 0 } = init; - return { files, filesWithIssues, issues, errors, cachedFiles }; + const { + files = 0, + filesWithIssues = new Set(), + issues = 0, + errors = 0, + cachedFiles = 0, + skippedFiles = 0, + } = init; + return { files, filesWithIssues, issues, errors, cachedFiles, skippedFiles }; } From 0fa6fa43505a5a74a5b4075240b3f242498f45e9 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Fri, 28 Aug 2026 15:42:07 +0200 Subject: [PATCH 4/5] Address comments --- packages/cspell/bin.mjs | 3 +-- packages/cspell/src/commandLint.ts | 6 +++--- packages/cspell/src/lint/lint.ts | 10 ++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/cspell/bin.mjs b/packages/cspell/bin.mjs index 80e676f06d71..77e7ab332acc 100755 --- a/packages/cspell/bin.mjs +++ b/packages/cspell/bin.mjs @@ -6,7 +6,6 @@ import { CommanderError, program } from 'commander'; import { ApplicationError, CheckFailed, run } from './dist/esm/app.js'; run(program, process.argv).catch((e) => { - process.exitCode = process.exitCode || 1; if (!(e instanceof CommanderError) && !(e instanceof CheckFailed)) { const verbose = process.argv.includes('--verbose') || process.argv.includes('-v'); const msg = !verbose && e instanceof ApplicationError ? e.message : format(e); @@ -14,7 +13,7 @@ run(program, process.argv).catch((e) => { // It is possible an explicit exit code was set, use it if it was. process.exitCode = process.exitCode || 1; } - if (e instanceof CheckFailed) { + if (e instanceof CheckFailed || e instanceof CommanderError) { process.exitCode = e.exitCode; } }); diff --git a/packages/cspell/src/commandLint.ts b/packages/cspell/src/commandLint.ts index 171873292c12..097beb38b3cd 100644 --- a/packages/cspell/src/commandLint.ts +++ b/packages/cspell/src/commandLint.ts @@ -215,14 +215,14 @@ async function action(this: Command, fileGlobs: string[], cliOptions: LinterCliC options.color ??= canUseColor(options.color); const maxFileSizeErr = validateMaxFileSize(options.maxFileSize); if (maxFileSizeErr) { - this.error(`error: invalid option value for --max-file-size: ${maxFileSizeErr}`); + this.error(`error: invalid option value for --max-file-size: ${maxFileSizeErr}`, { exitCode: 1 }); } const { mustFindFiles, fileList, files, file, forceCheck } = options; if (forceCheck && !file?.length && !files?.length && !fileList?.length) { - this.error('error: --force-check requires --file, --files, or --file-list to be specified'); + this.error('error: --force-check requires --file, --files, or --file-list to be specified', { exitCode: 1 }); } if (fileGlobs.length && (file?.length || files?.length)) { - this.error('error: mixing globs and --file is not supported'); + this.error('error: mixing globs and --file is not supported', { exitCode: 1 }); } const result = await App.lint(fileGlobs, options); if (!fileGlobs.length && !result.files && !result.errors && !fileList && !files?.length && !file?.length) { diff --git a/packages/cspell/src/lint/lint.ts b/packages/cspell/src/lint/lint.ts index e776679cc954..cc8ef033909c 100644 --- a/packages/cspell/src/lint/lint.ts +++ b/packages/cspell/src/lint/lint.ts @@ -309,7 +309,7 @@ async function determineFilesToCheck( async function determineFilesToCheckFromCliFiles(): Promise> { const { fileLists } = cfg; const hasFileLists = !!fileLists.length; - const { allGlobs, excludeGlobs, normalizedExcludes } = globInfo; + const { gitIgnore, allGlobs, excludeGlobs, normalizedExcludes } = globInfo; // Get Exclusions from the config files. const { root } = cfg; @@ -346,9 +346,11 @@ async function determineFilesToCheck( : cliFiles || []; const opFilterExcludedFiles = opFilter(filterOutExcludedFilesFn(globMatcher)); - const files = isAsyncIterable(foundFiles) - ? pipeAsync(foundFiles, opFilterExcludedFiles, filesToProcessAsync) - : filesToProcess(pipe(foundFiles, opFilterExcludedFiles)); + const filtered = + !cfg.options.forceCheck && gitIgnore ? await gitIgnore.filterOutIgnored(foundFiles) : foundFiles; + const files = isAsyncIterable(filtered) + ? pipeAsync(filtered, opFilterExcludedFiles, filesToProcessAsync) + : filesToProcess(pipe(filtered, opFilterExcludedFiles)); return files; } From d33907e683c2609fda48362ccbeac419f704bcae Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Fri, 28 Aug 2026 15:53:23 +0200 Subject: [PATCH 5/5] Update commandLint.ts --- packages/cspell/src/commandLint.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cspell/src/commandLint.ts b/packages/cspell/src/commandLint.ts index 097beb38b3cd..171873292c12 100644 --- a/packages/cspell/src/commandLint.ts +++ b/packages/cspell/src/commandLint.ts @@ -215,14 +215,14 @@ async function action(this: Command, fileGlobs: string[], cliOptions: LinterCliC options.color ??= canUseColor(options.color); const maxFileSizeErr = validateMaxFileSize(options.maxFileSize); if (maxFileSizeErr) { - this.error(`error: invalid option value for --max-file-size: ${maxFileSizeErr}`, { exitCode: 1 }); + this.error(`error: invalid option value for --max-file-size: ${maxFileSizeErr}`); } const { mustFindFiles, fileList, files, file, forceCheck } = options; if (forceCheck && !file?.length && !files?.length && !fileList?.length) { - this.error('error: --force-check requires --file, --files, or --file-list to be specified', { exitCode: 1 }); + this.error('error: --force-check requires --file, --files, or --file-list to be specified'); } if (fileGlobs.length && (file?.length || files?.length)) { - this.error('error: mixing globs and --file is not supported', { exitCode: 1 }); + this.error('error: mixing globs and --file is not supported'); } const result = await App.lint(fileGlobs, options); if (!fileGlobs.length && !result.files && !result.errors && !fileList && !files?.length && !file?.length) {