|
1 | 1 | import { lint } from "./bindings.js"; |
2 | | -import { debugAssertIsNonNull } from "./utils/asserts.ts"; |
| 2 | +import { debugAssertIsNonNull, debugAssertIsNotUndefined } from "./utils/asserts.ts"; |
3 | 3 |
|
4 | 4 | // Lazy-loaded JS plugin-related functions. |
5 | 5 | // The type annotations below use `typeof import("./plugins/index.ts").<fn>` so that the lazy-loaded variables |
@@ -29,15 +29,20 @@ function loadPluginWrapper( |
29 | 29 | pluginNameIsAlias: boolean, |
30 | 30 | workspaceUri: string | null | undefined, |
31 | 31 | ): Promise<string> { |
| 32 | + // Type generated by NAPI-RS for `lint` is inaccurate. |
| 33 | + // `Option::None` on Rust side becomes `null` on JS side, not `undefined`. |
| 34 | + debugAssertIsNotUndefined(pluginName, "`pluginName` should not be `undefined`"); |
| 35 | + debugAssertIsNotUndefined(workspaceUri, "`workspaceUri` should not be `undefined`"); |
| 36 | + |
32 | 37 | if (loadPlugin === null) { |
33 | 38 | // Use promises here instead of making `loadPluginWrapper` an async function, |
34 | 39 | // to avoid a micro-tick and extra wrapper `Promise` in all later calls to `loadPluginWrapper` |
35 | 40 | return import("./plugins/index.ts").then((mod) => { |
36 | 41 | ({ loadPlugin, lintFile, setupRuleConfigs } = mod); |
37 | | - return loadPlugin(path, pluginName ?? null, pluginNameIsAlias, workspaceUri ?? null); |
| 42 | + return loadPlugin(path, pluginName, pluginNameIsAlias, workspaceUri); |
38 | 43 | }); |
39 | 44 | } |
40 | | - return loadPlugin(path, pluginName ?? null, pluginNameIsAlias, workspaceUri ?? null); |
| 45 | + return loadPlugin(path, pluginName, pluginNameIsAlias, workspaceUri); |
41 | 46 | } |
42 | 47 |
|
43 | 48 | /** |
@@ -78,18 +83,23 @@ function lintFileWrapper( |
78 | 83 | globalsJSON: string, |
79 | 84 | workspaceUri: string | null | undefined, |
80 | 85 | ): string | null { |
| 86 | + // Type generated by NAPI-RS for `lint` is inaccurate. |
| 87 | + // `Option::None` on Rust side becomes `null` on JS side, not `undefined`. |
| 88 | + debugAssertIsNotUndefined(buffer, "`buffer` should not be `undefined`"); |
| 89 | + debugAssertIsNotUndefined(workspaceUri, "`workspaceUri` should not be `undefined`"); |
| 90 | + |
81 | 91 | // `lintFileWrapper` is never called without `loadPluginWrapper` being called first, |
82 | 92 | // so `lintFile` must be defined here |
83 | 93 | debugAssertIsNonNull(lintFile); |
84 | 94 | return lintFile( |
85 | 95 | filePath, |
86 | 96 | bufferId, |
87 | | - buffer ?? null, |
| 97 | + buffer, |
88 | 98 | ruleIds, |
89 | 99 | optionsIds, |
90 | 100 | settingsJSON, |
91 | 101 | globalsJSON, |
92 | | - workspaceUri ?? null, |
| 102 | + workspaceUri, |
93 | 103 | ); |
94 | 104 | } |
95 | 105 |
|
|
0 commit comments