From 076362b14d0951afa727cfefbcc132aa4d4b1f0a Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Fri, 2 Aug 2024 08:58:16 +0200 Subject: [PATCH] fix: Use the resolved root when setting Glob Root (#6027) --- packages/cspell/fixtures/issue-6025/README.md | 17 +++++++++++++++++ packages/cspell/fixtures/issue-6025/cspell.json | 1 + .../issue-6025/nested/cspell.config.yaml | 4 ++++ .../issue-6025/sample/getting_started.md | 5 +++++ packages/cspell/src/app/lint/lint.test.ts | 5 ++++- packages/cspell/src/app/lint/lint.ts | 2 +- 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 packages/cspell/fixtures/issue-6025/README.md create mode 100644 packages/cspell/fixtures/issue-6025/cspell.json create mode 100644 packages/cspell/fixtures/issue-6025/nested/cspell.config.yaml create mode 100644 packages/cspell/fixtures/issue-6025/sample/getting_started.md diff --git a/packages/cspell/fixtures/issue-6025/README.md b/packages/cspell/fixtures/issue-6025/README.md new file mode 100644 index 00000000000..5270a488b45 --- /dev/null +++ b/packages/cspell/fixtures/issue-6025/README.md @@ -0,0 +1,17 @@ +# Issue 6025 + +See: [#6025](https://github.com/streetsidesoftware/cspell/issues/6025) + +The Glob Root was not getting correctly set: + +Cause: [lint.ts#L406-L409](https://github.com/streetsidesoftware/cspell/pull/6004/files#diff-ef0c79008fac4e61b9dc76115f6847434e3db08e41cc4a8673cf84b35a103306L406-L409) + +```diff + async function run(): Promise { + if (cfg.options.root) { +- process.env[ENV_CSPELL_GLOB_ROOT] = cfg.root; ++ setEnvironmentVariable(ENV_CSPELL_GLOB_ROOT, cfg.options.root); + } +``` + +`cfg.root` has been resolved, while `cfg.options.root` is still relative. diff --git a/packages/cspell/fixtures/issue-6025/cspell.json b/packages/cspell/fixtures/issue-6025/cspell.json new file mode 100644 index 00000000000..0967ef424bc --- /dev/null +++ b/packages/cspell/fixtures/issue-6025/cspell.json @@ -0,0 +1 @@ +{} diff --git a/packages/cspell/fixtures/issue-6025/nested/cspell.config.yaml b/packages/cspell/fixtures/issue-6025/nested/cspell.config.yaml new file mode 100644 index 00000000000..8fd29909237 --- /dev/null +++ b/packages/cspell/fixtures/issue-6025/nested/cspell.config.yaml @@ -0,0 +1,4 @@ +overrides: + - filename: sample/getting_started.md + words: + - funcignore diff --git a/packages/cspell/fixtures/issue-6025/sample/getting_started.md b/packages/cspell/fixtures/issue-6025/sample/getting_started.md new file mode 100644 index 00000000000..58bb41d982d --- /dev/null +++ b/packages/cspell/fixtures/issue-6025/sample/getting_started.md @@ -0,0 +1,5 @@ +# Getting Started + +``` +funcignore +``` diff --git a/packages/cspell/src/app/lint/lint.test.ts b/packages/cspell/src/app/lint/lint.test.ts index c9441f90e29..e29fb0d4f70 100644 --- a/packages/cspell/src/app/lint/lint.test.ts +++ b/packages/cspell/src/app/lint/lint.test.ts @@ -14,7 +14,9 @@ const samples = path.resolve(root, 'samples'); const latexSamples = path.resolve(samples, 'latex'); const failFastSamples = path.resolve(samples, 'fail-fast'); const hiddenSamples = path.resolve(samples, 'hidden-test'); -const filesToCheck = path.resolve(root, 'fixtures/features/file-list/files-to-check.txt'); +const fixtures = path.resolve(root, 'fixtures'); +const features = path.resolve(fixtures, 'features'); +const filesToCheck = path.resolve(features, 'file-list/files-to-check.txt'); const filesToCheckWithMissing = path.resolve(root, 'fixtures/features/file-list/files-to-check-missing.txt'); const configSamples = path.resolve(samples, 'config'); @@ -72,6 +74,7 @@ describe('Linter Validation Tests', () => { ${[]} | ${{ ...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: [] })} `('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/app/lint/lint.ts b/packages/cspell/src/app/lint/lint.ts index 746c1429fd5..f323d3ce029 100644 --- a/packages/cspell/src/app/lint/lint.ts +++ b/packages/cspell/src/app/lint/lint.ts @@ -418,7 +418,7 @@ export async function runLint(cfg: LintRequest): Promise { async function run(): Promise { if (cfg.options.root) { - setEnvironmentVariable(ENV_CSPELL_GLOB_ROOT, cfg.options.root); + setEnvironmentVariable(ENV_CSPELL_GLOB_ROOT, cfg.root); } const configInfo: ConfigInfo = await readConfig(cfg.configFile, cfg.root);