From 04862f30b36e0b36171b009e7097767ecbb03f71 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Tue, 5 Oct 2021 17:11:34 +0200 Subject: [PATCH 1/2] fix: fix #1807 Make sure files are counted, even if they are cached. --- packages/cspell-types/src/CSpellReporter.ts | 1 + packages/cspell/src/cli-reporter.ts | 5 +++-- packages/cspell/src/fileHelper.ts | 3 ++- packages/cspell/src/lint.ts | 9 +++++---- packages/cspell/src/util/cache/DiskCache.test.ts | 9 ++++++--- packages/cspell/src/util/cache/DiskCache.ts | 6 ++++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/cspell-types/src/CSpellReporter.ts b/packages/cspell-types/src/CSpellReporter.ts index 9033641f033c..4e6e46e3e88e 100644 --- a/packages/cspell-types/src/CSpellReporter.ts +++ b/packages/cspell-types/src/CSpellReporter.ts @@ -43,6 +43,7 @@ export interface ProgressFileComplete extends ProgressBase { elapsedTimeMs: number | undefined; processed: boolean | undefined; numErrors: number | undefined; + cached?: boolean; } export type ProgressEmitter = (p: ProgressItem | ProgressFileComplete) => void; diff --git a/packages/cspell/src/cli-reporter.ts b/packages/cspell/src/cli-reporter.ts index 251f668b4bae..843163889d1f 100644 --- a/packages/cspell/src/cli-reporter.ts +++ b/packages/cspell/src/cli-reporter.ts @@ -66,13 +66,14 @@ function reportProgress(p: ProgressItem) { const fn = (' '.repeat(fc.length) + p.fileNum).slice(-fc.length); const idx = fn + '/' + fc; const filename = chalk.gray(relativeFilename(p.filename)); - const time = reportTime(p.elapsedTimeMs); + const time = reportTime(p.elapsedTimeMs, !!p.cached); const skipped = p.processed === false ? ' skipped' : ''; const hasErrors = p.numErrors ? chalk.red` X` : ''; console.error(`${idx} ${filename} ${time}${skipped}${hasErrors}`); } -function reportTime(elapsedTimeMs: number | undefined): string { +function reportTime(elapsedTimeMs: number | undefined, cached: boolean): string { + if (cached) return chalk.green('cached'); if (elapsedTimeMs === undefined) return '-'; const color = elapsedTimeMs < 1000 ? chalk.white : elapsedTimeMs < 2000 ? chalk.yellow : chalk.redBright; return color(elapsedTimeMs.toFixed(2) + 'ms'); diff --git a/packages/cspell/src/fileHelper.ts b/packages/cspell/src/fileHelper.ts index c30b56936a77..8e7125e3d823 100644 --- a/packages/cspell/src/fileHelper.ts +++ b/packages/cspell/src/fileHelper.ts @@ -39,7 +39,8 @@ export interface FileResult { issues: Issue[]; errors: number; configErrors: number; - elapsedTimeMs: number; + elapsedTimeMs: number | undefined; + cached?: boolean; } export function fileInfoToDocument( diff --git a/packages/cspell/src/lint.ts b/packages/cspell/src/lint.ts index 62acc1a4353c..43510981ff72 100644 --- a/packages/cspell/src/lint.ts +++ b/packages/cspell/src/lint.ts @@ -99,7 +99,7 @@ export async function runLint(cfg: CSpellApplicationConfiguration): Promise + const emitProgress = (filename: string, fileNum: number, result: FileResult) => reporter.progress({ type: 'ProgressFileComplete', fileNum, @@ -108,6 +108,7 @@ export async function runLint(cfg: CSpellApplicationConfiguration): Promise reporter.issue(issue)); - status.files += 1; if (result.issues.length || result.errors) { status.filesWithIssues.add(filename); status.issues += result.issues.length; diff --git a/packages/cspell/src/util/cache/DiskCache.test.ts b/packages/cspell/src/util/cache/DiskCache.test.ts index fcee80fae805..cba42f95e8be 100644 --- a/packages/cspell/src/util/cache/DiskCache.test.ts +++ b/packages/cspell/src/util/cache/DiskCache.test.ts @@ -76,7 +76,8 @@ describe('DiskCache', () => { const cachedResult = await diskCache.getCachedLintResults('file', TEST_CONFIG__INFO); expect(cachedResult).toMatchObject(RESULT_NO_ISSUES); - expect(cachedResult?.elapsedTimeMs).toEqual(0); + expect(cachedResult?.elapsedTimeMs).toBeUndefined(); + expect(cachedResult?.cached).toBe(true); expect(mockReadFileInfo).toHaveBeenCalledTimes(0); expect(cachedResult?.fileInfo.filename).toEqual('file'); @@ -94,7 +95,8 @@ describe('DiskCache', () => { const cachedResult = await diskCache.getCachedLintResults('file', TEST_CONFIG__INFO); expect(cachedResult).toMatchObject(RESULT_NO_ISSUES); - expect(cachedResult?.elapsedTimeMs).toEqual(0); + expect(cachedResult?.elapsedTimeMs).toBeUndefined(); + expect(cachedResult?.cached).toBe(false); expect(mockReadFileInfo).toHaveBeenCalledTimes(0); expect(cachedResult?.fileInfo.filename).toEqual('file'); @@ -116,7 +118,8 @@ describe('DiskCache', () => { const cachedResult = await diskCache.getCachedLintResults('file', TEST_CONFIG__INFO); expect(cachedResult).toMatchObject(result); - expect(cachedResult?.elapsedTimeMs).toEqual(0); + expect(cachedResult?.elapsedTimeMs).toBeUndefined(); + expect(cachedResult?.cached).toBe(true); expect(mockReadFileInfo).toHaveBeenCalledTimes(1); expect(cachedResult?.fileInfo).toEqual(fileInfo); diff --git a/packages/cspell/src/util/cache/DiskCache.ts b/packages/cspell/src/util/cache/DiskCache.ts index e21b0390a5fe..17889ac4bace 100644 --- a/packages/cspell/src/util/cache/DiskCache.ts +++ b/packages/cspell/src/util/cache/DiskCache.ts @@ -44,12 +44,14 @@ export class DiskCache implements CSpellLintResultCache { // Skip reading empty files and files without lint error const hasErrors = meta.result.errors > 0 || meta.result.configErrors > 0 || meta.result.issues.length > 0; - const shouldReadFile = meta.size !== 0 && hasErrors; + const cached = !!meta.size; + const shouldReadFile = cached && hasErrors; return { ...meta.result, - elapsedTimeMs: 0, + elapsedTimeMs: undefined, fileInfo: shouldReadFile ? await readFileInfo(filename) : { filename }, + cached, }; } From a3c0c7fe7cd398df218fbfd4f849e5ebed310741 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Tue, 5 Oct 2021 18:12:22 +0200 Subject: [PATCH 2/2] Update snapshots with the new file count. --- integration-tests/snapshots/AdaDoom3/AdaDoom3/report.yaml | 2 +- integration-tests/snapshots/AdaDoom3/AdaDoom3/snapshot.txt | 2 +- .../snapshots/Azure/azure-rest-api-specs/snapshot.txt | 2 +- .../snapshots/SoftwareBrothers/admin-bro/snapshot.txt | 2 +- integration-tests/snapshots/TheAlgorithms/Python/report.yaml | 2 +- .../snapshots/TheAlgorithms/Python/snapshot.txt | 2 +- integration-tests/snapshots/django/django/report.yaml | 2 +- integration-tests/snapshots/django/django/snapshot.txt | 2 +- integration-tests/snapshots/liriliri/licia/snapshot.txt | 2 +- .../snapshots/microsoft/TypeScript-Website/report.yaml | 2 +- .../snapshots/microsoft/TypeScript-Website/snapshot.txt | 2 +- integration-tests/snapshots/php/php-src/report.yaml | 2 +- integration-tests/snapshots/php/php-src/snapshot.txt | 2 +- integration-tests/snapshots/prettier/prettier/snapshot.txt | 2 +- integration-tests/snapshots/pycontribs/jira/report.yaml | 2 +- integration-tests/snapshots/pycontribs/jira/snapshot.txt | 2 +- packages/cspell/src/lint.ts | 5 +++-- 17 files changed, 19 insertions(+), 18 deletions(-) diff --git a/integration-tests/snapshots/AdaDoom3/AdaDoom3/report.yaml b/integration-tests/snapshots/AdaDoom3/AdaDoom3/report.yaml index fc612c5d49b4..227808c646d0 100644 --- a/integration-tests/snapshots/AdaDoom3/AdaDoom3/report.yaml +++ b/integration-tests/snapshots/AdaDoom3/AdaDoom3/report.yaml @@ -3,7 +3,7 @@ Repository: AdaDoom3/AdaDoom3 Url: https://github.com/AdaDoom3/AdaDoom3.git Args: ["**/*.*"] Summary: - files: 103 + files: 105 filesWithIssues: 98 issues: 3265 errors: 0 diff --git a/integration-tests/snapshots/AdaDoom3/AdaDoom3/snapshot.txt b/integration-tests/snapshots/AdaDoom3/AdaDoom3/snapshot.txt index fdd72c38d258..aa115dad503c 100644 --- a/integration-tests/snapshots/AdaDoom3/AdaDoom3/snapshot.txt +++ b/integration-tests/snapshots/AdaDoom3/AdaDoom3/snapshot.txt @@ -3,7 +3,7 @@ Repository: AdaDoom3/AdaDoom3 Url: "https://github.com/AdaDoom3/AdaDoom3.git" Args: ["**/*.*"] Lines: - CSpell: Files checked: 103, Issues found: 3265 in 98 files + CSpell: Files checked: 105, Issues found: 3265 in 98 files exit code: 1 ./Engine/Assembly/PPC/neo-engine-cpu.adb:5:78 - Unknown word (Squirek) -- Copyright (C) 2016 Justin Squirek ./Engine/Assembly/x86-64/neo-engine-cpu.adb:101:111 - Unknown word (OSXSAVE) -- ECX_Register, 27); -- OSXSAVE diff --git a/integration-tests/snapshots/Azure/azure-rest-api-specs/snapshot.txt b/integration-tests/snapshots/Azure/azure-rest-api-specs/snapshot.txt index 960122c1b260..6215bb33da09 100644 --- a/integration-tests/snapshots/Azure/azure-rest-api-specs/snapshot.txt +++ b/integration-tests/snapshots/Azure/azure-rest-api-specs/snapshot.txt @@ -3,7 +3,7 @@ Repository: Azure/azure-rest-api-specs Url: "https://github.com/Azure/azure-rest-api-specs.git" Args: ["--config=cSpell.json","**/*.{md,ts,js}"] Lines: - CSpell: Files checked: 1678, Issues found: 1721 in 584 files + CSpell: Files checked: 1679, Issues found: 1721 in 584 files exit code: 1 ./README.md:20:179 - Unknown word (Dataplane) -- RPs' Resource types or Dataplane API versions that represent ./README.md:30:134 - Unknown word (dataplane) -- per resource type or dataplane service version. This diff --git a/integration-tests/snapshots/SoftwareBrothers/admin-bro/snapshot.txt b/integration-tests/snapshots/SoftwareBrothers/admin-bro/snapshot.txt index c4848dfab3c3..212a2cc08ccb 100644 --- a/integration-tests/snapshots/SoftwareBrothers/admin-bro/snapshot.txt +++ b/integration-tests/snapshots/SoftwareBrothers/admin-bro/snapshot.txt @@ -3,7 +3,7 @@ Repository: SoftwareBrothers/admin-bro Url: "https://github.com/SoftwareBrothers/admin-bro.git" Args: ["src/**/*.{ts,js,tsx,jsx}","**/*.md"] Lines: - CSpell: Files checked: 360, Issues found: 6 in 5 files + CSpell: Files checked: 361, Issues found: 6 in 5 files exit code: 1 ./cy/readme.md:433:45 - Unknown word (Favourite) -- Sequelize Resources” → Favourite Places link inside the ./src/backend/utils/build-feature/build-feature.spec.ts:86:14 - Unknown word (falsey) -- it('merges falsey options', function diff --git a/integration-tests/snapshots/TheAlgorithms/Python/report.yaml b/integration-tests/snapshots/TheAlgorithms/Python/report.yaml index 0bb9d23182de..35fdf278f364 100644 --- a/integration-tests/snapshots/TheAlgorithms/Python/report.yaml +++ b/integration-tests/snapshots/TheAlgorithms/Python/report.yaml @@ -3,7 +3,7 @@ Repository: TheAlgorithms/Python Url: https://github.com/TheAlgorithms/Python.git Args: ["**/*.{md,py}"] Summary: - files: 783 + files: 939 filesWithIssues: 395 issues: 2537 errors: 0 diff --git a/integration-tests/snapshots/TheAlgorithms/Python/snapshot.txt b/integration-tests/snapshots/TheAlgorithms/Python/snapshot.txt index 6be70e8f6a06..c3dcb602f16e 100644 --- a/integration-tests/snapshots/TheAlgorithms/Python/snapshot.txt +++ b/integration-tests/snapshots/TheAlgorithms/Python/snapshot.txt @@ -3,7 +3,7 @@ Repository: TheAlgorithms/Python Url: "https://github.com/TheAlgorithms/Python.git" Args: ["**/*.{md,py}"] Lines: - CSpell: Files checked: 783, Issues found: 2537 in 395 files + CSpell: Files checked: 939, Issues found: 2537 in 395 files exit code: 1 ./CONTRIBUTING.md:131:33 - Unknown word (pytest) -- doctests will be run by pytest as part of our automated ./CONTRIBUTING.md:134:14 - Unknown word (doctest) -- python3 -m doctest -v my_submission.py diff --git a/integration-tests/snapshots/django/django/report.yaml b/integration-tests/snapshots/django/django/report.yaml index 9ad7191201e7..7be904b80873 100644 --- a/integration-tests/snapshots/django/django/report.yaml +++ b/integration-tests/snapshots/django/django/report.yaml @@ -3,7 +3,7 @@ Repository: django/django Url: https://github.com/django/django.git Args: ["**/*.{md,py}"] Summary: - files: 2132 + files: 2701 filesWithIssues: 878 issues: 7789 errors: 0 diff --git a/integration-tests/snapshots/django/django/snapshot.txt b/integration-tests/snapshots/django/django/snapshot.txt index 11810ecebb26..bdd107e0b97e 100644 --- a/integration-tests/snapshots/django/django/snapshot.txt +++ b/integration-tests/snapshots/django/django/snapshot.txt @@ -3,7 +3,7 @@ Repository: django/django Url: "https://github.com/django/django.git" Args: ["**/*.{md,py}"] Lines: - CSpell: Files checked: 2132, Issues found: 7789 in 878 files + CSpell: Files checked: 2701, Issues found: 7789 in 878 files exit code: 1 ./django/apps/config.py:125:76 - Unknown word (isclass) -- getmembers(mod, inspect.isclass) ./django/apps/registry.py:132:40 - Unknown word (unconfigured) -- not ready" is due to unconfigured settings, accessing diff --git a/integration-tests/snapshots/liriliri/licia/snapshot.txt b/integration-tests/snapshots/liriliri/licia/snapshot.txt index 4df96c941f29..2eeef4d22830 100644 --- a/integration-tests/snapshots/liriliri/licia/snapshot.txt +++ b/integration-tests/snapshots/liriliri/licia/snapshot.txt @@ -3,7 +3,7 @@ Repository: liriliri/licia Url: "https://github.com/liriliri/licia.git" Args: ["**/*.*"] Lines: - CSpell: Files checked: 1362, Issues found: 353 in 86 files + CSpell: Files checked: 1365, Issues found: 353 in 86 files exit code: 1 ./CHANGELOG.md:227:26 - Unknown word (unenumerable) -- feat(allKeys): support unenumerable and symbol ./CHANGELOG.md:85:22 - Unknown word (eval) -- fix(Class): unsafe-eval CSP violation diff --git a/integration-tests/snapshots/microsoft/TypeScript-Website/report.yaml b/integration-tests/snapshots/microsoft/TypeScript-Website/report.yaml index b9de7922e1ee..782bad475922 100644 --- a/integration-tests/snapshots/microsoft/TypeScript-Website/report.yaml +++ b/integration-tests/snapshots/microsoft/TypeScript-Website/report.yaml @@ -3,7 +3,7 @@ Repository: microsoft/TypeScript-Website Url: https://github.com/microsoft/TypeScript-Website.git Args: ["--config=${repoConfig}/cspell.json","**/*.*"] Summary: - files: 705 + files: 706 filesWithIssues: 149 issues: 571 errors: 0 diff --git a/integration-tests/snapshots/microsoft/TypeScript-Website/snapshot.txt b/integration-tests/snapshots/microsoft/TypeScript-Website/snapshot.txt index a7acbfe80014..b1ce0fcf230b 100644 --- a/integration-tests/snapshots/microsoft/TypeScript-Website/snapshot.txt +++ b/integration-tests/snapshots/microsoft/TypeScript-Website/snapshot.txt @@ -3,7 +3,7 @@ Repository: microsoft/TypeScript-Website Url: "https://github.com/microsoft/TypeScript-Website.git" Args: ["--config=../../../../config/repositories/microsoft/TypeScript-Website/cspell.json","**/*.*"] Lines: - CSpell: Files checked: 705, Issues found: 571 in 149 files + CSpell: Files checked: 706, Issues found: 571 in 149 files exit code: 1 ./docs/Deprecating a page.md:3:109 - Unknown word (Dont) -- deleting because [Cool URIs Dont Change](https://www ./docs/New TypeScript Version.md:115:67 - Unknown word (schemastore) -- schemastore.git /tmp/schemastore diff --git a/integration-tests/snapshots/php/php-src/report.yaml b/integration-tests/snapshots/php/php-src/report.yaml index e2b17b18ccf3..6c12c80461ab 100644 --- a/integration-tests/snapshots/php/php-src/report.yaml +++ b/integration-tests/snapshots/php/php-src/report.yaml @@ -3,7 +3,7 @@ Repository: php/php-src Url: https://github.com/php/php-src.git Args: ["--config=${repoConfig}/cspell.json","**/*.{md,c,h,php}"] Summary: - files: 1826 + files: 1827 filesWithIssues: 1106 issues: 19948 errors: 0 diff --git a/integration-tests/snapshots/php/php-src/snapshot.txt b/integration-tests/snapshots/php/php-src/snapshot.txt index 9fd1ebb19e5b..6fbb98e89cae 100644 --- a/integration-tests/snapshots/php/php-src/snapshot.txt +++ b/integration-tests/snapshots/php/php-src/snapshot.txt @@ -3,7 +3,7 @@ Repository: php/php-src Url: "https://github.com/php/php-src.git" Args: ["--config=../../../../config/repositories/php/php-src/cspell.json","**/*.{md,c,h,php}"] Lines: - CSpell: Files checked: 1826, Issues found: 19948 in 1106 files + CSpell: Files checked: 1827, Issues found: 19948 in 1106 files exit code: 1 ./CODING_STANDARDS.md:105:8 - Unknown word (setclientencoding) -- pg_setclientencoding ./CODING_STANDARDS.md:126:5 - Unknown word (fooselect) -- fooselect_bar diff --git a/integration-tests/snapshots/prettier/prettier/snapshot.txt b/integration-tests/snapshots/prettier/prettier/snapshot.txt index 3667cf212128..8264a4adb97a 100644 --- a/integration-tests/snapshots/prettier/prettier/snapshot.txt +++ b/integration-tests/snapshots/prettier/prettier/snapshot.txt @@ -3,5 +3,5 @@ Repository: prettier/prettier Url: "https://github.com/prettier/prettier.git" Args: [] Lines: - CSpell: Files checked: 1733, Issues found: 0 in 0 files + CSpell: Files checked: 1740, Issues found: 0 in 0 files exit code: 0 diff --git a/integration-tests/snapshots/pycontribs/jira/report.yaml b/integration-tests/snapshots/pycontribs/jira/report.yaml index 2c178e7c939b..59470c7f99ed 100644 --- a/integration-tests/snapshots/pycontribs/jira/report.yaml +++ b/integration-tests/snapshots/pycontribs/jira/report.yaml @@ -3,7 +3,7 @@ Repository: pycontribs/jira Url: https://github.com/pycontribs/jira.git Args: ["**/*.*"] Summary: - files: 69 + files: 76 filesWithIssues: 36 issues: 459 errors: 0 diff --git a/integration-tests/snapshots/pycontribs/jira/snapshot.txt b/integration-tests/snapshots/pycontribs/jira/snapshot.txt index 0bb202b5cb1a..2c71c190c282 100644 --- a/integration-tests/snapshots/pycontribs/jira/snapshot.txt +++ b/integration-tests/snapshots/pycontribs/jira/snapshot.txt @@ -3,7 +3,7 @@ Repository: pycontribs/jira Url: "https://github.com/pycontribs/jira.git" Args: ["**/*.*"] Lines: - CSpell: Files checked: 69, Issues found: 459 in 36 files + CSpell: Files checked: 76, Issues found: 459 in 36 files exit code: 1 ./AUTHORS.rst:3:21 - Unknown word (Contribs) -- Development Team (PyContribs) ./AUTHORS.rst:5:7 - Unknown word (Speakmon) -- - Ben Speakmon reporter.issue(issue));