Skip to content

Commit e3fbf14

Browse files
committed
refactor(napi/parser): move clippy attrs onto NAPI functions (#16236)
Pure refactor. Remove blanket disable of `clippy::needless_pass_by_value` lint rule, and disable it on individual NAPI functions instead. This reveals one other function which was taking a `String` when it could take a `&str`.
1 parent 380a0af commit e3fbf14

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

napi/parser/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Napi value need to be passed as value
2-
#![expect(clippy::needless_pass_by_value)]
3-
41
#[cfg(all(
52
feature = "allocator",
63
not(any(target_arch = "arm", target_os = "freebsd", target_family = "wasm"))
@@ -87,13 +84,13 @@ fn parse_impl<'a>(
8784
.parse()
8885
}
8986

90-
fn parse_with_return(filename: &str, source_text: String, options: &ParserOptions) -> ParseResult {
87+
fn parse_with_return(filename: &str, source_text: &str, options: &ParserOptions) -> ParseResult {
9188
let allocator = Allocator::default();
9289
let source_type =
9390
get_source_type(filename, options.lang.as_deref(), options.source_type.as_deref());
9491
let ast_type = get_ast_type(source_type, options);
9592
let ranges = options.range.unwrap_or(false);
96-
let ret = parse_impl(&allocator, source_type, &source_text, options);
93+
let ret = parse_impl(&allocator, source_type, source_text, options);
9794

9895
let mut program = ret.program;
9996
let mut module_record = ret.module_record;
@@ -104,10 +101,10 @@ fn parse_with_return(filename: &str, source_text: String, options: &ParserOption
104101
diagnostics.extend(semantic_ret.errors);
105102
}
106103

107-
let mut errors = OxcError::from_diagnostics(filename, &source_text, diagnostics);
104+
let mut errors = OxcError::from_diagnostics(filename, source_text, diagnostics);
108105

109106
let mut comments =
110-
convert_utf8_to_utf16(&source_text, &mut program, &mut module_record, &mut errors);
107+
convert_utf8_to_utf16(source_text, &mut program, &mut module_record, &mut errors);
111108

112109
let program_and_fixes = match ast_type {
113110
AstType::JavaScript => {
@@ -142,13 +139,14 @@ fn parse_with_return(filename: &str, source_text: String, options: &ParserOption
142139

143140
/// Parse synchronously.
144141
#[napi]
142+
#[allow(clippy::needless_pass_by_value, clippy::allow_attributes)]
145143
pub fn parse_sync(
146144
filename: String,
147145
source_text: String,
148146
options: Option<ParserOptions>,
149147
) -> ParseResult {
150148
let options = options.unwrap_or_default();
151-
parse_with_return(&filename, source_text, &options)
149+
parse_with_return(&filename, &source_text, &options)
152150
}
153151

154152
pub struct ResolveTask {
@@ -164,7 +162,7 @@ impl Task for ResolveTask {
164162

165163
fn compute(&mut self) -> napi::Result<Self::Output> {
166164
let source_text = mem::take(&mut self.source_text);
167-
Ok(parse_with_return(&self.filename, source_text, &self.options))
165+
Ok(parse_with_return(&self.filename, &source_text, &self.options))
168166
}
169167

170168
fn resolve(&mut self, _: napi::Env, result: Self::Output) -> napi::Result<Self::JsValue> {

napi/parser/src/raw_transfer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const BUMP_ALIGN: usize = 16;
4444
/// Does not check that the offset is within bounds of `buffer`.
4545
/// To ensure it always is, provide a `Uint8Array` of at least `BUFFER_SIZE + BUFFER_ALIGN` bytes.
4646
#[napi(skip_typescript)]
47+
#[allow(clippy::needless_pass_by_value, clippy::allow_attributes)]
4748
pub fn get_buffer_offset(buffer: Uint8Array) -> u32 {
4849
let buffer = &*buffer;
4950
let offset = (BUFFER_ALIGN - (buffer.as_ptr() as usize % BUFFER_ALIGN)) % BUFFER_ALIGN;
@@ -76,6 +77,7 @@ pub fn get_buffer_offset(buffer: Uint8Array) -> u32 {
7677
///
7778
/// Panics if source text is too long, or AST takes more memory than is available in the buffer.
7879
#[napi(skip_typescript)]
80+
#[allow(clippy::needless_pass_by_value, clippy::allow_attributes)]
7981
pub unsafe fn parse_raw_sync(
8082
filename: String,
8183
mut buffer: Uint8Array,

0 commit comments

Comments
 (0)