Skip to content

Commit

Permalink
fix(harper.js): config now persists across calls
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Dec 19, 2024
1 parent 97f1d3b commit d49cbe8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ main.js
pnpm-lock.yaml
package-lock.json
yarn.lock
dist
17 changes: 17 additions & 0 deletions packages/harper.js/src/Linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ for (const [linterName, Linter] of Object.entries(linters)) {
const lintConfig = await linter.getLintConfig();
expect(lintConfig).toHaveProperty('repeated_words');
});

test(`${linterName} can both get and set its configuration`, async () => {
const linter = new Linter();

let lintConfig = await linter.getLintConfig();

for (const key of Object.keys(lintConfig)) {
lintConfig[key] = true;
}

await linter.setLintConfig(lintConfig);
lintConfig = await linter.getLintConfig();

for (const key of Object.keys(lintConfig)) {
expect(lintConfig[key]).toBe(true);
}
});
}

test('Linters have the same config format', async () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/harper.js/src/LocalLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export default class LocalLinter implements Linter {

/** Initialize the WebAssembly and construct the inner Linter. */
private async initialize(): Promise<void> {
const wasm = await loadWasm();
wasm.setup();
this.inner = wasm.Linter.new();
if (!this.inner) {
const wasm = await loadWasm();
wasm.setup();
this.inner = wasm.Linter.new();
}
}

async setup(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/harper.js/src/loadWasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function setWasmUri(uri: string) {
export default async function loadWasm() {
const wasm = await import('wasm');
// @ts-ignore
await wasm.default(getWasmUri());
await wasm.default({ module_or_path: getWasmUri() });

return wasm;
}

0 comments on commit d49cbe8

Please sign in to comment.