diff --git a/packages/cspell/fixtures/issue-6353/cspell.config.yaml b/packages/cspell/fixtures/issue-6353/cspell.config.yaml new file mode 100644 index 00000000000..e23c246e26b --- /dev/null +++ b/packages/cspell/fixtures/issue-6353/cspell.config.yaml @@ -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' diff --git a/packages/cspell/fixtures/issue-6353/docs/README.md b/packages/cspell/fixtures/issue-6353/docs/README.md new file mode 100644 index 00000000000..de035e90c60 --- /dev/null +++ b/packages/cspell/fixtures/issue-6353/docs/README.md @@ -0,0 +1,3 @@ +# Docs + +This is where the docs are. diff --git a/packages/cspell/fixtures/issue-6353/docs/no-check/README.md b/packages/cspell/fixtures/issue-6353/docs/no-check/README.md new file mode 100644 index 00000000000..7f36afe3d6c --- /dev/null +++ b/packages/cspell/fixtures/issue-6353/docs/no-check/README.md @@ -0,0 +1,5 @@ +# README.md + +Do not spell check this file. + +It has mistakkkes. diff --git a/packages/cspell/fixtures/issue-6353/docs/no-check/cspell.json b/packages/cspell/fixtures/issue-6353/docs/no-check/cspell.json new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/packages/cspell/fixtures/issue-6353/docs/no-check/cspell.json @@ -0,0 +1 @@ +{} diff --git a/packages/cspell/src/app/__snapshots__/app.test.ts.snap b/packages/cspell/src/app/__snapshots__/app.test.ts.snap index 47043cb6df2..8c3f9c2fe20 100644 --- a/packages/cspell/src/app/__snapshots__/app.test.ts.snap +++ b/packages/cspell/src/app/__snapshots__/app.test.ts.snap @@ -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`] = ` diff --git a/packages/cspell/src/app/app.test.ts b/packages/cspell/src/app/app.test.ts index 7965e580e7b..5ea58300083 100644 --- a/packages/cspell/src/app/app.test.ts +++ b/packages/cspell/src/app/app.test.ts @@ -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; diff --git a/packages/cspell/src/app/lint/lint.ts b/packages/cspell/src/app/lint/lint.ts index 092c1fa7055..29f8b9a0dbb 100644 --- a/packages/cspell/src/app/lint/lint.ts +++ b/packages/cspell/src/app/lint/lint.ts @@ -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 @@ -744,3 +750,7 @@ async function writeDictionaryLog() { await writeFileOrStream(filename, data); } + +function globPattern(g: Glob) { + return typeof g === 'string' ? g : g.glob; +}