Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions napi/oxlint2/src-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,7 @@ const diagnostics: DiagnosticReport[] = [];
const textDecoder = new TextDecoder('utf-8', { ignoreBOM: true });

// Run rules on a file.
//
// TODO(camc314): why do we have to destructure here?
// In `./bindings.d.ts`, it doesn't indicate that we have to
// (typed as `(filePath: string, bufferId: number, buffer: Uint8Array | undefined | null, ruleIds: number[])`).
function lintFile([filePath, bufferId, buffer, ruleIds]: [
string,
number,
Uint8Array | undefined | null,
number[],
]) {
function lintFile(filePath: string, bufferId: number, buffer: Uint8Array | undefined | null, ruleIds: number[]) {
// If new buffer, add it to `buffers` array. Otherwise, get existing buffer from array.
// Do this before checks below, to make sure buffer doesn't get garbage collected when not expected
// if there's an error.
Expand Down Expand Up @@ -274,8 +265,6 @@ function lintFile([filePath, bufferId, buffer, ruleIds]: [
// --------------------

// Call Rust, passing `loadPlugin` and `lintFile` as callbacks
// TODO(camc314): why is there a `@ts-expect-error` here?
// @ts-expect-error
const success = await lint(loadPlugin, lintFile);

// Note: It's recommended to set `process.exitCode` instead of calling `process.exit()`.
Expand Down
31 changes: 23 additions & 8 deletions napi/oxlint2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use napi::{
Status,
bindgen_prelude::{Promise, Uint8Array},
bindgen_prelude::{FnArgs, Promise, Uint8Array},
threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode},
};
use napi_derive::napi;
Expand All @@ -23,19 +23,34 @@ use generated::raw_transfer_constants::{BLOCK_ALIGN, BUFFER_SIZE};

#[napi]
pub type JsLintFileCb = ThreadsafeFunction<
(String, u32, Option<Uint8Array>, Vec<u32>),
String, /* Vec<LintFileResult> */
(String, u32, Option<Uint8Array>, Vec<u32>),
// Arguments
FnArgs<(
String, // Absolute path of file to lint
u32, // Buffer ID
Option<Uint8Array>, // Buffer (optional)
Vec<u32>, // Array of rule IDs
)>,
// Return value
String, // `Vec<LintFileResult>`, serialized to JSON
// Arguments (repeated)
FnArgs<(String, u32, Option<Uint8Array>, Vec<u32>)>,
// Error status
Status,
// CalleeHandled
false,
>;

#[napi]
pub type JsLoadPluginCb = ThreadsafeFunction<
String, /* PluginName */
Promise<String /* PluginLoadResult */>,
String, /* PluginName */
// Arguments
String, // Absolute path of plugin file
// Return value
Promise<String>, // `PluginLoadResult`, serialized to JSON
// Arguments (repeated)
String,
// Error status
Status,
// CalleeHandled
false,
>;

Expand Down Expand Up @@ -113,7 +128,7 @@ fn wrap_lint_file(cb: JsLintFileCb) -> ExternalLinterLintFileCb {

// Send data to JS
let status = cb.call_with_return_value(
(file_path, buffer_id, buffer, rule_ids),
FnArgs::from((file_path, buffer_id, buffer, rule_ids)),
ThreadsafeFunctionCallMode::NonBlocking,
move |result, _env| {
let _ = match &result {
Expand Down
Loading