Skip to content

Commit

Permalink
fix: Improve cli summary and progress (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Feb 3, 2022
1 parent 7d7a449 commit d52d68a
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 41 deletions.
1 change: 1 addition & 0 deletions cspell.json
Expand Up @@ -2,6 +2,7 @@
"$schema": "./cspell.schema.json",
"version": "0.2",
"cache": {
"useCache": true,
"cacheLocation": "./.cspell/.cspellcache",
"cacheStrategy": "content"
},
Expand Down
22 changes: 17 additions & 5 deletions packages/cspell-types/src/CSpellReporter.ts
Expand Up @@ -29,23 +29,35 @@ export type ErrorEmitter = (message: string, error: ErrorLike) => void;

export type SpellingErrorEmitter = (issue: Issue) => void;

export type ProgressTypes = 'ProgressFileComplete';
export type ProgressItem = ProgressFileComplete;
export type ProgressTypes = 'ProgressFileBegin' | 'ProgressFileComplete';
export type ProgressItem = ProgressFileBegin | ProgressFileComplete;

interface ProgressBase {
export interface ProgressBase {
type: ProgressTypes;
}
export interface ProgressFileComplete extends ProgressBase {
type: 'ProgressFileComplete';

export interface ProgressFileBase extends ProgressBase {
type: ProgressTypes;
fileNum: number;
fileCount: number;
filename: string;
}

export interface ProgressFileComplete extends ProgressFileBase {
type: 'ProgressFileComplete';
elapsedTimeMs: number | undefined;
processed: boolean | undefined;
numErrors: number | undefined;
cached?: boolean;
}

/**
* Notification sent just before processing a file.
*/
export interface ProgressFileBegin extends ProgressFileBase {
type: 'ProgressFileBegin';
}

export type ProgressEmitter = (p: ProgressItem | ProgressFileComplete) => void;

export interface RunResult {
Expand Down
116 changes: 111 additions & 5 deletions packages/cspell/src/__snapshots__/app.test.ts.snap
Expand Up @@ -10,6 +10,12 @@ log ./samples/fail-fast/second-fail.txt:1:1 - Unknown word (iamtypotoo)
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 ..."
`;

exports[`Validate cli app --fail-fast with config Expect Error: [Function CheckFailed] 1`] = `Array []`;

exports[`Validate cli app --fail-fast with config Expect Error: [Function CheckFailed] 2`] = `
Expand All @@ -18,6 +24,11 @@ log ./samples/fail-fast/first-fail.txt:1:1 - Unknown word (iamtypo)
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 ..."
`;

exports[`Validate cli app --fail-fast with option Expect Error: [Function CheckFailed] 1`] = `Array []`;

exports[`Validate cli app --fail-fast with option Expect Error: [Function CheckFailed] 2`] = `
Expand All @@ -26,6 +37,11 @@ log ./samples/fail-fast/first-fail.txt:1:1 - Unknown word (iamtypo)
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 ..."
`;

exports[`Validate cli app --help Expect Error: outputHelp 1`] = `
Array [
"Usage: cspell [options] [command]",
Expand Down Expand Up @@ -53,6 +69,8 @@ Array [

exports[`Validate cli app --help Expect Error: outputHelp 2`] = `""`;

exports[`Validate cli app --help Expect Error: outputHelp 3`] = `""`;

exports[`Validate cli app --no-fail-fast with config Expect Error: [Function CheckFailed] 1`] = `Array []`;

exports[`Validate cli app --no-fail-fast with config Expect Error: [Function CheckFailed] 2`] = `
Expand All @@ -63,20 +81,33 @@ log ./samples/fail-fast/second-fail.txt:1:1 - Unknown word (iamtypotoo)
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 ..."
`;

exports[`Validate cli app LICENSE Expect Error: undefined 1`] = `Array []`;

exports[`Validate cli app LICENSE Expect Error: undefined 2`] = `
"error 1/1 ./LICENSE 0.00ms
error CSpell: Files checked: 1, Issues found: 0 in 0 files"
`;

exports[`Validate cli app LICENSE Expect Error: undefined 3`] = `
"
1/1 ./LICENSE ..."
`;

exports[`Validate cli app bad config Expect Error: [Function CheckFailed] 1`] = `Array []`;

exports[`Validate cli app bad config Expect Error: [Function CheckFailed] 2`] = `
"error Configuration Error: Failed to find config file at: \\"./src/app.test.ts\\"
error CSpell: Files checked: 0, Issues found: 0 in 0 files"
`;

exports[`Validate cli app bad config Expect Error: [Function CheckFailed] 3`] = `""`;

exports[`Validate cli app check LICENSE Expect Error: undefined 1`] = `
Array [
"MIT License",
Expand Down Expand Up @@ -111,6 +142,8 @@ log
log "
`;

exports[`Validate cli app check LICENSE Expect Error: undefined 3`] = `""`;

exports[`Validate cli app check help Expect Error: outputHelp 1`] = `
Array [
"Usage: cspell check [options] <files...>",
Expand All @@ -129,6 +162,8 @@ Array [
exports[`Validate cli app check help Expect Error: outputHelp 2`] = `""`;
exports[`Validate cli app check help Expect Error: outputHelp 3`] = `""`;
exports[`Validate cli app check missing Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app check missing Expect Error: [Function CheckFailed] 2`] = `
Expand All @@ -137,6 +172,8 @@ log
error File not found \\"./missing-file.txt\\""
`;
exports[`Validate cli app check missing Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli app check with spelling errors Expect Error: [Function CheckFailed] 1`] = `
Array [
" [NEDERLANDS]",
Expand Down Expand Up @@ -243,20 +280,29 @@ log
log "
`;
exports[`Validate cli app check with spelling errors Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli app cspell-bad.json Expect Error: undefined 1`] = `Array []`;
exports[`Validate cli app cspell-bad.json Expect Error: undefined 2`] = `
"error 1/1 ./src/app.test.ts 0.00ms
error CSpell: Files checked: 1, Issues found: 0 in 0 files"
`;
exports[`Validate cli app cspell-bad.json Expect Error: undefined 3`] = `
"
1/1 ./src/app.test.ts ..."
`;
exports[`Validate cli app cspell-import-missing.json Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app cspell-import-missing.json Expect Error: [Function CheckFailed] 2`] = `
"error Configuration Error: Failed to read config file: \\"./samples/intentionally-missing-file.json\\"
error CSpell: Files checked: 0, Issues found: 0 in 0 files"
`;
exports[`Validate cli app cspell-import-missing.json Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli app current_file --verbose Expect Error: undefined 1`] = `Array []`;
exports[`Validate cli app current_file --verbose Expect Error: undefined 2`] = `
Expand Down Expand Up @@ -293,38 +339,57 @@ error 1/1 ./src/app.test.ts 0.00ms
error CSpell: Files checked: 1, Issues found: 0 in 0 files"
`;
exports[`Validate cli app current_file --verbose Expect Error: undefined 3`] = `
"
1/1 ./src/app.test.ts ..."
`;
exports[`Validate cli app current_file Expect Error: undefined 1`] = `Array []`;
exports[`Validate cli app current_file Expect Error: undefined 2`] = `
"error 1/1 ./src/app.test.ts 0.00ms
error CSpell: Files checked: 1, Issues found: 0 in 0 files"
`;
exports[`Validate cli app current_file Expect Error: undefined 3`] = `
"
1/1 ./src/app.test.ts ..."
`;
exports[`Validate cli app current_file languageId Expect Error: undefined 1`] = `Array []`;
exports[`Validate cli app current_file languageId Expect Error: undefined 2`] = `
"error 1/1 ./src/app.test.ts 0.00ms
error CSpell: Files checked: 1, Issues found: 0 in 0 files"
`;
exports[`Validate cli app link 1`] = `Array []`;
exports[`Validate cli app current_file languageId Expect Error: undefined 3`] = `
"
1/1 ./src/app.test.ts ..."
`;
exports[`Validate cli app link 1`] = `""`;
exports[`Validate cli app link add 1`] = `Array []`;
exports[`Validate cli app link add 1`] = `""`;
exports[`Validate cli app link list 1`] = `Array []`;
exports[`Validate cli app link list 1`] = `""`;
exports[`Validate cli app link ls 1`] = `Array []`;
exports[`Validate cli app link ls 1`] = `""`;
exports[`Validate cli app link remove 1`] = `Array []`;
exports[`Validate cli app link remove 1`] = `""`;
exports[`Validate cli app must find force no error Expect Error: undefined 1`] = `Array []`;
exports[`Validate cli app must find force no error Expect Error: undefined 2`] = `"error CSpell: Files checked: 0, Issues found: 0 in 0 files"`;
exports[`Validate cli app must find force no error Expect Error: undefined 3`] = `""`;
exports[`Validate cli app must find with error Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app must find with error Expect Error: [Function CheckFailed] 2`] = `"error CSpell: Files checked: 0, Issues found: 0 in 0 files"`;
exports[`Validate cli app must find with error Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli app no-args Expect Error: outputHelp 1`] = `
Array [
"Usage: cspell lint [options] [globs...]",
Expand Down Expand Up @@ -394,10 +459,14 @@ Array [
exports[`Validate cli app no-args Expect Error: outputHelp 2`] = `""`;
exports[`Validate cli app no-args Expect Error: outputHelp 3`] = `""`;
exports[`Validate cli app not found error by default Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app not found error by default Expect Error: [Function CheckFailed] 2`] = `"error CSpell: Files checked: 0, Issues found: 0 in 0 files"`;
exports[`Validate cli app not found error by default Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli app samples/Dutch.txt Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app samples/Dutch.txt Expect Error: [Function CheckFailed] 2`] = `
Expand Down Expand Up @@ -594,6 +663,11 @@ log ./samples/Dutch.txt:78:18 - Unknown word (ANBI)
error CSpell: Files checked: 1, Issues found: 189 in 1 files"
`;
exports[`Validate cli app samples/Dutch.txt Expect Error: [Function CheckFailed] 3`] = `
"
1/1 ./samples/Dutch.txt ..."
`;
exports[`Validate cli app success suggest run with ["suggest", "café", "--num-suggestions=1", "--no-include-ties"] 1`] = `Array []`;
exports[`Validate cli app success suggest run with ["suggest", "café", "--num-suggestions=1", "--no-include-ties"] 2`] = `
Expand Down Expand Up @@ -1193,6 +1267,16 @@ log ./samples/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 ..."
`;
exports[`Validate cli app with forbidden words Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app with forbidden words Expect Error: [Function CheckFailed] 2`] = `
Expand All @@ -1203,6 +1287,11 @@ log ./samples/src/sample-with-forbidden-words.md:5:3 - Forbidden word (colour)
error CSpell: Files checked: 1, Issues found: 3 in 1 files"
`;
exports[`Validate cli app with forbidden words Expect Error: [Function CheckFailed] 3`] = `
"
1/1 ./samples/src/sample-with-forbidden-words.md ..."
`;
exports[`Validate cli app with spelling errors --debug Dutch.txt Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app with spelling errors --debug Dutch.txt Expect Error: [Function CheckFailed] 2`] = `
Expand Down Expand Up @@ -1401,6 +1490,8 @@ exports[`Validate cli app with spelling errors --silent Dutch.txt Expect Error:
exports[`Validate cli app with spelling errors --silent Dutch.txt Expect Error: [Function CheckFailed] 2`] = `""`;
exports[`Validate cli app with spelling errors --silent Dutch.txt Expect Error: [Function CheckFailed] 3`] = `""`;
exports[`Validate cli app with spelling errors Dutch.txt --legacy Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app with spelling errors Dutch.txt --legacy Expect Error: [Function CheckFailed] 2`] = `
Expand Down Expand Up @@ -1597,6 +1688,11 @@ log ./samples/Dutch.txt[78, 18]: Unknown word: ANBI
error CSpell: Files checked: 1, Issues found: 189 in 1 files"
`;
exports[`Validate cli app with spelling errors Dutch.txt --legacy Expect Error: [Function CheckFailed] 3`] = `
"
1/1 ./samples/Dutch.txt ..."
`;
exports[`Validate cli app with spelling errors Dutch.txt Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app with spelling errors Dutch.txt Expect Error: [Function CheckFailed] 2`] = `
Expand Down Expand Up @@ -1793,6 +1889,11 @@ log ./samples/Dutch.txt:78:18 - Unknown word (ANBI)
error CSpell: Files checked: 1, Issues found: 189 in 1 files"
`;
exports[`Validate cli app with spelling errors Dutch.txt Expect Error: [Function CheckFailed] 3`] = `
"
1/1 ./samples/Dutch.txt ..."
`;
exports[`Validate cli app with spelling errors Dutch.txt words only Expect Error: [Function CheckFailed] 1`] = `Array []`;
exports[`Validate cli app with spelling errors Dutch.txt words only Expect Error: [Function CheckFailed] 2`] = `
Expand Down Expand Up @@ -1988,3 +2089,8 @@ log instelling
log ANBI
error CSpell: Files checked: 1, Issues found: 189 in 1 files"
`;
exports[`Validate cli app with spelling errors Dutch.txt words only Expect Error: [Function CheckFailed] 3`] = `
"
1/1 ./samples/Dutch.txt ..."
`;

0 comments on commit d52d68a

Please sign in to comment.