Skip to content

Commit

Permalink
fix: correctly handle excludes in files (#6375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Oct 16, 2024
1 parent 2ee3c55 commit 55c29fb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 16 deletions.
7 changes: 7 additions & 0 deletions packages/cspell/fixtures/issue-6373/cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: '0.2'
name: issue-6373
enableGlobDot: true
files:
- docs
- '!docs/no-check/**'
3 changes: 3 additions & 0 deletions packages/cspell/fixtures/issue-6373/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Docs

This is where the docs are.
5 changes: 5 additions & 0 deletions packages/cspell/fixtures/issue-6373/docs/no-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# README.md

Do not spell check this file.

It has mistakkkes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
20 changes: 20 additions & 0 deletions packages/cspell/src/app/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ error"
exports[`Validate cli > app 'issue-4811/*/README.md' Expect Error: undefined 3`] = `""`;
exports[`Validate cli > app 'issue-6373 .' Expect Error: [Function CheckFailed] 1`] = `[]`;
exports[`Validate cli > app 'issue-6373 .' Expect Error: [Function CheckFailed] 2`] = `
"log docs/no-check/README.md:5:8 - Unknown word (mistakkkes)
log
error CSpell: Files checked: 4, Issues found: 1 in 1 file.
error"
`;
exports[`Validate cli > app 'issue-6373 .' Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli > app 'issue-6373' Expect Error: undefined 1`] = `[]`;
exports[`Validate cli > app 'issue-6373' Expect Error: undefined 2`] = `
"error CSpell: Files checked: 1, Issues found: 0 in 0 files.
error"
`;
exports[`Validate cli > app 'issue-6373' Expect Error: undefined 3`] = `""`;
exports[`Validate cli > app 'link add' 1`] = `""`;
exports[`Validate cli > app 'link list' 1`] = `""`;
Expand Down
14 changes: 12 additions & 2 deletions packages/cspell/src/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ describe('Validate cli', () => {
${'reporter'} | ${['-r', pathFix('features/reporter'), '-c', pathFix('features/reporter/cspell.config.yaml')]} | ${undefined} | ${false} | ${true} | ${false}
${'issue-4811 **/README.md'} | ${['-r', pIssues('issue-4811'), '--no-progress', '**/README.md']} | ${undefined} | ${true} | ${false} | ${false}
${'issue-4811'} | ${['-r', pIssues('issue-4811'), '--no-progress', '.']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'issue-6373 .'} | ${['-r', pathFix('issue-6373'), '--no-progress', '.']} | ${app.CheckFailed} | ${true} | ${true} | ${false}
${'issue-6373'} | ${['-r', pathFix('issue-6373'), '--no-progress']} | ${undefined} | ${true} | ${false} | ${false}
${'verify globRoot works'} | ${['-r', pathFix('globRoot'), '.']} | ${undefined} | ${true} | ${false} | ${false}
`('app $msg Expect Error: $errorCheck', async ({ testArgs, errorCheck, eError, eLog, eInfo }: TestCase) => {
chalk.level = 1;
Expand All @@ -226,8 +228,8 @@ describe('Validate cli', () => {
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));
const result = await asyncResult(app.run(commander, args));
expect(result).toEqual(errorCheck);

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

Expand Down Expand Up @@ -426,3 +428,11 @@ function makeLogger() {
function escapeRegExp(s: string): string {
return s.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&').replaceAll('-', '\\x2d');
}

async function asyncResult<T>(p: Promise<T>): Promise<T | Error> {
try {
return await p;
} catch (e) {
return e as Error;
}
}
5 changes: 4 additions & 1 deletion packages/cspell/src/app/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,10 @@ async function determineGlobs(configInfo: ConfigInfo, cfg: LintRequest): Promise
const cliExcludeGlobs = extractPatterns(cfg.excludes).map((p) => p.glob as Glob);
const normalizedExcludes = normalizeGlobsToRoot(cliExcludeGlobs, cfg.root, true);
const includeGlobs = combinedGlobs.filter((g) => !g.startsWith('!'));
const excludeGlobs = [...combinedGlobs.filter((g) => g.startsWith('!')), ...normalizedExcludes];
const excludeGlobs = [
...combinedGlobs.filter((g) => g.startsWith('!')).map((g) => g.slice(1)),
...normalizedExcludes,
];
const fileGlobs: string[] = includeGlobs;

const appGlobs = { allGlobs, gitIgnore, fileGlobs, excludeGlobs, normalizedExcludes };
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 55c29fb

Please sign in to comment.