Skip to content

Commit

Permalink
fix: Ignore negative globs in ignore patterns. (#6388)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Oct 18, 2024
1 parent cbdb4e6 commit 1672c99
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/cspell/fixtures/issue-6353/cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: '0.2'
name: issue-6373
enableGlobDot: true
files:
- docs
ignorePaths:
- 'docs/no-check/**'
- '!docs/no-check/README.md'
3 changes: 3 additions & 0 deletions packages/cspell/fixtures/issue-6353/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-6353/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 @@
{}
10 changes: 10 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,16 @@ error"
exports[`Validate cli > app 'issue-4811/*/README.md' Expect Error: undefined 3`] = `""`;
exports[`Validate cli > app 'issue-6353' Expect Error: undefined 1`] = `[]`;
exports[`Validate cli > app 'issue-6353' Expect Error: undefined 2`] = `
"info Negative glob exclusions are not supported: !docs/no-check/README.md
error CSpell: Files checked: 1, Issues found: 0 in 0 files.
error"
`;
exports[`Validate cli > app 'issue-6353' 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`] = `
Expand Down
1 change: 1 addition & 0 deletions packages/cspell/src/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('Validate cli', () => {
${'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}
${'issue-6353'} | ${['-r', pathFix('issue-6353'), '--no-progress']} | ${undefined} | ${true} | ${false} | ${true}
${'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 Down
12 changes: 11 additions & 1 deletion packages/cspell/src/app/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,13 @@ async function determineFilesToCheck(

// Get Exclusions from the config files.
const { root } = cfg;
const globsToExclude = [...(configInfo.config.ignorePaths || []), ...excludeGlobs];
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
Expand Down Expand Up @@ -744,3 +750,7 @@ async function writeDictionaryLog() {

await writeFileOrStream(filename, data);
}

function globPattern(g: Glob) {
return typeof g === 'string' ? g : g.glob;
}

0 comments on commit 1672c99

Please sign in to comment.