harper.js 0.20.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/harper.d.ts +9 -0
- package/dist/harper.js +660 -584
- package/package.json +2 -2
- package/src/Linter.test.ts +14 -0
- package/src/Linter.ts +7 -0
- package/src/LocalLinter.ts +12 -0
- package/src/WorkerLinter/index.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harper.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Elijah Potter",
|
|
6
6
|
"description": "The grammar checker for developers.",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "vite",
|
|
19
19
|
"build": "tsc && vite build",
|
|
20
|
-
"test": "vitest run --browser chromium
|
|
20
|
+
"test": "vitest run --browser chromium"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@microsoft/api-documenter": "^7.26.5",
|
package/src/Linter.test.ts
CHANGED
|
@@ -169,6 +169,20 @@ for (const [linterName, Linter] of Object.entries(linters)) {
|
|
|
169
169
|
expect(firstLints.length).toBeGreaterThan(secondLints.length);
|
|
170
170
|
expect(secondLints.length).toBe(0);
|
|
171
171
|
});
|
|
172
|
+
|
|
173
|
+
test(`${linterName} can add words to the dictionary`, async () => {
|
|
174
|
+
const source = 'asdf is not a word';
|
|
175
|
+
|
|
176
|
+
const linter = new Linter();
|
|
177
|
+
let lints = await linter.lint(source);
|
|
178
|
+
|
|
179
|
+
expect(lints).toHaveLength(1);
|
|
180
|
+
|
|
181
|
+
await linter.importWords(['asdf']);
|
|
182
|
+
lints = await linter.lint(source);
|
|
183
|
+
|
|
184
|
+
expect(lints).toHaveLength(0);
|
|
185
|
+
});
|
|
172
186
|
}
|
|
173
187
|
|
|
174
188
|
test('Linters have the same config format', async () => {
|
package/src/Linter.ts
CHANGED
|
@@ -63,4 +63,11 @@ export default interface Linter {
|
|
|
63
63
|
|
|
64
64
|
/** Clear records of all previously ignored lints. */
|
|
65
65
|
clearIgnoredLints(): Promise<void>;
|
|
66
|
+
|
|
67
|
+
/** Import words into the dictionary. This is a significant operation, so try to batch words. */
|
|
68
|
+
importWords(words: string[]): Promise<void>;
|
|
69
|
+
|
|
70
|
+
/** Export all added words from the dictionary. Note that this will NOT export anything from the curated dictionary,
|
|
71
|
+
* only words from previous calls to `this.importWords`. */
|
|
72
|
+
exportWords(): Promise<string[]>;
|
|
66
73
|
}
|
package/src/LocalLinter.ts
CHANGED
|
@@ -124,4 +124,16 @@ export default class LocalLinter implements Linter {
|
|
|
124
124
|
|
|
125
125
|
return this.inner!.clear_ignored_lints();
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
async importWords(words: string[]): Promise<void> {
|
|
129
|
+
await this.initialize();
|
|
130
|
+
|
|
131
|
+
return this.inner!.import_words(words);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async exportWords(): Promise<string[]> {
|
|
135
|
+
await this.initialize();
|
|
136
|
+
|
|
137
|
+
return this.inner!.export_words();
|
|
138
|
+
}
|
|
127
139
|
}
|
|
@@ -129,6 +129,14 @@ export default class WorkerLinter implements Linter {
|
|
|
129
129
|
return this.rpc('clearIgnoredLints', []);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
async importWords(words: string[]): Promise<void> {
|
|
133
|
+
return this.rpc('importWords', [words]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async exportWords(): Promise<string[]> {
|
|
137
|
+
return this.rpc('exportWords', []);
|
|
138
|
+
}
|
|
139
|
+
|
|
132
140
|
/** Run a procedure on the remote worker. */
|
|
133
141
|
private async rpc(procName: string, args: any[]): Promise<any> {
|
|
134
142
|
const promise = new Promise((resolve, reject) => {
|