Skip to content

Commit 7af38e1

Browse files
committed
refactor(napi/oxlint): simplify ExternalLinterLintFileCb type (#12572)
The function returned by `wrap_lint_file` only returns `String`s as errors, so no need to downcast return value to dynamic `Box<dyn std::error::Error + Send + Sync>` - just `String` is fine.
1 parent 2b29463 commit 7af38e1

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

crates/oxc_linter/src/external_linter.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,8 @@ pub type ExternalLinterLoadPluginCb = Arc<
1818
+ 'static,
1919
>;
2020

21-
pub type ExternalLinterLintFileCb = Arc<
22-
dyn Fn(
23-
String,
24-
Vec<u32>,
25-
&Allocator,
26-
) -> Result<Vec<LintFileResult>, Box<dyn std::error::Error + Send + Sync>>
27-
+ Sync
28-
+ Send,
29-
>;
21+
pub type ExternalLinterLintFileCb =
22+
Arc<dyn Fn(String, Vec<u32>, &Allocator) -> Result<Vec<LintFileResult>, String> + Sync + Send>;
3023

3124
#[derive(Clone, Debug, Deserialize, Serialize)]
3225
pub enum PluginLoadResult {

napi/oxlint2/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ fn wrap_lint_file(cb: JsLintFileCb) -> ExternalLinterLintFileCb {
158158
);
159159

160160
if status != Status::Ok {
161-
return Err(format!("Failed to schedule callback: {status:?}").into());
161+
return Err(format!("Failed to schedule callback: {status:?}"));
162162
}
163163

164164
match rx.recv() {
165165
Ok(Ok(x)) => Ok(x),
166-
Ok(Err(e)) => Err(format!("Callback reported error: {e}").into()),
167-
Err(e) => Err(format!("Callback did not respond: {e}").into()),
166+
Ok(Err(e)) => Err(format!("Callback reported error: {e}")),
167+
Err(e) => Err(format!("Callback did not respond: {e}")),
168168
}
169169
})
170170
}

0 commit comments

Comments
 (0)