Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make sure issues are reported relative to the specified root #5043

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ./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`] = `[]`;
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 ./samples/fail-fast/first-fail.txt"
1/2 ./first-fail.txt"
`;

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 ./samples/fail-fast/first-fail.txt"
1/2 ./first-fail.txt"
`;

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 ./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`] = `[]`;
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 ./fixtures/misc/star-not.md"
1/1 ./star-not.md"
`;

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 ./fixtures/misc/not-fond.md"
1/1 ./not-fond.md"
`;

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 ./fixtures/issue-2998/fix-words.txt"
1/1 ./fix-words.txt"
`;

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 ./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`] = `[]`;
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
Loading