Skip to content

Commit

Permalink
fix: Make sure issues are reported relative to the specified root (#5043
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Jason3S authored Dec 6, 2023
1 parent 075c843 commit 6622244
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
44 changes: 22 additions & 22 deletions packages/cspell/src/app/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 [90m./samples/fail-fast/first-fail.txt[39m
2/2 [90m./samples/fail-fast/second-fail.txt[39m"
1/2 [90m./first-fail.txt[39m
2/2 [90m./second-fail.txt[39m"
`;

exports[`Validate cli > app '--fail-fast with config' Expect Error: [Function CheckFailed] 1`] = `[]`;
Expand All @@ -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 [90m./samples/fail-fast/first-fail.txt[39m"
1/2 [90m./first-fail.txt[39m"
`;

exports[`Validate cli > app '--fail-fast with option' Expect Error: [Function CheckFailed] 1`] = `[]`;
Expand All @@ -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 [90m./samples/fail-fast/first-fail.txt[39m"
1/2 [90m./first-fail.txt[39m"
`;

exports[`Validate cli > app '--help' Expect Error: 'outputHelp' 1`] = `
Expand Down Expand Up @@ -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 [90m./samples/fail-fast/first-fail.txt[39m
2/2 [90m./samples/fail-fast/second-fail.txt[39m"
1/2 [90m./first-fail.txt[39m
2/2 [90m./second-fail.txt[39m"
`;

exports[`Validate cli > app 'Explicit file://' Expect Error: undefined 1`] = `[]`;
Expand All @@ -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 [90m./fixtures/misc/star-not.md[39m"
1/1 [90m./star-not.md[39m"
`;

exports[`Validate cli > app 'Explicit not found file://' Expect Error: [Function CheckFailed] 1`] = `[]`;
Expand All @@ -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 [90m./fixtures/misc/not-fond.md[39m"
1/1 [90m./not-fond.md[39m"
`;

exports[`Validate cli > app 'LICENSE' Expect Error: undefined 1`] = `[]`;
Expand Down Expand Up @@ -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 [90m./fixtures/issue-2998/fix-words.txt[39m"
1/1 [90m./fix-words.txt[39m"
`;
exports[`Validate cli > app 'link add' 1`] = `""`;
Expand Down Expand Up @@ -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 [90m./samples/cspell-bad.json[39m
2/6 [90m./samples/cspell-includes.json[39m
3/6 [90m./samples/cspell-missing-dict.json[39m
4/6 [90m./samples/sample.c[39m
5/6 [90m./samples/sample.py[39m
6/6 [90m./samples/text.txt[39m"
1/6 [90m./cspell-bad.json[39m
2/6 [90m./cspell-includes.json[39m
3/6 [90m./cspell-missing-dict.json[39m
4/6 [90m./sample.c[39m
5/6 [90m./sample.py[39m
6/6 [90m./text.txt[39m"
`;
exports[`Validate cli > app 'with forbidden words' Expect Error: [Function CheckFailed] 1`] = `[]`;
Expand Down
14 changes: 7 additions & 7 deletions packages/cspell/src/app/cli-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 6622244

Please sign in to comment.