Skip to content

Commit 55c29fb

Browse files
authored
fix: correctly handle excludes in files (#6375)
1 parent 2ee3c55 commit 55c29fb

File tree

8 files changed

+65
-16
lines changed

8 files changed

+65
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
2+
version: '0.2'
3+
name: issue-6373
4+
enableGlobDot: true
5+
files:
6+
- docs
7+
- '!docs/no-check/**'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Docs
2+
3+
This is where the docs are.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# README.md
2+
3+
Do not spell check this file.
4+
5+
It has mistakkkes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

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

+20
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,26 @@ error"
551551
552552
exports[`Validate cli > app 'issue-4811/*/README.md' Expect Error: undefined 3`] = `""`;
553553
554+
exports[`Validate cli > app 'issue-6373 .' Expect Error: [Function CheckFailed] 1`] = `[]`;
555+
556+
exports[`Validate cli > app 'issue-6373 .' Expect Error: [Function CheckFailed] 2`] = `
557+
"log docs/no-check/README.md:5:8 - Unknown word (mistakkkes)
558+
log
559+
error CSpell: Files checked: 4, Issues found: 1 in 1 file.
560+
error"
561+
`;
562+
563+
exports[`Validate cli > app 'issue-6373 .' Expect Error: [Function CheckFailed] 3`] = `""`;
564+
565+
exports[`Validate cli > app 'issue-6373' Expect Error: undefined 1`] = `[]`;
566+
567+
exports[`Validate cli > app 'issue-6373' Expect Error: undefined 2`] = `
568+
"error CSpell: Files checked: 1, Issues found: 0 in 0 files.
569+
error"
570+
`;
571+
572+
exports[`Validate cli > app 'issue-6373' Expect Error: undefined 3`] = `""`;
573+
554574
exports[`Validate cli > app 'link add' 1`] = `""`;
555575
556576
exports[`Validate cli > app 'link list' 1`] = `""`;

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ describe('Validate cli', () => {
200200
${'reporter'} | ${['-r', pathFix('features/reporter'), '-c', pathFix('features/reporter/cspell.config.yaml')]} | ${undefined} | ${false} | ${true} | ${false}
201201
${'issue-4811 **/README.md'} | ${['-r', pIssues('issue-4811'), '--no-progress', '**/README.md']} | ${undefined} | ${true} | ${false} | ${false}
202202
${'issue-4811'} | ${['-r', pIssues('issue-4811'), '--no-progress', '.']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
203+
${'issue-6373 .'} | ${['-r', pathFix('issue-6373'), '--no-progress', '.']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
204+
${'issue-6373'} | ${['-r', pathFix('issue-6373'), '--no-progress']} | ${undefined} | ${true} | ${false} | ${false}
203205
${'verify globRoot works'} | ${['-r', pathFix('globRoot'), '.']} | ${undefined} | ${true} | ${false} | ${false}
204206
`('app $msg Expect Error: $errorCheck', async ({ testArgs, errorCheck, eError, eLog, eInfo }: TestCase) => {
205207
chalk.level = 1;
@@ -226,8 +228,8 @@ describe('Validate cli', () => {
226228
chalk.level = 1;
227229
const commander = getCommander();
228230
const args = argv(...testArgs);
229-
const result = app.run(commander, args);
230-
await (!errorCheck ? expect(result).resolves.toBeUndefined() : expect(result).rejects.toThrow(errorCheck));
231+
const result = await asyncResult(app.run(commander, args));
232+
expect(result).toEqual(errorCheck);
231233

232234
eError ? expect(error).toHaveBeenCalled() : expect(error).not.toHaveBeenCalled();
233235

@@ -426,3 +428,11 @@ function makeLogger() {
426428
function escapeRegExp(s: string): string {
427429
return s.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&').replaceAll('-', '\\x2d');
428430
}
431+
432+
async function asyncResult<T>(p: Promise<T>): Promise<T | Error> {
433+
try {
434+
return await p;
435+
} catch (e) {
436+
return e as Error;
437+
}
438+
}

packages/cspell/src/app/lint/lint.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,10 @@ async function determineGlobs(configInfo: ConfigInfo, cfg: LintRequest): Promise
530530
const cliExcludeGlobs = extractPatterns(cfg.excludes).map((p) => p.glob as Glob);
531531
const normalizedExcludes = normalizeGlobsToRoot(cliExcludeGlobs, cfg.root, true);
532532
const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
533-
const excludeGlobs = [...combinedGlobs.filter((g) => g.startsWith('!')), ...normalizedExcludes];
533+
const excludeGlobs = [
534+
...combinedGlobs.filter((g) => g.startsWith('!')).map((g) => g.slice(1)),
535+
...normalizedExcludes,
536+
];
534537
const fileGlobs: string[] = includeGlobs;
535538

536539
const appGlobs = { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes };

pnpm-lock.yaml

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)