From c625479be185f287e297a1dcddbcfa2aa24b0d0d Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Thu, 25 Feb 2021 15:48:47 +0100 Subject: [PATCH] fix: make sure to export all needed cspell types. (#1006) * ci: spell check `.github` as well. * Update cspellrc.json * Update cspell.yml * Update cspell-dict.txt * Update test.yml * Update cspell.json * fix: make sure the types are exported. * dev: add some tests * testing: update cspell integration test --- .github/workflows/cspell.yml | 12 +--- .github/workflows/test.yml | 2 +- cspell-dict.txt | 17 +++++- cspell.json | 2 + cspellrc.json | 7 +++ package.json | 2 +- packages/cspell/cSpell.json | 11 +++- packages/cspell/src/index.test.ts | 55 ++++++++++++++++++ packages/cspell/src/index.ts | 2 + test-packages/test-cspell/src/index.ts | 77 +++++++++++++++++++++++--- 10 files changed, 163 insertions(+), 24 deletions(-) create mode 100644 cspellrc.json diff --git a/.github/workflows/cspell.yml b/.github/workflows/cspell.yml index 41cf98ed7b43..dcf9c6bb4343 100644 --- a/.github/workflows/cspell.yml +++ b/.github/workflows/cspell.yml @@ -1,23 +1,13 @@ name: cSpell TS/MD on: pull_request: - paths: - - "**/*.md" - - "**/*.ts" - - "cspell-dict.txt" - - "cspell.json" push: branches: - master - paths: - - "**/*.md" - - "**/*.ts" - - "cspell-dict.txt" - - "cspell.json" jobs: cspell: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: npx cspell "**/*.*" + - run: npx cspell@latest "**/*" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e9a45c99bb7b..7a4a68fbc68e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: run: node ./bin.js trace test - name: verify the spell checker runs - run: node ./bin.js "**/*.*" + run: node ./bin.js -c cspellrc.json # Ensure the repository is clean after build & test - run: git --no-pager diff --compact-summary --exit-code diff --git a/cspell-dict.txt b/cspell-dict.txt index 6279aa293bf5..1ddb91dd5f19 100644 --- a/cspell-dict.txt +++ b/cspell-dict.txt @@ -1,20 +1,30 @@ +DAWG +WORDCHARS +alexiosc backreference backreferences bitjson +cheatsheets codecov codeql cosmiconfig coverallsapp -DAWG +cspellrc +dependabot deserialize deserializer deserializers +exonum gzipped issuehunt lcov +lerna lgtm liberapay +licia +liriliri macos +megistos micromatch monorepo multiline @@ -24,13 +34,16 @@ otechie patreon popd pushd +pycontribs repo repos retryable serializers +specberus streetsidesoftware submodule tidelift tsdk -WORDCHARS +webdeveric +wireapp xregexp diff --git a/cspell.json b/cspell.json index 4ae091f40f46..496c9e6f0795 100644 --- a/cspell.json +++ b/cspell.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", "version": "0.2", "dictionaryDefinitions": [ { @@ -18,6 +19,7 @@ "**/.gitignore", "**/.vscode/**", "**/{cspell.*,cSpell.*,.cspell.*,cspell.config.*}", + "*.{png,jpg,pdf}", "**/*.snap", "**/*.trie", "**/coverage/**", diff --git a/cspellrc.json b/cspellrc.json new file mode 100644 index 000000000000..a058d21e3bfe --- /dev/null +++ b/cspellrc.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", + "version": "0.2", + "name": "Run Config", + "files": ["**/*", ".github/**/*"], + "import": ["./cspell.json"] +} diff --git a/package.json b/package.json index 8f63d58f1e3f..b4a8d23cf908 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "build": "lerna run build", "build-schema": "lerna run build-schema", "build-integration-tests": "cd ./integration-tests && npm i", - "check-spelling": "npx cspell '**/*.*'", + "check-spelling": "npx cspell@latest -c cspellrc.json", "clean-build": "lerna run clean-build", "clean": "lerna run clean && rimraf lcov.info", "coverage": "lerna run coverage --stream && npm run coverage-collect", diff --git a/packages/cspell/cSpell.json b/packages/cspell/cSpell.json index 22b40a906882..a6255e3c7ddd 100644 --- a/packages/cspell/cSpell.json +++ b/packages/cspell/cSpell.json @@ -21,6 +21,15 @@ "**/.cspell.json", ".vscode/**" ], - "dictionaryDefinitions": [], + "dictionaryDefinitions": [ + { + "name": "workspace", + "file": "../../cspell-dict.txt", + "description": "Custom Workspace Dictionary" + } + ], + "dictionaries": [ + "workspace" + ], "ignoreWords": [] } diff --git a/packages/cspell/src/index.test.ts b/packages/cspell/src/index.test.ts index 7dd1e795d55c..f812ecac6291 100644 --- a/packages/cspell/src/index.test.ts +++ b/packages/cspell/src/index.test.ts @@ -1,7 +1,62 @@ import * as index from './index'; +// Make sure the types are exported. +import { CSpellApplicationOptions, RunResult, Emitters, Issue, ProgressFileComplete } from './index'; + describe('Validate index.ts', () => { test('index', () => { expect(index).toBeDefined(); }); + + test('quick run', async () => { + const appOptions: CSpellApplicationOptions = {}; + const logger = new Logger(); + + const result: RunResult = await index.lint(['*.md'], appOptions, logger); + + expect(result).toEqual( + expect.objectContaining({ + errors: 0, + issues: 0, + }) + ); + }); }); + +class Logger implements Emitters { + log: string[] = []; + issueCount = 0; + errorCount = 0; + debugCount = 0; + infoCount = 0; + progressCount = 0; + issues: Issue[] = []; + + issue = (issue: Issue) => { + this.issues.push(issue); + this.issueCount += 1; + const { uri, row, col, text } = issue; + this.log.push(`Issue: ${uri}[${row}, ${col}]: Unknown word: ${text}`); + }; + + error = (message: string, error: Error) => { + this.errorCount += 1; + this.log.push(`Error: ${message} ${error.toString()}`); + return Promise.resolve(); + }; + + info = (message: string) => { + this.infoCount += 1; + this.log.push(`Info: ${message}`); + }; + + debug = (message: string) => { + this.debugCount += 1; + this.log.push(`Debug: ${message}`); + }; + + progress = (p: ProgressFileComplete) => { + this.progressCount += 1; + this.log.push(`Progress: ${p.type} ${p.fileNum} ${p.fileCount} ${p.filename}`); + }; +} diff --git a/packages/cspell/src/index.ts b/packages/cspell/src/index.ts index 5e9b13c558ed..cd7dd6ad931a 100644 --- a/packages/cspell/src/index.ts +++ b/packages/cspell/src/index.ts @@ -1,2 +1,4 @@ export * from './application'; export * from './emitters'; +export { BaseOptions, CSpellApplicationOptions, TraceOptions } from './options'; +export { RunResult } from './lint'; diff --git a/test-packages/test-cspell/src/index.ts b/test-packages/test-cspell/src/index.ts index c6030ad26a1a..8cb618641174 100644 --- a/test-packages/test-cspell/src/index.ts +++ b/test-packages/test-cspell/src/index.ts @@ -1,14 +1,75 @@ import { assert } from 'console'; -import { checkText, lint, trace } from 'cspell/dist/application'; +import { + checkText, + lint, + trace, + Emitters, + Issue, + ProgressFileComplete, + CSpellApplicationOptions, + RunResult, +} from 'cspell'; import { run } from 'cspell/dist/app'; -console.log('start'); +async function test() { + console.log('start'); -/** - * The main goal here is to make sure it compiles. The unit tests are validation that it compiled as expected. - */ -const functions = [checkText, lint, trace, run]; + /** + * The main goal here is to make sure it compiles. The unit tests are validation that it compiled as expected. + */ + const functions = [checkText, lint, trace, run]; -functions.forEach((fn) => assert(typeof fn === 'function', "typeof %o === 'function'", fn)); + functions.forEach((fn) => assert(typeof fn === 'function', "typeof %o === 'function'", fn)); -console.log('done'); + const logger = new ConsoleLogger(); + + const options: CSpellApplicationOptions = {}; + + const result: RunResult = await lint(['*.md'], options, logger); + assert(result.errors === 0); + assert(result.issues === 0); + assert(result.files === 2); + + console.log(JSON.stringify(result)); + + console.log('done'); +} + +class ConsoleLogger implements Emitters { + log: string[] = []; + issueCount = 0; + errorCount = 0; + debugCount = 0; + infoCount = 0; + progressCount = 0; + issues: Issue[] = []; + + issue = (issue: Issue) => { + this.issueCount += 1; + const { uri, row, col, text } = issue; + console.log(`Issue: ${uri}[${row}, ${col}]: Unknown word: ${text}`); + }; + + error = (message: string, error: Error) => { + this.errorCount += 1; + console.error(`Error: ${message} ${error.toString()}`); + return Promise.resolve(); + }; + + info = (_message: string) => { + this.infoCount += 1; + // console.info(`Info: ${message}`); + }; + + debug = (_message: string) => { + this.debugCount += 1; + // console.debug(`Debug: ${message}`); + }; + + progress = (p: ProgressFileComplete) => { + this.progressCount += 1; + console.error(`Progress: ${p.type} ${p.fileNum} ${p.fileCount} ${p.filename}`); + }; +} + +test();