From 6622244db14e823f95c07ecc1ef181466154d706 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Wed, 6 Dec 2023 12:08:31 +0100 Subject: [PATCH] fix: Make sure issues are reported relative to the specified root (#5043) --- .../src/app/__snapshots__/app.test.ts.snap | 44 +++++++++---------- packages/cspell/src/app/cli-reporter.ts | 14 +++--- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/cspell/src/app/__snapshots__/app.test.ts.snap b/packages/cspell/src/app/__snapshots__/app.test.ts.snap index 64daad7661f..ebd59d14b10 100644 --- a/packages/cspell/src/app/__snapshots__/app.test.ts.snap +++ b/packages/cspell/src/app/__snapshots__/app.test.ts.snap @@ -12,8 +12,8 @@ error CSpell: Files checked: 2, Issues found: 2 in 2 files" exports[`Validate cli > app '--fail-fast no option' Expect Error: [Function CheckFailed] 3`] = ` " -1/2 ./samples/fail-fast/first-fail.txt -2/2 ./samples/fail-fast/second-fail.txt" +1/2 ./first-fail.txt +2/2 ./second-fail.txt" `; exports[`Validate cli > app '--fail-fast with config' Expect Error: [Function CheckFailed] 1`] = `[]`; @@ -26,7 +26,7 @@ error CSpell: Files checked: 1, Issues found: 1 in 1 files" exports[`Validate cli > app '--fail-fast with config' Expect Error: [Function CheckFailed] 3`] = ` " -1/2 ./samples/fail-fast/first-fail.txt" +1/2 ./first-fail.txt" `; exports[`Validate cli > app '--fail-fast with option' Expect Error: [Function CheckFailed] 1`] = `[]`; @@ -39,7 +39,7 @@ error CSpell: Files checked: 1, Issues found: 1 in 1 files" exports[`Validate cli > app '--fail-fast with option' Expect Error: [Function CheckFailed] 3`] = ` " -1/2 ./samples/fail-fast/first-fail.txt" +1/2 ./first-fail.txt" `; exports[`Validate cli > app '--help' Expect Error: 'outputHelp' 1`] = ` @@ -83,8 +83,8 @@ error CSpell: Files checked: 2, Issues found: 2 in 2 files" exports[`Validate cli > app '--no-fail-fast with config' Expect Error: [Function CheckFailed] 3`] = ` " -1/2 ./samples/fail-fast/first-fail.txt -2/2 ./samples/fail-fast/second-fail.txt" +1/2 ./first-fail.txt +2/2 ./second-fail.txt" `; exports[`Validate cli > app 'Explicit file://' Expect Error: undefined 1`] = `[]`; @@ -96,7 +96,7 @@ error CSpell: Files checked: 1, Issues found: 0 in 0 files" exports[`Validate cli > app 'Explicit file://' Expect Error: undefined 3`] = ` " -1/1 ./fixtures/misc/star-not.md" +1/1 ./star-not.md" `; exports[`Validate cli > app 'Explicit not found file://' Expect Error: [Function CheckFailed] 1`] = `[]`; @@ -109,7 +109,7 @@ error CSpell: Files checked: 1, Issues found: 0 in 1 files" exports[`Validate cli > app 'Explicit not found file://' Expect Error: [Function CheckFailed] 3`] = ` " -1/1 ./fixtures/misc/not-fond.md" +1/1 ./not-fond.md" `; exports[`Validate cli > app 'LICENSE' Expect Error: undefined 1`] = `[]`; @@ -443,7 +443,7 @@ error CSpell: Files checked: 1, Issues found: 0 in 0 files" exports[`Validate cli > app 'issue-2998 --language-id' Expect Error: undefined 3`] = ` " -1/1 ./fixtures/issue-2998/fix-words.txt" +1/1 ./fix-words.txt" `; exports[`Validate cli > app 'link add' 1`] = `""`; @@ -1033,24 +1033,24 @@ error 0.00ms error 0.00ms error 0.00ms error 0.00ms X -log ./samples/text.txt:1:14 - Unknown word (fulll) -log ./samples/text.txt:1:23 - Unknown word (errrorrrs) -log ./samples/text.txt:3:4 - Unknown word (hass) -log ./samples/text.txt:3:9 - Unknown word (someissues) -log ./samples/text.txt:3:23 - Unknown word (everyline) -log ./samples/text.txt:5:24 - Unknown word (okkk) -log ./samples/text.txt:5:32 - Unknown word (reead) +log ./text.txt:1:14 - Unknown word (fulll) +log ./text.txt:1:23 - Unknown word (errrorrrs) +log ./text.txt:3:4 - Unknown word (hass) +log ./text.txt:3:9 - Unknown word (someissues) +log ./text.txt:3:23 - Unknown word (everyline) +log ./text.txt:5:24 - Unknown word (okkk) +log ./text.txt:5:32 - Unknown word (reead) error CSpell: Files checked: 6, Issues found: 7 in 1 files" `; exports[`Validate cli > app 'with errors and excludes' Expect Error: [Function CheckFailed] 3`] = ` " -1/6 ./samples/cspell-bad.json -2/6 ./samples/cspell-includes.json -3/6 ./samples/cspell-missing-dict.json -4/6 ./samples/sample.c -5/6 ./samples/sample.py -6/6 ./samples/text.txt" +1/6 ./cspell-bad.json +2/6 ./cspell-includes.json +3/6 ./cspell-missing-dict.json +4/6 ./sample.c +5/6 ./sample.py +6/6 ./text.txt" `; exports[`Validate cli > app 'with forbidden words' Expect Error: [Function CheckFailed] 1`] = `[]`; diff --git a/packages/cspell/src/app/cli-reporter.ts b/packages/cspell/src/app/cli-reporter.ts index 8165a3f632e..f8751820c55 100644 --- a/packages/cspell/src/app/cli-reporter.ts +++ b/packages/cspell/src/app/cli-reporter.ts @@ -61,7 +61,7 @@ function nullEmitter() { /* empty */ } -function relativeFilename(filename: string, cwd = process.cwd()): string { +function relativeFilename(filename: string, cwd: string): string { const rel = path.relative(cwd, filename); if (rel.startsWith('..')) return filename; return '.' + path.sep + rel; @@ -74,20 +74,20 @@ function relativeUriFilename(uri: string, fsPathRoot: string): string { return '.' + path.sep + rel; } -function reportProgress(p: ProgressItem) { +function reportProgress(p: ProgressItem, cwd: string) { if (p.type === 'ProgressFileComplete') { return reportProgressFileComplete(p); } if (p.type === 'ProgressFileBegin') { - return reportProgressFileBegin(p); + return reportProgressFileBegin(p, cwd); } } -function reportProgressFileBegin(p: ProgressFileBegin) { +function reportProgressFileBegin(p: ProgressFileBegin, cwd: string) { const fc = '' + p.fileCount; const fn = (' '.repeat(fc.length) + p.fileNum).slice(-fc.length); const idx = fn + '/' + fc; - const filename = chalk.gray(relativeFilename(p.filename)); + const filename = chalk.gray(relativeFilename(p.filename, cwd)); process.stderr.write(`\r${idx} ${filename}`); } @@ -151,7 +151,7 @@ export function getReporter(options: ReporterOptions, config?: ReporterConfigura emitters[msgType]?.(message); } - const root = URI.file(options.root || process.cwd()); + const root = URI.file(path.resolve(options.root || process.cwd())); const fsPathRoot = root.fsPath; function relativeIssue(fn: (i: ReporterIssue) => void): (i: Issue) => void { const fnFilename = options.relative @@ -192,7 +192,7 @@ export function getReporter(options: ReporterOptions, config?: ReporterConfigura error: silent ? nullEmitter : errorEmitter, info: infoEmitter, debug: emitters.Debug, - progress: !silent && progress ? reportProgress : nullEmitter, + progress: !silent && progress ? (p) => reportProgress(p, fsPathRoot) : nullEmitter, result: !silent && summary ? resultEmitter : nullEmitter, }; }