Skip to content

Commit 2b29463

Browse files
committed
refactor(napi/oxlint): re-order code (#12571)
Pure refactor - does not change any code, just moves it around. Reverse the order of Rust code relating to `loadPlugin` and `lintFile`, for consistency with JS-side code, which has `loadPlugin` first.
1 parent 370b382 commit 2b29463

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

napi/oxlint2/src/lib.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,52 @@ mod generated {
2222
use generated::raw_transfer_constants::{BLOCK_ALIGN, BUFFER_SIZE};
2323

2424
#[napi]
25-
pub type JsLintFileCb = ThreadsafeFunction<
25+
pub type JsLoadPluginCb = ThreadsafeFunction<
2626
// Arguments
27-
FnArgs<(
28-
String, // Absolute path of file to lint
29-
u32, // Buffer ID
30-
Option<Uint8Array>, // Buffer (optional)
31-
Vec<u32>, // Array of rule IDs
32-
)>,
27+
String, // Absolute path of plugin file
3328
// Return value
34-
String, // `Vec<LintFileResult>`, serialized to JSON
29+
Promise<String>, // `PluginLoadResult`, serialized to JSON
3530
// Arguments (repeated)
36-
FnArgs<(String, u32, Option<Uint8Array>, Vec<u32>)>,
31+
String,
3732
// Error status
3833
Status,
3934
// CalleeHandled
4035
false,
4136
>;
4237

4338
#[napi]
44-
pub type JsLoadPluginCb = ThreadsafeFunction<
39+
pub type JsLintFileCb = ThreadsafeFunction<
4540
// Arguments
46-
String, // Absolute path of plugin file
41+
FnArgs<(
42+
String, // Absolute path of file to lint
43+
u32, // Buffer ID
44+
Option<Uint8Array>, // Buffer (optional)
45+
Vec<u32>, // Array of rule IDs
46+
)>,
4747
// Return value
48-
Promise<String>, // `PluginLoadResult`, serialized to JSON
48+
String, // `Vec<LintFileResult>`, serialized to JSON
4949
// Arguments (repeated)
50-
String,
50+
FnArgs<(String, u32, Option<Uint8Array>, Vec<u32>)>,
5151
// Error status
5252
Status,
5353
// CalleeHandled
5454
false,
5555
>;
5656

57+
fn wrap_load_plugin(cb: JsLoadPluginCb) -> ExternalLinterLoadPluginCb {
58+
let cb = Arc::new(cb);
59+
Arc::new(move |plugin_name| {
60+
Box::pin({
61+
let cb = Arc::clone(&cb);
62+
async move {
63+
let result = cb.call_async(plugin_name).await?.into_future().await?;
64+
let plugin_load_result: PluginLoadResult = serde_json::from_str(&result)?;
65+
Ok(plugin_load_result)
66+
}
67+
})
68+
})
69+
}
70+
5771
fn wrap_lint_file(cb: JsLintFileCb) -> ExternalLinterLintFileCb {
5872
let cb = Arc::new(cb);
5973
Arc::new(move |file_path: String, rule_ids: Vec<u32>, allocator: &Allocator| {
@@ -155,20 +169,6 @@ fn wrap_lint_file(cb: JsLintFileCb) -> ExternalLinterLintFileCb {
155169
})
156170
}
157171

158-
fn wrap_load_plugin(cb: JsLoadPluginCb) -> ExternalLinterLoadPluginCb {
159-
let cb = Arc::new(cb);
160-
Arc::new(move |plugin_name| {
161-
Box::pin({
162-
let cb = Arc::clone(&cb);
163-
async move {
164-
let result = cb.call_async(plugin_name).await?.into_future().await?;
165-
let plugin_load_result: PluginLoadResult = serde_json::from_str(&result)?;
166-
Ok(plugin_load_result)
167-
}
168-
})
169-
})
170-
}
171-
172172
#[expect(clippy::allow_attributes)]
173173
#[allow(clippy::trailing_empty_array, clippy::unused_async)] // https://github.com/napi-rs/napi-rs/issues/2758
174174
#[napi]

0 commit comments

Comments
 (0)