Skip to content

Commit

Permalink
fix: make sure to export all needed cspell types. (#1006)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jason3S authored Feb 25, 2021
1 parent bec0af6 commit c625479
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 24 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/cspell.yml
Original file line number Diff line number Diff line change
@@ -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 "**/*"
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions cspell-dict.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,13 +34,16 @@ otechie
patreon
popd
pushd
pycontribs
repo
repos
retryable
serializers
specberus
streetsidesoftware
submodule
tidelift
tsdk
WORDCHARS
webdeveric
wireapp
xregexp
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
"version": "0.2",
"dictionaryDefinitions": [
{
Expand All @@ -18,6 +19,7 @@
"**/.gitignore",
"**/.vscode/**",
"**/{cspell.*,cSpell.*,.cspell.*,cspell.config.*}",
"*.{png,jpg,pdf}",
"**/*.snap",
"**/*.trie",
"**/coverage/**",
Expand Down
7 changes: 7 additions & 0 deletions cspellrc.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion packages/cspell/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"**/.cspell.json",
".vscode/**"
],
"dictionaryDefinitions": [],
"dictionaryDefinitions": [
{
"name": "workspace",
"file": "../../cspell-dict.txt",
"description": "Custom Workspace Dictionary"
}
],
"dictionaries": [
"workspace"
],
"ignoreWords": []
}
55 changes: 55 additions & 0 deletions packages/cspell/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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}`);
};
}
2 changes: 2 additions & 0 deletions packages/cspell/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './application';
export * from './emitters';
export { BaseOptions, CSpellApplicationOptions, TraceOptions } from './options';
export { RunResult } from './lint';
77 changes: 69 additions & 8 deletions test-packages/test-cspell/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit c625479

Please sign in to comment.