From c3cfbfb480f60c3343969c3f32a836b10dd76a07 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 6 Sep 2024 03:07:01 +0000 Subject: [PATCH 01/28] chore: `clippy::allow_attributes` (#5521) https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html#expectlint https://rust-lang.github.io/rust-clippy/master/index.html#/allow_attributes --- Cargo.toml | 11 ++++++----- tasks/ast_tools/src/codegen.rs | 4 ++-- tasks/ast_tools/src/derives/get_span.rs | 2 +- tasks/ast_tools/src/fmt.rs | 4 ++-- tasks/ast_tools/src/generators/ast_builder.rs | 5 ++--- tasks/ast_tools/src/generators/mod.rs | 6 +++--- tasks/ast_tools/src/generators/visit.rs | 2 +- tasks/ast_tools/src/layout.rs | 2 +- tasks/ast_tools/src/markers.rs | 4 ++-- tasks/ast_tools/src/passes/calc_layout.rs | 2 +- tasks/ast_tools/src/passes/linker.rs | 2 +- tasks/ast_tools/src/rust_ast.rs | 3 +-- tasks/ast_tools/src/util.rs | 2 -- tasks/benchmark/benches/sourcemap.rs | 2 +- tasks/benchmark/src/lib.rs | 2 +- tasks/coverage/src/driver.rs | 5 ++--- tasks/coverage/src/lib.rs | 2 +- tasks/coverage/src/suite.rs | 4 ++-- tasks/coverage/src/typescript/meta.rs | 2 +- tasks/prettier_conformance/src/lib.rs | 2 +- 20 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8c6780f8f89f82..0ceb7b95ad3e3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,11 +25,12 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(cov all = { level = "warn", priority = -1 } empty_docs = { level = "allow", priority = 1 } # From `Tsify` # restriction -dbg_macro = "warn" -todo = "warn" -unimplemented = "warn" -print_stdout = "warn" # Must be opt-in -print_stderr = "warn" # Must be opt-in +dbg_macro = "warn" +todo = "warn" +unimplemented = "warn" +print_stdout = "warn" # Must be opt-in +print_stderr = "warn" # Must be opt-in +allow_attributes = "warn" # I like the explicitness of this rule as it removes confusion around `clone`. # This increases readability, avoids `clone` mindlessly and heap allocating by accident. clone_on_ref_ptr = "warn" diff --git a/tasks/ast_tools/src/codegen.rs b/tasks/ast_tools/src/codegen.rs index 4722b444855c9a..78da48f8af4e19 100644 --- a/tasks/ast_tools/src/codegen.rs +++ b/tasks/ast_tools/src/codegen.rs @@ -39,7 +39,7 @@ impl SideEffect { Ok(()) } - #[allow(clippy::unnecessary_wraps)] + #[expect(clippy::unnecessary_wraps)] pub fn path(&self) -> Option { let Self(path, _) = self; let path = path.to_string_lossy(); @@ -63,7 +63,7 @@ impl From for SideEffect { pub trait Runner { type Context; type Output; - #[allow(dead_code)] + #[expect(dead_code)] fn name(&self) -> &'static str; fn run(&mut self, ctx: &Self::Context) -> Result; } diff --git a/tasks/ast_tools/src/derives/get_span.rs b/tasks/ast_tools/src/derives/get_span.rs index 4d44c969acdd7b..38a73ecc77a1cb 100644 --- a/tasks/ast_tools/src/derives/get_span.rs +++ b/tasks/ast_tools/src/derives/get_span.rs @@ -86,7 +86,7 @@ impl Derive for DeriveGetSpanMut { } } -#[allow(clippy::too_many_arguments)] +#[expect(clippy::too_many_arguments)] fn derive( trait_name: &str, method_name: &str, diff --git a/tasks/ast_tools/src/fmt.rs b/tasks/ast_tools/src/fmt.rs index 5e62cf049c554b..df45187dba3305 100644 --- a/tasks/ast_tools/src/fmt.rs +++ b/tasks/ast_tools/src/fmt.rs @@ -69,7 +69,7 @@ lazy_static! { /// /// We use this when inserting outer attributes (`#![allow(unused)]`) or plain comments (`//` not `///`). /// `quote!` macro ignores plain comments, so it's not possible to produce them otherwise. -#[allow(dead_code)] // `insert!` macro is not currently used +#[expect(dead_code)] // `insert!` macro is not currently used struct InsertReplacer; impl Replacer for InsertReplacer { @@ -109,7 +109,7 @@ lazy_static! { /// /// We use `endl!();` because `quote!` macro ignores whitespace, /// so we have to use another means to generate line breaks. -#[allow(dead_code)] // `endl!` macro is not currently used +#[expect(dead_code)] // `endl!` macro is not currently used struct EndlReplacer; impl Replacer for EndlReplacer { diff --git a/tasks/ast_tools/src/generators/ast_builder.rs b/tasks/ast_tools/src/generators/ast_builder.rs index 28366b1ec780ce..55d50b6613f26d 100644 --- a/tasks/ast_tools/src/generators/ast_builder.rs +++ b/tasks/ast_tools/src/generators/ast_builder.rs @@ -150,7 +150,6 @@ fn generate_enum_variant_builder_fn( .or_else(|| var_type.transparent_type_id()) .and_then(|id| ctx.type_def(id)) .expect("type not found!"); - #[allow(clippy::single_match_else)] let (params, inner_builder) = match ty { TypeDef::Struct(it) => (get_struct_params(it, ctx), struct_builder_name(it)), TypeDef::Enum(_) => panic!("Unsupported!"), @@ -306,7 +305,7 @@ fn generate_struct_builder_fn(ty: &StructDef, ctx: &LateCtx) -> TokenStream { } // TODO: remove me -#[allow(dead_code)] +#[expect(dead_code)] #[derive(Debug)] struct Param { is_default: bool, @@ -415,7 +414,7 @@ impl<'p> DocComment<'p> { /// /// Each line will be turned into its own paragraph. // TODO: remove me - #[allow(dead_code)] + #[expect(dead_code)] pub fn with_description_lines(mut self, description: L) -> Self where S: Into>, diff --git a/tasks/ast_tools/src/generators/mod.rs b/tasks/ast_tools/src/generators/mod.rs index d7a02c18390280..e16f356d06f412 100644 --- a/tasks/ast_tools/src/generators/mod.rs +++ b/tasks/ast_tools/src/generators/mod.rs @@ -15,7 +15,7 @@ pub use ast_kind::AstKindGenerator; pub use visit::{VisitGenerator, VisitMutGenerator}; /// Inserts a newline in the `TokenStream`. -#[allow(unused)] +#[expect(unused)] macro_rules! endl { () => { /* only works in the context of `quote` macro family! */ @@ -51,12 +51,12 @@ pub(crate) use define_generator; /// Similar to how `insert` macro works in the context of `quote` macro family, But this one can be /// used outside and accepts expressions. /// Wraps the result of the given expression in `insert!({value here});` and outputs it as `TokenStream`. -#[allow(unused)] +#[expect(unused)] macro_rules! insert { ($fmt:literal $(, $args:expr)*) => {{ let txt = format!($fmt, $($args)*); format!(r#"insert!("{}");"#, txt).parse::().unwrap() }}; } -#[allow(unused_imports)] +#[expect(unused_imports)] pub(crate) use insert; diff --git a/tasks/ast_tools/src/generators/visit.rs b/tasks/ast_tools/src/generators/visit.rs index f57070bb41564e..8c217071cfdd2f 100644 --- a/tasks/ast_tools/src/generators/visit.rs +++ b/tasks/ast_tools/src/generators/visit.rs @@ -534,7 +534,7 @@ impl<'a> VisitBuilder<'a> { enter_scope_at = ix; } - #[allow(unreachable_code)] + #[expect(unreachable_code)] if have_enter_node { // NOTE: this is disabled intentionally unreachable!("`#[visit(enter_before)]` attribute is disabled!"); diff --git a/tasks/ast_tools/src/layout.rs b/tasks/ast_tools/src/layout.rs index 8c2eb95f06fa84..d8d58100beecd2 100644 --- a/tasks/ast_tools/src/layout.rs +++ b/tasks/ast_tools/src/layout.rs @@ -55,7 +55,7 @@ impl KnownLayout { self.niches } - #[allow(unused)] + #[expect(unused)] #[inline] pub fn offsets(&self) -> Option<&Vec> { self.offsets.as_ref() diff --git a/tasks/ast_tools/src/markers.rs b/tasks/ast_tools/src/markers.rs index 5252df1ff63a22..6521d5538f13ad 100644 --- a/tasks/ast_tools/src/markers.rs +++ b/tasks/ast_tools/src/markers.rs @@ -137,7 +137,7 @@ pub fn get_visit_markers<'a, I>(attrs: I) -> crate::Result where I: IntoIterator, { - #[allow(clippy::trivially_copy_pass_by_ref)] + #[expect(clippy::trivially_copy_pass_by_ref)] fn predicate(it: &&Attribute) -> bool { it.path().is_ident("visit") } @@ -186,7 +186,7 @@ pub fn get_scope_markers<'a, I>(attrs: I) -> crate::Result where I: IntoIterator, { - #[allow(clippy::trivially_copy_pass_by_ref)] + #[expect(clippy::trivially_copy_pass_by_ref)] fn predicate(it: &&Attribute) -> bool { it.path().is_ident("scope") } diff --git a/tasks/ast_tools/src/passes/calc_layout.rs b/tasks/ast_tools/src/passes/calc_layout.rs index 777e2d776d5f33..705c66e34b65f3 100644 --- a/tasks/ast_tools/src/passes/calc_layout.rs +++ b/tasks/ast_tools/src/passes/calc_layout.rs @@ -104,7 +104,7 @@ fn calc_enum_layout(ty: &mut Enum, ctx: &EarlyCtx) -> Result { } } - #[allow(clippy::needless_pass_by_value)] + #[expect(clippy::needless_pass_by_value)] fn fold_layout(mut acc: KnownLayout, layout: KnownLayout) -> KnownLayout { // SAFETY: we are folding valid layouts so it is safe. unsafe { diff --git a/tasks/ast_tools/src/passes/linker.rs b/tasks/ast_tools/src/passes/linker.rs index d26bbbc40e82ea..74f27eec8a227d 100644 --- a/tasks/ast_tools/src/passes/linker.rs +++ b/tasks/ast_tools/src/passes/linker.rs @@ -10,7 +10,7 @@ pub trait Unresolved { fn unresolved(&self) -> bool; // TODO: remove me - #[allow(dead_code)] + #[expect(dead_code)] fn resolved(&self) -> bool { !self.unresolved() } diff --git a/tasks/ast_tools/src/rust_ast.rs b/tasks/ast_tools/src/rust_ast.rs index 64200dc674fd43..775949a1612068 100644 --- a/tasks/ast_tools/src/rust_ast.rs +++ b/tasks/ast_tools/src/rust_ast.rs @@ -191,7 +191,7 @@ impl AstType { } } - #[allow(unused)] + #[expect(unused)] pub fn visitable(&self) -> bool { match self { AstType::Enum(it) => it.meta.visitable, @@ -450,7 +450,6 @@ pub fn analyze(ast_ref: &AstRef) -> Result<()> { AstType::Macro(_) => None, }; - #[allow(clippy::match_same_arms)] match ast_attr { Some(AstAttr::Visit) => { ast_ref.borrow_mut().set_ast(true)?; diff --git a/tasks/ast_tools/src/util.rs b/tasks/ast_tools/src/util.rs index 52e48353e9fc8b..5be691c342c458 100644 --- a/tasks/ast_tools/src/util.rs +++ b/tasks/ast_tools/src/util.rs @@ -116,8 +116,6 @@ impl<'a> TypeIdentResult<'a> { } } -// TODO: remove me -#[allow(dead_code)] #[derive(Debug, PartialEq, Clone, Serialize)] pub enum TypeWrapper { None, diff --git a/tasks/benchmark/benches/sourcemap.rs b/tasks/benchmark/benches/sourcemap.rs index 839c3cbcdaab0d..691f69f034d044 100644 --- a/tasks/benchmark/benches/sourcemap.rs +++ b/tasks/benchmark/benches/sourcemap.rs @@ -6,7 +6,7 @@ use oxc_sourcemap::ConcatSourceMapBuilder; use oxc_span::SourceType; use oxc_tasks_common::TestFiles; -#[allow(clippy::cast_possible_truncation)] +#[expect(clippy::cast_possible_truncation)] fn bench_sourcemap(criterion: &mut Criterion) { let mut group = criterion.benchmark_group("sourcemap"); diff --git a/tasks/benchmark/src/lib.rs b/tasks/benchmark/src/lib.rs index d11106d64cc32a..ac1dc144928719 100644 --- a/tasks/benchmark/src/lib.rs +++ b/tasks/benchmark/src/lib.rs @@ -27,7 +27,7 @@ static GLOBAL: NeverGrowInPlaceAllocator = NeverGrowInPlaceAllocator; pub struct NeverGrowInPlaceAllocator; // SAFETY: Methods simply delegate to `System` allocator -#[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] +#[expect(unsafe_code, clippy::undocumented_unsafe_blocks)] unsafe impl GlobalAlloc for NeverGrowInPlaceAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { System.alloc(layout) diff --git a/tasks/coverage/src/driver.rs b/tasks/coverage/src/driver.rs index 59f8ec93fa3efd..3e0c6e6de069e8 100644 --- a/tasks/coverage/src/driver.rs +++ b/tasks/coverage/src/driver.rs @@ -2,8 +2,7 @@ use std::{collections::HashSet, ops::ControlFlow, path::PathBuf}; use oxc::CompilerInterface; -#[allow(clippy::wildcard_imports)] -use oxc::ast::{ast::*, Trivias}; +use oxc::ast::{ast::Program, Trivias}; use oxc::codegen::CodegenOptions; use oxc::diagnostics::OxcDiagnostic; use oxc::minifier::CompressOptions; @@ -17,7 +16,7 @@ use oxc::transformer::{TransformOptions, TransformerReturn}; use crate::suite::TestResult; -#[allow(clippy::struct_excessive_bools)] +#[expect(clippy::struct_excessive_bools)] #[derive(Default)] pub struct Driver { pub path: PathBuf, diff --git a/tasks/coverage/src/lib.rs b/tasks/coverage/src/lib.rs index b8f7afea7d3bd8..35ecdda830dd2d 100644 --- a/tasks/coverage/src/lib.rs +++ b/tasks/coverage/src/lib.rs @@ -132,7 +132,7 @@ impl AppArgs { // Generate v8 test262 status file, which is used to skip failed tests // see https://chromium.googlesource.com/v8/v8/+/refs/heads/main/test/test262/test262.status - #[allow(clippy::missing_panics_doc)] + #[expect(clippy::missing_panics_doc)] pub fn run_sync_v8_test262_status(&self) { let res = agent() .get("http://raw.githubusercontent.com/v8/v8/main/test/test262/test262.status") diff --git a/tasks/coverage/src/suite.rs b/tasks/coverage/src/suite.rs index cc6c7a1c718d6f..8c7751dff1d0c4 100644 --- a/tasks/coverage/src/suite.rs +++ b/tasks/coverage/src/suite.rs @@ -191,7 +191,7 @@ pub trait Suite { } /// # Errors - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss)] fn print_coverage( &self, name: &str, @@ -310,7 +310,7 @@ pub trait Case: Sized + Sync + Send + UnwindSafe { fn run(&mut self); /// Async version of run - #[allow(clippy::unused_async)] + #[expect(clippy::unused_async)] async fn run_async(&mut self) {} /// Execute the parser once and get the test result diff --git a/tasks/coverage/src/typescript/meta.rs b/tasks/coverage/src/typescript/meta.rs index 735be18a7054d5..3d001c933d1eff 100644 --- a/tasks/coverage/src/typescript/meta.rs +++ b/tasks/coverage/src/typescript/meta.rs @@ -17,7 +17,7 @@ lazy_static::lazy_static! { static ref TEST_BRACES: Regex = Regex::new(r"^[[:space:]]*[{|}][[:space:]]*$").unwrap(); } -#[allow(unused)] +#[expect(unused)] #[derive(Debug)] pub struct CompilerSettings { pub modules: Vec, diff --git a/tasks/prettier_conformance/src/lib.rs b/tasks/prettier_conformance/src/lib.rs index c9706bedfb6bd8..c5fe9710eea666 100644 --- a/tasks/prettier_conformance/src/lib.rs +++ b/tasks/prettier_conformance/src/lib.rs @@ -82,7 +82,7 @@ impl TestRunner { } /// # Panics - #[allow(clippy::cast_precision_loss)] + #[expect(clippy::cast_precision_loss)] pub fn run(mut self) { let fixture_root = &self.fixtures_root; // Read the first level of directories that contain `__snapshots__` From 2a43fa4efdb35cb54b4de4ca2ab9a89c2fa49e53 Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Fri, 6 Sep 2024 11:19:48 +0800 Subject: [PATCH 02/28] style(linter): introduce the writing style from PR #5491 and reduce the if nesting (#5512) Related to #5491 --- crates/oxc_linter/src/ast_util.rs | 8 +- .../src/rules/eslint/default_case.rs | 41 +++--- .../src/rules/eslint/for_direction.rs | 128 +++++++++--------- .../rules/eslint/no_async_promise_executor.rs | 1 - .../oxc_linter/src/rules/eslint/no_console.rs | 31 +++-- .../eslint/no_template_curly_in_string.rs | 54 ++++---- .../src/rules/eslint/no_this_before_super.rs | 18 +-- .../rules/eslint/no_unused_vars/allowed.rs | 7 +- .../rules/eslint/prefer_numeric_literals.rs | 49 +++---- crates/oxc_linter/src/rules/eslint/radix.rs | 43 +++--- .../src/rules/eslint/require_await.rs | 66 ++++----- .../oxc_linter/src/rules/import/namespace.rs | 60 ++++---- .../src/rules/jsx_a11y/no_autofocus.rs | 35 ++--- .../src/rules/jsx_a11y/no_redundant_roles.rs | 41 +++--- .../jsx_a11y/role_supports_aria_props.rs | 51 +++---- .../rules/nextjs/no_unwanted_polyfillio.rs | 101 +++++++------- .../src/rules/oxc/bad_min_max_func.rs | 43 +++--- .../src/rules/oxc/bad_replace_all_arg.rs | 10 +- .../src/rules/oxc/number_arg_out_of_range.rs | 41 +++--- .../rules/react_perf/jsx_no_jsx_as_prop.rs | 4 +- .../typescript/consistent_type_imports.rs | 4 +- .../no_non_null_asserted_optional_chain.rs | 84 ++++++------ .../src/rules/unicorn/no_thenable.rs | 23 ++-- .../src/rules/unicorn/prefer_string_slice.rs | 20 ++- .../src/rules/vitest/no_conditional_tests.rs | 39 +++--- crates/oxc_linter/src/utils/express.rs | 4 +- .../oxc_semantic/tests/integration/scopes.rs | 7 +- .../tests/integration/util/class_tester.rs | 12 +- 28 files changed, 508 insertions(+), 517 deletions(-) diff --git a/crates/oxc_linter/src/ast_util.rs b/crates/oxc_linter/src/ast_util.rs index a501edc92862a2..726ff94656203f 100644 --- a/crates/oxc_linter/src/ast_util.rs +++ b/crates/oxc_linter/src/ast_util.rs @@ -430,11 +430,7 @@ pub fn get_function_like_declaration<'b>( ctx: &LintContext<'b>, ) -> Option<&'b BindingIdentifier<'b>> { let parent = outermost_paren_parent(node, ctx)?; + let decl = parent.kind().as_variable_declarator()?; - if let AstKind::VariableDeclarator(decl) = parent.kind() { - let ident = decl.id.get_binding_identifier()?; - Some(ident) - } else { - None - } + decl.id.get_binding_identifier() } diff --git a/crates/oxc_linter/src/rules/eslint/default_case.rs b/crates/oxc_linter/src/rules/eslint/default_case.rs index 7cd1034496a8a3..e3e329dcf19298 100644 --- a/crates/oxc_linter/src/rules/eslint/default_case.rs +++ b/crates/oxc_linter/src/rules/eslint/default_case.rs @@ -65,25 +65,30 @@ impl Rule for DefaultCase { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { if let AstKind::SwitchStatement(switch) = node.kind() { let cases = &switch.cases; - if !cases.is_empty() && !cases.iter().any(|case| case.test.is_none()) { - if let Some(last_case) = cases.last() { - let has_default_comment = ctx - .semantic() - .trivias() - .comments_range(last_case.span.start..switch.span.end) - .last() - .is_some_and(|comment| { - let raw = comment.span.source_text(ctx.semantic().source_text()).trim(); - match &self.comment_pattern { - Some(comment_pattern) => comment_pattern.is_match(raw), - None => raw.eq_ignore_ascii_case("no default"), - } - }); - - if !has_default_comment { - ctx.diagnostic(default_case_diagnostic(switch.span)); + + if cases.is_empty() || cases.iter().any(|case| case.test.is_none()) { + return; + } + + let Some(last_case) = cases.last() else { + return; + }; + + let has_default_comment = ctx + .semantic() + .trivias() + .comments_range(last_case.span.start..switch.span.end) + .last() + .is_some_and(|comment| { + let raw = comment.span.source_text(ctx.semantic().source_text()).trim(); + match &self.comment_pattern { + Some(comment_pattern) => comment_pattern.is_match(raw), + None => raw.eq_ignore_ascii_case("no default"), } - } + }); + + if !has_default_comment { + ctx.diagnostic(default_case_diagnostic(switch.span)); } } } diff --git a/crates/oxc_linter/src/rules/eslint/for_direction.rs b/crates/oxc_linter/src/rules/eslint/for_direction.rs index 648535d90e9f70..e1ff0b9ee337b6 100644 --- a/crates/oxc_linter/src/rules/eslint/for_direction.rs +++ b/crates/oxc_linter/src/rules/eslint/for_direction.rs @@ -83,68 +83,74 @@ declare_oxc_lint!( impl Rule for ForDirection { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::ForStatement(for_loop) = node.kind() { - if let Some(Expression::BinaryExpression(test)) = &for_loop.test { - let (counter, counter_position) = match (&test.left, &test.right) { - (Expression::Identifier(counter), _) => (counter, LEFT), - (_, Expression::Identifier(counter)) => (counter, RIGHT), - _ => return, - }; - let test_operator = &test.operator; - let wrong_direction = match (test_operator, counter_position) { - (BinaryOperator::LessEqualThan | BinaryOperator::LessThan, RIGHT) - | (BinaryOperator::GreaterEqualThan | BinaryOperator::GreaterThan, LEFT) => { - FORWARD - } - (BinaryOperator::LessEqualThan | BinaryOperator::LessThan, LEFT) - | (BinaryOperator::GreaterEqualThan | BinaryOperator::GreaterThan, RIGHT) => { - BACKWARD - } - _ => return, - }; - if let Some(update) = &for_loop.update { - let update_direction = get_update_direction(update, counter); - if update_direction == wrong_direction { - let update_span = get_update_span(update); - ctx.diagnostic_with_dangerous_fix( - for_direction_diagnostic(test.span, update_span), - |fixer| { - let mut start = 0; - let mut end = 0; - if let Expression::UpdateExpression(update) = update { - if update.span().start == update.argument.span().start { - start = update.argument.span().end; - end = update.span().end; - } else { - start = update.span().start; - end = update.argument.span().start; - } - } else if let Expression::AssignmentExpression(update) = update { - start = update.left.span().end; - end = update.right.span().start; - } - let span = Span::new(start, end); - let mut new_operator_str = ""; - if let Expression::UpdateExpression(update) = update { - if let UpdateOperator::Increment = update.operator { - new_operator_str = "--"; - } else if let UpdateOperator::Decrement = update.operator { - new_operator_str = "++"; - } - } else if let Expression::AssignmentExpression(update) = update { - if let AssignmentOperator::Addition = update.operator { - new_operator_str = "-="; - } else if let AssignmentOperator::Subtraction = update.operator - { - new_operator_str = "+="; - } - } - fixer.replace(span, new_operator_str) - }, - ); + let AstKind::ForStatement(for_loop) = node.kind() else { + return; + }; + + let Some(Expression::BinaryExpression(test)) = &for_loop.test else { + return; + }; + + let (counter, counter_position) = match (&test.left, &test.right) { + (Expression::Identifier(counter), _) => (counter, LEFT), + (_, Expression::Identifier(counter)) => (counter, RIGHT), + _ => return, + }; + + let test_operator = &test.operator; + let wrong_direction = match (test_operator, counter_position) { + (BinaryOperator::LessEqualThan | BinaryOperator::LessThan, RIGHT) + | (BinaryOperator::GreaterEqualThan | BinaryOperator::GreaterThan, LEFT) => FORWARD, + (BinaryOperator::LessEqualThan | BinaryOperator::LessThan, LEFT) + | (BinaryOperator::GreaterEqualThan | BinaryOperator::GreaterThan, RIGHT) => BACKWARD, + _ => return, + }; + + let Some(update) = &for_loop.update else { + return; + }; + + let update_direction = get_update_direction(update, counter); + if update_direction == wrong_direction { + ctx.diagnostic_with_dangerous_fix( + for_direction_diagnostic(test.span, get_update_span(update)), + |fixer| { + let mut span = Span::new(0, 0); + + let mut new_operator_str = ""; + + match update { + Expression::UpdateExpression(update) => { + if update.span().start == update.argument.span().start { + span.start = update.argument.span().end; + span.end = update.span().end; + } else { + span.start = update.span().start; + span.end = update.argument.span().start; + } + + if let UpdateOperator::Increment = update.operator { + new_operator_str = "--"; + } else if let UpdateOperator::Decrement = update.operator { + new_operator_str = "++"; + } + } + Expression::AssignmentExpression(update) => { + span.start = update.left.span().end; + span.end = update.right.span().start; + + if let AssignmentOperator::Addition = update.operator { + new_operator_str = "-="; + } else if let AssignmentOperator::Subtraction = update.operator { + new_operator_str = "+="; + } + } + _ => {} } - } - } + + fixer.replace(span, new_operator_str) + }, + ); } } } diff --git a/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs b/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs index 63d1b8523bb2bf..9e8c1af1b41c49 100644 --- a/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs +++ b/crates/oxc_linter/src/rules/eslint/no_async_promise_executor.rs @@ -60,7 +60,6 @@ impl Rule for NoAsyncPromiseExecutor { let mut span = match expression.get_inner_expression() { Expression::ArrowFunctionExpression(arrow) if arrow.r#async => arrow.span, Expression::FunctionExpression(func) if func.r#async => func.span, - _ => return, }; diff --git a/crates/oxc_linter/src/rules/eslint/no_console.rs b/crates/oxc_linter/src/rules/eslint/no_console.rs index c8a2ea595cc9dc..5bf03d311fa920 100644 --- a/crates/oxc_linter/src/rules/eslint/no_console.rs +++ b/crates/oxc_linter/src/rules/eslint/no_console.rs @@ -68,21 +68,22 @@ impl Rule for NoConsole { } fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::CallExpression(call_expr) = node.kind() { - if let Some(mem) = call_expr.callee.as_member_expression() { - if let Expression::Identifier(ident) = mem.object() { - if ctx.semantic().is_reference_to_global_variable(ident) - && ident.name == "console" - && !self - .allow - .iter() - .any(|s| mem.static_property_name().is_some_and(|f| f == s)) - { - if let Some(mem) = mem.static_property_info() { - ctx.diagnostic(no_console_diagnostic(mem.0)); - } - } - } + let AstKind::CallExpression(call_expr) = node.kind() else { + return; + }; + let Some(mem) = call_expr.callee.as_member_expression() else { + return; + }; + let Expression::Identifier(ident) = mem.object() else { + return; + }; + + if ctx.semantic().is_reference_to_global_variable(ident) + && ident.name == "console" + && !self.allow.iter().any(|s| mem.static_property_name().is_some_and(|f| f == s)) + { + if let Some(mem) = mem.static_property_info() { + ctx.diagnostic(no_console_diagnostic(mem.0)); } } } diff --git a/crates/oxc_linter/src/rules/eslint/no_template_curly_in_string.rs b/crates/oxc_linter/src/rules/eslint/no_template_curly_in_string.rs index 06b85678fc8fa7..fcc230ef16e851 100644 --- a/crates/oxc_linter/src/rules/eslint/no_template_curly_in_string.rs +++ b/crates/oxc_linter/src/rules/eslint/no_template_curly_in_string.rs @@ -34,36 +34,38 @@ declare_oxc_lint!( impl Rule for NoTemplateCurlyInString { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::StringLiteral(literal) = node.kind() { - let text = literal.value.as_str(); - if let Some(start_index) = text.find("${") { - let mut open_braces_count = 0; - let mut end_index = None; + let AstKind::StringLiteral(literal) = node.kind() else { + return; + }; - for (i, c) in text[start_index..].char_indices() { - let real_index = start_index + i; - if c == '{' { - open_braces_count += 1; - } else if c == '}' && open_braces_count > 0 { - open_braces_count -= 1; - if open_braces_count == 0 { - end_index = Some(real_index); - break; - } + let text = literal.value.as_str(); + if let Some(start_index) = text.find("${") { + let mut open_braces_count = 0; + let mut end_index = None; + + for (i, c) in text[start_index..].char_indices() { + let real_index = start_index + i; + if c == '{' { + open_braces_count += 1; + } else if c == '}' && open_braces_count > 0 { + open_braces_count -= 1; + if open_braces_count == 0 { + end_index = Some(real_index); + break; } } + } - if let Some(end_index) = end_index { - let literal_span_start = literal.span.start + 1; - let match_start = u32::try_from(start_index) - .expect("Conversion from usize to u32 failed for match_start"); - let match_end = u32::try_from(end_index + 1) - .expect("Conversion from usize to u32 failed for match_end"); - ctx.diagnostic(no_template_curly_in_string_diagnostic(Span::new( - literal_span_start + match_start, - literal_span_start + match_end, - ))); - } + if let Some(end_index) = end_index { + let literal_span_start = literal.span.start + 1; + let match_start = u32::try_from(start_index) + .expect("Conversion from usize to u32 failed for match_start"); + let match_end = u32::try_from(end_index + 1) + .expect("Conversion from usize to u32 failed for match_end"); + ctx.diagnostic(no_template_curly_in_string_diagnostic(Span::new( + literal_span_start + match_start, + literal_span_start + match_end, + ))); } } } diff --git a/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs index b77a80e5565e56..019328a864204b 100644 --- a/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs +++ b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs @@ -135,15 +135,15 @@ impl Rule for NoThisBeforeSuper { impl NoThisBeforeSuper { fn is_wanted_node(node: &AstNode, ctx: &LintContext<'_>) -> Option { let parent = ctx.nodes().parent_node(node.id())?; - if let AstKind::MethodDefinition(mdef) = parent.kind() { - if matches!(mdef.kind, MethodDefinitionKind::Constructor) { - let parent_2 = ctx.nodes().parent_node(parent.id())?; - let parent_3 = ctx.nodes().parent_node(parent_2.id())?; - if let AstKind::Class(c) = parent_3.kind() { - let super_class = c.super_class.as_ref()?; - return Some(!matches!(super_class, Expression::NullLiteral(_))); - } - } + let method_def = parent.kind().as_method_definition()?; + + if matches!(method_def.kind, MethodDefinitionKind::Constructor) { + let parent_2 = ctx.nodes().parent_node(parent.id())?; + let parent_3 = ctx.nodes().parent_node(parent_2.id())?; + + let class = parent_3.kind().as_class()?; + let super_class = class.super_class.as_ref()?; + return Some(!matches!(super_class, Expression::NullLiteral(_))); } Some(false) diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs index 6330ac5bbfaa68..1199491f022bcd 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs @@ -176,11 +176,8 @@ impl NoUnusedVars { // find FormalParameters. Should be the next parent of param, but this // is safer. let Some((params, params_id)) = symbol.iter_parents().find_map(|p| { - if let AstKind::FormalParameters(params) = p.kind() { - Some((params, p.id())) - } else { - None - } + let params = p.kind().as_formal_parameters()?; + Some((params, p.id())) }) else { debug_assert!(false, "FormalParameter should always have a parent FormalParameters"); return false; diff --git a/crates/oxc_linter/src/rules/eslint/prefer_numeric_literals.rs b/crates/oxc_linter/src/rules/eslint/prefer_numeric_literals.rs index 63072d2eb0522f..e7e2c8d694047f 100644 --- a/crates/oxc_linter/src/rules/eslint/prefer_numeric_literals.rs +++ b/crates/oxc_linter/src/rules/eslint/prefer_numeric_literals.rs @@ -58,41 +58,42 @@ declare_oxc_lint!( impl Rule for PreferNumericLiterals { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::CallExpression(call_expr) = node.kind() { - match &call_expr.callee.without_parentheses() { - Expression::Identifier(ident) if ident.name == "parseInt" => { - if is_parse_int_call(ctx, ident, None) { + let AstKind::CallExpression(call_expr) = node.kind() else { + return; + }; + + match &call_expr.callee.without_parentheses() { + Expression::Identifier(ident) if ident.name == "parseInt" => { + if is_parse_int_call(ctx, ident, None) { + check_arguments(call_expr, ctx); + } + } + Expression::StaticMemberExpression(member_expr) => { + if let Expression::Identifier(ident) = &member_expr.object { + if is_parse_int_call(ctx, ident, Some(member_expr)) { check_arguments(call_expr, ctx); } - } - Expression::StaticMemberExpression(member_expr) => { - if let Expression::Identifier(ident) = &member_expr.object { + } else if let Expression::ParenthesizedExpression(paren_expr) = &member_expr.object + { + if let Expression::Identifier(ident) = &paren_expr.expression { if is_parse_int_call(ctx, ident, Some(member_expr)) { check_arguments(call_expr, ctx); } - } else if let Expression::ParenthesizedExpression(paren_expr) = - &member_expr.object - { - if let Expression::Identifier(ident) = &paren_expr.expression { - if is_parse_int_call(ctx, ident, Some(member_expr)) { - check_arguments(call_expr, ctx); - } - } } } - Expression::ChainExpression(chain_expr) => { - if let Some(MemberExpression::StaticMemberExpression(member_expr)) = - chain_expr.expression.as_member_expression() - { - if let Expression::Identifier(ident) = &member_expr.object { - if is_parse_int_call(ctx, ident, Some(member_expr)) { - check_arguments(call_expr, ctx); - } + } + Expression::ChainExpression(chain_expr) => { + if let Some(MemberExpression::StaticMemberExpression(member_expr)) = + chain_expr.expression.as_member_expression() + { + if let Expression::Identifier(ident) = &member_expr.object { + if is_parse_int_call(ctx, ident, Some(member_expr)) { + check_arguments(call_expr, ctx); } } } - _ => {} } + _ => {} } } } diff --git a/crates/oxc_linter/src/rules/eslint/radix.rs b/crates/oxc_linter/src/rules/eslint/radix.rs index 0acf696ca3b3a8..07fb0f6c1387be 100644 --- a/crates/oxc_linter/src/rules/eslint/radix.rs +++ b/crates/oxc_linter/src/rules/eslint/radix.rs @@ -66,40 +66,41 @@ impl Rule for Radix { } fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::CallExpression(call_expr) = node.kind() { - match call_expr.callee.without_parentheses() { - Expression::Identifier(ident) => { - if ident.name == "parseInt" + let AstKind::CallExpression(call_expr) = node.kind() else { + return; + }; + + match call_expr.callee.without_parentheses() { + Expression::Identifier(ident) => { + if ident.name == "parseInt" + && ctx.symbols().is_global_reference(ident.reference_id().unwrap()) + { + Self::check_arguments(self, call_expr, ctx); + } + } + Expression::StaticMemberExpression(member_expr) => { + if let Expression::Identifier(ident) = member_expr.object.without_parentheses() { + if ident.name == "Number" + && member_expr.property.name == "parseInt" && ctx.symbols().is_global_reference(ident.reference_id().unwrap()) { Self::check_arguments(self, call_expr, ctx); } } - Expression::StaticMemberExpression(member_expr) => { - if let Expression::Identifier(ident) = member_expr.object.without_parentheses() - { + } + Expression::ChainExpression(chain_expr) => { + if let Some(member_expr) = chain_expr.expression.as_member_expression() { + if let Expression::Identifier(ident) = member_expr.object() { if ident.name == "Number" - && member_expr.property.name == "parseInt" + && member_expr.static_property_name() == Some("parseInt") && ctx.symbols().is_global_reference(ident.reference_id().unwrap()) { Self::check_arguments(self, call_expr, ctx); } } } - Expression::ChainExpression(chain_expr) => { - if let Some(member_expr) = chain_expr.expression.as_member_expression() { - if let Expression::Identifier(ident) = member_expr.object() { - if ident.name == "Number" - && member_expr.static_property_name() == Some("parseInt") - && ctx.symbols().is_global_reference(ident.reference_id().unwrap()) - { - Self::check_arguments(self, call_expr, ctx); - } - } - } - } - _ => {} } + _ => {} } } } diff --git a/crates/oxc_linter/src/rules/eslint/require_await.rs b/crates/oxc_linter/src/rules/eslint/require_await.rs index e35736f56ab1f3..4e8482415b133b 100644 --- a/crates/oxc_linter/src/rules/eslint/require_await.rs +++ b/crates/oxc_linter/src/rules/eslint/require_await.rs @@ -73,48 +73,48 @@ declare_oxc_lint!( impl Rule for RequireAwait { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::FunctionBody(body) = node.kind() { - if body.is_empty() { - return; - } - - let Some(parent) = ctx.nodes().parent_node(node.id()) else { - return; - }; + let AstKind::FunctionBody(body) = node.kind() else { + return; + }; + if body.is_empty() { + return; + } + let Some(parent) = ctx.nodes().parent_node(node.id()) else { + return; + }; - match parent.kind() { - AstKind::Function(func) => { - if func.r#async && !func.generator { - let mut finder = AwaitFinder { found: false }; - finder.visit_function_body(body); - if !finder.found { - if let Some(AstKind::ObjectProperty(p)) = - ctx.nodes().parent_kind(parent.id()) - { - if let PropertyKey::StaticIdentifier(iden) = &p.key { - ctx.diagnostic(require_await_diagnostic(iden.span)); - } else { - ctx.diagnostic(require_await_diagnostic(func.span)); - } + match parent.kind() { + AstKind::Function(func) => { + if func.r#async && !func.generator { + let mut finder = AwaitFinder { found: false }; + finder.visit_function_body(body); + if !finder.found { + if let Some(AstKind::ObjectProperty(p)) = + ctx.nodes().parent_kind(parent.id()) + { + if let PropertyKey::StaticIdentifier(iden) = &p.key { + ctx.diagnostic(require_await_diagnostic(iden.span)); } else { - ctx.diagnostic(require_await_diagnostic( - func.id.as_ref().map_or(func.span, |ident| ident.span), - )); + ctx.diagnostic(require_await_diagnostic(func.span)); } + } else { + ctx.diagnostic(require_await_diagnostic( + func.id.as_ref().map_or(func.span, |ident| ident.span), + )); } } } - AstKind::ArrowFunctionExpression(func) => { - if func.r#async { - let mut finder = AwaitFinder { found: false }; - finder.visit_function_body(body); - if !finder.found { - ctx.diagnostic(require_await_diagnostic(func.span)); - } + } + AstKind::ArrowFunctionExpression(func) => { + if func.r#async { + let mut finder = AwaitFinder { found: false }; + finder.visit_function_body(body); + if !finder.found { + ctx.diagnostic(require_await_diagnostic(func.span)); } } - _ => {} } + _ => {} } } } diff --git a/crates/oxc_linter/src/rules/import/namespace.rs b/crates/oxc_linter/src/rules/import/namespace.rs index 13d993e1438bd1..e89abf298ea9bc 100644 --- a/crates/oxc_linter/src/rules/import/namespace.rs +++ b/crates/oxc_linter/src/rules/import/namespace.rs @@ -214,42 +214,32 @@ fn check_deep_namespace_for_node( namespaces: &[String], module: &Arc, ctx: &LintContext<'_>, -) { - if let AstKind::MemberExpression(expr) = node.kind() { - let Some((span, name)) = expr.static_property_info() else { - return; - }; - - if let Some(module_source) = get_module_request_name(name, module) { - let Some(parent_node) = ctx.nodes().parent_node(node.id()) else { - return; - }; - if let Some(module_record) = module.loaded_modules.get(module_source.as_str()) { - let mut namespaces = namespaces.to_owned(); - namespaces.push(name.into()); - check_deep_namespace_for_node( - parent_node, - source, - &namespaces, - module_record.value(), - ctx, - ); - } - } else { - check_binding_exported( - name, - || { - if namespaces.len() > 1 { - no_export_in_deeply_imported_namespace(span, name, &namespaces.join(".")) - } else { - no_export(span, name, source) - } - }, - module, - ctx, - ); - } +) -> Option<()> { + let expr = node.kind().as_member_expression()?; + let (span, name) = expr.static_property_info()?; + + if let Some(module_source) = get_module_request_name(name, module) { + let parent_node = ctx.nodes().parent_node(node.id())?; + let module_record = module.loaded_modules.get(module_source.as_str())?; + let mut namespaces = namespaces.to_owned(); + namespaces.push(name.into()); + check_deep_namespace_for_node(parent_node, source, &namespaces, module_record.value(), ctx); + } else { + check_binding_exported( + name, + || { + if namespaces.len() > 1 { + no_export_in_deeply_imported_namespace(span, name, &namespaces.join(".")) + } else { + no_export(span, name, source) + } + }, + module, + ctx, + ); } + + None } fn check_deep_namespace_for_object_pattern( diff --git a/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs b/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs index 8c21c707c7b493..183e13d6b4df62 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs @@ -94,28 +94,31 @@ impl Rule for NoAutofocus { } fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::JSXElement(jsx_el) = node.kind() { - if let Option::Some(autofocus) = has_jsx_prop(&jsx_el.opening_element, "autoFocus") { - let Some(element_type) = get_element_type(ctx, &jsx_el.opening_element) else { - return; - }; - if self.ignore_non_dom { - if HTML_TAG.contains(&element_type) { - if let oxc_ast::ast::JSXAttributeItem::Attribute(attr) = autofocus { - ctx.diagnostic_with_fix(no_autofocus_diagnostic(attr.span), |fixer| { - fixer.delete(&attr.span) - }); - } - } - return; - } - + let AstKind::JSXElement(jsx_el) = node.kind() else { + return; + }; + let Some(autofocus) = has_jsx_prop(&jsx_el.opening_element, "autoFocus") else { + return; + }; + let Some(element_type) = get_element_type(ctx, &jsx_el.opening_element) else { + return; + }; + + if self.ignore_non_dom { + if HTML_TAG.contains(&element_type) { if let oxc_ast::ast::JSXAttributeItem::Attribute(attr) = autofocus { ctx.diagnostic_with_fix(no_autofocus_diagnostic(attr.span), |fixer| { fixer.delete(&attr.span) }); } } + return; + } + + if let oxc_ast::ast::JSXAttributeItem::Attribute(attr) = autofocus { + ctx.diagnostic_with_fix(no_autofocus_diagnostic(attr.span), |fixer| { + fixer.delete(&attr.span) + }); } } } diff --git a/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs b/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs index 808ca9d67531fe..bf1183646167d7 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs @@ -58,26 +58,27 @@ static DEFAULT_ROLE_EXCEPTIONS: phf::Map<&'static str, &'static str> = phf_map! impl Rule for NoRedundantRoles { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::JSXOpeningElement(jsx_el) = node.kind() { - if let Some(component) = get_element_type(ctx, jsx_el) { - if let Some(JSXAttributeItem::Attribute(attr)) = - has_jsx_prop_ignore_case(jsx_el, "role") - { - if let Some(JSXAttributeValue::StringLiteral(role_values)) = &attr.value { - let roles: Vec = role_values - .value - .split_whitespace() - .map(std::string::ToString::to_string) - .collect(); - for role in &roles { - let exceptions = DEFAULT_ROLE_EXCEPTIONS.get(&component); - if exceptions.map_or(false, |set| set.contains(role)) { - ctx.diagnostic_with_fix( - no_redundant_roles_diagnostic(attr.span, &component, role), - |fixer| fixer.delete_range(attr.span), - ); - } - } + let AstKind::JSXOpeningElement(jsx_el) = node.kind() else { + return; + }; + let Some(component) = get_element_type(ctx, jsx_el) else { + return; + }; + + if let Some(JSXAttributeItem::Attribute(attr)) = has_jsx_prop_ignore_case(jsx_el, "role") { + if let Some(JSXAttributeValue::StringLiteral(role_values)) = &attr.value { + let roles: Vec = role_values + .value + .split_whitespace() + .map(std::string::ToString::to_string) + .collect(); + for role in &roles { + let exceptions = DEFAULT_ROLE_EXCEPTIONS.get(&component); + if exceptions.map_or(false, |set| set.contains(role)) { + ctx.diagnostic_with_fix( + no_redundant_roles_diagnostic(attr.span, &component, role), + |fixer| fixer.delete_range(attr.span), + ); } } } diff --git a/crates/oxc_linter/src/rules/jsx_a11y/role_supports_aria_props.rs b/crates/oxc_linter/src/rules/jsx_a11y/role_supports_aria_props.rs index d658fe693e0e04..af5476e0084dcf 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/role_supports_aria_props.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/role_supports_aria_props.rs @@ -64,30 +64,33 @@ fn is_implicit_diagnostic(span: Span, x1: &str, x2: &str, x3: &str) -> OxcDiagno impl Rule for RoleSupportsAriaProps { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::JSXOpeningElement(jsx_el) = node.kind() { - if let Some(el_type) = get_element_type(ctx, jsx_el) { - let role = has_jsx_prop_ignore_case(jsx_el, "role"); - let role_value = role.map_or_else( - || get_implicit_role(jsx_el, &el_type), - |i| get_string_literal_prop_value(i), - ); - let is_implicit = role_value.is_some() && role.is_none(); - if let Some(role_value) = role_value { - if !VALID_ARIA_ROLES.contains(role_value) { - return; - } - let invalid_props = get_invalid_aria_props_for_role(role_value); - for attr in &jsx_el.attributes { - if let JSXAttributeItem::Attribute(attr) = attr { - let name = get_jsx_attribute_name(&attr.name).to_lowercase(); - if invalid_props.contains(&&name.as_str()) { - ctx.diagnostic(if is_implicit { - is_implicit_diagnostic(attr.span, &name, role_value, &el_type) - } else { - default(attr.span, &name, role_value) - }); - } - } + let AstKind::JSXOpeningElement(jsx_el) = node.kind() else { + return; + }; + let Some(el_type) = get_element_type(ctx, jsx_el) else { + return; + }; + + let role = has_jsx_prop_ignore_case(jsx_el, "role"); + let role_value = role.map_or_else( + || get_implicit_role(jsx_el, &el_type), + |i| get_string_literal_prop_value(i), + ); + let is_implicit = role_value.is_some() && role.is_none(); + if let Some(role_value) = role_value { + if !VALID_ARIA_ROLES.contains(role_value) { + return; + } + let invalid_props = get_invalid_aria_props_for_role(role_value); + for attr in &jsx_el.attributes { + if let JSXAttributeItem::Attribute(attr) = attr { + let name = get_jsx_attribute_name(&attr.name).to_lowercase(); + if invalid_props.contains(&&name.as_str()) { + ctx.diagnostic(if is_implicit { + is_implicit_diagnostic(attr.span, &name, role_value, &el_type) + } else { + default(attr.span, &name, role_value) + }); } } } diff --git a/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs b/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs index f9aff5d42f3da0..6f05555f6bbc23 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs @@ -107,62 +107,67 @@ const NEXT_POLYFILLED_FEATURES: Set<&'static str> = phf_set! { impl Rule for NoUnwantedPolyfillio { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::JSXOpeningElement(jsx_el) = node.kind() { - let Some(tag_name) = jsx_el.name.get_identifier_name() else { return }; + let AstKind::JSXOpeningElement(jsx_el) = node.kind() else { + return; + }; - if tag_name.as_str() != "script" { - let next_script_import_local_name = get_next_script_import_local_name(ctx); - if !matches!(next_script_import_local_name, Some(import) if tag_name.as_str() == import.as_str()) - { - return; - } - } + let Some(tag_name) = jsx_el.name.get_identifier_name() else { + return; + }; - if jsx_el.attributes.len() == 0 { + if tag_name.as_str() != "script" { + let next_script_import_local_name = get_next_script_import_local_name(ctx); + if !matches!(next_script_import_local_name, Some(import) if tag_name.as_str() == import.as_str()) + { return; } + } + + if jsx_el.attributes.len() == 0 { + return; + } + + let Some(JSXAttributeItem::Attribute(src)) = jsx_el.attributes.iter().find(|attr| { + matches!( + attr, + JSXAttributeItem::Attribute(jsx_attr) + if matches!( + &jsx_attr.name, + JSXAttributeName::Identifier(id) if id.name.as_str() == "src" + ) + ) + }) else { + return; + }; - let Some(JSXAttributeItem::Attribute(src)) = jsx_el.attributes.iter().find(|attr| { - matches!( - attr, - JSXAttributeItem::Attribute(jsx_attr) - if matches!( - &jsx_attr.name, - JSXAttributeName::Identifier(id) if id.name.as_str() == "src" - ) - ) - }) else { + let Some(JSXAttributeValue::StringLiteral(src_value)) = &src.value else { + return; + }; + + if src_value.value.as_str().starts_with("https://cdn.polyfill.io/v2/") + || src_value.value.as_str().starts_with("https://polyfill.io/v3/") + { + let Ok(url) = url::Url::parse(src_value.value.as_str()) else { + return; + }; + let Some((_, features_value)) = url.query_pairs().find(|(key, _)| key == "features") + else { return; }; - if let Some(JSXAttributeValue::StringLiteral(src_value)) = &src.value { - if src_value.value.as_str().starts_with("https://cdn.polyfill.io/v2/") - || src_value.value.as_str().starts_with("https://polyfill.io/v3/") - { - let Ok(url) = url::Url::parse(src_value.value.as_str()) else { - return; - }; - - let Some((_, features_value)) = - url.query_pairs().find(|(key, _)| key == "features") - else { - return; - }; - let unwanted_features: Vec<&str> = features_value - .split(',') - .filter(|feature| NEXT_POLYFILLED_FEATURES.contains(feature)) - .collect(); - if !unwanted_features.is_empty() { - ctx.diagnostic(no_unwanted_polyfillio_diagnostic( - &format!( - "{} {}", - unwanted_features.join(", "), - if unwanted_features.len() > 1 { "are" } else { "is" } - ), - src.span, - )); - } - } + let unwanted_features: Vec<&str> = features_value + .split(',') + .filter(|feature| NEXT_POLYFILLED_FEATURES.contains(feature)) + .collect(); + if !unwanted_features.is_empty() { + ctx.diagnostic(no_unwanted_polyfillio_diagnostic( + &format!( + "{} {}", + unwanted_features.join(", "), + if unwanted_features.len() > 1 { "are" } else { "is" } + ), + src.span, + )); } } } diff --git a/crates/oxc_linter/src/rules/oxc/bad_min_max_func.rs b/crates/oxc_linter/src/rules/oxc/bad_min_max_func.rs index 1943bed76d9ceb..18983f5aa24541 100644 --- a/crates/oxc_linter/src/rules/oxc/bad_min_max_func.rs +++ b/crates/oxc_linter/src/rules/oxc/bad_min_max_func.rs @@ -39,31 +39,32 @@ impl Rule for BadMinMaxFunc { let AstKind::CallExpression(call_expr) = node.kind() else { return; }; + let Some((out_min_max, inner_exprs)) = Self::min_max(call_expr) else { + return; + }; - if let Some((out_min_max, inner_exprs)) = Self::min_max(call_expr) { - for expr in inner_exprs { - if let Some((inner_min_max, ..)) = Self::min_max(expr) { - let constant_result = match (&out_min_max, &inner_min_max) { - (MinMax::Max(max), MinMax::Min(min)) => { - if max > min { - Some(max) - } else { - None - } + for expr in inner_exprs { + if let Some((inner_min_max, ..)) = Self::min_max(expr) { + let constant_result = match (&out_min_max, &inner_min_max) { + (MinMax::Max(max), MinMax::Min(min)) => { + if max > min { + Some(max) + } else { + None } - (MinMax::Min(min), MinMax::Max(max)) => { - if min < max { - Some(min) - } else { - None - } + } + (MinMax::Min(min), MinMax::Max(max)) => { + if min < max { + Some(min) + } else { + None } - _ => None, - }; - - if let Some(constant) = constant_result { - ctx.diagnostic(bad_min_max_func_diagnostic(*constant, call_expr.span)); } + _ => None, + }; + + if let Some(constant) = constant_result { + ctx.diagnostic(bad_min_max_func_diagnostic(*constant, call_expr.span)); } } } diff --git a/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs b/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs index 44e1da35c92d3b..99ab0edc7de05c 100644 --- a/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs +++ b/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs @@ -96,12 +96,10 @@ fn resolve_flags<'a>( } } Expression::Identifier(ident) => { - if let Some(decl) = get_declaration_of_variable(ident, ctx) { - if let AstKind::VariableDeclarator(var_decl) = decl.kind() { - if let Some(init) = &var_decl.init { - return resolve_flags(init, ctx); - } - } + let decl = get_declaration_of_variable(ident, ctx)?; + let var_decl = decl.kind().as_variable_declarator()?; + if let Some(init) = &var_decl.init { + return resolve_flags(init, ctx); } None } diff --git a/crates/oxc_linter/src/rules/oxc/number_arg_out_of_range.rs b/crates/oxc_linter/src/rules/oxc/number_arg_out_of_range.rs index 2ba128e74d7e0b..05ca3b90afa1fc 100644 --- a/crates/oxc_linter/src/rules/oxc/number_arg_out_of_range.rs +++ b/crates/oxc_linter/src/rules/oxc/number_arg_out_of_range.rs @@ -43,34 +43,29 @@ impl Rule for NumberArgOutOfRange { let AstKind::CallExpression(expr) = node.kind() else { return; }; + let Some(member) = expr.callee.get_member_expr() else { + return; + }; - if let Some(member) = expr.callee.get_member_expr() { - if let Some(Argument::NumericLiteral(literal)) = expr.arguments.first() { - let value = literal.value; - match member.static_property_name() { - Some(name @ "toString") => { - if !(2.0_f64..=36.0_f64).contains(&value) { - ctx.diagnostic(number_arg_out_of_range_diagnostic( - name, 2, 36, expr.span, - )); - } + if let Some(Argument::NumericLiteral(literal)) = expr.arguments.first() { + let value = literal.value; + match member.static_property_name() { + Some(name @ "toString") => { + if !(2.0_f64..=36.0_f64).contains(&value) { + ctx.diagnostic(number_arg_out_of_range_diagnostic(name, 2, 36, expr.span)); } - Some(name @ ("toFixed" | "toExponential")) => { - if !(0.0_f64..=20.0_f64).contains(&value) { - ctx.diagnostic(number_arg_out_of_range_diagnostic( - name, 0, 20, expr.span, - )); - } + } + Some(name @ ("toFixed" | "toExponential")) => { + if !(0.0_f64..=20.0_f64).contains(&value) { + ctx.diagnostic(number_arg_out_of_range_diagnostic(name, 0, 20, expr.span)); } - Some(name @ "toPrecision") => { - if !(1.0_f64..=21.0_f64).contains(&value) { - ctx.diagnostic(number_arg_out_of_range_diagnostic( - name, 1, 21, expr.span, - )); - } + } + Some(name @ "toPrecision") => { + if !(1.0_f64..=21.0_f64).contains(&value) { + ctx.diagnostic(number_arg_out_of_range_diagnostic(name, 1, 21, expr.span)); } - _ => {} } + _ => {} } } } diff --git a/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs b/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs index 5f68e2bb2007af..b17eb02b042ad2 100644 --- a/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs +++ b/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs @@ -50,9 +50,7 @@ impl ReactPerfRule for JsxNoJsxAsProp { kind: &AstKind<'_>, _symbol_id: SymbolId, ) -> Option<(/* decl */ Span, /* init */ Option)> { - let AstKind::VariableDeclarator(decl) = kind else { - return None; - }; + let decl = kind.as_variable_declarator()?; let init_span = decl.init.as_ref().and_then(check_expression)?; Some((decl.id.span(), Some(init_span))) } diff --git a/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs index 5613a11aba3afb..4fce9cb24a2a8d 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs @@ -547,9 +547,7 @@ fn get_type_only_named_import<'a>( source: &str, ) -> Option<&'a ImportDeclaration<'a>> { let root = ctx.nodes().root_node()?; - let AstKind::Program(program) = root.kind() else { - return None; - }; + let program = root.kind().as_program()?; for stmt in &program.body { let Statement::ImportDeclaration(import_decl) = stmt else { diff --git a/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_optional_chain.rs b/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_optional_chain.rs index 48a8ddfd5d869b..0d81a720edd321 100644 --- a/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_optional_chain.rs +++ b/crates/oxc_linter/src/rules/typescript/no_non_null_asserted_optional_chain.rs @@ -39,53 +39,55 @@ declare_oxc_lint!( impl Rule for NoNonNullAssertedOptionalChain { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if let AstKind::TSNonNullExpression(non_null_expr) = node.kind() { - let chain_span = match non_null_expr.expression.get_inner_expression() { - Expression::ChainExpression(chain) => match &chain.expression { - ChainElement::ComputedMemberExpression(member) if member.optional => { - Some(member.object.span()) - } - ChainElement::StaticMemberExpression(member) if member.optional => { - Some(member.object.span()) - } - ChainElement::PrivateFieldExpression(member) if member.optional => { - Some(member.object.span()) - } - ChainElement::CallExpression(call) if call.optional => Some(call.callee.span()), - _ => None, - }, - Expression::CallExpression(call) => { - if call.optional && !is_parent_member_or_call(node, ctx) { - Some(call.callee.span()) - } else if let Some(member) = call.callee.as_member_expression() { - if member.optional() && !is_parent_member_or_call(node, ctx) { - Some(member.object().span()) - } else { - None - } - } else { - None - } + let AstKind::TSNonNullExpression(non_null_expr) = node.kind() else { + return; + }; + + let chain_span = match non_null_expr.expression.get_inner_expression() { + Expression::ChainExpression(chain) => match &chain.expression { + ChainElement::ComputedMemberExpression(member) if member.optional => { + Some(member.object.span()) + } + ChainElement::StaticMemberExpression(member) if member.optional => { + Some(member.object.span()) } - expr @ match_member_expression!(Expression) => { - let member_expr = expr.to_member_expression(); - if member_expr.optional() && !is_parent_member_or_call(node, ctx) { - Some(member_expr.object().span()) + ChainElement::PrivateFieldExpression(member) if member.optional => { + Some(member.object.span()) + } + ChainElement::CallExpression(call) if call.optional => Some(call.callee.span()), + _ => None, + }, + Expression::CallExpression(call) => { + if call.optional && !is_parent_member_or_call(node, ctx) { + Some(call.callee.span()) + } else if let Some(member) = call.callee.as_member_expression() { + if member.optional() && !is_parent_member_or_call(node, ctx) { + Some(member.object().span()) } else { None } + } else { + None } - _ => None, - }; - - if let Some(chain_span) = chain_span { - let chain_span_end = chain_span.end; - let non_null_end = non_null_expr.span.end - 1; - ctx.diagnostic(no_non_null_asserted_optional_chain_diagnostic( - Span::new(chain_span_end, chain_span_end), - Span::new(non_null_end, non_null_end), - )); } + expr @ match_member_expression!(Expression) => { + let member_expr = expr.to_member_expression(); + if member_expr.optional() && !is_parent_member_or_call(node, ctx) { + Some(member_expr.object().span()) + } else { + None + } + } + _ => None, + }; + + if let Some(chain_span) = chain_span { + let chain_span_end = chain_span.end; + let non_null_end = non_null_expr.span.end - 1; + ctx.diagnostic(no_non_null_asserted_optional_chain_diagnostic( + Span::new(chain_span_end, chain_span_end), + Span::new(non_null_end, non_null_end), + )); } } diff --git a/crates/oxc_linter/src/rules/unicorn/no_thenable.rs b/crates/oxc_linter/src/rules/unicorn/no_thenable.rs index 5b4205ae5b52a6..3da15aaa2636ff 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_thenable.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_thenable.rs @@ -2,7 +2,7 @@ use oxc_ast::{ ast::{ match_expression, Argument, ArrayExpressionElement, AssignmentExpression, AssignmentTarget, BindingPatternKind, CallExpression, Declaration, Expression, ModuleDeclaration, - ObjectPropertyKind, PropertyKey, VariableDeclarator, + ObjectPropertyKind, PropertyKey, }, AstKind, }; @@ -239,18 +239,17 @@ fn check_expression(expr: &Expression, ctx: &LintContext<'_>) -> Option { + if lit.value == "then" { + Some(lit.span) + } else { + None + } } - } else { - None + _ => None, } }) }) diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_string_slice.rs b/crates/oxc_linter/src/rules/unicorn/prefer_string_slice.rs index 3bb91587bbd63e..1e77485781bfdd 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_string_slice.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_string_slice.rs @@ -47,19 +47,15 @@ impl Rule for PreferStringSlice { return; }; - let (span, name) = match member_expr { - MemberExpression::StaticMemberExpression(v) => { - if !matches!(v.property.name.as_str(), "substr" | "substring") { - return; - } - (v.property.span, &v.property.name) + if let MemberExpression::StaticMemberExpression(v) = member_expr { + if !matches!(v.property.name.as_str(), "substr" | "substring") { + return; } - _ => return, - }; - - ctx.diagnostic_with_fix(prefer_string_slice_diagnostic(span, name.as_str()), |fixer| { - fixer.replace(span, "slice") - }); + ctx.diagnostic_with_fix( + prefer_string_slice_diagnostic(v.property.span, v.property.name.as_str()), + |fixer| fixer.replace(v.property.span, "slice"), + ); + } } } diff --git a/crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs b/crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs index 17be91c8848be2..2f3eacda2c4e2b 100644 --- a/crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs +++ b/crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs @@ -66,30 +66,29 @@ impl Rule for NoConditionalTests { } } -fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) { +fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) -> Option<()> { let node = possible_jest_node.node; - if let AstKind::CallExpression(call_expr) = node.kind() { - if is_type_of_jest_fn_call( - call_expr, - possible_jest_node, - ctx, - &[ - JestFnKind::General(JestGeneralFnKind::Describe), - JestFnKind::General(JestGeneralFnKind::Test), - ], - ) { - let if_statement_node = ctx - .nodes() - .iter_parents(node.id()) - .find(|node| matches!(node.kind(), AstKind::IfStatement(_))); + let call_expr = node.kind().as_call_expression()?; - let Some(node) = if_statement_node else { return }; + if is_type_of_jest_fn_call( + call_expr, + possible_jest_node, + ctx, + &[ + JestFnKind::General(JestGeneralFnKind::Describe), + JestFnKind::General(JestGeneralFnKind::Test), + ], + ) { + let if_statement_node = ctx + .nodes() + .iter_parents(node.id()) + .find(|node| matches!(node.kind(), AstKind::IfStatement(_)))?; - if let AstKind::IfStatement(if_statement) = node.kind() { - ctx.diagnostic(no_conditional_tests(if_statement.span)); - } - } + let if_statement = if_statement_node.kind().as_if_statement()?; + ctx.diagnostic(no_conditional_tests(if_statement.span)); } + + None } #[test] diff --git a/crates/oxc_linter/src/utils/express.rs b/crates/oxc_linter/src/utils/express.rs index 41d19baf2b5fd3..56e9e9e4b4fd39 100644 --- a/crates/oxc_linter/src/utils/express.rs +++ b/crates/oxc_linter/src/utils/express.rs @@ -21,9 +21,7 @@ use phf::{phf_set, set::Set}; pub fn as_endpoint_registration<'a, 'n>( node: &'n AstKind<'a>, ) -> Option<(Option>, &'n [Argument<'a>])> { - let AstKind::CallExpression(call) = node else { - return None; - }; + let call = node.as_call_expression()?; let callee = call.callee.as_member_expression()?; let method_name = callee.static_property_name()?; if !ROUTER_HANDLER_METHOD_NAMES.contains(method_name) { diff --git a/crates/oxc_semantic/tests/integration/scopes.rs b/crates/oxc_semantic/tests/integration/scopes.rs index cd12d4fe9c03fd..3be5e8dfbe95ea 100644 --- a/crates/oxc_semantic/tests/integration/scopes.rs +++ b/crates/oxc_semantic/tests/integration/scopes.rs @@ -188,11 +188,8 @@ fn test_enums() { .nodes() .iter() .find_map(|node| { - if let AstKind::TSEnumDeclaration(e) = node.kind() { - Some((node, e)) - } else { - None - } + let e = node.kind().as_ts_enum_declaration()?; + Some((node, e)) }) .expect("Expected TS test case to have an enum declaration for A."); diff --git a/crates/oxc_semantic/tests/integration/util/class_tester.rs b/crates/oxc_semantic/tests/integration/util/class_tester.rs index fca21516257acf..757bd51b5ce21c 100644 --- a/crates/oxc_semantic/tests/integration/util/class_tester.rs +++ b/crates/oxc_semantic/tests/integration/util/class_tester.rs @@ -1,6 +1,5 @@ use std::rc::Rc; -use oxc_ast::AstKind; use oxc_semantic::Semantic; use oxc_syntax::class::ClassId; @@ -14,11 +13,12 @@ impl<'a> ClassTester<'a> { pub(super) fn has_class(semantic: Semantic<'a>, name: &str) -> Self { let class_id = semantic.classes().iter_enumerated().find_map(|(class_id, ast_node_id)| { let kind = semantic.nodes().kind(*ast_node_id); - if let AstKind::Class(class) = kind { - if class.id.clone().is_some_and(|id| id.name == name) { - return Some(class_id); - }; - } + let class = kind.as_class()?; + + if class.id.clone().is_some_and(|id| id.name == name) { + return Some(class_id); + }; + None }); ClassTester { From 10e8984d933a57f378f9393ba9005f10ab905b8f Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Fri, 6 Sep 2024 03:23:26 +0000 Subject: [PATCH 03/28] ci: fix paths in the `.generated_ast_watch_list.yml`. (#5520) --- .github/.generated_ast_watch_list.yml | 3 ++- tasks/ast_tools/src/main.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/.generated_ast_watch_list.yml b/.github/.generated_ast_watch_list.yml index 887a9d0cf5b1a7..672b12650674c9 100644 --- a/.github/.generated_ast_watch_list.yml +++ b/.github/.generated_ast_watch_list.yml @@ -27,4 +27,5 @@ src: - 'crates/oxc_ast/src/generated/derive_content_hash.rs' - 'crates/oxc_regular_expression/src/generated/derive_content_hash.rs' - 'crates/oxc_syntax/src/generated/derive_content_hash.rs' - - 'tasks/ast_codegen/src/**' + - 'tasks/ast_codegen/src/**/*' + - '.github/.generated_ast_watch_list.yml' diff --git a/tasks/ast_tools/src/main.rs b/tasks/ast_tools/src/main.rs index 6f4fc02d99c687..b804b649052f23 100644 --- a/tasks/ast_tools/src/main.rs +++ b/tasks/ast_tools/src/main.rs @@ -125,7 +125,8 @@ fn write_ci_filter( push_item(side_effect.as_str()); } - push_item("tasks/ast_codegen/src/**"); + push_item("tasks/ast_codegen/src/**/*"); + push_item(output_path); write_all_to(output.as_bytes(), output_path) } From 88b7ddb7e0d1c46995a6a2c5f49bdb5236519b50 Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Fri, 6 Sep 2024 03:28:33 +0000 Subject: [PATCH 04/28] fix(regular_expression): Handle unterminated character class (#5523) `/[/` is reported by `debug_assert!`, but should not. --- crates/oxc_regular_expression/src/body_parser/mod.rs | 4 ++++ crates/oxc_regular_expression/src/body_parser/parser.rs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/oxc_regular_expression/src/body_parser/mod.rs b/crates/oxc_regular_expression/src/body_parser/mod.rs index be0e18bd65dcf8..f2612fbf5abfb3 100644 --- a/crates/oxc_regular_expression/src/body_parser/mod.rs +++ b/crates/oxc_regular_expression/src/body_parser/mod.rs @@ -171,6 +171,10 @@ mod test { ("(?=a){1}", ParserOptions::default().with_unicode_mode()), ("(?!a){1}", ParserOptions::default().with_unicode_mode()), (r"[\d-\D]", ParserOptions::default().with_unicode_mode()), + ("[", ParserOptions::default()), + ("[", ParserOptions::default().with_unicode_sets_mode()), + ("[[", ParserOptions::default().with_unicode_sets_mode()), + ("[[]", ParserOptions::default().with_unicode_sets_mode()), ("[z-a]", ParserOptions::default()), (r"[a-c]]", ParserOptions::default().with_unicode_mode()), ( diff --git a/crates/oxc_regular_expression/src/body_parser/parser.rs b/crates/oxc_regular_expression/src/body_parser/parser.rs index 4d180c1bada400..e65ddedc6ea106 100644 --- a/crates/oxc_regular_expression/src/body_parser/parser.rs +++ b/crates/oxc_regular_expression/src/body_parser/parser.rs @@ -771,7 +771,10 @@ impl<'a> PatternParser<'a> { &mut self, ) -> Result<(ast::CharacterClassContentsKind, Vec<'a, ast::CharacterClassContents<'a>>)> { // [empty] - if self.reader.peek().filter(|&cp| cp == ']' as u32).is_some() { + if self.reader.peek().filter(|&cp| cp == ']' as u32).is_some() + // Unterminated + || self.reader.peek().is_none() + { return Ok((ast::CharacterClassContentsKind::Union, Vec::new_in(self.allocator))); } From 32d4bbb519c3176f6b52364b0b21c5e2c07610b7 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 6 Sep 2024 12:04:06 +0800 Subject: [PATCH 05/28] feat(transformer): add `TransformOptions::enable_all` method (#5495) Make it **really** explicit about which transformer options are being turned on. I also need this in monitor-oxc. --- Cargo.lock | 1 + crates/oxc_transformer/Cargo.toml | 1 + .../oxc_transformer/examples/transformer.rs | 21 ++++++++++---- .../src/options/transformer.rs | 29 +++++++++++++++++++ tasks/benchmark/benches/transformer.rs | 15 ++-------- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f5be95f34d9d6..316fa82cc3cb54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1960,6 +1960,7 @@ dependencies = [ "oxc_span", "oxc_syntax", "oxc_traverse", + "pico-args", "ropey", "rustc-hash", "serde", diff --git a/crates/oxc_transformer/Cargo.toml b/crates/oxc_transformer/Cargo.toml index 1223d3d20c5aa1..df5fc5f710dd01 100644 --- a/crates/oxc_transformer/Cargo.toml +++ b/crates/oxc_transformer/Cargo.toml @@ -41,6 +41,7 @@ oxc-browserslist = { workspace = true } [dev-dependencies] oxc_parser = { workspace = true } oxc_codegen = { workspace = true } +pico-args = { workspace = true } [features] default = [] diff --git a/crates/oxc_transformer/examples/transformer.rs b/crates/oxc_transformer/examples/transformer.rs index 025958a68a7764..8e89b308fb3438 100644 --- a/crates/oxc_transformer/examples/transformer.rs +++ b/crates/oxc_transformer/examples/transformer.rs @@ -7,6 +7,7 @@ use oxc_parser::Parser; use oxc_semantic::SemanticBuilder; use oxc_span::SourceType; use oxc_transformer::{EnvOptions, Targets, TransformOptions, Transformer}; +use pico_args::Arguments; // Instruction: // create a `test.tsx`, @@ -14,7 +15,10 @@ use oxc_transformer::{EnvOptions, Targets, TransformOptions, Transformer}; // or `just watch "run -p oxc_transformer --example transformer"` fn main() { - let name = env::args().nth(1).unwrap_or_else(|| "test.tsx".to_string()); + let mut args = Arguments::from_env(); + let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); + let targets: Option = args.opt_value_from_str("--targets").unwrap_or(None); + let path = Path::new(&name); let source_text = std::fs::read_to_string(path).expect("{name} not found"); let allocator = Allocator::default(); @@ -34,17 +38,22 @@ fn main() { println!("{source_text}\n"); let mut program = ret.program; - let transform_options = TransformOptions::from_preset_env(&EnvOptions { - targets: Targets::from_query("chrome 51"), - ..EnvOptions::default() - }) - .unwrap(); let (symbols, scopes) = SemanticBuilder::new(&source_text, source_type) .build(&program) .semantic .into_symbol_table_and_scope_tree(); + let transform_options = if let Some(targets) = &targets { + TransformOptions::from_preset_env(&EnvOptions { + targets: Targets::from_query(targets), + ..EnvOptions::default() + }) + .unwrap() + } else { + TransformOptions::enable_all() + }; + let _ = Transformer::new( &allocator, path, diff --git a/crates/oxc_transformer/src/options/transformer.rs b/crates/oxc_transformer/src/options/transformer.rs index 9a1e9f4f6d562e..02f2aec2c46f84 100644 --- a/crates/oxc_transformer/src/options/transformer.rs +++ b/crates/oxc_transformer/src/options/transformer.rs @@ -55,6 +55,35 @@ pub struct TransformOptions { } impl TransformOptions { + /// Explicitly enable all plugins that are ready, mainly for testing purposes. + pub fn enable_all() -> Self { + Self { + cwd: PathBuf::new(), + assumptions: CompilerAssumptions::default(), + typescript: TypeScriptOptions::default(), + react: ReactOptions { development: true, ..ReactOptions::default() }, + regexp: RegExpOptions { + sticky_flag: true, + unicode_flag: true, + dot_all_flag: true, + look_behind_assertions: true, + named_capture_groups: true, + unicode_property_escapes: true, + match_indices: true, + set_notation: true, + }, + es2015: ES2015Options { + // Turned off because it is not ready. + arrow_function: None, + }, + es2016: ES2016Options { exponentiation_operator: true }, + es2018: ES2018Options { object_rest_spread: Some(ObjectRestSpreadOptions::default()) }, + es2019: ES2019Options { optional_catch_binding: true }, + es2020: ES2020Options { nullish_coalescing_operator: true }, + es2021: ES2021Options { logical_assignment_operators: true }, + } + } + fn from_targets_and_bugfixes(targets: Option<&Versions>, bugfixes: bool) -> Self { Self { es2015: ES2015Options::from_targets_and_bugfixes(targets, bugfixes), diff --git a/tasks/benchmark/benches/transformer.rs b/tasks/benchmark/benches/transformer.rs index ff416db2986b92..5263ce8aef8bfc 100644 --- a/tasks/benchmark/benches/transformer.rs +++ b/tasks/benchmark/benches/transformer.rs @@ -6,7 +6,7 @@ use oxc_parser::{Parser, ParserReturn}; use oxc_semantic::SemanticBuilder; use oxc_span::SourceType; use oxc_tasks_common::TestFiles; -use oxc_transformer::{EnvOptions, Targets, TransformOptions, Transformer}; +use oxc_transformer::{TransformOptions, Transformer}; fn bench_transformer(criterion: &mut Criterion) { let mut group = criterion.benchmark_group("transformer"); @@ -40,17 +40,6 @@ fn bench_transformer(criterion: &mut Criterion) { // in measure. let trivias_copy = trivias.clone(); - let env_options = EnvOptions { - // >= ES2016 - targets: Targets::from_query("chrome 51"), - ..Default::default() - }; - let mut transform_options = - TransformOptions::from_preset_env(&env_options).unwrap(); - - // Enable React related plugins - transform_options.react.development = true; - runner.run(|| { let ret = Transformer::new( &allocator, @@ -58,7 +47,7 @@ fn bench_transformer(criterion: &mut Criterion) { source_type, source_text, trivias, - transform_options, + TransformOptions::enable_all(), ) .build_with_symbols_and_scopes(symbols, scopes, program); From 1bed5ce2a5fc89b3aa89fdf5e92ad8abc089e4a9 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 6 Sep 2024 04:04:26 +0000 Subject: [PATCH 06/28] chore: run `cargo +nightly fmt` to sort imports (#5503) They are never going to be stable are they ... https://github.com/oxc-project/oxc/blob/cedf7a4daa4084523050d9ae1b4555e5174c6347/.rustfmt.toml#L8-L16 --- crates/oxc/src/compiler.rs | 5 +- crates/oxc_allocator/src/boxed.rs | 3 +- crates/oxc_allocator/src/clone_in.rs | 5 + crates/oxc_allocator/src/vec.rs | 3 +- crates/oxc_ast/src/ast/js.rs | 6 +- crates/oxc_ast/src/ast/mod.rs | 5 +- crates/oxc_ast/src/ast_impl/js.rs | 6 +- crates/oxc_ast/src/ast_impl/jsx.rs | 7 +- crates/oxc_ast/src/ast_impl/literal.rs | 5 +- crates/oxc_ast/src/lib.rs | 7 +- crates/oxc_codegen/src/annotation_comment.rs | 1 + crates/oxc_codegen/src/binary_expr_visitor.rs | 6 +- crates/oxc_codegen/src/lib.rs | 4 +- crates/oxc_codegen/src/sourcemap_builder.rs | 1 - .../oxc_codegen/tests/integration/esbuild.rs | 30 +- crates/oxc_codegen/tests/integration/ts.rs | 2 +- crates/oxc_diagnostics/src/lib.rs | 1 + crates/oxc_index/src/rayon_impl.rs | 28 +- .../tests/deno/mod.rs | 6 +- crates/oxc_linter/src/ast_util.rs | 3 +- crates/oxc_linter/src/config/env.rs | 3 +- crates/oxc_linter/src/config/globals.rs | 6 +- crates/oxc_linter/src/config/mod.rs | 3 +- .../oxc_linter/src/config/settings/jsdoc.rs | 6 +- crates/oxc_linter/src/config/settings/mod.rs | 3 +- .../oxc_linter/src/config/settings/react.rs | 2 +- crates/oxc_linter/src/context.rs | 1 + crates/oxc_linter/src/fixer/fix.rs | 8 +- crates/oxc_linter/src/fixer/mod.rs | 3 +- crates/oxc_linter/src/frameworks.rs | 3 +- crates/oxc_linter/src/options/mod.rs | 5 +- crates/oxc_linter/src/rule.rs | 4 +- .../oxc_linter/src/rules/eslint/func_names.rs | 34 +- .../src/rules/eslint/getter_return.rs | 14 +- .../src/rules/eslint/no_obj_calls.rs | 2 +- .../oxc_linter/src/rules/eslint/no_undef.rs | 2 +- .../rules/eslint/no_unused_vars/allowed.rs | 5 +- .../eslint/no_unused_vars/binding_pattern.rs | 1 + .../no_unused_vars/fixers/fix_symbol.rs | 5 +- .../eslint/no_unused_vars/fixers/fix_vars.rs | 4 +- .../rules/eslint/no_unused_vars/fixers/mod.rs | 4 +- .../rules/eslint/no_unused_vars/ignored.rs | 7 +- .../src/rules/eslint/no_unused_vars/mod.rs | 5 +- .../rules/eslint/no_unused_vars/options.rs | 21 +- .../src/rules/eslint/no_unused_vars/symbol.rs | 6 +- .../eslint/no_unused_vars/tests/eslint.rs | 537 ++++++++++++------ .../rules/eslint/no_unused_vars/tests/oxc.rs | 9 +- .../src/rules/eslint/no_unused_vars/usage.rs | 9 +- .../src/rules/import/no_dynamic_require.rs | 3 +- .../src/rules/jest/prefer_jest_mocked.rs | 3 +- .../src/rules/jest/prefer_to_have_length.rs | 22 +- .../src/rules/oxc/no_accumulating_spread.rs | 2 +- .../rules/oxc/no_async_endpoint_handlers.rs | 11 +- .../rules/react/jsx_curly_brace_presence.rs | 6 +- .../rules/react/jsx_props_no_spread_multi.rs | 6 +- .../rules/react_perf/jsx_no_jsx_as_prop.rs | 3 +- .../no_side_effects_in_initialization/mod.rs | 2 +- .../src/rules/typescript/array_type.rs | 5 +- .../unicorn/consistent_function_scoping.rs | 2 + .../unicorn/no_useless_spread/const_eval.rs | 1 + .../rules/unicorn/no_useless_spread/mod.rs | 2 +- .../src/rules/unicorn/no_useless_undefined.rs | 4 +- .../unicorn/prefer_string_replace_all.rs | 4 +- crates/oxc_linter/src/table.rs | 6 +- crates/oxc_linter/src/utils/react_perf.rs | 3 +- crates/oxc_linter/src/utils/vitest.rs | 2 +- crates/oxc_macros/src/declare_oxc_lint.rs | 20 +- .../src/ast_passes/fold_constants.rs | 1 - crates/oxc_minifier/src/ast_passes/mod.rs | 7 +- .../src/node_util/check_for_state_change.rs | 1 - crates/oxc_minifier/src/node_util/mod.rs | 1 - .../src/plugins/replace_global_defines.rs | 3 +- crates/oxc_parser/src/js/object.rs | 4 +- crates/oxc_parser/src/lexer/regex.rs | 2 +- crates/oxc_parser/src/modifiers.rs | 2 +- crates/oxc_parser/src/ts/statement.rs | 1 + crates/oxc_regular_expression/src/ast.rs | 1 - .../src/body_parser/mod.rs | 3 +- .../src/body_parser/parser.rs | 1 + crates/oxc_regular_expression/src/lib.rs | 8 +- crates/oxc_semantic/src/checker/typescript.rs | 7 +- crates/oxc_semantic/src/counter.rs | 1 + .../src/post_transform_checker.rs | 3 +- crates/oxc_semantic/src/unresolved_stack.rs | 11 +- .../oxc_semantic/tests/integration/modules.rs | 5 +- .../oxc_semantic/tests/integration/scopes.rs | 6 +- crates/oxc_span/src/atom.rs | 5 +- crates/oxc_span/src/source_type/error.rs | 1 + crates/oxc_span/src/source_type/mod.rs | 4 +- crates/oxc_span/src/span/mod.rs | 1 + crates/oxc_span/src/span/types.rs | 3 +- crates/oxc_syntax/src/identifier.rs | 1 - crates/oxc_syntax/src/node.rs | 4 +- crates/oxc_syntax/src/operator.rs | 5 +- crates/oxc_syntax/src/reference.rs | 4 +- crates/oxc_syntax/src/scope.rs | 3 +- crates/oxc_syntax/src/symbol.rs | 3 +- crates/oxc_transformer/src/env/targets/mod.rs | 3 +- crates/oxc_transformer/src/es2015/options.rs | 3 +- crates/oxc_transformer/src/es2016/mod.rs | 3 +- crates/oxc_transformer/src/es2018/mod.rs | 3 +- .../src/es2018/object_rest_spread/mod.rs | 5 +- .../es2018/object_rest_spread/object_rest.rs | 3 +- .../object_rest_spread/object_spread.rs | 3 +- crates/oxc_transformer/src/es2018/options.rs | 3 +- crates/oxc_transformer/src/es2019/mod.rs | 3 +- crates/oxc_transformer/src/es2020/mod.rs | 3 +- .../src/es2020/nullish_coalescing_operator.rs | 5 +- crates/oxc_transformer/src/es2021/mod.rs | 3 +- crates/oxc_transformer/src/lib.rs | 5 +- .../src/typescript/annotations.rs | 1 + .../src/typescript/namespace.rs | 3 +- .../oxc_transformer/src/typescript/options.rs | 4 +- crates/oxc_traverse/src/lib.rs | 7 +- napi/parser/src/lib.rs | 2 +- napi/parser/src/module_lexer.rs | 2 +- napi/transform/src/context.rs | 7 +- napi/transform/src/isolated_declaration.rs | 1 - napi/transform/src/options.rs | 1 - napi/transform/src/transformer.rs | 4 +- tasks/ast_tools/src/derives/clone_in.rs | 3 +- tasks/ast_tools/src/derives/content_eq.rs | 3 +- tasks/ast_tools/src/derives/content_hash.rs | 3 +- tasks/ast_tools/src/derives/get_span.rs | 3 +- tasks/ast_tools/src/derives/mod.rs | 3 +- .../src/generators/assert_layouts.rs | 3 +- tasks/ast_tools/src/generators/ast_builder.rs | 9 +- tasks/ast_tools/src/generators/ast_kind.rs | 3 +- tasks/ast_tools/src/generators/visit.rs | 3 +- tasks/ast_tools/src/markers.rs | 3 +- tasks/ast_tools/src/passes/calc_layout.rs | 3 +- tasks/ast_tools/src/passes/linker.rs | 9 +- tasks/ast_tools/src/rust_ast.rs | 10 +- tasks/ast_tools/src/schema/defs.rs | 3 +- tasks/ast_tools/src/schema/get_ident.rs | 3 +- tasks/ast_tools/src/schema/mod.rs | 2 +- tasks/coverage/src/babel/mod.rs | 3 +- tasks/coverage/src/driver.rs | 25 +- tasks/coverage/src/runtime/mod.rs | 5 +- tasks/coverage/src/suite.rs | 6 +- tasks/coverage/src/tools/prettier.rs | 8 +- tasks/coverage/src/tools/semantic.rs | 8 +- tasks/coverage/src/tools/sourcemap.rs | 9 +- tasks/coverage/src/tools/transformer.rs | 10 +- tasks/coverage/src/typescript/meta.rs | 12 +- .../src/typescript/transpile_runner.rs | 10 +- tasks/transform_conformance/src/test_case.rs | 14 +- tasks/website/src/linter/rules/doc_page.rs | 6 +- tasks/website/src/linter/rules/test.rs | 6 +- 149 files changed, 779 insertions(+), 541 deletions(-) diff --git a/crates/oxc/src/compiler.rs b/crates/oxc/src/compiler.rs index ab0b20eeb05a36..9a5af6bfc62a3c 100644 --- a/crates/oxc/src/compiler.rs +++ b/crates/oxc/src/compiler.rs @@ -5,11 +5,10 @@ use oxc_ast::{ast::Program, Trivias}; use oxc_codegen::{CodeGenerator, CodegenOptions, CommentOptions}; use oxc_diagnostics::OxcDiagnostic; use oxc_mangler::{MangleOptions, Mangler}; -use oxc_parser::{ParseOptions, Parser, ParserReturn}; -use oxc_span::SourceType; - use oxc_minifier::{CompressOptions, Compressor}; +use oxc_parser::{ParseOptions, Parser, ParserReturn}; use oxc_semantic::{ScopeTree, SemanticBuilder, SemanticBuilderReturn, SymbolTable}; +use oxc_span::SourceType; use oxc_transformer::{TransformOptions, Transformer, TransformerReturn}; #[derive(Default)] diff --git a/crates/oxc_allocator/src/boxed.rs b/crates/oxc_allocator/src/boxed.rs index bb2f9fd538ce3e..ec67ea0acf9fc3 100644 --- a/crates/oxc_allocator/src/boxed.rs +++ b/crates/oxc_allocator/src/boxed.rs @@ -130,9 +130,8 @@ impl<'a, T> Box<'a, T> { mod test { use std::hash::{DefaultHasher, Hash, Hasher}; - use crate::Allocator; - use super::Box; + use crate::Allocator; #[test] fn box_deref_mut() { diff --git a/crates/oxc_allocator/src/clone_in.rs b/crates/oxc_allocator/src/clone_in.rs index bca581f860136e..79d1a6364ca597 100644 --- a/crates/oxc_allocator/src/clone_in.rs +++ b/crates/oxc_allocator/src/clone_in.rs @@ -30,6 +30,7 @@ where T: CloneIn<'alloc, Cloned = C>, { type Cloned = Option; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { self.as_ref().map(|it| it.clone_in(allocator)) } @@ -40,6 +41,7 @@ where T: CloneIn<'new_alloc, Cloned = C>, { type Cloned = Box<'new_alloc, C>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { Box::new_in(self.as_ref().clone_in(allocator), allocator) } @@ -50,6 +52,7 @@ where T: CloneIn<'new_alloc, Cloned = C>, { type Cloned = Vec<'new_alloc, C>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { Vec::from_iter_in(self.iter().map(|it| it.clone_in(allocator)), allocator) } @@ -57,6 +60,7 @@ where impl<'alloc, T: Copy> CloneIn<'alloc> for Cell { type Cloned = Cell; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { Cell::new(self.get()) } @@ -64,6 +68,7 @@ impl<'alloc, T: Copy> CloneIn<'alloc> for Cell { impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for &'old_alloc str { type Cloned = &'new_alloc str; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { allocator.alloc_str(self) } diff --git a/crates/oxc_allocator/src/vec.rs b/crates/oxc_allocator/src/vec.rs index a31e927c6e0edc..6220bbf23fd57a 100644 --- a/crates/oxc_allocator/src/vec.rs +++ b/crates/oxc_allocator/src/vec.rs @@ -123,9 +123,8 @@ impl<'alloc, T: Hash> Hash for Vec<'alloc, T> { #[cfg(test)] mod test { - use crate::Allocator; - use super::Vec; + use crate::Allocator; #[test] fn vec_debug() { diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 91be58de65ef77..15b58056816b7a 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -18,15 +18,13 @@ use oxc_syntax::{ scope::ScopeId, symbol::SymbolId, }; - -use super::macros::inherit_variants; -use super::*; - #[cfg(feature = "serialize")] use serde::Serialize; #[cfg(feature = "serialize")] use tsify::Tsify; +use super::{macros::inherit_variants, *}; + /// Represents the root of a JavaScript abstract syntax tree (AST), containing metadata about the source, directives, top-level statements, and scope information. #[ast(visit)] #[scope( diff --git a/crates/oxc_ast/src/ast/mod.rs b/crates/oxc_ast/src/ast/mod.rs index a02fbf82d51de9..3370e1c2314086 100644 --- a/crates/oxc_ast/src/ast/mod.rs +++ b/crates/oxc_ast/src/ast/mod.rs @@ -182,9 +182,6 @@ pub(crate) mod macros; pub(crate) mod ts; use macros::inherit_variants; - -pub use self::{js::*, jsx::*, literal::*, ts::*}; - // Re-export AST types from other crates pub use oxc_span::{Atom, Language, LanguageVariant, ModuleKind, SourceType, Span}; pub use oxc_syntax::{ @@ -193,3 +190,5 @@ pub use oxc_syntax::{ AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator, }, }; + +pub use self::{js::*, jsx::*, literal::*, ts::*}; diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index f9f198d35dc398..e487e9773faddc 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -1,5 +1,3 @@ -use crate::ast::*; - use std::{borrow::Cow, cell::Cell, fmt}; use oxc_allocator::{Box, FromIn, Vec}; @@ -8,6 +6,8 @@ use oxc_syntax::{ operator::UnaryOperator, reference::ReferenceId, scope::ScopeFlags, symbol::SymbolId, }; +use crate::ast::*; + #[cfg(feature = "serialize")] #[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)] const TS_APPEND_CONTENT: &'static str = r#" @@ -1079,6 +1079,7 @@ impl<'a> FormalParameters<'a> { pub fn is_empty(&self) -> bool { self.items.is_empty() } + pub fn has_parameter(&self) -> bool { !self.is_empty() || self.rest.is_some() } @@ -1427,6 +1428,7 @@ impl<'a> ImportDeclarationSpecifier<'a> { ImportDeclarationSpecifier::ImportDefaultSpecifier(specifier) => &specifier.local, } } + pub fn name(&self) -> Cow<'a, str> { Cow::Borrowed(self.local().name.as_str()) } diff --git a/crates/oxc_ast/src/ast_impl/jsx.rs b/crates/oxc_ast/src/ast_impl/jsx.rs index e62f6640fa5142..d8b6503b1b814c 100644 --- a/crates/oxc_ast/src/ast_impl/jsx.rs +++ b/crates/oxc_ast/src/ast_impl/jsx.rs @@ -1,9 +1,11 @@ //! [JSX](https://facebook.github.io/jsx) -use crate::ast::*; -use oxc_span::{Atom, Span}; use std::fmt; +use oxc_span::{Atom, Span}; + +use crate::ast::*; + // 1.2 JSX Elements impl<'a> JSXIdentifier<'a> { @@ -91,6 +93,7 @@ impl<'a> JSXAttributeName<'a> { Self::NamespacedName(_) => None, } } + pub fn get_identifier(&self) -> &JSXIdentifier<'a> { match self { Self::Identifier(ident) => ident.as_ref(), diff --git a/crates/oxc_ast/src/ast_impl/literal.rs b/crates/oxc_ast/src/ast_impl/literal.rs index 3d968a433d3a02..982fecdaed1d6b 100644 --- a/crates/oxc_ast/src/ast_impl/literal.rs +++ b/crates/oxc_ast/src/ast_impl/literal.rs @@ -3,8 +3,6 @@ // Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]` #![allow(non_snake_case)] -use crate::ast::*; - use std::{ borrow::Cow, fmt, @@ -16,6 +14,8 @@ use oxc_regular_expression::ast::Pattern; use oxc_span::{cmp::ContentEq, hash::ContentHash, Atom, Span}; use oxc_syntax::number::NumberBase; +use crate::ast::*; + impl BooleanLiteral { pub fn new(span: Span, value: bool) -> Self { Self { span, value } @@ -187,6 +187,7 @@ impl ContentHash for RegExpFlags { impl<'alloc> CloneIn<'alloc> for RegExpFlags { type Cloned = Self; + fn clone_in(&self, _: &'alloc oxc_allocator::Allocator) -> Self::Cloned { *self } diff --git a/crates/oxc_ast/src/lib.rs b/crates/oxc_ast/src/lib.rs index e8cc9c1bd4e148..72469eef6623ed 100644 --- a/crates/oxc_ast/src/lib.rs +++ b/crates/oxc_ast/src/lib.rs @@ -51,13 +51,10 @@ mod generated { } pub mod visit { - pub use crate::generated::visit::*; - pub use crate::generated::visit_mut::*; + pub use crate::generated::{visit::*, visit_mut::*}; } -pub use generated::ast_builder; -pub use generated::ast_kind; - +pub use generated::{ast_builder, ast_kind}; pub use num_bigint::BigUint; pub use crate::{ diff --git a/crates/oxc_codegen/src/annotation_comment.rs b/crates/oxc_codegen/src/annotation_comment.rs index 1525692f2abcb1..257ffebce4dbf3 100644 --- a/crates/oxc_codegen/src/annotation_comment.rs +++ b/crates/oxc_codegen/src/annotation_comment.rs @@ -34,6 +34,7 @@ impl AnnotationComment { pub fn span(&self) -> Span { self.comment.span } + pub fn kind(&self) -> CommentKind { self.comment.kind } diff --git a/crates/oxc_codegen/src/binary_expr_visitor.rs b/crates/oxc_codegen/src/binary_expr_visitor.rs index 1165ad8ca8481d..8f48c8ed6f1523 100644 --- a/crates/oxc_codegen/src/binary_expr_visitor.rs +++ b/crates/oxc_codegen/src/binary_expr_visitor.rs @@ -4,8 +4,10 @@ use std::ops::Not; use oxc_ast::ast::{BinaryExpression, Expression, LogicalExpression}; -use oxc_syntax::operator::{BinaryOperator, LogicalOperator}; -use oxc_syntax::precedence::{GetPrecedence, Precedence}; +use oxc_syntax::{ + operator::{BinaryOperator, LogicalOperator}, + precedence::{GetPrecedence, Precedence}, +}; use crate::{ gen::{Gen, GenExpr}, diff --git a/crates/oxc_codegen/src/lib.rs b/crates/oxc_codegen/src/lib.rs index 6f977574e3eb85..c2516e0a14d2c2 100644 --- a/crates/oxc_codegen/src/lib.rs +++ b/crates/oxc_codegen/src/lib.rs @@ -25,6 +25,7 @@ use oxc_syntax::{ }; use rustc_hash::FxHashMap; +use self::annotation_comment::AnnotationComment; use crate::{ binary_expr_visitor::BinaryExpressionVisitor, operator::Operator, sourcemap_builder::SourcemapBuilder, @@ -34,8 +35,6 @@ pub use crate::{ gen::{Gen, GenExpr}, }; -use self::annotation_comment::AnnotationComment; - /// Code generator without whitespace removal. pub type CodeGenerator<'a> = Codegen<'a>; @@ -563,6 +562,7 @@ impl<'a> Codegen<'a> { ) -> impl DoubleEndedIterator + '_ { self.trivias.comments_range(start..end) } + /// In some scenario, we want to move the comment that should be codegened to another position. /// ```js /// /* @__NO_SIDE_EFFECTS__ */ export const a = function() { diff --git a/crates/oxc_codegen/src/sourcemap_builder.rs b/crates/oxc_codegen/src/sourcemap_builder.rs index f8142321ecf787..31ddb113d75888 100644 --- a/crates/oxc_codegen/src/sourcemap_builder.rs +++ b/crates/oxc_codegen/src/sourcemap_builder.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use nonmax::NonMaxU32; - use oxc_index::{Idx, IndexVec}; use oxc_span::Span; use oxc_syntax::identifier::{LS, PS}; diff --git a/crates/oxc_codegen/tests/integration/esbuild.rs b/crates/oxc_codegen/tests/integration/esbuild.rs index 73ca1c5d5df58f..0b52ce294304bf 100644 --- a/crates/oxc_codegen/tests/integration/esbuild.rs +++ b/crates/oxc_codegen/tests/integration/esbuild.rs @@ -990,16 +990,26 @@ fn test_avoid_slash_script() { test("/*! \";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\"])));\n"); - test( "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\", \"\"])), a);\n"); - test( "String.raw`${a}\";\nvar _a;\nString.raw(_a || (_a = __template([\"\", \"<\\/script\"])), a);\n"); - test( "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/SCRIPT\"])));\n"); - test( "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/ScRiPt\"])));\n"); + test( + "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\"])));\n", + ); + test( + "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/script\", \"\"])), a);\n", + ); + test( + "String.raw`${a}\";\nvar _a;\nString.raw(_a || (_a = __template([\"\", \"<\\/script\"])), a);\n", + ); + test( + "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/SCRIPT\"])));\n", + ); + test( + "String.raw`\";\nvar _a;\nString.raw(_a || (_a = __template([\"<\\/ScRiPt\"])));\n", + ); // Negative cases test("x = ';", "d = x satisfies y;", "export @x declare abstract class C {}", - "div``" + "div``", ]; let snapshot = cases.into_iter().fold(String::new(), |mut w, case| { diff --git a/crates/oxc_diagnostics/src/lib.rs b/crates/oxc_diagnostics/src/lib.rs index 8f14a93bbd2be9..1b837344b040a6 100644 --- a/crates/oxc_diagnostics/src/lib.rs +++ b/crates/oxc_diagnostics/src/lib.rs @@ -108,6 +108,7 @@ impl Diagnostic for OxcDiagnostic { fn code<'a>(&'a self) -> Option> { self.code.is_some().then(|| Box::new(&self.code) as Box) } + fn url<'a>(&'a self) -> Option> { self.url.as_ref().map(Box::new).map(|c| c as Box) } diff --git a/crates/oxc_index/src/rayon_impl.rs b/crates/oxc_index/src/rayon_impl.rs index 36cc42e2513462..fcd18c756674b4 100644 --- a/crates/oxc_index/src/rayon_impl.rs +++ b/crates/oxc_index/src/rayon_impl.rs @@ -3,19 +3,21 @@ #![allow(clippy::manual_assert)] /// Disabled lint since we copy code from https://github.com/rayon-rs/rayon/blob/97c1133c2366a301a2d4ab35cf686bca7f74830f/src/vec.rs#L1-L284 use alloc::vec::Vec; -use core::iter; -use core::mem; -use core::ops::{Range, RangeBounds}; -use core::ptr; -use core::slice; -use rayon::iter::plumbing::{bridge, Consumer, Producer, ProducerCallback, UnindexedConsumer}; -use rayon::iter::{ - IndexedParallelIterator, IntoParallelIterator, ParallelDrainRange, ParallelIterator, +use core::{ + iter, mem, + ops::{Range, RangeBounds}, + ptr, slice, }; -use rayon::slice::{Iter, IterMut}; -use crate::Idx; -use crate::IndexVec; +use rayon::{ + iter::{ + plumbing::{bridge, Consumer, Producer, ProducerCallback, UnindexedConsumer}, + IndexedParallelIterator, IntoParallelIterator, ParallelDrainRange, ParallelIterator, + }, + slice::{Iter, IterMut}, +}; + +use crate::{Idx, IndexVec}; impl<'data, I: Idx, T: Sync + 'data> IntoParallelIterator for &'data IndexVec { type Item = &'data T; @@ -87,8 +89,8 @@ impl IndexedParallelIterator for IntoIter { } impl<'data, I: Idx, T: Send> ParallelDrainRange for &'data mut IndexVec { - type Iter = Drain<'data, T>; type Item = T; + type Iter = Drain<'data, T>; fn par_drain>(self, range: R) -> Self::Iter { Drain { orig_len: self.len(), range: simplify_range(range, self.len()), vec: &mut self.raw } @@ -202,8 +204,8 @@ impl DrainProducer<'_, T> { } impl<'data, T: 'data + Send> Producer for DrainProducer<'data, T> { - type Item = T; type IntoIter = SliceDrain<'data, T>; + type Item = T; fn into_iter(mut self) -> Self::IntoIter { // replace the slice so we don't drop it twice diff --git a/crates/oxc_isolated_declarations/tests/deno/mod.rs b/crates/oxc_isolated_declarations/tests/deno/mod.rs index fcfea244053ebb..2f9f110837eebe 100644 --- a/crates/oxc_isolated_declarations/tests/deno/mod.rs +++ b/crates/oxc_isolated_declarations/tests/deno/mod.rs @@ -223,15 +223,15 @@ export function foo(a: any): number { ); transform_dts_test( - "export const foo = { str: \"bar\", bool: true, bool2: false, num: 42, nullish: null } as const;", - "export declare const foo: { + "export const foo = { str: \"bar\", bool: true, bool2: false, num: 42, nullish: null } as const;", + "export declare const foo: { readonly str: \"bar\"; readonly bool: true; readonly bool2: false; readonly num: 42; readonly nullish: null; };", - ); + ); transform_dts_test( "export const foo = { str: [1, 2] as const } as const;", diff --git a/crates/oxc_linter/src/ast_util.rs b/crates/oxc_linter/src/ast_util.rs index 726ff94656203f..127fcc26d45966 100644 --- a/crates/oxc_linter/src/ast_util.rs +++ b/crates/oxc_linter/src/ast_util.rs @@ -1,7 +1,6 @@ use core::hash::Hasher; -use oxc_ast::ast::BindingIdentifier; -use oxc_ast::AstKind; +use oxc_ast::{ast::BindingIdentifier, AstKind}; use oxc_semantic::{AstNode, AstNodeId, SymbolId}; use oxc_span::{hash::ContentHash, GetSpan, Span}; use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator}; diff --git a/crates/oxc_linter/src/config/env.rs b/crates/oxc_linter/src/config/env.rs index ee1bd9e6c871a3..02ca9aebe0df7b 100644 --- a/crates/oxc_linter/src/config/env.rs +++ b/crates/oxc_linter/src/config/env.rs @@ -1,7 +1,8 @@ +use std::{borrow::Borrow, hash::Hash}; + use rustc_hash::FxHashMap; use schemars::JsonSchema; use serde::Deserialize; -use std::{borrow::Borrow, hash::Hash}; /// Predefine global variables. /// diff --git a/crates/oxc_linter/src/config/globals.rs b/crates/oxc_linter/src/config/globals.rs index 0b7440ab2e0aea..419703bb994bba 100644 --- a/crates/oxc_linter/src/config/globals.rs +++ b/crates/oxc_linter/src/config/globals.rs @@ -1,7 +1,8 @@ +use std::{borrow, fmt, hash}; + use rustc_hash::FxHashMap; use schemars::JsonSchema; use serde::{de::Visitor, Deserialize}; -use std::{borrow, fmt, hash}; /// Add or remove global variables. /// @@ -122,9 +123,10 @@ impl<'de> Visitor<'de> for GlobalValueVisitor { #[cfg(test)] mod test { - use super::*; use serde_json::json; + use super::*; + macro_rules! globals { ($($json:tt)+) => { OxlintGlobals::deserialize(&json!($($json)+)).unwrap() diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index 816fe04a878144..9e1b7d424cad75 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -195,9 +195,8 @@ mod test { use rustc_hash::FxHashSet; use serde::Deserialize; - use crate::rules::RULES; - use super::OxlintConfig; + use crate::rules::RULES; #[test] fn test_from_file() { diff --git a/crates/oxc_linter/src/config/settings/jsdoc.rs b/crates/oxc_linter/src/config/settings/jsdoc.rs index 8b1c47c10203d9..50b0a0314771cb 100644 --- a/crates/oxc_linter/src/config/settings/jsdoc.rs +++ b/crates/oxc_linter/src/config/settings/jsdoc.rs @@ -1,10 +1,11 @@ use std::borrow::Cow; -use crate::utils::default_true; use rustc_hash::FxHashMap; use schemars::JsonSchema; use serde::Deserialize; +use crate::utils::default_true; + // #[derive(Debug, Deserialize, JsonSchema)] pub struct JSDocPluginSettings { @@ -196,9 +197,10 @@ enum TagNamePreference { #[cfg(test)] mod test { - use serde::Deserialize; use std::borrow::Cow; + use serde::Deserialize; + use super::JSDocPluginSettings; #[test] diff --git a/crates/oxc_linter/src/config/settings/mod.rs b/crates/oxc_linter/src/config/settings/mod.rs index e3ff653e8119ec..9d61c49c088522 100644 --- a/crates/oxc_linter/src/config/settings/mod.rs +++ b/crates/oxc_linter/src/config/settings/mod.rs @@ -35,9 +35,8 @@ mod test { use oxc_span::CompactStr; use serde::Deserialize; - use crate::config::settings::react::ComponentAttrs; - use super::OxlintSettings; + use crate::config::settings::react::ComponentAttrs; fn as_attrs, I: IntoIterator>( attrs: I, diff --git a/crates/oxc_linter/src/config/settings/react.rs b/crates/oxc_linter/src/config/settings/react.rs index 71fec9c9468ea0..eeed7115f0c07d 100644 --- a/crates/oxc_linter/src/config/settings/react.rs +++ b/crates/oxc_linter/src/config/settings/react.rs @@ -53,7 +53,7 @@ fn get_component_attrs_by_name<'c>( for item in components { match item { CustomComponent::NameOnly(comp_name) if comp_name == name => { - return Some(Cow::Owned(vec![])) + return Some(Cow::Owned(vec![])); } CustomComponent::ObjectWithOneAttr { name: comp_name, attribute } if comp_name == name => diff --git a/crates/oxc_linter/src/context.rs b/crates/oxc_linter/src/context.rs index 941066f0eb0fc9..2acf631e493e06 100644 --- a/crates/oxc_linter/src/context.rs +++ b/crates/oxc_linter/src/context.rs @@ -62,6 +62,7 @@ pub struct LintContext<'a> { impl<'a> LintContext<'a> { const WEBSITE_BASE_URL: &'static str = "https://oxc.rs/docs/guide/usage/linter/rules"; + /// # Panics /// If `semantic.cfg()` is `None`. pub fn new(file_path: Box, semantic: Rc>) -> Self { diff --git a/crates/oxc_linter/src/fixer/fix.rs b/crates/oxc_linter/src/fixer/fix.rs index 9d42dd7b9b841f..37d5f25ee46e4e 100644 --- a/crates/oxc_linter/src/fixer/fix.rs +++ b/crates/oxc_linter/src/fixer/fix.rs @@ -261,6 +261,7 @@ impl GetSpan for RuleFix<'_> { impl<'a> Deref for RuleFix<'a> { type Target = CompositeFix<'a>; + fn deref(&self) -> &Self::Target { &self.fix } @@ -407,7 +408,10 @@ impl<'a> CompositeFix<'a> { Self::None => 0, Self::Single(_) => 1, Self::Multiple(fs) => { - debug_assert!(fs.len() > 1, "Single-element or empty composite fix vecs should have been turned into CompositeFix::None or CompositeFix::Single"); + debug_assert!( + fs.len() > 1, + "Single-element or empty composite fix vecs should have been turned into CompositeFix::None or CompositeFix::Single" + ); fs.len() } } @@ -427,6 +431,7 @@ impl<'a> CompositeFix<'a> { } } } + // TODO: do we want this? // pub fn extend(&mut self, fix: CompositeFix<'a>) { // match self { @@ -460,6 +465,7 @@ impl<'a> CompositeFix<'a> { CompositeFix::None => Fix::empty(), } } + /// Merges multiple fixes to one, returns an [`Fix::empty`] (which will not fix anything) if: /// /// 1. `fixes` is empty diff --git a/crates/oxc_linter/src/fixer/mod.rs b/crates/oxc_linter/src/fixer/mod.rs index 88e644ac796e4e..5e572c845e911d 100644 --- a/crates/oxc_linter/src/fixer/mod.rs +++ b/crates/oxc_linter/src/fixer/mod.rs @@ -2,14 +2,13 @@ mod fix; use std::borrow::Cow; +pub use fix::{CompositeFix, Fix, FixKind, RuleFix}; use oxc_codegen::{CodeGenerator, CodegenOptions}; use oxc_diagnostics::OxcDiagnostic; use oxc_span::{GetSpan, Span}; use crate::LintContext; -pub use fix::{CompositeFix, Fix, FixKind, RuleFix}; - /// Produces [`RuleFix`] instances. Inspired by ESLint's [`RuleFixer`]. /// /// [`RuleFixer`]: https://github.com/eslint/eslint/blob/main/lib/linter/rule-fixer.js diff --git a/crates/oxc_linter/src/frameworks.rs b/crates/oxc_linter/src/frameworks.rs index c0451940fae696..77d34ec98605ec 100644 --- a/crates/oxc_linter/src/frameworks.rs +++ b/crates/oxc_linter/src/frameworks.rs @@ -1,6 +1,7 @@ +use std::{hash, path::Path}; + use bitflags::bitflags; use oxc_semantic::ModuleRecord; -use std::{hash, path::Path}; bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/oxc_linter/src/options/mod.rs b/crates/oxc_linter/src/options/mod.rs index 348949bb708384..5e42cda837e1d8 100644 --- a/crates/oxc_linter/src/options/mod.rs +++ b/crates/oxc_linter/src/options/mod.rs @@ -3,7 +3,9 @@ mod plugins; use std::{convert::From, path::PathBuf}; +pub use allow_warn_deny::AllowWarnDeny; use oxc_diagnostics::Error; +pub use plugins::LintPluginOptions; use rustc_hash::FxHashSet; use crate::{ @@ -11,9 +13,6 @@ use crate::{ FrameworkFlags, RuleCategory, RuleEnum, RuleWithSeverity, }; -pub use allow_warn_deny::AllowWarnDeny; -pub use plugins::LintPluginOptions; - #[derive(Debug)] pub struct LintOptions { /// Allow / Deny rules in order. [("allow" / "deny", rule name)] diff --git a/crates/oxc_linter/src/rule.rs b/crates/oxc_linter/src/rule.rs index f30f6ab72e6479..93885ab4e4f818 100644 --- a/crates/oxc_linter/src/rule.rs +++ b/crates/oxc_linter/src/rule.rs @@ -203,6 +203,7 @@ impl RuleFixMeta { } } } + pub fn emoji(self) -> Option<&'static str> { match self { Self::None => None, @@ -254,9 +255,10 @@ impl RuleWithSeverity { #[cfg(test)] mod test { - use crate::rules::RULES; use markdown::{to_html_with_options, Options}; + use crate::rules::RULES; + #[test] fn ensure_documentation() { assert!(!RULES.is_empty()); diff --git a/crates/oxc_linter/src/rules/eslint/func_names.rs b/crates/oxc_linter/src/rules/eslint/func_names.rs index 1e805c0123aad5..4b3607a59c8b30 100644 --- a/crates/oxc_linter/src/rules/eslint/func_names.rs +++ b/crates/oxc_linter/src/rules/eslint/func_names.rs @@ -1,10 +1,12 @@ use std::borrow::Cow; -use oxc_ast::ast::{ - AssignmentTarget, AssignmentTargetProperty, BindingPatternKind, Expression, Function, - FunctionType, MethodDefinitionKind, PropertyKey, PropertyKind, +use oxc_ast::{ + ast::{ + AssignmentTarget, AssignmentTargetProperty, BindingPatternKind, Expression, Function, + FunctionType, MethodDefinitionKind, PropertyKey, PropertyKind, + }, + AstKind, }; -use oxc_ast::AstKind; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::AstNodeId; @@ -485,10 +487,10 @@ fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: AstNodeId) -> Optio | AstKind::TSNonNullExpression(_) | AstKind::TSSatisfiesExpression(_) => continue, AstKind::AssignmentExpression(assign) => { - return assign.left.get_identifier().map(Cow::Borrowed) + return assign.left.get_identifier().map(Cow::Borrowed); } AstKind::VariableDeclarator(decl) => { - return decl.id.get_identifier().as_ref().map(Atom::as_str).map(Cow::Borrowed) + return decl.id.get_identifier().as_ref().map(Atom::as_str).map(Cow::Borrowed); } AstKind::ObjectProperty(prop) => { return prop.key.static_name().and_then(|name| { @@ -497,7 +499,7 @@ fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: AstNodeId) -> Optio } else { None } - }) + }); } AstKind::PropertyDefinition(prop) => { return prop.key.static_name().and_then(|name| { @@ -506,7 +508,7 @@ fn guess_function_name<'a>(ctx: &LintContext<'a>, parent_id: AstNodeId) -> Optio } else { None } - }) + }); } _ => return None, } @@ -532,9 +534,10 @@ fn is_valid_identifier_name(name: &str) -> bool { #[test] fn test() { - use crate::tester::Tester; use serde_json::json; + use crate::tester::Tester; + let always = Some(json!(["always"])); let as_needed = Some(json!(["as-needed"])); let never = Some(json!(["never"])); @@ -679,8 +682,7 @@ fn test() { ("class C { foo = function bar() {} }", never.clone()), // { "ecmaVersion": 2022 } ]; - let fix = - vec![ + let fix = vec![ // lb ("const foo = function() {}", "const foo = function foo() {}", always.clone()), ( @@ -784,16 +786,18 @@ fn test() { "const foo = async function* foo(){}", always.clone(), ), - // we can't fix this case because adding a name would cause the - ("const setState = Component.prototype.setState; + // we can't fix this case because adding a name would cause the + ( + "const setState = Component.prototype.setState; Component.prototype.setState = function (update, callback) { return setState.call(this, update, callback); };", - "const setState = Component.prototype.setState; + "const setState = Component.prototype.setState; Component.prototype.setState = function (update, callback) { return setState.call(this, update, callback); };", - always.clone(),), + always.clone(), + ), ]; Tester::new(FuncNames::NAME, pass, fail).expect_fix(fix).test_and_snapshot(); diff --git a/crates/oxc_linter/src/rules/eslint/getter_return.rs b/crates/oxc_linter/src/rules/eslint/getter_return.rs index 3b1b4a6439d6ca..f16d40969fe1a1 100644 --- a/crates/oxc_linter/src/rules/eslint/getter_return.rs +++ b/crates/oxc_linter/src/rules/eslint/getter_return.rs @@ -466,15 +466,19 @@ fn test() { ), ("var foo = { get bar() { try { return a(); } catch {} } };", None), ("var foo = { get bar() { try { return a(); } catch { } finally { } } };", None), - (" + ( + " var foo = { get bar() { for (let i = 0; i<10; i++) { return i; } } - }", None), - (" + }", + None, + ), + ( + " var foo = { get bar() { let i = 0; @@ -482,7 +486,9 @@ fn test() { return i; } } - }", None), + }", + None, + ), ]; Tester::new(GetterReturn::NAME, pass, fail) diff --git a/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs b/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs index ce71ffa0ac37b4..a3ea2f037d3cb9 100644 --- a/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs +++ b/crates/oxc_linter/src/rules/eslint/no_obj_calls.rs @@ -116,7 +116,7 @@ fn resolve_global_binding<'a, 'b: 'a>( } // handles "let a = globalThis.JSON; let b = a; a();" Some(parent_expr) if parent_expr.is_member_expression() => { - return global_this_member(parent_expr.to_member_expression()) + return global_this_member(parent_expr.to_member_expression()); } _ => None, } diff --git a/crates/oxc_linter/src/rules/eslint/no_undef.rs b/crates/oxc_linter/src/rules/eslint/no_undef.rs index 2383aa970e491e..d36b103e09865a 100644 --- a/crates/oxc_linter/src/rules/eslint/no_undef.rs +++ b/crates/oxc_linter/src/rules/eslint/no_undef.rs @@ -156,7 +156,7 @@ fn test() { "class C { static { a; let a; } }", "class C { static { function a() {} a; } }", "class C { static { a; function a() {} } }", - "String;Array;Boolean;" + "String;Array;Boolean;", ]; let fail = vec![ diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs index 1199491f022bcd..66a405bca59c87 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs @@ -5,9 +5,8 @@ use oxc_ast::{ast::*, AstKind}; use oxc_semantic::{AstNode, AstNodeId, Semantic}; use oxc_span::GetSpan; -use crate::rules::eslint::no_unused_vars::binding_pattern::{BindingContext, HasAnyUsedBinding}; - use super::{options::ArgsOption, NoUnusedVars, Symbol}; +use crate::rules::eslint::no_unused_vars::binding_pattern::{BindingContext, HasAnyUsedBinding}; impl<'s, 'a> Symbol<'s, 'a> { /// Returns `true` if this function is use. @@ -87,7 +86,7 @@ impl<'s, 'a> Symbol<'s, 'a> { return b .body .first() - .is_some_and(|s| matches!(s, Statement::ReturnStatement(_))) + .is_some_and(|s| matches!(s, Statement::ReturnStatement(_))); } _ => return false, }, diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/binding_pattern.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/binding_pattern.rs index b1cf3cccfff7e0..73b2e26d0e9a51 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/binding_pattern.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/binding_pattern.rs @@ -14,6 +14,7 @@ impl<'s, 'a> BindingContext<'s, 'a> { pub fn symbol(&self, symbol_id: SymbolId) -> Symbol<'s, 'a> { Symbol::new(self.semantic, symbol_id) } + #[inline] pub fn has_usages(&self, symbol_id: SymbolId) -> bool { self.symbol(symbol_id).has_usages(self.options) diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs index d067d65edc54d8..b37af6435788f8 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs @@ -1,9 +1,10 @@ -use super::Symbol; -use crate::fixer::{Fix, RuleFix, RuleFixer}; #[allow(clippy::wildcard_imports)] use oxc_ast::{ast::*, AstKind}; use oxc_span::{CompactStr, GetSpan, Span}; +use super::Symbol; +use crate::fixer::{Fix, RuleFix, RuleFixer}; + impl<'s, 'a> Symbol<'s, 'a> { /// Delete a single declarator from a [`VariableDeclaration`] list with more /// than one declarator. diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_vars.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_vars.rs index 058d4810d792d6..dbe187f3c79b0d 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_vars.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_vars.rs @@ -44,7 +44,9 @@ impl NoUnusedVars { AstKind::VariableDeclaration(decl) => (decl.span, &decl.declarations), _ => { #[cfg(debug_assertions)] - panic!("VariableDeclarator nodes should always be direct children of VariableDeclaration nodes"); + panic!( + "VariableDeclarator nodes should always be direct children of VariableDeclaration nodes" + ); #[cfg(not(debug_assertions))] return fixer.noop(); } diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/mod.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/mod.rs index 01c3a985e1d669..8e4901ddc82000 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/mod.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/mod.rs @@ -2,10 +2,10 @@ mod fix_imports; mod fix_symbol; mod fix_vars; -use super::{NoUnusedVars, Symbol}; - use fix_symbol::BindingInfo; +use super::{NoUnusedVars, Symbol}; + // source text will never be large enough for this usize to be truncated when // getting cast to a u32 #[allow(clippy::cast_possible_truncation)] diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/ignored.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/ignored.rs index 12623015bd5baa..e6c313af6b0dd0 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/ignored.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/ignored.rs @@ -1,4 +1,3 @@ -use super::{NoUnusedVars, Symbol}; use oxc_ast::{ ast::{ ArrayAssignmentTarget, AssignmentTarget, AssignmentTargetMaybeDefault, @@ -9,6 +8,8 @@ use oxc_ast::{ }; use regex::Regex; +use super::{NoUnusedVars, Symbol}; + #[derive(Debug, Default, Clone, Copy)] pub(super) enum FoundStatus { /// The target identifier was not found @@ -342,10 +343,10 @@ impl NoUnusedVars { #[cfg(test)] mod test { - use crate::rule::Rule as _; + use oxc_span::Atom; use super::super::NoUnusedVars; - use oxc_span::Atom; + use crate::rule::Rule as _; #[test] fn test_ignored() { diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs index 13cc2f12525c29..e3726233226654 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs @@ -11,15 +11,14 @@ mod usage; use std::ops::Deref; +use options::NoUnusedVarsOptions; use oxc_ast::AstKind; use oxc_macros::declare_oxc_lint; use oxc_semantic::{AstNode, ScopeFlags, SymbolFlags, SymbolId}; use oxc_span::GetSpan; +use symbol::Symbol; use crate::{context::LintContext, rule::Rule}; -use options::NoUnusedVarsOptions; - -use symbol::Symbol; #[derive(Debug, Default, Clone)] pub struct NoUnusedVars(Box); diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/options.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/options.rs index 7042cc48e08405..0c4ac93e358f42 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/options.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/options.rs @@ -257,10 +257,12 @@ impl ArgsOption { pub const fn is_after_used(&self) -> bool { matches!(self, Self::AfterUsed) } + #[inline] pub const fn is_all(&self) -> bool { matches!(self, Self::All) } + #[inline] pub const fn is_none(&self) -> bool { matches!(self, Self::None) @@ -281,6 +283,7 @@ impl CaughtErrors { pub const fn all() -> Self { Self(true) } + pub const fn none() -> Self { Self(false) } @@ -407,18 +410,14 @@ impl From for NoUnusedVarsOptions { let Some(config) = value.get(0) else { return Self::default() }; match config { Value::String(vars) => { - let vars: VarsOption = vars - .try_into() - .unwrap(); + let vars: VarsOption = vars.try_into().unwrap(); Self { vars, ..Default::default() } } Value::Object(config) => { let vars = config .get("vars") .map(|vars| { - let vars: VarsOption = vars - .try_into() - .unwrap(); + let vars: VarsOption = vars.try_into().unwrap(); vars }) .unwrap_or_default(); @@ -432,9 +431,7 @@ impl From for NoUnusedVarsOptions { let args: ArgsOption = config .get("args") .map(|args| { - let args: ArgsOption = args - .try_into() - .unwrap(); + let args: ArgsOption = args.try_into().unwrap(); args }) .unwrap_or_default(); @@ -445,9 +442,7 @@ impl From for NoUnusedVarsOptions { let caught_errors: CaughtErrors = config .get("caughtErrors") .map(|caught_errors| { - let caught_errors: CaughtErrors = caught_errors - .try_into() - .unwrap(); + let caught_errors: CaughtErrors = caught_errors.try_into().unwrap(); caught_errors }) .unwrap_or_default(); @@ -487,7 +482,7 @@ impl From for NoUnusedVarsOptions { caught_errors_ignore_pattern, destructured_array_ignore_pattern, ignore_class_with_static_init_block, - report_used_ignore_pattern + report_used_ignore_pattern, } } Value::Null => Self::default(), diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs index 3c55961d83064e..12594f8692fa8d 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs @@ -1,8 +1,10 @@ -use oxc_ast::ast::{ImportDeclarationSpecifier, VariableDeclarator}; use std::{cell::OnceCell, fmt}; use oxc_ast::{ - ast::{AssignmentTarget, BindingIdentifier, BindingPattern, IdentifierReference}, + ast::{ + AssignmentTarget, BindingIdentifier, BindingPattern, IdentifierReference, + ImportDeclarationSpecifier, VariableDeclarator, + }, AstKind, }; use oxc_semantic::{ diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/eslint.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/eslint.rs index 34c4856e682684..61302856e6dca1 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/eslint.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/eslint.rs @@ -1,8 +1,7 @@ //! Test cases from vanilla eslint -use crate::{tester::Tester, RuleMeta as _}; - use super::NoUnusedVars; +use crate::{tester::Tester, RuleMeta as _}; /// These are tests from ESLint that are not passing. If you make a change that /// causes this test to fail, that's a good thing! @@ -30,127 +29,209 @@ fn fixme() { #[test] fn test() { let pass = vec![ - ("var foo = 5; + ( + "var foo = 5; label: while (true) { console.log(foo); break label; - }", None), -("var foo = 5; + }", + None, + ), + ( + "var foo = 5; while (true) { console.log(foo); break; - }", None), -("for (let prop in box) { + }", + None, + ), + ( + "for (let prop in box) { box[prop] = parseInt(box[prop]); - }", None), // { "ecmaVersion": 6 }, -("var box = {a: 2}; + }", + None, + ), // { "ecmaVersion": 6 }, + ( + "var box = {a: 2}; for (var prop in box) { box[prop] = parseInt(box[prop]); - }", None), -("f({ set foo(a) { return; } });", None), -("a; var a;", Some(serde_json::json!(["all"]))), -("var a=10; alert(a);", Some(serde_json::json!(["all"]))), -("var a=10; (function() { alert(a); })();", Some(serde_json::json!(["all"]))), -("var a=10; (function() { setTimeout(function() { alert(a); }, 0); })();", Some(serde_json::json!(["all"]))), -("var a=10; d[a] = 0;", Some(serde_json::json!(["all"]))), -("(function() { var a=10; return a; })();", Some(serde_json::json!(["all"]))), -("(function g() {})()", Some(serde_json::json!(["all"]))), -("function f(a) {alert(a);}; f();", Some(serde_json::json!(["all"]))), -("var c = 0; function f(a){ var b = a; return b; }; f(c);", Some(serde_json::json!(["all"]))), -("function a(x, y){ return y; }; a();", Some(serde_json::json!(["all"]))), -("var arr1 = [1, 2]; var arr2 = [3, 4]; for (var i in arr1) { arr1[i] = 5; } for (var i in arr2) { arr2[i] = 10; }", Some(serde_json::json!(["all"]))), -("var a=10;", Some(serde_json::json!(["local"]))), -(r#"var min = "min"; Math[min];"#, Some(serde_json::json!(["all"]))), -("Foo.bar = function(baz) { return baz; };", Some(serde_json::json!(["all"]))), -("myFunc(function foo() {}.bind(this))", None), -("myFunc(function foo(){}.toString())", None), -("function foo(first, second) { + }", + None, + ), + ("f({ set foo(a) { return; } });", None), + ("a; var a;", Some(serde_json::json!(["all"]))), + ("var a=10; alert(a);", Some(serde_json::json!(["all"]))), + ("var a=10; (function() { alert(a); })();", Some(serde_json::json!(["all"]))), + ( + "var a=10; (function() { setTimeout(function() { alert(a); }, 0); })();", + Some(serde_json::json!(["all"])), + ), + ("var a=10; d[a] = 0;", Some(serde_json::json!(["all"]))), + ("(function() { var a=10; return a; })();", Some(serde_json::json!(["all"]))), + ("(function g() {})()", Some(serde_json::json!(["all"]))), + ("function f(a) {alert(a);}; f();", Some(serde_json::json!(["all"]))), + ( + "var c = 0; function f(a){ var b = a; return b; }; f(c);", + Some(serde_json::json!(["all"])), + ), + ("function a(x, y){ return y; }; a();", Some(serde_json::json!(["all"]))), + ( + "var arr1 = [1, 2]; var arr2 = [3, 4]; for (var i in arr1) { arr1[i] = 5; } for (var i in arr2) { arr2[i] = 10; }", + Some(serde_json::json!(["all"])), + ), + ("var a=10;", Some(serde_json::json!(["local"]))), + (r#"var min = "min"; Math[min];"#, Some(serde_json::json!(["all"]))), + ("Foo.bar = function(baz) { return baz; };", Some(serde_json::json!(["all"]))), + ("myFunc(function foo() {}.bind(this))", None), + ("myFunc(function foo(){}.toString())", None), + ( + "function foo(first, second) { doStuff(function() { - console.log(second);});}; foo()", None), -("(function() { var doSomething = function doSomething() {}; doSomething() }())", None), -// ("/*global a */ a;", None), -("var a=10; (function() { alert(a); })();", Some(serde_json::json!([{ "vars": "all" }]))), -("function g(bar, baz) { return baz; }; g();", Some(serde_json::json!([{ "vars": "all" }]))), -("function g(bar, baz) { return baz; }; g();", Some(serde_json::json!([{ "vars": "all", "args": "after-used" }]))), -("function g(bar, baz) { return bar; }; g();", Some(serde_json::json!([{ "vars": "all", "args": "none" }]))), -("function g(bar, baz) { return 2; }; g();", Some(serde_json::json!([{ "vars": "all", "args": "none" }]))), -("function g(bar, baz) { return bar + baz; }; g();", Some(serde_json::json!([{ "vars": "local", "args": "all" }]))), -("var g = function(bar, baz) { return 2; }; g();", Some(serde_json::json!([{ "vars": "all", "args": "none" }]))), -("(function z() { z(); })();", None), -(" ", None), // { "globals": { "a": true } }, -(r#"var who = "Paul"; - module.exports = `Hello ${who}!`;"#, None), // { "ecmaVersion": 6 }, -("export var foo = 123;", None), // { "ecmaVersion": 6, "sourceType": "module" }, -("export function foo () {}", None), // { "ecmaVersion": 6, "sourceType": "module" }, -("let toUpper = (partial) => partial.toUpperCase; export {toUpper}", None), // { "ecmaVersion": 6, "sourceType": "module" }, -("export class foo {}", None), // { "ecmaVersion": 6, "sourceType": "module" }, -("class Foo{}; var x = new Foo(); x.foo()", None), // { "ecmaVersion": 6 }, -(r#"const foo = "hello!";function bar(foobar = foo) { foobar.replace(/!$/, " world!");} - bar();"#, None), // { "ecmaVersion": 6 }, -("function Foo(){}; var x = new Foo(); x.foo()", None), -("function foo() {var foo = 1; return foo}; foo();", None), -("function foo(foo) {return foo}; foo(1);", None), -("function foo() {function foo() {return 1;}; return foo()}; foo();", None), -("function foo() {var foo = 1; return foo}; foo();", None), // { "ecmaVersion": 6 }, -("function foo(foo) {return foo}; foo(1);", None), // { "ecmaVersion": 6 }, -("function foo() {function foo() {return 1;}; return foo()}; foo();", None), // { "ecmaVersion": 6 }, -("const x = 1; const [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, -("const x = 1; const {y = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, -("const x = 1; const {z: [y = x]} = {}; foo(y);", None), // { "ecmaVersion": 6 }, -("const x = []; const {z: [y] = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, -("const x = 1; let y; [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, -("const x = 1; let y; ({z: [y = x]} = {}); foo(y);", None), // { "ecmaVersion": 6 }, -("const x = []; let y; ({z: [y] = x} = {}); foo(y);", None), // { "ecmaVersion": 6 }, -("const x = 1; function foo(y = x) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, -("const x = 1; function foo({y = x} = {}) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, -("const x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, -("const x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, -("var x = 1; var [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, -("var x = 1; var {y = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, -("var x = 1; var {z: [y = x]} = {}; foo(y);", None), // { "ecmaVersion": 6 }, -("var x = []; var {z: [y] = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, -("var x = 1, y; [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, -("var x = 1, y; ({z: [y = x]} = {}); foo(y);", None), // { "ecmaVersion": 6 }, -("var x = [], y; ({z: [y] = x} = {}); foo(y);", None), // { "ecmaVersion": 6 }, -("var x = 1; function foo(y = x) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, -("var x = 1; function foo({y = x} = {}) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, -("var x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, -("var x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, -// ("/*exported toaster*/ var toaster = 'great'", None), -// ("/*exported toaster, poster*/ var toaster = 1; poster = 0;", None), -// ("/*exported x*/ var { x } = y", None), // { "ecmaVersion": 6 }, -// ("/*exported x, y*/ var { x, y } = z", None), // { "ecmaVersion": 6 }, -// ("/*eslint custom/use-every-a:1*/ var a;", None), -// ("/*eslint custom/use-every-a:1*/ !function(a) { return 1; }", None), -// ("/*eslint custom/use-every-a:1*/ !function() { var a; return 1 }", None), -("var _a;", Some(serde_json::json!([{ "vars": "all", "varsIgnorePattern": "^_" }]))), -("var a; function foo() { var _b; } foo();", Some(serde_json::json!([{ "vars": "local", "varsIgnorePattern": "^_" }]))), -("function foo(_a) { } foo();", Some(serde_json::json!([{ "args": "all", "argsIgnorePattern": "^_" }]))), -("function foo(a, _b) { return a; } foo();", Some(serde_json::json!([{ "args": "after-used", "argsIgnorePattern": "^_" }]))), -("var [ firstItemIgnored, secondItem ] = items; - console.log(secondItem);", Some(serde_json::json!([{ "vars": "all", "varsIgnorePattern": "[iI]gnored" }]))), // { "ecmaVersion": 6 }, -("const [ a, _b, c ] = items; - console.log(a+c);", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -("const [ [a, _b, c] ] = items; - console.log(a+c);", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -("const { x: [_a, foo] } = bar; - console.log(foo);", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -("function baz([_b, foo]) { foo; }; - baz()", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -("function baz({x: [_b, foo]}) {foo}; - baz()", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -("function baz([{x: [_b, foo]}]) {foo}; - baz()", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -(" + console.log(second);});}; foo()", + None, + ), + ("(function() { var doSomething = function doSomething() {}; doSomething() }())", None), + // ("/*global a */ a;", None), + ("var a=10; (function() { alert(a); })();", Some(serde_json::json!([{ "vars": "all" }]))), + ( + "function g(bar, baz) { return baz; }; g();", + Some(serde_json::json!([{ "vars": "all" }])), + ), + ( + "function g(bar, baz) { return baz; }; g();", + Some(serde_json::json!([{ "vars": "all", "args": "after-used" }])), + ), + ( + "function g(bar, baz) { return bar; }; g();", + Some(serde_json::json!([{ "vars": "all", "args": "none" }])), + ), + ( + "function g(bar, baz) { return 2; }; g();", + Some(serde_json::json!([{ "vars": "all", "args": "none" }])), + ), + ( + "function g(bar, baz) { return bar + baz; }; g();", + Some(serde_json::json!([{ "vars": "local", "args": "all" }])), + ), + ( + "var g = function(bar, baz) { return 2; }; g();", + Some(serde_json::json!([{ "vars": "all", "args": "none" }])), + ), + ("(function z() { z(); })();", None), + (" ", None), // { "globals": { "a": true } }, + ( + r#"var who = "Paul"; + module.exports = `Hello ${who}!`;"#, + None, + ), // { "ecmaVersion": 6 }, + ("export var foo = 123;", None), // { "ecmaVersion": 6, "sourceType": "module" }, + ("export function foo () {}", None), // { "ecmaVersion": 6, "sourceType": "module" }, + ("let toUpper = (partial) => partial.toUpperCase; export {toUpper}", None), // { "ecmaVersion": 6, "sourceType": "module" }, + ("export class foo {}", None), // { "ecmaVersion": 6, "sourceType": "module" }, + ("class Foo{}; var x = new Foo(); x.foo()", None), // { "ecmaVersion": 6 }, + ( + r#"const foo = "hello!";function bar(foobar = foo) { foobar.replace(/!$/, " world!");} + bar();"#, + None, + ), // { "ecmaVersion": 6 }, + ("function Foo(){}; var x = new Foo(); x.foo()", None), + ("function foo() {var foo = 1; return foo}; foo();", None), + ("function foo(foo) {return foo}; foo(1);", None), + ("function foo() {function foo() {return 1;}; return foo()}; foo();", None), + ("function foo() {var foo = 1; return foo}; foo();", None), // { "ecmaVersion": 6 }, + ("function foo(foo) {return foo}; foo(1);", None), // { "ecmaVersion": 6 }, + ("function foo() {function foo() {return 1;}; return foo()}; foo();", None), // { "ecmaVersion": 6 }, + ("const x = 1; const [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = 1; const {y = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = 1; const {z: [y = x]} = {}; foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = []; const {z: [y] = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = 1; let y; [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = 1; let y; ({z: [y = x]} = {}); foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = []; let y; ({z: [y] = x} = {}); foo(y);", None), // { "ecmaVersion": 6 }, + ("const x = 1; function foo(y = x) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, + ("const x = 1; function foo({y = x} = {}) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, + ("const x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, + ("const x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, + ("var x = 1; var [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = 1; var {y = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = 1; var {z: [y = x]} = {}; foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = []; var {z: [y] = x} = {}; foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = 1, y; [y = x] = []; foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = 1, y; ({z: [y = x]} = {}); foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = [], y; ({z: [y] = x} = {}); foo(y);", None), // { "ecmaVersion": 6 }, + ("var x = 1; function foo(y = x) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, + ("var x = 1; function foo({y = x} = {}) { bar(y); } foo();", None), // { "ecmaVersion": 6 }, + ("var x = 1; function foo(y = function(z = x) { bar(z); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, + ("var x = 1; function foo(y = function() { bar(x); }) { y(); } foo();", None), // { "ecmaVersion": 6 }, + // ("/*exported toaster*/ var toaster = 'great'", None), + // ("/*exported toaster, poster*/ var toaster = 1; poster = 0;", None), + // ("/*exported x*/ var { x } = y", None), // { "ecmaVersion": 6 }, + // ("/*exported x, y*/ var { x, y } = z", None), // { "ecmaVersion": 6 }, + // ("/*eslint custom/use-every-a:1*/ var a;", None), + // ("/*eslint custom/use-every-a:1*/ !function(a) { return 1; }", None), + // ("/*eslint custom/use-every-a:1*/ !function() { var a; return 1 }", None), + ("var _a;", Some(serde_json::json!([{ "vars": "all", "varsIgnorePattern": "^_" }]))), + ( + "var a; function foo() { var _b; } foo();", + Some(serde_json::json!([{ "vars": "local", "varsIgnorePattern": "^_" }])), + ), + ( + "function foo(_a) { } foo();", + Some(serde_json::json!([{ "args": "all", "argsIgnorePattern": "^_" }])), + ), + ( + "function foo(a, _b) { return a; } foo();", + Some(serde_json::json!([{ "args": "after-used", "argsIgnorePattern": "^_" }])), + ), + ( + "var [ firstItemIgnored, secondItem ] = items; + console.log(secondItem);", + Some(serde_json::json!([{ "vars": "all", "varsIgnorePattern": "[iI]gnored" }])), + ), // { "ecmaVersion": 6 }, + ( + "const [ a, _b, c ] = items; + console.log(a+c);", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + "const [ [a, _b, c] ] = items; + console.log(a+c);", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + "const { x: [_a, foo] } = bar; + console.log(foo);", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + "function baz([_b, foo]) { foo; }; + baz()", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + "function baz({x: [_b, foo]}) {foo}; + baz()", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + "function baz([{x: [_b, foo]}]) {foo}; + baz()", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + " let _a, b; foo.forEach(item => { [_a, b] = item; doSomething(b); }); - ", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 6 }, -(" + ", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 6 }, + ( + " // doesn't report _x let _x, y; _x = 1; @@ -162,8 +243,11 @@ fn test() { [_a, b] = foo; _a = 1; b; - ", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }]))), // { "ecmaVersion": 2018 }, -(" + ", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_" }])), + ), // { "ecmaVersion": 2018 }, + ( + " // doesn't report _x let _x, y; _x = 1; @@ -175,103 +259,188 @@ fn test() { _a = 1; ({_a, ...b } = foo); b; - ", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_", "ignoreRestSiblings": true }]))), // { "ecmaVersion": 2018 }, -("try {} catch ([firstError]) {}", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "Error$" }]))), // { "ecmaVersion": 2015 }, -("(function(obj) { var name; for ( name in obj ) return; })({});", None), -("(function(obj) { var name; for ( name in obj ) { return; } })({});", None), -("(function(obj) { for ( var name in obj ) { return true } })({})", None), -("(function(obj) { for ( var name in obj ) return true })({})", None), -("(function(obj) { let name; for ( name in obj ) return; })({});", None), // { "ecmaVersion": 6 }, -("(function(obj) { let name; for ( name in obj ) { return; } })({});", None), // { "ecmaVersion": 6 }, -("(function(obj) { for ( let name in obj ) { return true } })({})", None), // { "ecmaVersion": 6 }, -("(function(obj) { for ( let name in obj ) return true })({})", None), // { "ecmaVersion": 6 }, -("(function(obj) { for ( const name in obj ) { return true } })({})", None), // { "ecmaVersion": 6 }, -("(function(obj) { for ( const name in obj ) return true })({})", None), // { "ecmaVersion": 6 }, -("(function(iter) { let name; for ( name of iter ) return; })({});", None), // { "ecmaVersion": 6 }, -("(function(iter) { let name; for ( name of iter ) { return; } })({});", None), // { "ecmaVersion": 6 }, -("(function(iter) { for ( let name of iter ) { return true } })({})", None), // { "ecmaVersion": 6 }, -("(function(iter) { for ( let name of iter ) return true })({})", None), // { "ecmaVersion": 6 }, -("(function(iter) { for ( const name of iter ) { return true } })({})", None), // { "ecmaVersion": 6 }, -("(function(iter) { for ( const name of iter ) return true })({})", None), // { "ecmaVersion": 6 }, -("let x = 0; foo = (0, x++);", None), // { "ecmaVersion": 6 }, -("let x = 0; foo = (0, x += 1);", None), // { "ecmaVersion": 6 }, -("let x = 0; foo = (0, x = x + 1);", None), // { "ecmaVersion": 6 }, -("try{}catch(err){}", Some(serde_json::json!([{ "caughtErrors": "none" }]))), -("try{}catch(err){console.error(err);}", Some(serde_json::json!([{ "caughtErrors": "all" }]))), -("try{}catch(ignoreErr){}", Some(serde_json::json!([{ "caughtErrorsIgnorePattern": "^ignore" }]))), -("try{}catch(ignoreErr){}", Some(serde_json::json!([{ "caughtErrors": "all", "caughtErrorsIgnorePattern": "^ignore" }]))), -("try {} catch ({ message, stack }) {}", Some(serde_json::json!([{ "caughtErrorsIgnorePattern": "message|stack" }]))), // { "ecmaVersion": 2015 }, -("try {} catch ({ errors: [firstError] }) {}", Some(serde_json::json!([{ "caughtErrorsIgnorePattern": "Error$" }]))), // { "ecmaVersion": 2015 }, -("try{}catch(err){}", Some(serde_json::json!([{ "caughtErrors": "none", "vars": "all", "args": "all" }]))), -("const data = { type: 'coords', x: 1, y: 2 }; + ", + Some( + serde_json::json!([{ "destructuredArrayIgnorePattern": "^_", "ignoreRestSiblings": true }]), + ), + ), // { "ecmaVersion": 2018 }, + ( + "try {} catch ([firstError]) {}", + Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "Error$" }])), + ), // { "ecmaVersion": 2015 }, + ("(function(obj) { var name; for ( name in obj ) return; })({});", None), + ("(function(obj) { var name; for ( name in obj ) { return; } })({});", None), + ("(function(obj) { for ( var name in obj ) { return true } })({})", None), + ("(function(obj) { for ( var name in obj ) return true })({})", None), + ("(function(obj) { let name; for ( name in obj ) return; })({});", None), // { "ecmaVersion": 6 }, + ("(function(obj) { let name; for ( name in obj ) { return; } })({});", None), // { "ecmaVersion": 6 }, + ("(function(obj) { for ( let name in obj ) { return true } })({})", None), // { "ecmaVersion": 6 }, + ("(function(obj) { for ( let name in obj ) return true })({})", None), // { "ecmaVersion": 6 }, + ("(function(obj) { for ( const name in obj ) { return true } })({})", None), // { "ecmaVersion": 6 }, + ("(function(obj) { for ( const name in obj ) return true })({})", None), // { "ecmaVersion": 6 }, + ("(function(iter) { let name; for ( name of iter ) return; })({});", None), // { "ecmaVersion": 6 }, + ("(function(iter) { let name; for ( name of iter ) { return; } })({});", None), // { "ecmaVersion": 6 }, + ("(function(iter) { for ( let name of iter ) { return true } })({})", None), // { "ecmaVersion": 6 }, + ("(function(iter) { for ( let name of iter ) return true })({})", None), // { "ecmaVersion": 6 }, + ("(function(iter) { for ( const name of iter ) { return true } })({})", None), // { "ecmaVersion": 6 }, + ("(function(iter) { for ( const name of iter ) return true })({})", None), // { "ecmaVersion": 6 }, + ("let x = 0; foo = (0, x++);", None), // { "ecmaVersion": 6 }, + ("let x = 0; foo = (0, x += 1);", None), // { "ecmaVersion": 6 }, + ("let x = 0; foo = (0, x = x + 1);", None), // { "ecmaVersion": 6 }, + ("try{}catch(err){}", Some(serde_json::json!([{ "caughtErrors": "none" }]))), + ( + "try{}catch(err){console.error(err);}", + Some(serde_json::json!([{ "caughtErrors": "all" }])), + ), + ( + "try{}catch(ignoreErr){}", + Some(serde_json::json!([{ "caughtErrorsIgnorePattern": "^ignore" }])), + ), + ( + "try{}catch(ignoreErr){}", + Some( + serde_json::json!([{ "caughtErrors": "all", "caughtErrorsIgnorePattern": "^ignore" }]), + ), + ), + ( + "try {} catch ({ message, stack }) {}", + Some(serde_json::json!([{ "caughtErrorsIgnorePattern": "message|stack" }])), + ), // { "ecmaVersion": 2015 }, + ( + "try {} catch ({ errors: [firstError] }) {}", + Some(serde_json::json!([{ "caughtErrorsIgnorePattern": "Error$" }])), + ), // { "ecmaVersion": 2015 }, + ( + "try{}catch(err){}", + Some(serde_json::json!([{ "caughtErrors": "none", "vars": "all", "args": "all" }])), + ), + ( + "const data = { type: 'coords', x: 1, y: 2 }; const { type, ...coords } = data; - console.log(coords);", Some(serde_json::json!([{ "ignoreRestSiblings": true }]))), // { "ecmaVersion": 2018 }, -("try {} catch ({ foo, ...bar }) { console.log(bar); }", Some(serde_json::json!([{ "ignoreRestSiblings": true }]))), // { "ecmaVersion": 2018 }, -("var a = 0, b; b = a = a + 1; foo(b);", None), -("var a = 0, b; b = a += a + 1; foo(b);", None), -("var a = 0, b; b = a++; foo(b);", None), -("function foo(a) { var b = a = a + 1; bar(b) } foo();", None), -("function foo(a) { var b = a += a + 1; bar(b) } foo();", None), -("function foo(a) { var b = a++; bar(b) } foo();", None), -(r#"var unregisterFooWatcher; + console.log(coords);", + Some(serde_json::json!([{ "ignoreRestSiblings": true }])), + ), // { "ecmaVersion": 2018 }, + ( + "try {} catch ({ foo, ...bar }) { console.log(bar); }", + Some(serde_json::json!([{ "ignoreRestSiblings": true }])), + ), // { "ecmaVersion": 2018 }, + ("var a = 0, b; b = a = a + 1; foo(b);", None), + ("var a = 0, b; b = a += a + 1; foo(b);", None), + ("var a = 0, b; b = a++; foo(b);", None), + ("function foo(a) { var b = a = a + 1; bar(b) } foo();", None), + ("function foo(a) { var b = a += a + 1; bar(b) } foo();", None), + ("function foo(a) { var b = a++; bar(b) } foo();", None), + ( + r#"var unregisterFooWatcher; // ... unregisterFooWatcher = $scope.$watch( "foo", function() { // ...some code.. unregisterFooWatcher(); }); - "#, None), -("var ref; + "#, + None, + ), + ( + "var ref; ref = setInterval( function(){ clearInterval(ref); }, 10); - ", None), -("var _timer; + ", + None, + ), + ( + "var _timer; function f() { _timer = setTimeout(function () {}, _timer ? 100 : 0); } f(); - ", None), -("function foo(cb) { cb = function() { function something(a) { cb(1 + a); } register(something); }(); } foo();", None), -("function* foo(cb) { cb = yield function(a) { cb(1 + a); }; } foo();", None), // { "ecmaVersion": 6 }, -("function foo(cb) { cb = tag`hello${function(a) { cb(1 + a); }}`; } foo();", None), // { "ecmaVersion": 6 }, -("function foo(cb) { var b; cb = b = function(a) { cb(1 + a); }; b(); } foo();", None), -("function someFunction() { + ", + None, + ), + ( + "function foo(cb) { cb = function() { function something(a) { cb(1 + a); } register(something); }(); } foo();", + None, + ), + ("function* foo(cb) { cb = yield function(a) { cb(1 + a); }; } foo();", None), // { "ecmaVersion": 6 }, + ("function foo(cb) { cb = tag`hello${function(a) { cb(1 + a); }}`; } foo();", None), // { "ecmaVersion": 6 }, + ("function foo(cb) { var b; cb = b = function(a) { cb(1 + a); }; b(); } foo();", None), + ( + "function someFunction() { var a = 0, i; for (i = 0; i < 2; i++) { a = myFunction(a); } } someFunction(); - ", None), -("(function(a, b, {c, d}) { d })", Some(serde_json::json!([{ "argsIgnorePattern": "c" }]))), // { "ecmaVersion": 6 }, -("(function(a, b, {c, d}) { c })", Some(serde_json::json!([{ "argsIgnorePattern": "d" }]))), // { "ecmaVersion": 6 }, -("(function(a, b, c) { c })", Some(serde_json::json!([{ "argsIgnorePattern": "c" }]))), -("(function(a, b, {c, d}) { c })", Some(serde_json::json!([{ "argsIgnorePattern": "[cd]" }]))), // { "ecmaVersion": 6 }, -("(class { set foo(UNUSED) {} })", None), // { "ecmaVersion": 6 }, -("class Foo { set bar(UNUSED) {} } console.log(Foo)", None), // { "ecmaVersion": 6 }, -("(({a, ...rest}) => rest)", Some(serde_json::json!([{ "args": "all", "ignoreRestSiblings": true }]))), // { "ecmaVersion": 2018 }, -("let foo, rest; + ", + None, + ), + ("(function(a, b, {c, d}) { d })", Some(serde_json::json!([{ "argsIgnorePattern": "c" }]))), // { "ecmaVersion": 6 }, + ("(function(a, b, {c, d}) { c })", Some(serde_json::json!([{ "argsIgnorePattern": "d" }]))), // { "ecmaVersion": 6 }, + ("(function(a, b, c) { c })", Some(serde_json::json!([{ "argsIgnorePattern": "c" }]))), + ( + "(function(a, b, {c, d}) { c })", + Some(serde_json::json!([{ "argsIgnorePattern": "[cd]" }])), + ), // { "ecmaVersion": 6 }, + ("(class { set foo(UNUSED) {} })", None), // { "ecmaVersion": 6 }, + ("class Foo { set bar(UNUSED) {} } console.log(Foo)", None), // { "ecmaVersion": 6 }, + ( + "(({a, ...rest}) => rest)", + Some(serde_json::json!([{ "args": "all", "ignoreRestSiblings": true }])), + ), // { "ecmaVersion": 2018 }, + ( + "let foo, rest; ({ foo, ...rest } = something); - console.log(rest);", Some(serde_json::json!([{ "ignoreRestSiblings": true }]))), // { "ecmaVersion": 2020 }, -// ("/*eslint custom/use-every-a:1*/ !function(b, a) { return 1 }", None), -("var a = function () { a(); }; a();", None), -("var a = function(){ return function () { a(); } }; a();", None), -("const a = () => { a(); }; a();", None), // { "ecmaVersion": 2015 }, -("const a = () => () => { a(); }; a();", None), // { "ecmaVersion": 2015 }, -(r#"export * as ns from "source""#, None), // { "ecmaVersion": 2020, "sourceType": "module" }, -("import.meta", None), // { "ecmaVersion": 2020, "sourceType": "module" }, -// NOTE (@DonIsaac) ESLint thinks this counts as being used, I disagree -// ("var a; a ||= 1;", None), // { "ecmaVersion": 2021 }, -// ("var a; a &&= 1;", None), // { "ecmaVersion": 2021 }, -// ("var a; a ??= 1;", None), // { "ecmaVersion": 2021 }, -("class Foo { static {} }", Some(serde_json::json!([{ "ignoreClassWithStaticInitBlock": true }]))), // { "ecmaVersion": 2022 }, -("class Foo { static {} }", Some(serde_json::json!([{ "ignoreClassWithStaticInitBlock": true, "varsIgnorePattern": "^_" }]))), // { "ecmaVersion": 2022 }, -("class Foo { static {} }", Some(serde_json::json!([{ "ignoreClassWithStaticInitBlock": false, "varsIgnorePattern": "^Foo" }]))), // { "ecmaVersion": 2022 }, -("const a = 5; const _c = a + 5;", Some(serde_json::json!([{ "args": "all", "varsIgnorePattern": "^_", "reportUsedIgnorePattern": true }]))), // { "ecmaVersion": 6 }, -("(function foo(a, _b) { return a + 5 })(5)", Some(serde_json::json!([{ "args": "all", "argsIgnorePattern": "^_", "reportUsedIgnorePattern": true }]))), -("const [ a, _b, c ] = items; - console.log(a+c);", Some(serde_json::json!([{ "destructuredArrayIgnorePattern": "^_", "reportUsedIgnorePattern": true }]))), // { "ecmaVersion": 6 } + console.log(rest);", + Some(serde_json::json!([{ "ignoreRestSiblings": true }])), + ), // { "ecmaVersion": 2020 }, + // ("/*eslint custom/use-every-a:1*/ !function(b, a) { return 1 }", None), + ("var a = function () { a(); }; a();", None), + ("var a = function(){ return function () { a(); } }; a();", None), + ("const a = () => { a(); }; a();", None), // { "ecmaVersion": 2015 }, + ("const a = () => () => { a(); }; a();", None), // { "ecmaVersion": 2015 }, + (r#"export * as ns from "source""#, None), // { "ecmaVersion": 2020, "sourceType": "module" }, + ("import.meta", None), // { "ecmaVersion": 2020, "sourceType": "module" }, + // NOTE (@DonIsaac) ESLint thinks this counts as being used, I disagree + // ("var a; a ||= 1;", None), // { "ecmaVersion": 2021 }, + // ("var a; a &&= 1;", None), // { "ecmaVersion": 2021 }, + // ("var a; a ??= 1;", None), // { "ecmaVersion": 2021 }, + ( + "class Foo { static {} }", + Some(serde_json::json!([{ "ignoreClassWithStaticInitBlock": true }])), + ), // { "ecmaVersion": 2022 }, + ( + "class Foo { static {} }", + Some( + serde_json::json!([{ "ignoreClassWithStaticInitBlock": true, "varsIgnorePattern": "^_" }]), + ), + ), // { "ecmaVersion": 2022 }, + ( + "class Foo { static {} }", + Some( + serde_json::json!([{ "ignoreClassWithStaticInitBlock": false, "varsIgnorePattern": "^Foo" }]), + ), + ), // { "ecmaVersion": 2022 }, + ( + "const a = 5; const _c = a + 5;", + Some( + serde_json::json!([{ "args": "all", "varsIgnorePattern": "^_", "reportUsedIgnorePattern": true }]), + ), + ), // { "ecmaVersion": 6 }, + ( + "(function foo(a, _b) { return a + 5 })(5)", + Some( + serde_json::json!([{ "args": "all", "argsIgnorePattern": "^_", "reportUsedIgnorePattern": true }]), + ), + ), + ( + "const [ a, _b, c ] = items; + console.log(a+c);", + Some( + serde_json::json!([{ "destructuredArrayIgnorePattern": "^_", "reportUsedIgnorePattern": true }]), + ), + ), // { "ecmaVersion": 6 } ]; let fail = vec![ diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs index 52c72dce83312b..b3bf68f00e2643 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs @@ -1,8 +1,9 @@ //! Test cases created by oxc maintainers +use serde_json::json; + use super::NoUnusedVars; use crate::{tester::Tester, FixKind, RuleMeta as _}; -use serde_json::json; #[test] fn test_vars_simple() { @@ -296,8 +297,8 @@ fn test_vars_destructure() { "caughtErrors": "none", "ignoreRestSiblings": true, "vars": "all" - }])) - ) + }])), + ), ]; let fail = vec![ ("const { a, ...rest } = obj", Some(json!( [{ "ignoreRestSiblings": true }] ))), @@ -493,7 +494,7 @@ fn test_functions() { }); ", "const foo = () => function bar() { }\nfoo()", - "module.exports.foo = () => function bar() { }" + "module.exports.foo = () => function bar() { }", ]; let fail = vec![ diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs index da47a11b86a669..898a26b34a95cb 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs @@ -163,7 +163,7 @@ impl<'s, 'a> Symbol<'s, 'a> { return b .body .first() - .is_some_and(|s| matches!(s, Statement::ReturnStatement(_))) + .is_some_and(|s| matches!(s, Statement::ReturnStatement(_))); } _ => return false, }, @@ -603,7 +603,8 @@ impl<'s, 'a> Symbol<'s, 'a> { let decl_scope_id = self.scope_id(); let call_scope_id = self.get_ref_scope(reference); let Some(container_id) = self.declaration().kind().get_container_scope_id() else { - debug_assert!(false, + debug_assert!( + false, "Found a function call or or new expr reference on a node flagged as a function or class, but the symbol's declaration node has no scope id. It should always be a container." ); return false; @@ -667,7 +668,7 @@ impl<'s, 'a> Symbol<'s, 'a> { continue; } AstKind::VariableDeclarator(decl) if needs_variable_identifier => { - return decl.id.get_binding_identifier().and_then(|id| id.symbol_id.get()) + return decl.id.get_binding_identifier().and_then(|id| id.symbol_id.get()); } AstKind::AssignmentTarget(target) if needs_variable_identifier => { return match target { @@ -676,7 +677,7 @@ impl<'s, 'a> Symbol<'s, 'a> { .get() .and_then(|rid| self.symbols().get_reference(rid).symbol_id()), _ => None, - } + }; } AstKind::Program(_) => { return None; diff --git a/crates/oxc_linter/src/rules/import/no_dynamic_require.rs b/crates/oxc_linter/src/rules/import/no_dynamic_require.rs index 1ec10227418566..579af30e2b36fe 100644 --- a/crates/oxc_linter/src/rules/import/no_dynamic_require.rs +++ b/crates/oxc_linter/src/rules/import/no_dynamic_require.rs @@ -89,9 +89,10 @@ fn is_static_value(expr: &Expression) -> bool { #[test] fn test() { - use crate::tester::Tester; use serde_json::json; + use crate::tester::Tester; + let pass = vec![ (r#"import _ from "lodash""#, None), (r#"require("foo")"#, None), diff --git a/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs b/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs index 5699f56b8ca684..e97ee6eaf39cfa 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs @@ -136,9 +136,10 @@ fn can_fix<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> bool { #[test] fn test() { - use crate::tester::Tester; use std::path::PathBuf; + use crate::tester::Tester; + let pass = vec![ ("foo();", None, None, None), ("jest.mocked(foo).mockReturnValue(1);", None, None, None), diff --git a/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs b/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs index 02b96210be2b07..ab87b5d9a0b049 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs @@ -216,13 +216,15 @@ fn tests() { ("expect(files.length).toStrictEqual(1);", None), ("expect(files.length).not.toStrictEqual(1);", None), ( - "expect((meta.get('pages') as YArray).length).toBe((originalMeta.get('pages') as YArray).length);", - None + "expect((meta.get('pages') as YArray).length).toBe((originalMeta.get('pages') as YArray).length);", + None, ), ( "expect(assetTypeContainer.getElementsByTagName('time').length).toEqual( 0, - );", None) + );", + None, + ), ]; let fix = vec![ @@ -249,19 +251,19 @@ fn tests() { ("expect(files.length).toStrictEqual(1);", "expect(files).toHaveLength(1);", None), ("expect(files.length).not.toStrictEqual(1);", "expect(files).not.toHaveLength(1);", None), ( - "expect((meta.get('pages') as YArray).length).toBe((originalMeta.get('pages') as YArray).length);", - "expect((meta.get('pages') as YArray)).toHaveLength((originalMeta.get('pages') as YArray).length);", - None + "expect((meta.get('pages') as YArray).length).toBe((originalMeta.get('pages') as YArray).length);", + "expect((meta.get('pages') as YArray)).toHaveLength((originalMeta.get('pages') as YArray).length);", + None, ), ( "expect(assetTypeContainer.getElementsByTagName('time').length).toEqual( 0, - );", + );", "expect(assetTypeContainer.getElementsByTagName('time')).toHaveLength( 0, - );", - None - ) + );", + None, + ), ]; Tester::new(PreferToHaveLength::NAME, pass, fail) diff --git a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs index 891918707bf4ba..0e8525cace8dcb 100644 --- a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs @@ -394,7 +394,7 @@ fn test() { "let foo = {}; for (const i in [1,2,3]) { foo[i] = i; }", "let foo = {}; for (let i of [1,2,3]) { foo[i] = i; }", "let foo = {}; for (const i of [1,2,3]) { foo[i] = i; }", - "let foo = {}; while (Object.keys(foo).length < 10) { foo[Object.keys(foo).length] = Object.keys(foo).length; }", + "let foo = {}; while (Object.keys(foo).length < 10) { foo[Object.keys(foo).length] = Object.keys(foo).length; }", ]; let fail = vec![ diff --git a/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs b/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs index d78cd0854c7baf..bb25775aa83862 100644 --- a/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs +++ b/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs @@ -1,15 +1,15 @@ use std::ops::Deref; +use oxc_ast::{ + ast::{Argument, ArrowFunctionExpression, Expression, Function}, + AstKind, +}; use oxc_diagnostics::{LabeledSpan, OxcDiagnostic}; use oxc_macros::declare_oxc_lint; use oxc_span::{CompactStr, Span}; use serde_json::Value; use crate::{context::LintContext, rule::Rule, utils, AstNode}; -use oxc_ast::{ - ast::{Argument, ArrowFunctionExpression, Expression, Function}, - AstKind, -}; #[derive(Debug, Default, Clone)] pub struct NoAsyncEndpointHandlers(Box); @@ -296,9 +296,10 @@ impl NoAsyncEndpointHandlers { #[test] fn test() { - use crate::tester::Tester; use serde_json::json; + use crate::tester::Tester; + let pass = vec![ ("app.get('/', fooController)", None), ("app.get('/', (req, res) => {})", None), diff --git a/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs b/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs index 4712eff9aa48b8..71fade98ad5df2 100644 --- a/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs +++ b/crates/oxc_linter/src/rules/react/jsx_curly_brace_presence.rs @@ -36,6 +36,7 @@ enum Allowed { impl TryFrom<&str> for Allowed { type Error = (); + fn try_from(value: &str) -> Result { match value { "always" => Ok(Self::Always), @@ -50,6 +51,7 @@ impl Allowed { pub fn is_never(self) -> bool { matches!(self, Self::Never) } + #[inline] pub fn is_always(self) -> bool { matches!(self, Self::Always) @@ -327,6 +329,7 @@ impl Rule for JsxCurlyBracePresence { _ => default, } } + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { match node.kind() { AstKind::JSXElement(el) => { @@ -559,9 +562,10 @@ fn has_adjacent_jsx_expression_containers<'a>( #[test] fn test() { - use crate::tester::Tester; use serde_json::json; + use crate::tester::Tester; + let pass = vec![ ("foo", None), ("<>foo", None), diff --git a/crates/oxc_linter/src/rules/react/jsx_props_no_spread_multi.rs b/crates/oxc_linter/src/rules/react/jsx_props_no_spread_multi.rs index c3bc7f6729d75e..0688956e72d751 100644 --- a/crates/oxc_linter/src/rules/react/jsx_props_no_spread_multi.rs +++ b/crates/oxc_linter/src/rules/react/jsx_props_no_spread_multi.rs @@ -1,11 +1,9 @@ -use rustc_hash::FxHashMap; - +use itertools::Itertools; use oxc_ast::{ast::JSXAttributeItem, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::{Atom, Span}; - -use itertools::Itertools; +use rustc_hash::FxHashMap; use crate::{ context::LintContext, diff --git a/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs b/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs index b17eb02b042ad2..7e77c23674f668 100644 --- a/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs +++ b/crates/oxc_linter/src/rules/react_perf/jsx_no_jsx_as_prop.rs @@ -1,9 +1,10 @@ -use crate::utils::ReactPerfRule; use oxc_ast::{ast::Expression, AstKind}; use oxc_macros::declare_oxc_lint; use oxc_semantic::SymbolId; use oxc_span::{GetSpan, Span}; +use crate::utils::ReactPerfRule; + #[derive(Debug, Default, Clone)] pub struct JsxNoJsxAsProp; diff --git a/crates/oxc_linter/src/rules/tree_shaking/no_side_effects_in_initialization/mod.rs b/crates/oxc_linter/src/rules/tree_shaking/no_side_effects_in_initialization/mod.rs index 4b1cfcb1ed990c..f9a494ef3fe850 100644 --- a/crates/oxc_linter/src/rules/tree_shaking/no_side_effects_in_initialization/mod.rs +++ b/crates/oxc_linter/src/rules/tree_shaking/no_side_effects_in_initialization/mod.rs @@ -641,7 +641,7 @@ fn test() { { let x = () => {}; } let x = ext export {/* tree-shaking no-side-effects-when-called */ x} - ", + ", // ExpressionStatement "ext()", // ForInStatement diff --git a/crates/oxc_linter/src/rules/typescript/array_type.rs b/crates/oxc_linter/src/rules/typescript/array_type.rs index c05cb425e9c62b..ab07e318f6bd52 100644 --- a/crates/oxc_linter/src/rules/typescript/array_type.rs +++ b/crates/oxc_linter/src/rules/typescript/array_type.rs @@ -37,7 +37,10 @@ fn generic(x0: &str, x1: &str, x2: &str, span3: Span) -> OxcDiagnostic { } fn generic_simple(x0: &str, x1: &str, x2: &str, span3: Span) -> OxcDiagnostic { - OxcDiagnostic::warn(format!("Array type using '{x0}{x2}[]' is forbidden for non-simple types. Use '{x1}<{x2}>' instead.")).with_label(span3) + OxcDiagnostic::warn(format!( + "Array type using '{x0}{x2}[]' is forbidden for non-simple types. Use '{x1}<{x2}>' instead." + )) + .with_label(span3) } fn array(x0: &str, x1: &str, x2: &str, span3: Span) -> OxcDiagnostic { diff --git a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs index a250fe518e9acc..651ce2bca1e349 100644 --- a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs +++ b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs @@ -157,6 +157,7 @@ impl Rule for ConsistentFunctionScoping { Self(Box::new(configuration)) } + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { let (function_declaration_symbol_id, function_body, reporter_span) = match node.kind() { AstKind::Function(function) => { @@ -284,6 +285,7 @@ impl<'a> Visit<'a> for ReferencesFinder { self.in_function += 1; } } + fn leave_node(&mut self, kind: AstKind<'a>) { if let AstKind::Function(_) = kind { self.in_function -= 1; diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_spread/const_eval.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_spread/const_eval.rs index 7e0ca4405f8e33..98ebbe2fb19c09 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_spread/const_eval.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_spread/const_eval.rs @@ -37,6 +37,7 @@ impl ValueHint { impl std::ops::BitAnd for ValueHint { type Output = Self; + fn bitand(self, rhs: Self) -> Self::Output { // NOTE: what about (NewArray, NewIterable), e.g. in // `foo ? new Set() : []` diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs index cbe55097997f30..79a68fd40434f1 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs @@ -1,5 +1,6 @@ mod const_eval; +use const_eval::{is_array_from, is_new_typed_array, ConstEval}; use oxc_ast::{ ast::{ ArrayExpression, ArrayExpressionElement, CallExpression, Expression, NewExpression, @@ -20,7 +21,6 @@ use crate::{ rule::Rule, AstNode, }; -use const_eval::{is_array_from, is_new_typed_array, ConstEval}; fn spread_in_list(span: Span, x1: &str) -> OxcDiagnostic { OxcDiagnostic::warn(format!("Using a spread operator here creates a new {x1} unnecessarily.")) diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs index d1ad71fe790217..84a32efcb04393 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs @@ -1,4 +1,3 @@ -use crate::{ast_util::is_method_call, context::LintContext, rule::Rule, AstNode}; use oxc_ast::{ ast::{Argument, CallExpression, Expression, VariableDeclarationKind}, AstKind, @@ -7,6 +6,8 @@ use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::{GetSpan, Span}; +use crate::{ast_util::is_method_call, context::LintContext, rule::Rule, AstNode}; + fn warn() -> OxcDiagnostic { OxcDiagnostic::warn("Do not use useless `undefined`.") .with_help("Consider removing `undefined` or using `null` instead.") @@ -149,6 +150,7 @@ impl Rule for NoUselessUndefined { .unwrap_or(true); Self { check_arguments, check_arrow_function_body } } + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { match node.kind() { AstKind::IdentifierReference(undefined_literal) diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_string_replace_all.rs b/crates/oxc_linter/src/rules/unicorn/prefer_string_replace_all.rs index 5b70f40961f83f..1799d43866a746 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_string_replace_all.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_string_replace_all.rs @@ -4,9 +4,7 @@ use oxc_ast::{ }; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::{CompactStr, Span}; - -use oxc_span::GetSpan; +use oxc_span::{CompactStr, GetSpan, Span}; use crate::{ast_util::extract_regex_flags, context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/table.rs b/crates/oxc_linter/src/table.rs index dc5a4ca3d1d6be..7fe893f733276a 100644 --- a/crates/oxc_linter/src/table.rs +++ b/crates/oxc_linter/src/table.rs @@ -146,10 +146,12 @@ impl RuleTableSection { #[cfg(test)] mod test { - use super::*; - use markdown::{to_html_with_options, Options}; use std::sync::OnceLock; + use markdown::{to_html_with_options, Options}; + + use super::*; + static TABLE: OnceLock = OnceLock::new(); fn table() -> &'static RuleTable { diff --git a/crates/oxc_linter/src/utils/react_perf.rs b/crates/oxc_linter/src/utils/react_perf.rs index 56b32fdc9d7018..4cf51fdd7653ba 100644 --- a/crates/oxc_linter/src/utils/react_perf.rs +++ b/crates/oxc_linter/src/utils/react_perf.rs @@ -1,6 +1,5 @@ use std::fmt; -use crate::{rule::Rule, AstNode, LintContext}; use oxc_ast::{ ast::{ BindingIdentifier, BindingPattern, BindingPatternKind, Expression, JSXAttributeItem, @@ -12,6 +11,8 @@ use oxc_diagnostics::OxcDiagnostic; use oxc_semantic::SymbolId; use oxc_span::Span; +use crate::{rule::Rule, AstNode, LintContext}; + fn react_perf_inline_diagnostic(message: &'static str, attr_span: Span) -> OxcDiagnostic { OxcDiagnostic::warn(message) .with_help(r"simplify props or memoize props in the parent component (https://react.dev/reference/react/memo#my-component-rerenders-when-a-prop-is-an-object-or-array).") diff --git a/crates/oxc_linter/src/utils/vitest.rs b/crates/oxc_linter/src/utils/vitest.rs index 1936e9df9180ae..17ff25c533e40d 100644 --- a/crates/oxc_linter/src/utils/vitest.rs +++ b/crates/oxc_linter/src/utils/vitest.rs @@ -1,4 +1,3 @@ -use crate::LintContext; use oxc_ast::{ ast::{Argument, CallExpression, Expression}, AstKind, @@ -10,6 +9,7 @@ use super::{ is_equality_matcher, parse_jest_fn_call, ParsedExpectFnCall, ParsedJestFnCallNew, PossibleJestNode, }; +use crate::LintContext; mod valid_vitest_fn; pub use crate::utils::vitest::valid_vitest_fn::VALID_VITEST_FN_CALL_CHAINS; diff --git a/crates/oxc_macros/src/declare_oxc_lint.rs b/crates/oxc_macros/src/declare_oxc_lint.rs index fc75d6fb36602d..8f80bcbe30cf4b 100644 --- a/crates/oxc_macros/src/declare_oxc_lint.rs +++ b/crates/oxc_macros/src/declare_oxc_lint.rs @@ -126,22 +126,24 @@ fn parse_fix(s: &str) -> proc_macro2::TokenStream { "none" => { return quote! { RuleFixMeta::None }; } - "pending" => { return quote! { RuleFixMeta::FixPending }; } - "fix" => { - return quote! { RuleFixMeta::Fixable(FixKind::SafeFix) } - }, - "suggestion" => { - return quote! { RuleFixMeta::Fixable(FixKind::Suggestion) } - }, + "pending" => { + return quote! { RuleFixMeta::FixPending }; + } + "fix" => return quote! { RuleFixMeta::Fixable(FixKind::SafeFix) }, + "suggestion" => return quote! { RuleFixMeta::Fixable(FixKind::Suggestion) }, // "fix-dangerous" => quote! { RuleFixMeta::Fixable(FixKind::Fix.union(FixKind::Dangerous)) }, // "suggestion" => quote! { RuleFixMeta::Fixable(FixKind::Suggestion) }, // "suggestion-dangerous" => quote! { RuleFixMeta::Fixable(FixKind::Suggestion.union(FixKind::Dangerous)) }, - "conditional" => panic!("Invalid fix capabilities: missing a fix kind. Did you mean 'fix-conditional'?"), + "conditional" => { + panic!("Invalid fix capabilities: missing a fix kind. Did you mean 'fix-conditional'?") + } "None" => panic!("Invalid fix capabilities. Did you mean 'none'?"), "Pending" => panic!("Invalid fix capabilities. Did you mean 'pending'?"), "Fix" => panic!("Invalid fix capabilities. Did you mean 'fix'?"), "Suggestion" => panic!("Invalid fix capabilities. Did you mean 'suggestion'?"), - invalid if !invalid.contains(SEP) => panic!("invalid fix capabilities: {invalid}. Valid capabilities are none, pending, fix, suggestion, or [fix|suggestion]_[conditional?]_[dangerous?]."), + invalid if !invalid.contains(SEP) => panic!( + "invalid fix capabilities: {invalid}. Valid capabilities are none, pending, fix, suggestion, or [fix|suggestion]_[conditional?]_[dangerous?]." + ), _ => {} } diff --git a/crates/oxc_minifier/src/ast_passes/fold_constants.rs b/crates/oxc_minifier/src/ast_passes/fold_constants.rs index 74f925555a93e6..2a009a4f071612 100644 --- a/crates/oxc_minifier/src/ast_passes/fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/fold_constants.rs @@ -5,7 +5,6 @@ use std::cmp::Ordering; use num_bigint::BigInt; - use oxc_ast::{ast::*, AstBuilder, Visit}; use oxc_span::{GetSpan, Span, SPAN}; use oxc_syntax::{ diff --git a/crates/oxc_minifier/src/ast_passes/mod.rs b/crates/oxc_minifier/src/ast_passes/mod.rs index be21f5a4dce662..3447e36bc9dd94 100644 --- a/crates/oxc_minifier/src/ast_passes/mod.rs +++ b/crates/oxc_minifier/src/ast_passes/mod.rs @@ -6,13 +6,12 @@ mod substitute_alternate_syntax; pub use collapse::Collapse; pub use fold_constants::FoldConstants; -pub use remove_dead_code::RemoveDeadCode; -pub use remove_syntax::RemoveSyntax; -pub use substitute_alternate_syntax::SubstituteAlternateSyntax; - use oxc_ast::ast::Program; use oxc_semantic::{ScopeTree, SymbolTable}; use oxc_traverse::{walk_program, Traverse, TraverseCtx}; +pub use remove_dead_code::RemoveDeadCode; +pub use remove_syntax::RemoveSyntax; +pub use substitute_alternate_syntax::SubstituteAlternateSyntax; use crate::node_util::NodeUtil; diff --git a/crates/oxc_minifier/src/node_util/check_for_state_change.rs b/crates/oxc_minifier/src/node_util/check_for_state_change.rs index bce3ab93cf714f..8f5f439a8e8cb4 100644 --- a/crates/oxc_minifier/src/node_util/check_for_state_change.rs +++ b/crates/oxc_minifier/src/node_util/check_for_state_change.rs @@ -1,5 +1,4 @@ use oxc_ast::ast::*; - use oxc_syntax::operator::UnaryOperator; /// A "simple" operator is one whose children are expressions, has no direct side-effects. diff --git a/crates/oxc_minifier/src/node_util/mod.rs b/crates/oxc_minifier/src/node_util/mod.rs index 67c0e530ee8eb6..38c3e74587fafc 100644 --- a/crates/oxc_minifier/src/node_util/mod.rs +++ b/crates/oxc_minifier/src/node_util/mod.rs @@ -7,7 +7,6 @@ use std::borrow::Cow; use num_bigint::BigInt; use num_traits::{One, Zero}; - use oxc_ast::ast::*; use oxc_semantic::{ScopeTree, SymbolTable}; use oxc_syntax::operator::{AssignmentOperator, LogicalOperator, UnaryOperator}; diff --git a/crates/oxc_minifier/src/plugins/replace_global_defines.rs b/crates/oxc_minifier/src/plugins/replace_global_defines.rs index 2c17f55630abc7..44681e6fa6f6ed 100644 --- a/crates/oxc_minifier/src/plugins/replace_global_defines.rs +++ b/crates/oxc_minifier/src/plugins/replace_global_defines.rs @@ -1,5 +1,4 @@ -use std::cmp::Ordering; -use std::sync::Arc; +use std::{cmp::Ordering, sync::Arc}; use oxc_allocator::Allocator; use oxc_ast::{ast::*, visit::walk_mut, AstBuilder, VisitMut}; diff --git a/crates/oxc_parser/src/js/object.rs b/crates/oxc_parser/src/js/object.rs index ac4f3db7195560..e69a98d9a430e6 100644 --- a/crates/oxc_parser/src/js/object.rs +++ b/crates/oxc_parser/src/js/object.rs @@ -73,7 +73,9 @@ impl<'a> ParserImpl<'a> { self.error(diagnostics::modifier_cannot_be_used_here(&modifier)); } else { #[cfg(debug_assertions)] - panic!("Kind::is_modifier_kind() is true but the token could not be converted to a Modifier.") + panic!( + "Kind::is_modifier_kind() is true but the token could not be converted to a Modifier." + ) } // re-parse self.bump_any(); diff --git a/crates/oxc_parser/src/lexer/regex.rs b/crates/oxc_parser/src/lexer/regex.rs index 5e0a1adf6f13f5..8d009124d9aea5 100644 --- a/crates/oxc_parser/src/lexer/regex.rs +++ b/crates/oxc_parser/src/lexer/regex.rs @@ -1,8 +1,8 @@ +use oxc_diagnostics::Result; use oxc_syntax::identifier::is_line_terminator; use super::{Kind, Lexer, RegExpFlags, Token}; use crate::diagnostics; -use oxc_diagnostics::Result; impl<'a> Lexer<'a> { /// Re-tokenize the current `/` or `/=` and return `RegExp` diff --git a/crates/oxc_parser/src/modifiers.rs b/crates/oxc_parser/src/modifiers.rs index 338376fb6607c6..8c9adffffed586 100644 --- a/crates/oxc_parser/src/modifiers.rs +++ b/crates/oxc_parser/src/modifiers.rs @@ -1,5 +1,4 @@ use bitflags::bitflags; - use oxc_allocator::Vec; use oxc_ast::ast::TSAccessibility; use oxc_diagnostics::{OxcDiagnostic, Result}; @@ -263,6 +262,7 @@ impl ModifierKind { } impl TryFrom for ModifierKind { type Error = (); + fn try_from(kind: Kind) -> std::result::Result { match kind { Kind::Abstract => Ok(Self::Abstract), diff --git a/crates/oxc_parser/src/ts/statement.rs b/crates/oxc_parser/src/ts/statement.rs index bf05d05a039beb..9d7039e899134b 100644 --- a/crates/oxc_parser/src/ts/statement.rs +++ b/crates/oxc_parser/src/ts/statement.rs @@ -98,6 +98,7 @@ impl<'a> ParserImpl<'a> { } } } + fn check_invalid_ts_enum_computed_property(&mut self, property: &Expression<'a>) { match property { Expression::StringLiteral(_) => {} diff --git a/crates/oxc_regular_expression/src/ast.rs b/crates/oxc_regular_expression/src/ast.rs index e398a4349d0e20..5db3e442006873 100644 --- a/crates/oxc_regular_expression/src/ast.rs +++ b/crates/oxc_regular_expression/src/ast.rs @@ -8,7 +8,6 @@ use oxc_allocator::{Box, CloneIn, Vec}; use oxc_ast_macros::ast; use oxc_span::{cmp::ContentEq, hash::ContentHash, Atom, Span}; - #[cfg(feature = "serialize")] use serde::Serialize; #[cfg(feature = "serialize")] diff --git a/crates/oxc_regular_expression/src/body_parser/mod.rs b/crates/oxc_regular_expression/src/body_parser/mod.rs index f2612fbf5abfb3..d3d2ef105b2c4a 100644 --- a/crates/oxc_regular_expression/src/body_parser/mod.rs +++ b/crates/oxc_regular_expression/src/body_parser/mod.rs @@ -9,9 +9,10 @@ pub use parser::PatternParser; #[cfg(test)] mod test { - use crate::{ParserOptions, PatternParser}; use oxc_allocator::Allocator; + use crate::{ParserOptions, PatternParser}; + #[test] fn should_pass() { let allocator = Allocator::default(); diff --git a/crates/oxc_regular_expression/src/body_parser/parser.rs b/crates/oxc_regular_expression/src/body_parser/parser.rs index e65ddedc6ea106..dec6903fb2352a 100644 --- a/crates/oxc_regular_expression/src/body_parser/parser.rs +++ b/crates/oxc_regular_expression/src/body_parser/parser.rs @@ -562,6 +562,7 @@ impl<'a> PatternParser<'a> { kind, }) } + // ``` // CharacterClassEscape[UnicodeMode] :: // [+UnicodeMode] p{ UnicodePropertyValueExpression } diff --git a/crates/oxc_regular_expression/src/lib.rs b/crates/oxc_regular_expression/src/lib.rs index d3720a70967278..9177cd4c4a5ed0 100644 --- a/crates/oxc_regular_expression/src/lib.rs +++ b/crates/oxc_regular_expression/src/lib.rs @@ -15,7 +15,7 @@ mod generated { mod derive_content_hash; } -pub use crate::body_parser::PatternParser; -pub use crate::flag_parser::FlagsParser; -pub use crate::literal_parser::Parser; -pub use crate::options::ParserOptions; +pub use crate::{ + body_parser::PatternParser, flag_parser::FlagsParser, literal_parser::Parser, + options::ParserOptions, +}; diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index 51ac2d48ac175f..43beef69ff074a 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -258,7 +258,12 @@ fn abstract_element_cannot_have_initializer( span: Span, init_or_impl: &str, ) -> OxcDiagnostic { - ts_error(code, format!("{elem_name} '{prop_name}' cannot have an {init_or_impl} because it is marked abstract.")) + ts_error( + code, + format!( + "{elem_name} '{prop_name}' cannot have an {init_or_impl} because it is marked abstract." + ), + ) .with_label(span) } diff --git a/crates/oxc_semantic/src/counter.rs b/crates/oxc_semantic/src/counter.rs index cca87e48186b02..2a06e2bee68086 100644 --- a/crates/oxc_semantic/src/counter.rs +++ b/crates/oxc_semantic/src/counter.rs @@ -25,6 +25,7 @@ impl<'a> Visit<'a> for Counter { fn enter_node(&mut self, _: AstKind<'a>) { self.nodes_count += 1; } + #[inline] fn enter_scope(&mut self, _: ScopeFlags, _: &Cell>) { self.scopes_count += 1; diff --git a/crates/oxc_semantic/src/post_transform_checker.rs b/crates/oxc_semantic/src/post_transform_checker.rs index a568548699c6b8..d87736a8666f0c 100644 --- a/crates/oxc_semantic/src/post_transform_checker.rs +++ b/crates/oxc_semantic/src/post_transform_checker.rs @@ -92,8 +92,6 @@ use std::{ }; use indexmap::IndexMap; -use rustc_hash::FxHasher; - use oxc_allocator::{Allocator, CloneIn}; #[allow(clippy::wildcard_imports)] use oxc_ast::{ast::*, visit::walk, Visit}; @@ -104,6 +102,7 @@ use oxc_syntax::{ scope::{ScopeFlags, ScopeId}, symbol::SymbolId, }; +use rustc_hash::FxHasher; use crate::{ScopeTree, SemanticBuilder, SymbolTable}; diff --git a/crates/oxc_semantic/src/unresolved_stack.rs b/crates/oxc_semantic/src/unresolved_stack.rs index d9500ce92770bd..4991241aeb2a32 100644 --- a/crates/oxc_semantic/src/unresolved_stack.rs +++ b/crates/oxc_semantic/src/unresolved_stack.rs @@ -1,8 +1,7 @@ use assert_unchecked::assert_unchecked; use oxc_span::Atom; -use rustc_hash::FxHashMap; - use oxc_syntax::reference::ReferenceId; +use rustc_hash::FxHashMap; /// The difference with Scope's `UnresolvedReferences` is that this type uses Atom as the key. its clone is very cheap! type TempUnresolvedReferences<'a> = FxHashMap, Vec>; @@ -21,16 +20,16 @@ pub(crate) struct UnresolvedReferencesStack<'a> { } impl<'a> UnresolvedReferencesStack<'a> { + // Initial scope depth. + // Start on 1 (`Program` scope depth). + // SAFETY: Must be >= 1 to ensure soundness of `current_and_parent_mut`. + const INITIAL_DEPTH: usize = 1; // Most programs will have at least 1 place where scope depth reaches 16, // so initialize `stack` with this length, to reduce reallocations as it grows. // This is just an estimate of a good initial size, but certainly better than // `Vec`'s default initial capacity of 4. // SAFETY: Must be >= 2 to ensure soundness of `current_and_parent_mut`. const INITIAL_SIZE: usize = 16; - // Initial scope depth. - // Start on 1 (`Program` scope depth). - // SAFETY: Must be >= 1 to ensure soundness of `current_and_parent_mut`. - const INITIAL_DEPTH: usize = 1; #[allow(clippy::assertions_on_constants)] const _SIZE_CHECK: () = assert!(Self::INITIAL_SIZE > Self::INITIAL_DEPTH); diff --git a/crates/oxc_semantic/tests/integration/modules.rs b/crates/oxc_semantic/tests/integration/modules.rs index 86d0e7f45181de..6f4cb4b00a261f 100644 --- a/crates/oxc_semantic/tests/integration/modules.rs +++ b/crates/oxc_semantic/tests/integration/modules.rs @@ -231,7 +231,10 @@ fn test_export_in_invalid_scope() { .expect_errors(true); test.has_some_symbol("x").contains_flags(SymbolFlags::Export).test(); let SemanticBuilderReturn { semantic, errors } = test.build_with_errors(); - assert!(!errors.is_empty(), "expected an export within a function to produce a check error, but no errors were produced"); + assert!( + !errors.is_empty(), + "expected an export within a function to produce a check error, but no errors were produced" + ); assert!(semantic.module_record().exported_bindings.is_empty()); } diff --git a/crates/oxc_semantic/tests/integration/scopes.rs b/crates/oxc_semantic/tests/integration/scopes.rs index 3be5e8dfbe95ea..f250e89c750255 100644 --- a/crates/oxc_semantic/tests/integration/scopes.rs +++ b/crates/oxc_semantic/tests/integration/scopes.rs @@ -199,7 +199,11 @@ fn test_enums() { "Expected `enum A` to be created in the top-level scope." ); let enum_decl_scope_id = enum_decl.scope_id.get().expect("Enum declaration has no scope id"); - assert_ne!(enum_node.scope_id(), enum_decl_scope_id, "Enum declaration nodes should contain the scope ID they create, not the scope ID they're created in."); + assert_ne!( + enum_node.scope_id(), + enum_decl_scope_id, + "Enum declaration nodes should contain the scope ID they create, not the scope ID they're created in." + ); assert_eq!(enum_decl.members.len(), 3); } diff --git a/crates/oxc_span/src/atom.rs b/crates/oxc_span/src/atom.rs index 8a0541d9613cfe..213dbd614f10ec 100644 --- a/crates/oxc_span/src/atom.rs +++ b/crates/oxc_span/src/atom.rs @@ -5,11 +5,11 @@ use std::{ }; use compact_str::CompactString; +use oxc_allocator::{Allocator, CloneIn, FromIn}; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer}; use crate::{cmp::ContentEq, hash::ContentHash, Span}; -use oxc_allocator::{Allocator, CloneIn, FromIn}; #[cfg(feature = "serialize")] #[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)] @@ -438,9 +438,10 @@ impl schemars::JsonSchema for CompactStr { #[cfg(test)] mod test { - use super::CompactStr; use compact_str::CompactString; + use super::CompactStr; + #[test] fn test_compactstr_eq() { let foo = CompactStr::new("foo"); diff --git a/crates/oxc_span/src/source_type/error.rs b/crates/oxc_span/src/source_type/error.rs index 72334364aaf2e8..69aa693ce72d4c 100644 --- a/crates/oxc_span/src/source_type/error.rs +++ b/crates/oxc_span/src/source_type/error.rs @@ -9,6 +9,7 @@ pub struct UnknownExtension(/* msg */ pub(crate) Cow<'static, str>); impl Deref for UnknownExtension { type Target = str; + fn deref(&self) -> &str { &self.0 } diff --git a/crates/oxc_span/src/source_type/mod.rs b/crates/oxc_span/src/source_type/mod.rs index 372d2093a6c779..6c0ceb42ea9aac 100644 --- a/crates/oxc_span/src/source_type/mod.rs +++ b/crates/oxc_span/src/source_type/mod.rs @@ -1,9 +1,10 @@ mod error; mod types; +use std::{hash::Hash, path::Path}; + pub use error::UnknownExtension; use oxc_allocator::{Allocator, CloneIn}; -use std::{hash::Hash, path::Path}; pub use types::*; use crate::{cmp::ContentEq, hash::ContentHash}; @@ -17,6 +18,7 @@ impl Default for SourceType { impl<'a> CloneIn<'a> for SourceType { type Cloned = Self; + #[inline] fn clone_in(&self, _: &'a Allocator) -> Self { *self diff --git a/crates/oxc_span/src/span/mod.rs b/crates/oxc_span/src/span/mod.rs index 1f332e914f117f..fb928f2a51d9c9 100644 --- a/crates/oxc_span/src/span/mod.rs +++ b/crates/oxc_span/src/span/mod.rs @@ -388,6 +388,7 @@ impl GetSpanMut for Span { impl<'a> CloneIn<'a> for Span { type Cloned = Self; + #[inline] fn clone_in(&self, _: &'a Allocator) -> Self { *self diff --git a/crates/oxc_span/src/span/types.rs b/crates/oxc_span/src/span/types.rs index ede19af7120886..b470f04f75d34a 100644 --- a/crates/oxc_span/src/span/types.rs +++ b/crates/oxc_span/src/span/types.rs @@ -1,11 +1,10 @@ // Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]` #![allow(non_snake_case)] +use oxc_ast_macros::ast; #[cfg(feature = "serialize")] use ::{serde::Serialize, tsify::Tsify}; -use oxc_ast_macros::ast; - /// Newtype for working with text ranges /// /// See the [`text-size`](https://docs.rs/text-size) crate for details. diff --git a/crates/oxc_syntax/src/identifier.rs b/crates/oxc_syntax/src/identifier.rs index 96b33425591128..ef5343f148beb8 100644 --- a/crates/oxc_syntax/src/identifier.rs +++ b/crates/oxc_syntax/src/identifier.rs @@ -1,5 +1,4 @@ use assert_unchecked::assert_unchecked; - use unicode_id_start::{is_id_continue_unicode, is_id_start_unicode}; pub const EOF: char = '\0'; diff --git a/crates/oxc_syntax/src/node.rs b/crates/oxc_syntax/src/node.rs index d0d5288dedc4fa..9efc14db981aec 100644 --- a/crates/oxc_syntax/src/node.rs +++ b/crates/oxc_syntax/src/node.rs @@ -1,11 +1,9 @@ use bitflags::bitflags; - use nonmax::NonMaxU32; +use oxc_index::Idx; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer}; -use oxc_index::Idx; - #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct AstNodeId(NonMaxU32); diff --git a/crates/oxc_syntax/src/operator.rs b/crates/oxc_syntax/src/operator.rs index 0e9855f6579651..8f1892432fc241 100644 --- a/crates/oxc_syntax/src/operator.rs +++ b/crates/oxc_syntax/src/operator.rs @@ -1,12 +1,11 @@ // Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]` #![allow(non_snake_case)] -#[cfg(feature = "serialize")] -use ::{serde::Serialize, tsify::Tsify}; - use oxc_allocator::CloneIn; use oxc_ast_macros::ast; use oxc_span::{cmp::ContentEq, hash::ContentHash}; +#[cfg(feature = "serialize")] +use ::{serde::Serialize, tsify::Tsify}; use crate::precedence::{GetPrecedence, Precedence}; diff --git a/crates/oxc_syntax/src/reference.rs b/crates/oxc_syntax/src/reference.rs index f2b0a4a6d2a79e..bf4c267e55a63d 100644 --- a/crates/oxc_syntax/src/reference.rs +++ b/crates/oxc_syntax/src/reference.rs @@ -1,11 +1,10 @@ use bitflags::bitflags; use nonmax::NonMaxU32; use oxc_allocator::CloneIn; +use oxc_index::Idx; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer}; -use oxc_index::Idx; - #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct ReferenceId(NonMaxU32); @@ -165,6 +164,7 @@ impl ReferenceFlags { impl<'alloc> CloneIn<'alloc> for ReferenceFlags { type Cloned = Self; + fn clone_in(&self, _: &'alloc oxc_allocator::Allocator) -> Self::Cloned { *self } diff --git a/crates/oxc_syntax/src/scope.rs b/crates/oxc_syntax/src/scope.rs index 3bf3a7b223f43a..d5ca05c436453f 100644 --- a/crates/oxc_syntax/src/scope.rs +++ b/crates/oxc_syntax/src/scope.rs @@ -1,10 +1,9 @@ use bitflags::bitflags; use nonmax::NonMaxU32; +use oxc_index::Idx; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer}; -use oxc_index::Idx; - #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct ScopeId(NonMaxU32); diff --git a/crates/oxc_syntax/src/symbol.rs b/crates/oxc_syntax/src/symbol.rs index 1ac6e953127eff..20a932c99811f9 100644 --- a/crates/oxc_syntax/src/symbol.rs +++ b/crates/oxc_syntax/src/symbol.rs @@ -1,10 +1,9 @@ use bitflags::bitflags; use nonmax::NonMaxU32; +use oxc_index::Idx; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer}; -use oxc_index::Idx; - #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct SymbolId(NonMaxU32); diff --git a/crates/oxc_transformer/src/env/targets/mod.rs b/crates/oxc_transformer/src/env/targets/mod.rs index 5f469a8fe9a463..345c50dce80976 100644 --- a/crates/oxc_transformer/src/env/targets/mod.rs +++ b/crates/oxc_transformer/src/env/targets/mod.rs @@ -10,9 +10,8 @@ use std::ops::{Deref, DerefMut}; use rustc_hash::FxHashMap; use serde::Deserialize; -use self::version::Version; - pub use self::query::Targets; +use self::version::Version; pub mod query; pub mod version; diff --git a/crates/oxc_transformer/src/es2015/options.rs b/crates/oxc_transformer/src/es2015/options.rs index d248163cc2b376..7864ca7f72024c 100644 --- a/crates/oxc_transformer/src/es2015/options.rs +++ b/crates/oxc_transformer/src/es2015/options.rs @@ -1,8 +1,7 @@ use serde::Deserialize; -use crate::env::{can_enable_plugin, Versions}; - use super::ArrowFunctionsOptions; +use crate::env::{can_enable_plugin, Versions}; #[derive(Debug, Default, Clone, Deserialize)] #[serde(default, rename_all = "camelCase", deny_unknown_fields)] diff --git a/crates/oxc_transformer/src/es2016/mod.rs b/crates/oxc_transformer/src/es2016/mod.rs index 9ec05ea231ee86..857c4fa0126230 100644 --- a/crates/oxc_transformer/src/es2016/mod.rs +++ b/crates/oxc_transformer/src/es2016/mod.rs @@ -1,12 +1,13 @@ mod exponentiation_operator; mod options; +use std::rc::Rc; + pub use exponentiation_operator::ExponentiationOperator; pub use options::ES2016Options; use oxc_allocator::Vec; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; -use std::rc::Rc; use crate::context::Ctx; diff --git a/crates/oxc_transformer/src/es2018/mod.rs b/crates/oxc_transformer/src/es2018/mod.rs index a8e14f75ae913c..c3c686ca819e01 100644 --- a/crates/oxc_transformer/src/es2018/mod.rs +++ b/crates/oxc_transformer/src/es2018/mod.rs @@ -1,11 +1,12 @@ mod object_rest_spread; mod options; +use std::rc::Rc; + pub use object_rest_spread::{ObjectRestSpread, ObjectRestSpreadOptions}; pub use options::ES2018Options; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; -use std::rc::Rc; use crate::context::Ctx; diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs b/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs index 21eac149cf4489..985889b73e5f59 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread/mod.rs @@ -26,14 +26,15 @@ //! * Babel plugin implementation: //! * Object rest/spread TC39 proposal: -use crate::context::Ctx; +use std::rc::Rc; use object_rest::ObjectRest; use object_spread::ObjectSpread; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; use serde::Deserialize; -use std::rc::Rc; + +use crate::context::Ctx; mod object_rest; mod object_spread; diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs b/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs index aa31390ccfe308..8e943d1c3ea378 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread/object_rest.rs @@ -24,9 +24,8 @@ //! * Babel plugin implementation: //! * Object rest/spread TC39 proposal: -use crate::context::Ctx; - use super::ObjectRestSpreadOptions; +use crate::context::Ctx; pub struct ObjectRest<'a> { _ctx: Ctx<'a>, diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs b/crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs index 538b16c5e8b796..52aac1a905b369 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread/object_spread.rs @@ -26,14 +26,13 @@ //! * Babel plugin implementation: //! * Object rest/spread TC39 proposal: -use crate::context::Ctx; - use oxc_ast::ast::*; use oxc_semantic::{ReferenceFlags, SymbolId}; use oxc_span::SPAN; use oxc_traverse::{Traverse, TraverseCtx}; use super::ObjectRestSpreadOptions; +use crate::context::Ctx; pub struct ObjectSpread<'a> { _ctx: Ctx<'a>, diff --git a/crates/oxc_transformer/src/es2018/options.rs b/crates/oxc_transformer/src/es2018/options.rs index a5d9688bfbecf6..1ac1831c114c1d 100644 --- a/crates/oxc_transformer/src/es2018/options.rs +++ b/crates/oxc_transformer/src/es2018/options.rs @@ -1,8 +1,7 @@ -use crate::env::{can_enable_plugin, Versions}; - use serde::Deserialize; use super::ObjectRestSpreadOptions; +use crate::env::{can_enable_plugin, Versions}; #[derive(Debug, Default, Clone, Deserialize)] #[serde(default, rename_all = "camelCase", deny_unknown_fields)] diff --git a/crates/oxc_transformer/src/es2019/mod.rs b/crates/oxc_transformer/src/es2019/mod.rs index c8cbb52242d104..452e659a7a9983 100644 --- a/crates/oxc_transformer/src/es2019/mod.rs +++ b/crates/oxc_transformer/src/es2019/mod.rs @@ -1,11 +1,12 @@ mod optional_catch_binding; mod options; +use std::rc::Rc; + pub use optional_catch_binding::OptionalCatchBinding; pub use options::ES2019Options; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; -use std::rc::Rc; use crate::context::Ctx; diff --git a/crates/oxc_transformer/src/es2020/mod.rs b/crates/oxc_transformer/src/es2020/mod.rs index d541a4f8fa1175..1f7e3a47e7c550 100644 --- a/crates/oxc_transformer/src/es2020/mod.rs +++ b/crates/oxc_transformer/src/es2020/mod.rs @@ -1,12 +1,13 @@ mod nullish_coalescing_operator; mod options; +use std::rc::Rc; + pub use nullish_coalescing_operator::NullishCoalescingOperator; pub use options::ES2020Options; use oxc_allocator::Vec; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; -use std::rc::Rc; use crate::context::Ctx; diff --git a/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs b/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs index 5d1c54ab198dfa..51e3518ca55629 100644 --- a/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs +++ b/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs @@ -30,13 +30,12 @@ use std::cell::Cell; -use oxc_semantic::{ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags}; -use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; - use oxc_allocator::{CloneIn, Vec}; use oxc_ast::ast::*; +use oxc_semantic::{ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags}; use oxc_span::SPAN; use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator}; +use oxc_traverse::{Ancestor, Traverse, TraverseCtx}; use crate::context::Ctx; diff --git a/crates/oxc_transformer/src/es2021/mod.rs b/crates/oxc_transformer/src/es2021/mod.rs index 392ff00949f2b2..6a94877c296b0d 100644 --- a/crates/oxc_transformer/src/es2021/mod.rs +++ b/crates/oxc_transformer/src/es2021/mod.rs @@ -1,12 +1,13 @@ mod logical_assignment_operators; mod options; +use std::rc::Rc; + pub use logical_assignment_operators::LogicalAssignmentOperators; pub use options::ES2021Options; use oxc_allocator::Vec; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; -use std::rc::Rc; use crate::context::Ctx; diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index d6d20c76694d25..4d968ecc24d01b 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -165,6 +165,7 @@ impl<'a> Traverse<'a> for Transformer<'a> { fn enter_class_body(&mut self, body: &mut ClassBody<'a>, ctx: &mut TraverseCtx<'a>) { self.x0_typescript.enter_class_body(body, ctx); } + fn enter_ts_module_declaration( &mut self, decl: &mut TSModuleDeclaration<'a>, @@ -296,7 +297,9 @@ impl<'a> Traverse<'a> for Transformer<'a> { if arrow.expression && arrow.body.statements.len() > 1 { let Statement::ExpressionStatement(statement) = arrow.body.statements.pop().unwrap() else { - unreachable!("The last statement in an ArrowFunctionExpression should always be an ExpressionStatement.") + unreachable!( + "The last statement in an ArrowFunctionExpression should always be an ExpressionStatement." + ) }; arrow .body diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index 7aaf1f09e22164..9d2d819f44b885 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -155,6 +155,7 @@ impl<'a> Traverse<'a> for TypeScriptAnnotations<'a> { program.body.push(self.ctx.ast.statement_module_declaration(export_decl)); } } + fn enter_arrow_function_expression( &mut self, expr: &mut ArrowFunctionExpression<'a>, diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index c2ee4a676b4769..e8b7b4339adeb8 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -11,12 +11,11 @@ use oxc_syntax::{ use oxc_traverse::{Traverse, TraverseCtx}; use rustc_hash::FxHashSet; -use crate::context::Ctx; - use super::{ diagnostics::{ambient_module_nested, namespace_exporting_non_const, namespace_not_supported}, TypeScriptOptions, }; +use crate::context::Ctx; pub struct TypeScriptNamespace<'a> { ctx: Ctx<'a>, diff --git a/crates/oxc_transformer/src/typescript/options.rs b/crates/oxc_transformer/src/typescript/options.rs index 656fa1dcb4eede..e21636d8bfe73e 100644 --- a/crates/oxc_transformer/src/typescript/options.rs +++ b/crates/oxc_transformer/src/typescript/options.rs @@ -159,7 +159,9 @@ where match value { "rewrite" => Ok(Some(RewriteExtensionsMode::Rewrite)), "remove" => Ok(Some(RewriteExtensionsMode::Remove)), - _ => Err(E::custom(format!("Expected RewriteExtensionsMode is either \"rewrite\" or \"remove\" but found: {value}"))), + _ => Err(E::custom(format!( + "Expected RewriteExtensionsMode is either \"rewrite\" or \"remove\" but found: {value}" + ))), } } } diff --git a/crates/oxc_traverse/src/lib.rs b/crates/oxc_traverse/src/lib.rs index fb0eefe82a358f..57dbf53aa2d1f8 100644 --- a/crates/oxc_traverse/src/lib.rs +++ b/crates/oxc_traverse/src/lib.rs @@ -73,11 +73,8 @@ mod generated { pub mod traverse; pub(super) mod walk; } -pub use generated::ancestor; -pub use generated::ancestor::Ancestor; -use generated::scopes_collector; -pub use generated::traverse::Traverse; -use generated::walk; +pub use generated::{ancestor, ancestor::Ancestor, traverse::Traverse}; +use generated::{scopes_collector, walk}; mod compile_fail_tests; diff --git a/napi/parser/src/lib.rs b/napi/parser/src/lib.rs index a7348a4c7a6cc7..4b439efa69758a 100644 --- a/napi/parser/src/lib.rs +++ b/napi/parser/src/lib.rs @@ -139,8 +139,8 @@ pub struct ResolveTask { #[napi] impl Task for ResolveTask { - type Output = ParseResult; type JsValue = ParseResult; + type Output = ParseResult; fn compute(&mut self) -> napi::Result { Ok(parse_with_return(&self.source_text, &self.options)) diff --git a/napi/parser/src/module_lexer.rs b/napi/parser/src/module_lexer.rs index 2f51b3007fb5bb..765a7e8403123d 100644 --- a/napi/parser/src/module_lexer.rs +++ b/napi/parser/src/module_lexer.rs @@ -140,8 +140,8 @@ pub struct ResolveTask { #[napi] impl Task for ResolveTask { - type Output = ModuleLexer; type JsValue = ModuleLexer; + type Output = ModuleLexer; fn compute(&mut self) -> napi::Result { Ok(module_lexer(&self.source_text, &self.options)) diff --git a/napi/transform/src/context.rs b/napi/transform/src/context.rs index a8d2aee8cb3893..6a9f8247668c09 100644 --- a/napi/transform/src/context.rs +++ b/napi/transform/src/context.rs @@ -1,12 +1,12 @@ -use oxc_allocator::Allocator; -use oxc_ast::{ast::Program, Trivias}; -use oxc_codegen::Codegen; use std::{ cell::{OnceCell, Ref, RefCell, RefMut}, path::Path, sync::Arc, }; +use oxc_allocator::Allocator; +use oxc_ast::{ast::Program, Trivias}; +use oxc_codegen::Codegen; use oxc_diagnostics::{Error, NamedSource, OxcDiagnostic}; use oxc_parser::{Parser, ParserReturn}; use oxc_span::SourceType; @@ -86,6 +86,7 @@ impl<'a> TransformContext<'a> { pub fn file_name(&self) -> &'a str { self.filename } + #[inline] pub fn file_path(&self) -> &'a Path { Path::new(self.filename) diff --git a/napi/transform/src/isolated_declaration.rs b/napi/transform/src/isolated_declaration.rs index 33b8be0164118a..5015a935eeed6e 100644 --- a/napi/transform/src/isolated_declaration.rs +++ b/napi/transform/src/isolated_declaration.rs @@ -1,5 +1,4 @@ use napi_derive::napi; - use oxc_allocator::Allocator; use oxc_codegen::CodegenReturn; use oxc_isolated_declarations::IsolatedDeclarations; diff --git a/napi/transform/src/options.rs b/napi/transform/src/options.rs index 37c2fb556163f8..dfe8cce1f620a0 100644 --- a/napi/transform/src/options.rs +++ b/napi/transform/src/options.rs @@ -2,7 +2,6 @@ use std::path::PathBuf; use napi::Either; use napi_derive::napi; - use oxc_transformer::{ ArrowFunctionsOptions, ES2015Options, ReactJsxRuntime, ReactOptions, RewriteExtensionsMode, TypeScriptOptions, diff --git a/napi/transform/src/transformer.rs b/napi/transform/src/transformer.rs index 63b82bae9dc547..88b26b6f69e25b 100644 --- a/napi/transform/src/transformer.rs +++ b/napi/transform/src/transformer.rs @@ -1,12 +1,12 @@ use napi_derive::napi; - -use crate::{context::TransformContext, isolated_declaration, SourceMap, TransformOptions}; use oxc_allocator::Allocator; use oxc_codegen::CodegenReturn; use oxc_semantic::SemanticBuilder; use oxc_span::SourceType; use oxc_transformer::Transformer; +use crate::{context::TransformContext, isolated_declaration, SourceMap, TransformOptions}; + // NOTE: Use JSDoc syntax for all doc comments, not rustdoc. // NOTE: Types must be aligned with [@types/babel__core](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/babel__core/index.d.ts). diff --git a/tasks/ast_tools/src/derives/clone_in.rs b/tasks/ast_tools/src/derives/clone_in.rs index 502a844c991137..58108b7baf18a0 100644 --- a/tasks/ast_tools/src/derives/clone_in.rs +++ b/tasks/ast_tools/src/derives/clone_in.rs @@ -3,14 +3,13 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use syn::Ident; +use super::{define_derive, Derive, DeriveOutput}; use crate::{ codegen::LateCtx, markers::CloneInAttribute, schema::{EnumDef, GetIdent, StructDef, TypeDef}, }; -use super::{define_derive, Derive, DeriveOutput}; - define_derive! { pub struct DeriveCloneIn; } diff --git a/tasks/ast_tools/src/derives/content_eq.rs b/tasks/ast_tools/src/derives/content_eq.rs index 7ba98e13bda7c2..29c1b59f43a22c 100644 --- a/tasks/ast_tools/src/derives/content_eq.rs +++ b/tasks/ast_tools/src/derives/content_eq.rs @@ -2,14 +2,13 @@ use itertools::Itertools; use proc_macro2::TokenStream; use quote::quote; +use super::{define_derive, Derive, DeriveOutput}; use crate::{ codegen::LateCtx, schema::{EnumDef, GetGenerics, StructDef, ToType, TypeDef}, util::ToIdent, }; -use super::{define_derive, Derive, DeriveOutput}; - define_derive! { pub struct DeriveContentEq; } diff --git a/tasks/ast_tools/src/derives/content_hash.rs b/tasks/ast_tools/src/derives/content_hash.rs index 1cab2ac020727d..9a129e8913fcb0 100644 --- a/tasks/ast_tools/src/derives/content_hash.rs +++ b/tasks/ast_tools/src/derives/content_hash.rs @@ -2,14 +2,13 @@ use itertools::Itertools; use proc_macro2::TokenStream; use quote::quote; +use super::{define_derive, Derive, DeriveOutput}; use crate::{ codegen::LateCtx, schema::{EnumDef, GetGenerics, StructDef, ToType, TypeDef}, util::ToIdent, }; -use super::{define_derive, Derive, DeriveOutput}; - define_derive! { pub struct DeriveContentHash; } diff --git a/tasks/ast_tools/src/derives/get_span.rs b/tasks/ast_tools/src/derives/get_span.rs index 38a73ecc77a1cb..9404eeb518dcae 100644 --- a/tasks/ast_tools/src/derives/get_span.rs +++ b/tasks/ast_tools/src/derives/get_span.rs @@ -2,14 +2,13 @@ use proc_macro2::TokenStream; use quote::quote; use syn::Ident; +use super::{define_derive, Derive, DeriveOutput}; use crate::{ codegen::LateCtx, schema::{EnumDef, GetGenerics, StructDef, ToType, TypeDef}, util::{ToIdent, TypeWrapper}, }; -use super::{define_derive, Derive, DeriveOutput}; - define_derive! { pub struct DeriveGetSpan; } diff --git a/tasks/ast_tools/src/derives/mod.rs b/tasks/ast_tools/src/derives/mod.rs index cdcdb1ae6b3372..555667a474e626 100644 --- a/tasks/ast_tools/src/derives/mod.rs +++ b/tasks/ast_tools/src/derives/mod.rs @@ -1,6 +1,7 @@ -use proc_macro2::TokenStream; use std::path::PathBuf; +use proc_macro2::TokenStream; + use crate::{codegen::LateCtx, schema::TypeDef}; mod clone_in; diff --git a/tasks/ast_tools/src/generators/assert_layouts.rs b/tasks/ast_tools/src/generators/assert_layouts.rs index f6cf2ffc01728f..6e58c7a176f92d 100644 --- a/tasks/ast_tools/src/generators/assert_layouts.rs +++ b/tasks/ast_tools/src/generators/assert_layouts.rs @@ -2,6 +2,7 @@ use proc_macro2::TokenStream; use quote::quote; use syn::Type; +use super::define_generator; use crate::{ codegen::{generated_header, LateCtx}, output, @@ -10,8 +11,6 @@ use crate::{ Generator, GeneratorOutput, }; -use super::define_generator; - define_generator! { pub struct AssertLayouts; } diff --git a/tasks/ast_tools/src/generators/ast_builder.rs b/tasks/ast_tools/src/generators/ast_builder.rs index 55d50b6613f26d..70cfd1351ab479 100644 --- a/tasks/ast_tools/src/generators/ast_builder.rs +++ b/tasks/ast_tools/src/generators/ast_builder.rs @@ -1,5 +1,4 @@ -use std::stringify; -use std::{borrow::Cow, collections::HashMap}; +use std::{borrow::Cow, collections::HashMap, stringify}; use convert_case::{Case, Casing}; use itertools::Itertools; @@ -8,9 +7,9 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote, ToTokens}; use syn::{parse_quote, Ident, Type}; -use crate::codegen::generated_header; +use super::define_generator; use crate::{ - codegen::LateCtx, + codegen::{generated_header, LateCtx}, output, schema::{ EnumDef, FieldDef, GetIdent, InheritDef, StructDef, ToType, TypeDef, TypeName, VariantDef, @@ -19,8 +18,6 @@ use crate::{ Generator, GeneratorOutput, }; -use super::define_generator; - define_generator! { pub struct AstBuilderGenerator; } diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index 76a475cb4981ff..350f1a7364d35f 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -3,6 +3,7 @@ use itertools::Itertools; use quote::{format_ident, quote}; use syn::{parse_quote, Arm, Ident, ImplItemFn, Type, Variant}; +use super::define_generator; use crate::{ codegen::{generated_header, LateCtx}, output, @@ -11,8 +12,6 @@ use crate::{ Generator, GeneratorOutput, }; -use super::define_generator; - define_generator! { pub struct AstKindGenerator; } diff --git a/tasks/ast_tools/src/generators/visit.rs b/tasks/ast_tools/src/generators/visit.rs index 8c217071cfdd2f..289d2847b96511 100644 --- a/tasks/ast_tools/src/generators/visit.rs +++ b/tasks/ast_tools/src/generators/visit.rs @@ -6,6 +6,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote, ToTokens}; use syn::{parse_quote, Ident}; +use super::define_generator; use crate::{ codegen::{generated_header, LateCtx}, generators::ast_kind::BLACK_LIST as KIND_BLACK_LIST, @@ -16,8 +17,6 @@ use crate::{ Generator, GeneratorOutput, }; -use super::define_generator; - define_generator! { pub struct VisitGenerator; } diff --git a/tasks/ast_tools/src/markers.rs b/tasks/ast_tools/src/markers.rs index 6521d5538f13ad..4165e623b2e5ab 100644 --- a/tasks/ast_tools/src/markers.rs +++ b/tasks/ast_tools/src/markers.rs @@ -38,8 +38,9 @@ impl Parse for VisitArg { pub struct VisitArgs(Punctuated); impl IntoIterator for VisitArgs { - type Item = VisitArg; type IntoIter = syn::punctuated::IntoIter; + type Item = VisitArg; + fn into_iter(self) -> Self::IntoIter { self.0.into_iter() } diff --git a/tasks/ast_tools/src/passes/calc_layout.rs b/tasks/ast_tools/src/passes/calc_layout.rs index 705c66e34b65f3..e66d6fc427ad2b 100644 --- a/tasks/ast_tools/src/passes/calc_layout.rs +++ b/tasks/ast_tools/src/passes/calc_layout.rs @@ -5,6 +5,7 @@ use lazy_static::lazy_static; use quote::ToTokens; use syn::Type; +use super::{define_pass, Pass}; use crate::{ codegen::EarlyCtx, layout::{KnownLayout, Layout}, @@ -13,8 +14,6 @@ use crate::{ Result, }; -use super::{define_pass, Pass}; - /// We use compiler to infer 64bit type layouts. #[cfg(not(target_pointer_width = "64"))] compile_error!("This module only supports 64bit architectures."); diff --git a/tasks/ast_tools/src/passes/linker.rs b/tasks/ast_tools/src/passes/linker.rs index 74f27eec8a227d..cac898840f8425 100644 --- a/tasks/ast_tools/src/passes/linker.rs +++ b/tasks/ast_tools/src/passes/linker.rs @@ -2,9 +2,8 @@ use std::borrow::Cow; use syn::parse_quote; -use crate::{codegen::EarlyCtx, rust_ast::Inherit, util::NormalizeError}; - use super::{define_pass, AstType, Pass, Result}; +use crate::{codegen::EarlyCtx, rust_ast::Inherit, util::NormalizeError}; pub trait Unresolved { fn unresolved(&self) -> bool; @@ -68,7 +67,9 @@ impl Pass for Linker { }) } _ => { - panic!("invalid inheritance, you can only inherit from enums and in enums.") + panic!( + "invalid inheritance, you can only inherit from enums and in enums." + ) } }; ty.item.variants.extend(variants.clone()); @@ -79,7 +80,7 @@ impl Pass for Linker { } Inherit::Linked { .. } => Ok(Ok(it)), }) - .collect::>>>()?; + .collect::>>>()?; let unresolved = inherits.iter().any(std::result::Result::is_err); ty.meta.inherits = inherits.into_iter().map(|it| it.unwrap_or_else(|it| it)).collect(); diff --git a/tasks/ast_tools/src/rust_ast.rs b/tasks/ast_tools/src/rust_ast.rs index 775949a1612068..d2c9271ee81fa2 100644 --- a/tasks/ast_tools/src/rust_ast.rs +++ b/tasks/ast_tools/src/rust_ast.rs @@ -9,13 +9,12 @@ use syn::{ Variant, Visibility, }; +use super::{parse_file, Itertools, PathBuf, Rc, Read, RefCell, Result}; use crate::{ layout::Layout, util::{unexpanded_macro_err, NormalizeError}, }; -use super::{parse_file, Itertools, PathBuf, Rc, Read, RefCell, Result}; - pub type AstRef = Rc>; #[derive(Debug, Clone)] @@ -459,7 +458,12 @@ pub fn analyze(ast_ref: &AstRef) -> Result<()> { // AST without visit! ast_ref.borrow_mut().set_ast(true)?; } - Some(AstAttr::None) => return Err(format!("All `enums` and `structs` defined in the source of truth should be marked with an `#[ast]` attribute(missing `#[ast]` on '{:?}')", ast_ref.borrow().ident())), + Some(AstAttr::None) => { + return Err(format!( + "All `enums` and `structs` defined in the source of truth should be marked with an `#[ast]` attribute(missing `#[ast]` on '{:?}')", + ast_ref.borrow().ident() + )); + } None => { /* unrelated items like `use`, `type` and `macro` definitions */ } } diff --git a/tasks/ast_tools/src/schema/defs.rs b/tasks/ast_tools/src/schema/defs.rs index 218c23867b2cba..46255991654779 100644 --- a/tasks/ast_tools/src/schema/defs.rs +++ b/tasks/ast_tools/src/schema/defs.rs @@ -1,13 +1,12 @@ use serde::Serialize; +use super::{with_either, TypeName}; use crate::{ markers::{DeriveAttributes, ScopeAttribute, ScopeMarkers, VisitMarkers}, util::{ToIdent, TypeAnalysis, TypeWrapper}, TypeId, }; -use super::{with_either, TypeName}; - #[derive(Debug, Serialize)] #[serde(untagged)] pub enum TypeDef { diff --git a/tasks/ast_tools/src/schema/get_ident.rs b/tasks/ast_tools/src/schema/get_ident.rs index 4b5ae5965d7c2a..35967dd99572b9 100644 --- a/tasks/ast_tools/src/schema/get_ident.rs +++ b/tasks/ast_tools/src/schema/get_ident.rs @@ -1,9 +1,8 @@ -use crate::util::ToIdent; - use super::{ defs::{EnumDef, StructDef, TypeDef}, with_either, }; +use crate::util::ToIdent; pub trait GetIdent { fn ident(&self) -> syn::Ident; diff --git a/tasks/ast_tools/src/schema/mod.rs b/tasks/ast_tools/src/schema/mod.rs index 3c81d93c0609e7..5121a6a2100bef 100644 --- a/tasks/ast_tools/src/schema/mod.rs +++ b/tasks/ast_tools/src/schema/mod.rs @@ -94,8 +94,8 @@ impl Schema { } impl<'a> IntoIterator for &'a Schema { - type Item = &'a TypeDef; type IntoIter = std::slice::Iter<'a, TypeDef>; + type Item = &'a TypeDef; fn into_iter(self) -> Self::IntoIter { self.defs.iter() diff --git a/tasks/coverage/src/babel/mod.rs b/tasks/coverage/src/babel/mod.rs index e658034412bea2..e8c7715473f839 100644 --- a/tasks/coverage/src/babel/mod.rs +++ b/tasks/coverage/src/babel/mod.rs @@ -1,7 +1,6 @@ use std::path::{Path, PathBuf}; -use oxc::span::SourceType; -use oxc::transformer::BabelOptions; +use oxc::{span::SourceType, transformer::BabelOptions}; use serde::{de::DeserializeOwned, Deserialize}; use serde_json::Value; diff --git a/tasks/coverage/src/driver.rs b/tasks/coverage/src/driver.rs index 3e0c6e6de069e8..0cfaf9d867fb6d 100644 --- a/tasks/coverage/src/driver.rs +++ b/tasks/coverage/src/driver.rs @@ -1,18 +1,19 @@ use std::{collections::HashSet, ops::ControlFlow, path::PathBuf}; -use oxc::CompilerInterface; - -use oxc::ast::{ast::Program, Trivias}; -use oxc::codegen::CodegenOptions; -use oxc::diagnostics::OxcDiagnostic; -use oxc::minifier::CompressOptions; -use oxc::parser::{ParseOptions, ParserReturn}; -use oxc::semantic::{ - post_transform_checker::{check_semantic_after_transform, check_semantic_ids}, - SemanticBuilderReturn, +use oxc::{ + ast::{ast::Program, Trivias}, + codegen::CodegenOptions, + diagnostics::OxcDiagnostic, + minifier::CompressOptions, + parser::{ParseOptions, ParserReturn}, + semantic::{ + post_transform_checker::{check_semantic_after_transform, check_semantic_ids}, + SemanticBuilderReturn, + }, + span::{SourceType, Span}, + transformer::{TransformOptions, TransformerReturn}, + CompilerInterface, }; -use oxc::span::{SourceType, Span}; -use oxc::transformer::{TransformOptions, TransformerReturn}; use crate::suite::TestResult; diff --git a/tasks/coverage/src/runtime/mod.rs b/tasks/coverage/src/runtime/mod.rs index 8a46ccbcc05981..8ccb4ee752e4c4 100644 --- a/tasks/coverage/src/runtime/mod.rs +++ b/tasks/coverage/src/runtime/mod.rs @@ -5,10 +5,7 @@ use std::{ time::Duration, }; -use oxc::allocator::Allocator; -use oxc::codegen::CodeGenerator; -use oxc::parser::Parser; -use oxc::span::SourceType; +use oxc::{allocator::Allocator, codegen::CodeGenerator, parser::Parser, span::SourceType}; use oxc_tasks_common::{agent, project_root}; use phf::{phf_set, Set}; use serde_json::json; diff --git a/tasks/coverage/src/suite.rs b/tasks/coverage/src/suite.rs index 8c7751dff1d0c4..d9784531f1cd96 100644 --- a/tasks/coverage/src/suite.rs +++ b/tasks/coverage/src/suite.rs @@ -10,8 +10,10 @@ use console::Style; use encoding_rs::UTF_16LE; use encoding_rs_io::DecodeReaderBytesBuilder; use futures::future::join_all; -use oxc::diagnostics::{GraphicalReportHandler, GraphicalTheme, NamedSource}; -use oxc::span::SourceType; +use oxc::{ + diagnostics::{GraphicalReportHandler, GraphicalTheme, NamedSource}, + span::SourceType, +}; use oxc_tasks_common::{normalize_path, Snapshot}; use rayon::prelude::*; use similar::{ChangeTag, TextDiff}; diff --git a/tasks/coverage/src/tools/prettier.rs b/tasks/coverage/src/tools/prettier.rs index 33b3edd9d71722..605c800626e3fe 100644 --- a/tasks/coverage/src/tools/prettier.rs +++ b/tasks/coverage/src/tools/prettier.rs @@ -1,8 +1,10 @@ use std::path::{Path, PathBuf}; -use oxc::allocator::Allocator; -use oxc::parser::{ParseOptions, Parser, ParserReturn}; -use oxc::span::SourceType; +use oxc::{ + allocator::Allocator, + parser::{ParseOptions, Parser, ParserReturn}, + span::SourceType, +}; use oxc_prettier::{Prettier, PrettierOptions}; use crate::{ diff --git a/tasks/coverage/src/tools/semantic.rs b/tasks/coverage/src/tools/semantic.rs index c77ac361d8d3f0..94cc04295f6630 100644 --- a/tasks/coverage/src/tools/semantic.rs +++ b/tasks/coverage/src/tools/semantic.rs @@ -1,8 +1,10 @@ use std::path::{Path, PathBuf}; -use oxc::span::SourceType; -use oxc::transformer::{ - ES2015Options, ReactJsxRuntime, ReactOptions, TransformOptions, TypeScriptOptions, +use oxc::{ + span::SourceType, + transformer::{ + ES2015Options, ReactJsxRuntime, ReactOptions, TransformOptions, TypeScriptOptions, + }, }; use crate::{ diff --git a/tasks/coverage/src/tools/sourcemap.rs b/tasks/coverage/src/tools/sourcemap.rs index d9ceb073a60dff..b26f6c2c278d07 100644 --- a/tasks/coverage/src/tools/sourcemap.rs +++ b/tasks/coverage/src/tools/sourcemap.rs @@ -4,11 +4,10 @@ use std::{ path::{Path, PathBuf}, }; -use oxc::allocator::Allocator; -use oxc::codegen::CodeGenerator; -use oxc::parser::Parser; -use oxc::sourcemap::SourcemapVisualizer; -use oxc::span::SourceType; +use oxc::{ + allocator::Allocator, codegen::CodeGenerator, parser::Parser, sourcemap::SourcemapVisualizer, + span::SourceType, +}; use oxc_tasks_common::TestFiles; use crate::{ diff --git a/tasks/coverage/src/tools/transformer.rs b/tasks/coverage/src/tools/transformer.rs index 369aa69cd0e0ad..ea682444912a56 100644 --- a/tasks/coverage/src/tools/transformer.rs +++ b/tasks/coverage/src/tools/transformer.rs @@ -1,9 +1,11 @@ use std::path::{Path, PathBuf}; -use oxc::span::SourceType; -use oxc::transformer::{ - ArrowFunctionsOptions, ES2015Options, ReactJsxRuntime, ReactOptions, TransformOptions, - TypeScriptOptions, +use oxc::{ + span::SourceType, + transformer::{ + ArrowFunctionsOptions, ES2015Options, ReactJsxRuntime, ReactOptions, TransformOptions, + TypeScriptOptions, + }, }; use crate::{ diff --git a/tasks/coverage/src/typescript/meta.rs b/tasks/coverage/src/typescript/meta.rs index 3d001c933d1eff..013800064de35a 100644 --- a/tasks/coverage/src/typescript/meta.rs +++ b/tasks/coverage/src/typescript/meta.rs @@ -2,11 +2,13 @@ use std::{collections::HashMap, fs, path::Path, sync::Arc}; -use oxc::allocator::Allocator; -use oxc::codegen::CodeGenerator; -use oxc::diagnostics::{NamedSource, OxcDiagnostic}; -use oxc::parser::Parser; -use oxc::span::SourceType; +use oxc::{ + allocator::Allocator, + codegen::CodeGenerator, + diagnostics::{NamedSource, OxcDiagnostic}, + parser::Parser, + span::SourceType, +}; use regex::Regex; use crate::workspace_root; diff --git a/tasks/coverage/src/typescript/transpile_runner.rs b/tasks/coverage/src/typescript/transpile_runner.rs index 5e9a2c16466865..b399e3fa4ac127 100644 --- a/tasks/coverage/src/typescript/transpile_runner.rs +++ b/tasks/coverage/src/typescript/transpile_runner.rs @@ -2,12 +2,10 @@ use std::path::{Path, PathBuf}; -use oxc::allocator::Allocator; -use oxc::codegen::CodeGenerator; -use oxc::diagnostics::OxcDiagnostic; -use oxc::isolated_declarations::IsolatedDeclarations; -use oxc::parser::Parser; -use oxc::span::SourceType; +use oxc::{ + allocator::Allocator, codegen::CodeGenerator, diagnostics::OxcDiagnostic, + isolated_declarations::IsolatedDeclarations, parser::Parser, span::SourceType, +}; use super::{ meta::{Baseline, BaselineFile}, diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 83fff14a93db4e..7dad3472bd6baf 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -3,12 +3,14 @@ use std::{ path::{Path, PathBuf}, }; -use oxc::allocator::Allocator; -use oxc::codegen::CodeGenerator; -use oxc::diagnostics::{Error, NamedSource, OxcDiagnostic}; -use oxc::parser::Parser; -use oxc::span::{SourceType, VALID_EXTENSIONS}; -use oxc::transformer::{BabelOptions, TransformOptions}; +use oxc::{ + allocator::Allocator, + codegen::CodeGenerator, + diagnostics::{Error, NamedSource, OxcDiagnostic}, + parser::Parser, + span::{SourceType, VALID_EXTENSIONS}, + transformer::{BabelOptions, TransformOptions}, +}; use oxc_tasks_common::{normalize_path, print_diff_in_terminal, project_root}; use crate::{ diff --git a/tasks/website/src/linter/rules/doc_page.rs b/tasks/website/src/linter/rules/doc_page.rs index 193d8dd1b01294..a4c4a5f40bacc9 100644 --- a/tasks/website/src/linter/rules/doc_page.rs +++ b/tasks/website/src/linter/rules/doc_page.rs @@ -1,12 +1,13 @@ //! Create documentation pages for each rule. Pages are printed as Markdown and //! get added to the website. -use oxc_linter::table::RuleTableRow; use std::{ fmt::{self, Write}, path::PathBuf, }; +use oxc_linter::table::RuleTableRow; + use super::HtmlWriter; pub fn render_rule_docs_page(rule: &RuleTableRow) -> Result { @@ -59,9 +60,10 @@ pub fn render_rule_docs_page(rule: &RuleTableRow) -> Result } fn rule_source(rule: &RuleTableRow) -> String { - use project_root::get_project_root; use std::sync::OnceLock; + use project_root::get_project_root; + const GITHUB_URL: &str = "https://github.com/oxc-project/oxc/blob/main"; const LINT_RULES_DIR: &str = "crates/oxc_linter/src/rules"; static ROOT: OnceLock = OnceLock::new(); diff --git a/tasks/website/src/linter/rules/test.rs b/tasks/website/src/linter/rules/test.rs index 672352b7a3403e..e70e6e3990002c 100644 --- a/tasks/website/src/linter/rules/test.rs +++ b/tasks/website/src/linter/rules/test.rs @@ -1,12 +1,12 @@ -use markdown::{to_html_with_options, Options}; -use oxc_diagnostics::NamedSource; -use scraper::{ElementRef, Html, Selector}; use std::sync::{Arc, OnceLock}; +use markdown::{to_html_with_options, Options}; use oxc_allocator::Allocator; +use oxc_diagnostics::NamedSource; use oxc_linter::table::RuleTable; use oxc_parser::Parser; use oxc_span::SourceType; +use scraper::{ElementRef, Html, Selector}; use super::{render_rule_docs_page, render_rules_table}; From ed8ab6d7c8b51e21a4c850481d0fa87615f614eb Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Fri, 6 Sep 2024 14:07:43 +0800 Subject: [PATCH 07/28] feat(oxc): conditional expose `oxc_cfg` in `oxc` crate (#5524) This is useful when the downside user wants to use `oxc_cfg`, and easy to reuse `petgraph` in `oxc_cfg` --- Cargo.lock | 1 + crates/oxc/Cargo.toml | 2 ++ crates/oxc/src/lib.rs | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 316fa82cc3cb54..f4b170790bb07e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1395,6 +1395,7 @@ version = "0.26.0" dependencies = [ "oxc_allocator", "oxc_ast", + "oxc_cfg", "oxc_codegen", "oxc_diagnostics", "oxc_index", diff --git a/crates/oxc/Cargo.toml b/crates/oxc/Cargo.toml index 64d8765f161154..cb38d9945c9bc6 100644 --- a/crates/oxc/Cargo.toml +++ b/crates/oxc/Cargo.toml @@ -40,6 +40,7 @@ oxc_mangler = { workspace = true, optional = true } oxc_codegen = { workspace = true, optional = true } oxc_sourcemap = { workspace = true, optional = true } oxc_isolated_declarations = { workspace = true, optional = true } +oxc_cfg = { workspace = true, optional = true } [features] full = ["codegen", "mangler", "minifier", "semantic", "transformer"] @@ -49,6 +50,7 @@ transformer = ["oxc_transformer"] minifier = ["oxc_mangler", "oxc_minifier"] codegen = ["oxc_codegen"] mangler = ["oxc_mangler"] +cfg = ["oxc_cfg"] serialize = ["oxc_ast/serialize", "oxc_semantic?/serialize", "oxc_span/serialize", "oxc_syntax/serialize"] diff --git a/crates/oxc/src/lib.rs b/crates/oxc/src/lib.rs index 0cc28b899758f5..7683c39ae84ea1 100644 --- a/crates/oxc/src/lib.rs +++ b/crates/oxc/src/lib.rs @@ -84,3 +84,9 @@ pub mod sourcemap { #[doc(inline)] pub use oxc_sourcemap::*; } + +#[cfg(feature = "cfg")] +pub mod cfg { + #[doc(inline)] + pub use oxc_cfg::*; +} From ed8937e9785fe4ed8ec5f649e8b11ec062f50d5a Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:08:49 +0000 Subject: [PATCH 08/28] perf(transformer): memoize rope instance (#5518) Currently only used in `jsx-source`, so memorize rope in JSXSource enough for now. close: #5500 --- crates/oxc_transformer/src/react/jsx.rs | 6 +- .../oxc_transformer/src/react/jsx_source.rs | 15 +- crates/oxc_transformer/src/react/utils.rs | 131 ++++++++++-------- 3 files changed, 85 insertions(+), 67 deletions(-) diff --git a/crates/oxc_transformer/src/react/jsx.rs b/crates/oxc_transformer/src/react/jsx.rs index 286cd9903d2366..c68aa22d44edee 100644 --- a/crates/oxc_transformer/src/react/jsx.rs +++ b/crates/oxc_transformer/src/react/jsx.rs @@ -11,7 +11,7 @@ use oxc_syntax::{ }; use oxc_traverse::{Traverse, TraverseCtx}; -use super::{diagnostics, utils::get_line_column}; +use super::diagnostics; pub use super::{ jsx_self::ReactJsxSelf, jsx_source::ReactJsxSource, @@ -560,7 +560,7 @@ impl<'a> ReactJsx<'a> { if let Some(span) = source_attr_span { self.jsx_source.report_error(span); } else { - let (line, column) = get_line_column(e.span().start, self.ctx.source_text); + let (line, column) = self.jsx_source.get_line_column(e.span().start); properties.push( self.jsx_source.get_object_property_kind_for_jsx_plugin(line, column, ctx), ); @@ -614,7 +614,7 @@ impl<'a> ReactJsx<'a> { if let Some(span) = source_attr_span { self.jsx_source.report_error(span); } else { - let (line, column) = get_line_column(e.span().start, self.ctx.source_text); + let (line, column) = self.jsx_source.get_line_column(e.span().start); let expr = self.jsx_source.get_source_object(line, column, ctx); arguments.push(Argument::from(expr)); } diff --git a/crates/oxc_transformer/src/react/jsx_source.rs b/crates/oxc_transformer/src/react/jsx_source.rs index d5b0924a0bec8c..6d6892f1b19486 100644 --- a/crates/oxc_transformer/src/react/jsx_source.rs +++ b/crates/oxc_transformer/src/react/jsx_source.rs @@ -3,6 +3,7 @@ use oxc_diagnostics::OxcDiagnostic; use oxc_span::{Span, SPAN}; use oxc_syntax::{number::NumberBase, symbol::SymbolFlags}; use oxc_traverse::{Traverse, TraverseCtx}; +use ropey::Rope; use super::utils::get_line_column; use crate::{context::Ctx, helpers::bindings::BoundIdentifier}; @@ -19,13 +20,14 @@ const FILE_NAME_VAR: &str = "jsxFileName"; /// In: `` /// Out: `` pub struct ReactJsxSource<'a> { - ctx: Ctx<'a>, filename_var: Option>, + source_rope: Option, + ctx: Ctx<'a>, } impl<'a> ReactJsxSource<'a> { pub fn new(ctx: Ctx<'a>) -> Self { - Self { ctx, filename_var: None } + Self { filename_var: None, source_rope: None, ctx } } } @@ -40,6 +42,13 @@ impl<'a> Traverse<'a> for ReactJsxSource<'a> { } impl<'a> ReactJsxSource<'a> { + pub fn get_line_column(&mut self, offset: u32) -> (usize, usize) { + if self.source_rope.is_none() { + self.source_rope = Some(Rope::from_str(self.ctx.source_text)); + } + get_line_column(self.source_rope.as_ref().unwrap(), offset, self.ctx.source_text) + } + pub fn get_object_property_kind_for_jsx_plugin( &mut self, line: usize, @@ -87,7 +96,7 @@ impl<'a> ReactJsxSource<'a> { // TODO: We shouldn't calculate line + column from scratch each time as it's expensive. // Build a table of byte indexes of each line's start on first usage, and save it. // Then calculate line and column from that. - let (line, column) = get_line_column(elem.span.start, self.ctx.source_text); + let (line, column) = self.get_line_column(elem.span.start); let object = self.get_source_object(line, column, ctx); let value = self .ctx diff --git a/crates/oxc_transformer/src/react/utils.rs b/crates/oxc_transformer/src/react/utils.rs index f1e120da06c86e..12a1ebc2eeee3e 100644 --- a/crates/oxc_transformer/src/react/utils.rs +++ b/crates/oxc_transformer/src/react/utils.rs @@ -6,9 +6,8 @@ use ropey::Rope; /// Column number is in UTF-16 characters, and starts at 1. /// /// This matches Babel's output. -pub fn get_line_column(offset: u32, source_text: &str) -> (usize, usize) { +pub fn get_line_column(rope: &Rope, offset: u32, source_text: &str) -> (usize, usize) { let offset = offset as usize; - let rope = Rope::from_str(source_text); // Get line number and byte offset of start of line let line_index = rope.byte_to_line(offset); let line_offset = rope.line_to_byte(line_index); @@ -18,74 +17,84 @@ pub fn get_line_column(offset: u32, source_text: &str) -> (usize, usize) { (line_index + 1, column_index + 1) } -#[test] -fn empty_file() { - assert_eq!(get_line_column(0, ""), (1, 1)); -} +#[cfg(test)] +mod test { + use ropey::Rope; -#[test] -fn first_line_start() { - assert_eq!(get_line_column(0, "foo\nbar\n"), (1, 1)); -} + fn test_line_column(offset: u32, source_text: &str) -> (usize, usize) { + let rope = Rope::from_str(source_text); + super::get_line_column(&rope, offset, source_text) + } -#[test] -fn first_line_middle() { - assert_eq!(get_line_column(5, "blahblahblah\noops\n"), (1, 6)); -} + #[test] + fn empty_file() { + assert_eq!(test_line_column(0, ""), (1, 1)); + } -#[test] -fn later_line_start() { - assert_eq!(get_line_column(8, "foo\nbar\nblahblahblah"), (3, 1)); -} + #[test] + fn first_line_start() { + assert_eq!(test_line_column(0, "foo\nbar\n"), (1, 1)); + } -#[test] -fn later_line_middle() { - assert_eq!(get_line_column(12, "foo\nbar\nblahblahblah"), (3, 5)); -} + #[test] + fn first_line_middle() { + assert_eq!(test_line_column(5, "blahblahblah\noops\n"), (1, 6)); + } -#[test] -fn after_2_byte_unicode() { - assert_eq!("£".len(), 2); - assert_eq!(utf16_len("£"), 1); - assert_eq!(get_line_column(4, "£abc"), (1, 4)); -} + #[test] + fn later_line_start() { + assert_eq!(test_line_column(8, "foo\nbar\nblahblahblah"), (3, 1)); + } -#[test] -fn after_3_byte_unicode() { - assert_eq!("अ".len(), 3); - assert_eq!(utf16_len("अ"), 1); - assert_eq!(get_line_column(5, "अabc"), (1, 4)); -} + #[test] + fn later_line_middle() { + assert_eq!(test_line_column(12, "foo\nbar\nblahblahblah"), (3, 5)); + } -#[test] -fn after_4_byte_unicode() { - assert_eq!("🍄".len(), 4); - assert_eq!(utf16_len("🍄"), 2); - assert_eq!(get_line_column(6, "🍄abc"), (1, 5)); -} + #[test] + fn after_2_byte_unicode() { + assert_eq!("£".len(), 2); + assert_eq!(utf16_len("£"), 1); + assert_eq!(test_line_column(4, "£abc"), (1, 4)); + } -#[test] -fn after_2_byte_unicode_on_previous_line() { - assert_eq!("£".len(), 2); - assert_eq!(utf16_len("£"), 1); - assert_eq!(get_line_column(4, "£\nabc"), (2, 2)); -} + #[test] + fn after_3_byte_unicode() { + assert_eq!("अ".len(), 3); + assert_eq!(utf16_len("अ"), 1); + assert_eq!(test_line_column(5, "अabc"), (1, 4)); + } -#[test] -fn after_3_byte_unicode_on_previous_line() { - assert_eq!("अ".len(), 3); - assert_eq!(utf16_len("अ"), 1); - assert_eq!(get_line_column(5, "अ\nabc"), (2, 2)); -} + #[test] + fn after_4_byte_unicode() { + assert_eq!("🍄".len(), 4); + assert_eq!(utf16_len("🍄"), 2); + assert_eq!(test_line_column(6, "🍄abc"), (1, 5)); + } -#[test] -fn after_4_byte_unicode_on_previous_line() { - assert_eq!("🍄".len(), 4); - assert_eq!(utf16_len("🍄"), 2); - assert_eq!(get_line_column(6, "🍄\nabc"), (2, 2)); -} + #[test] + fn after_2_byte_unicode_on_previous_line() { + assert_eq!("£".len(), 2); + assert_eq!(utf16_len("£"), 1); + assert_eq!(test_line_column(4, "£\nabc"), (2, 2)); + } -#[cfg(test)] -fn utf16_len(s: &str) -> usize { - s.encode_utf16().count() + #[test] + fn after_3_byte_unicode_on_previous_line() { + assert_eq!("अ".len(), 3); + assert_eq!(utf16_len("अ"), 1); + assert_eq!(test_line_column(5, "अ\nabc"), (2, 2)); + } + + #[test] + fn after_4_byte_unicode_on_previous_line() { + assert_eq!("🍄".len(), 4); + assert_eq!(utf16_len("🍄"), 2); + assert_eq!(test_line_column(6, "🍄\nabc"), (2, 2)); + } + + #[cfg(test)] + fn utf16_len(s: &str) -> usize { + s.encode_utf16().count() + } } From b4f75967bdb08938df5dbb1c259c8202d29d6842 Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:19:50 +0000 Subject: [PATCH 09/28] refactor(ast_tools): add some minimal logging. (#5519) --- .github/.generated_ast_watch_list.yml | 10 +++--- tasks/ast_tools/src/codegen.rs | 48 ++++++++++++++++++-------- tasks/ast_tools/src/main.rs | 49 +++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 21 deletions(-) diff --git a/.github/.generated_ast_watch_list.yml b/.github/.generated_ast_watch_list.yml index 672b12650674c9..bae9666219a6a3 100644 --- a/.github/.generated_ast_watch_list.yml +++ b/.github/.generated_ast_watch_list.yml @@ -11,11 +11,6 @@ src: - 'crates/oxc_span/src/span/types.rs' - 'crates/oxc_span/src/source_type/types.rs' - 'crates/oxc_regular_expression/src/ast.rs' - - 'crates/oxc_ast/src/generated/assert_layouts.rs' - - 'crates/oxc_ast/src/generated/ast_kind.rs' - - 'crates/oxc_ast/src/generated/ast_builder.rs' - - 'crates/oxc_ast/src/generated/visit.rs' - - 'crates/oxc_ast/src/generated/visit_mut.rs' - 'crates/oxc_ast/src/generated/derive_clone_in.rs' - 'crates/oxc_regular_expression/src/generated/derive_clone_in.rs' - 'crates/oxc_syntax/src/generated/derive_clone_in.rs' @@ -27,5 +22,10 @@ src: - 'crates/oxc_ast/src/generated/derive_content_hash.rs' - 'crates/oxc_regular_expression/src/generated/derive_content_hash.rs' - 'crates/oxc_syntax/src/generated/derive_content_hash.rs' + - 'crates/oxc_ast/src/generated/assert_layouts.rs' + - 'crates/oxc_ast/src/generated/ast_kind.rs' + - 'crates/oxc_ast/src/generated/ast_builder.rs' + - 'crates/oxc_ast/src/generated/visit.rs' + - 'crates/oxc_ast/src/generated/visit_mut.rs' - 'tasks/ast_codegen/src/**/*' - '.github/.generated_ast_watch_list.yml' diff --git a/tasks/ast_tools/src/codegen.rs b/tasks/ast_tools/src/codegen.rs index 78da48f8af4e19..4ccbb775d81255 100644 --- a/tasks/ast_tools/src/codegen.rs +++ b/tasks/ast_tools/src/codegen.rs @@ -7,6 +7,7 @@ use crate::{ derives::{Derive, DeriveOutput}, fmt::pretty_print, generators::{Generator, GeneratorOutput}, + log, logln, passes::Pass, rust_ast::{self, AstRef}, schema::{lower_ast_types, Schema, TypeDef}, @@ -39,11 +40,10 @@ impl SideEffect { Ok(()) } - #[expect(clippy::unnecessary_wraps)] - pub fn path(&self) -> Option { + pub fn path(&self) -> String { let Self(path, _) = self; let path = path.to_string_lossy(); - Some(path.replace('\\', "/")) + path.replace('\\', "/") } } @@ -63,7 +63,6 @@ impl From for SideEffect { pub trait Runner { type Context; type Output; - #[expect(dead_code)] fn name(&self) -> &'static str; fn run(&mut self, ctx: &Self::Context) -> Result; } @@ -185,28 +184,49 @@ impl AstCodegen { // early passes let ctx = { let ctx = EarlyCtx::new(modules); - _ = self - .passes - .into_iter() - .map(|mut runner| runner.run(&ctx)) - .collect::>>()?; + for mut runner in self.passes { + let name = runner.name(); + log!("Pass {name}... "); + runner.run(&ctx)?; + logln!("Done!"); + } ctx.into_late_ctx() }; let derives = self .derives .into_iter() - .map(|mut runner| runner.run(&ctx)) + .map(|mut runner| { + let name = runner.name(); + log!("Derive {name}... "); + let result = runner.run(&ctx); + if result.is_ok() { + logln!("Done!"); + } else { + logln!("Fail!"); + } + result + }) .map_ok(|output| output.0.into_iter().map(SideEffect::from)) .flatten_ok(); let outputs = self .generators .into_iter() - .map(|mut runner| runner.run(&ctx)) - .map_ok(SideEffect::from) - .chain(derives) - .collect::>>()?; + .map(|mut runner| { + let name = runner.name(); + log!("Generate {name}... "); + let result = runner.run(&ctx); + if result.is_ok() { + logln!("Done!"); + } else { + logln!("Fail!"); + } + result + }) + .map_ok(SideEffect::from); + + let outputs = derives.chain(outputs).collect::>>()?; Ok(AstCodegenResult { outputs, schema: ctx.schema }) } diff --git a/tasks/ast_tools/src/main.rs b/tasks/ast_tools/src/main.rs index b804b649052f23..b3b1bc4a7ded1e 100644 --- a/tasks/ast_tools/src/main.rs +++ b/tasks/ast_tools/src/main.rs @@ -50,6 +50,8 @@ pub struct CliOptions { /// Don't run cargo fmt at the end #[bpaf(switch)] no_fmt: bool, + /// Prints no logs. + quiet: bool, /// Path of output `schema.json`. schema: Option, } @@ -57,6 +59,11 @@ pub struct CliOptions { fn main() -> std::result::Result<(), Box> { let cli_options = cli_options().run(); + if cli_options.quiet { + // SAFETY: we haven't started using logger yet! + unsafe { logger::quiet() }; + } + let AstCodegenResult { outputs, schema } = SOURCE_PATHS .iter() .fold(AstCodegen::default(), AstCodegen::add_file) @@ -77,9 +84,11 @@ fn main() -> std::result::Result<(), Box> { if !cli_options.dry_run { let side_effects = outputs .into_iter() - .filter_map(|it| { + .map(|it| { let path = it.path(); + log!("Writing {path}..."); it.apply().unwrap(); + logln!(" Done!"); path }) .collect(); @@ -128,5 +137,41 @@ fn write_ci_filter( push_item("tasks/ast_codegen/src/**/*"); push_item(output_path); - write_all_to(output.as_bytes(), output_path) + log!("Writing {output_path}..."); + write_all_to(output.as_bytes(), output_path)?; + logln!(" Done!"); + Ok(()) } + +#[macro_use] +mod logger { + static mut LOG: bool = true; + + /// Shouldn't be called after first use of the logger macros. + pub(super) unsafe fn quiet() { + LOG = false; + } + + pub(super) fn __internal_log_enable() -> bool { + // SAFETY:`LOG` doesn't change from the moment we start using it. + unsafe { LOG } + } + + macro_rules! log { + ($fmt:literal $(, $args:expr)*) => { + if $crate::logger::__internal_log_enable() { + print!("{}", format!($fmt$(, $args)*)); + } + } + } + + macro_rules! logln { + ($fmt:literal $(, $args:expr)*) => { + $crate::log!("{}\n", format!($fmt $(, $args)*)); + } + } + + pub(super) use {log, logln}; +} + +pub(crate) use logger::{log, logln}; From 7a797ac6353bad66f98a5daba51a6fe234c58a4f Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:24:44 +0000 Subject: [PATCH 10/28] fix(semantic): incorrect reference when `MemberExpression` used in `TSPropertySignature` (#5525) close: https://github.com/oxc-project/oxc/issues/5435#issuecomment-2333032168 --- crates/oxc_semantic/src/builder.rs | 9 ++++----- .../signatures/property-with-type-import.snap | 19 +++++++++++++++++++ .../signatures/property-with-type-import.ts | 10 +++++++--- .../signatures/property-computed-name2.snap | 2 +- tasks/coverage/semantic_typescript.snap | 3 +++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index b97c8286f6998b..c63a92ebeac140 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -1891,9 +1891,9 @@ impl<'a> SemanticBuilder<'a> { } } AstKind::MemberExpression(_) => { - if !self.current_reference_flags.is_type() { - self.current_reference_flags = ReferenceFlags::Read; - } + // A.B = 1; + // ^^^ we can't treat A as Write reference, because it's the property(B) of A that change + self.current_reference_flags -= ReferenceFlags::Write; } AstKind::AssignmentTarget(_) => { self.current_reference_flags |= ReferenceFlags::Write; @@ -1966,8 +1966,7 @@ impl<'a> SemanticBuilder<'a> { self.current_reference_flags -= ReferenceFlags::Read; } } - AstKind::MemberExpression(_) - | AstKind::ExportNamedDeclaration(_) + AstKind::ExportNamedDeclaration(_) | AstKind::TSTypeQuery(_) // Clear the reference flags that are set in AstKind::PropertySignature | AstKind::PropertyKey(_) => { diff --git a/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap index 2c844c0dd35a8c..20291d123f00c0 100644 --- a/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap +++ b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap @@ -18,6 +18,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/ "id": 2, "node": "TSInterfaceDeclaration", "symbols": [] + }, + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 3, + "node": "TSInterfaceDeclaration", + "symbols": [] } ], "flags": "ScopeFlags(StrictMode | Top)", @@ -35,6 +42,12 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/ "id": 0, "name": "X", "node_id": 15 + }, + { + "flags": "ReferenceFlags(Type)", + "id": 2, + "name": "X", + "node_id": 27 } ] }, @@ -49,6 +62,12 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/ "id": 1, "name": "B", "node_id": 19 + }, + { + "flags": "ReferenceFlags(Type)", + "id": 3, + "name": "B", + "node_id": 32 } ] }, diff --git a/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts index da4d768c6ba681..24d87a8c3f2fae 100644 --- a/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts +++ b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts @@ -1,7 +1,11 @@ -import type X from 'mod'; +import type X from "mod"; type B = number; export interface A { - [X]: B -} \ No newline at end of file + [X]: B; +} + +export interface A { + [X.X]: B; +} diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name2.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name2.snap index 5b6304c581b019..a7fadc9a650fd6 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name2.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name2.snap @@ -39,7 +39,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio "node": "TSEnumDeclaration(Foo)", "references": [ { - "flags": "ReferenceFlags(Read)", + "flags": "ReferenceFlags(Type)", "id": 0, "name": "Foo", "node_id": 11 diff --git a/tasks/coverage/semantic_typescript.snap b/tasks/coverage/semantic_typescript.snap index f53e398365eed7..5cd7452b0a0c3f 100644 --- a/tasks/coverage/semantic_typescript.snap +++ b/tasks/coverage/semantic_typescript.snap @@ -16756,6 +16756,9 @@ rebuilt : SymbolId(20): [ReferenceId(14), ReferenceId(15), ReferenceId(17 Symbol reference IDs mismatch: after transform: SymbolId(25): [ReferenceId(13)] rebuilt : SymbolId(21): [] +Reference flags mismatch: +after transform: ReferenceId(12): ReferenceFlags(Write) +rebuilt : ReferenceId(16): ReferenceFlags(Read | Write) tasks/coverage/typescript/tests/cases/compiler/missingSemicolonInModuleSpecifier.ts semantic error: Bindings mismatch: From fce549e6486400d43e65675607efecf0e7ae810c Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:38:47 +0000 Subject: [PATCH 11/28] fix(diagnostics): ignore `Interrupted` and `BrokenPipe` errors while printing (#5526) closes #5452 --- .../oxc_diagnostics/src/reporter/graphical.rs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/oxc_diagnostics/src/reporter/graphical.rs b/crates/oxc_diagnostics/src/reporter/graphical.rs index 31c6a1f5ef2799..6751b2483b30e8 100644 --- a/crates/oxc_diagnostics/src/reporter/graphical.rs +++ b/crates/oxc_diagnostics/src/reporter/graphical.rs @@ -1,4 +1,4 @@ -use std::io::{BufWriter, Stdout, Write}; +use std::io::{BufWriter, ErrorKind, Stdout, Write}; use super::{writer, DiagnosticReporter}; use crate::{Error, GraphicalReportHandler}; @@ -16,11 +16,31 @@ impl Default for GraphicalReporter { impl DiagnosticReporter for GraphicalReporter { fn finish(&mut self) { - self.writer.flush().unwrap(); + self.writer + .flush() + .or_else(|e| { + // Do not panic when the process is skill (e.g. piping into `less`). + if matches!(e.kind(), ErrorKind::Interrupted | ErrorKind::BrokenPipe) { + Ok(()) + } else { + Err(e) + } + }) + .unwrap(); } fn render_diagnostics(&mut self, s: &[u8]) { - self.writer.write_all(s).unwrap(); + self.writer + .write_all(s) + .or_else(|e| { + // Do not panic when the process is skill (e.g. piping into `less`). + if matches!(e.kind(), ErrorKind::Interrupted | ErrorKind::BrokenPipe) { + Ok(()) + } else { + Err(e) + } + }) + .unwrap(); } fn render_error(&mut self, error: Error) -> Option { From ff88c1fc0723a3b103315e8023ef772b4cfa38ff Mon Sep 17 00:00:00 2001 From: Cam McHenry Date: Fri, 6 Sep 2024 03:30:28 -0400 Subject: [PATCH 12/28] fix(linter): Don't mark binding rest elements as unused in TS function overloads (#5470) - Fixes https://github.com/oxc-project/oxc/issues/5406 This implements a fix for the `BindingRestElement` symbol, which is currently unhandled and gets automatically marked as unused. If we happen to find that it is a child of declaration, then we will automatically allow the binding rest element. The code for this was based on what we currently do in `is_allowed_param_because_of_method`: https://github.com/oxc-project/oxc/blob/5187f384cb38b1ba69acc2cb9b677d72ef175e3e/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs#L258 I opted not to refactor this to re-use the same code though, as I think the duplication is still incidental and the implementations could diverge in the future. --- .../rules/eslint/no_unused_vars/allowed.rs | 15 ++++++++++++++ .../src/rules/eslint/no_unused_vars/mod.rs | 6 ++++++ .../rules/eslint/no_unused_vars/tests/oxc.rs | 19 ++++++++++++++++++ .../no_unused_vars@oxc-functions.snap | 20 +++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs index 66a405bca59c87..3a9cc1cb34f1bf 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs @@ -294,4 +294,19 @@ impl NoUnusedVars { _ => false, } } + + /// Returns `true` if this binding rest element should be allowed (i.e. not + /// reported). Currently, this handles the case where a rest element is part + /// of a TS function declaration. + pub(super) fn is_allowed_binding_rest_element(symbol: &Symbol) -> bool { + for parent in symbol.iter_parents() { + // If this is a binding rest element that is part of a TS function parameter, + // for example: `function foo(...messages: string[]) {}`, then we will allow it. + if let AstKind::Function(f) = parent.kind() { + return f.is_typescript_syntax(); + } + } + + false + } } diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs index e3726233226654..426a50bf05f770 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs @@ -297,6 +297,12 @@ impl NoUnusedVars { } ctx.diagnostic(diagnostic::param(symbol)); } + AstKind::BindingRestElement(_) => { + if NoUnusedVars::is_allowed_binding_rest_element(symbol) { + return; + } + ctx.diagnostic(diagnostic::declared(symbol)); + } AstKind::Class(_) | AstKind::Function(_) => { if self.is_allowed_class_or_function(symbol) { return; diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs index b3bf68f00e2643..6b79ab96c26017 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs @@ -495,12 +495,31 @@ fn test_functions() { ", "const foo = () => function bar() { }\nfoo()", "module.exports.foo = () => function bar() { }", + // https://github.com/oxc-project/oxc/issues/5406 + " + export function log(message: string, ...interpolations: unknown[]): void; + export function log(message: string, ...interpolations: unknown[]): void { + console.log(message, interpolations); + } + ", + "declare function func(strings: any, ...values: any[]): object" ]; let fail = vec![ "function foo() {}", "function foo() { foo() }", "const foo = () => { function bar() { } }\nfoo()", + " + export function log(message: string, ...interpolations: unknown[]): void; + export function log(message: string, ...interpolations: unknown[]): void { + console.log(message); + } + ", + " + export function log(...messages: unknown[]): void { + return; + } + ", ]; let fix = vec![ diff --git a/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-functions.snap b/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-functions.snap index 6903fab79de393..31c927622e235a 100644 --- a/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-functions.snap +++ b/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-functions.snap @@ -25,3 +25,23 @@ source: crates/oxc_linter/src/tester.rs 2 │ foo() ╰──── help: Consider removing this declaration. + + ⚠ eslint(no-unused-vars): Variable 'interpolations' is declared but never used. + ╭─[no_unused_vars.tsx:3:46] + 2 │ export function log(message: string, ...interpolations: unknown[]): void; + 3 │ export function log(message: string, ...interpolations: unknown[]): void { + · ──────────────┬───────────── + · ╰── 'interpolations' is declared here + 4 │ console.log(message); + ╰──── + help: Consider removing this declaration. + + ⚠ eslint(no-unused-vars): Variable 'messages' is declared but never used. + ╭─[no_unused_vars.tsx:2:29] + 1 │ + 2 │ export function log(...messages: unknown[]): void { + · ───────────┬────────── + · ╰── 'messages' is declared here + 3 │ return; + ╰──── + help: Consider removing this declaration. From 80d80b70c0984bcbd175d49045aaccb2c14510ed Mon Sep 17 00:00:00 2001 From: Valentinas Janeiko <2305836+valeneiko@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:30:26 +0100 Subject: [PATCH 13/28] ci: Passthrough OXC_VERSION and JEMALLOC_SYS_WITH_LG_PAGE to build container (#5531) Fixes: - https://github.com/oxc-project/oxc/issues/4891 Currently only Mac OS and Windows versions return correct version. Linux versions still returns `dev`. This is caused by Mac OS and Windows building on the host ([logs](https://github.com/oxc-project/oxc/actions/runs/10667173657/job/29564299213#step:6:16)), while Linux is building inside a container. Container builds do not have access to host env variables by default. --- Cross.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Cross.toml b/Cross.toml index b6dfa485df895a..643e89e206cff4 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,2 +1,6 @@ [build.env] -passthrough = ["CI"] # for crates/oxc_traverse/build.rs +passthrough = [ + "CI", # for crates/oxc_traverse/build.rs + "OXC_VERSION", + "JEMALLOC_SYS_WITH_LG_PAGE", +] From f95d35eca7ea9c17ceac793c8ff5c693c687fb76 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 6 Sep 2024 18:51:08 +0800 Subject: [PATCH 14/28] chore: format Cross.toml --- Cross.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cross.toml b/Cross.toml index 643e89e206cff4..11961798fd2abc 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,6 +1,6 @@ [build.env] passthrough = [ "CI", # for crates/oxc_traverse/build.rs - "OXC_VERSION", "JEMALLOC_SYS_WITH_LG_PAGE", -] + "OXC_VERSION", +] From 64eb2cccb7f9db7708caa84f830abb675830f120 Mon Sep 17 00:00:00 2001 From: oxc-bot Date: Fri, 6 Sep 2024 19:06:29 +0800 Subject: [PATCH 15/28] release: crates v0.27.0 (#5538) ## [0.27.0] - 2024-09-06 - bd820f9 semantic: [**BREAKING**] Remove `SymbolTable::get_symbol_id_from_name` and `SymbolTable::get_scope_id_from_name` (#5480) (overlookmotel) - cba93f5 ast: [**BREAKING**] Add `ThisExpression` variants to `JSXElementName` and `JSXMemberExpressionObject` (#5466) (overlookmotel) - 87c5df2 ast: [**BREAKING**] Rename `Expression::without_parentheses` (#5448) (overlookmotel) ### Features - e8bdd12 allocator: Add `AsMut` impl for `Box` (#5515) (overlookmotel) - 90facd3 ast: Add `ContentHash` trait; remove noop `Hash` implementation from `Span` (#5451) (rzvxa) - 23285f4 ast: Add `ContentEq` trait. (#5427) (rzvxa) - 59abf27 ast, parser: Add `oxc_regular_expression` types to the parser and AST. (#5256) (rzvxa) - 68a1c01 ast_tools: Add dedicated `Derive` trait. (#5278) (rzvxa) - c782916 codegen: Print `type_parameters` in `TaggedTemplateExpression` (#5438) (Dunqing) - 4cb63fe index: Impl rayon related to trait for IndexVec (#5421) (IWANABETHATGUY) - ba4b68c minifier: Remove parenthesized expression for dce (#5439) (Boshen) - ed8ab6d oxc: Conditional expose `oxc_cfg` in `oxc` crate (#5524) (IWANABETHATGUY) - 91b39c4 oxc_diagnostic: Impl DerefMut for OxcDiagnostic (#5474) (IWANABETHATGUY) - 10279f5 parser: Add syntax error for hyphen in `JSXMemberExpression` `` (#5440) (Boshen) - 0f50b1e semantic: Check for initializers in ambient `VariableDeclaration`s (#5463) (DonIsaac) - 62f7fff semantic: Check for non-declared, non-abstract object accessors without bodies (#5461) (DonIsaac) - 5407143 semantic: Check for non-declared, non-abstract class accessors without bodies (#5460) (DonIsaac) - 052e94c semantic: Check for parameter properties in constructor overloads (#5459) (DonIsaac) - 32d4bbb transformer: Add `TransformOptions::enable_all` method (#5495) (Boshen) - c59d8b3 transformer: Support all /regex/ to `new RegExp` transforms (#5387) (Dunqing) - cedf7a4 xtask: Impl `as_ast_kind` method for each variant (#5491) (IWANABETHATGUY) ### Bug Fixes - 0df1d9d ast, codegen, linter: Panics in fixers. (#5431) (rzvxa) - fce549e diagnostics: Ignore `Interrupted` and `BrokenPipe` errors while printing (#5526) (Boshen) - ea7a52f napi/transform: Fix test (Boshen) - 9b984b3 regex: Panic on displaying surrogated `UnicodeEscape` characters. (#5469) (rzvxa) - 88b7ddb regular_expression: Handle unterminated character class (#5523) (leaysgur) - 7a797ac semantic: Incorrect reference when `MemberExpression` used in `TSPropertySignature` (#5525) (Dunqing) - d8b9909 semantic: `IdentifierReference` within `TSPropertySignature` cannot reference type-only import binding (#5441) (Dunqing) - 8f9627d transformer: RegExp transform do not transform invalid regexps (#5494) (overlookmotel) - 2060efc transformer: RegExp transform don't transform all RegExps (#5486) (overlookmotel) - cfe5497 transformer: Do not create double reference in JSX transform (#5414) (overlookmotel) - 0617249 transformer/nullish-coalescing-operator: Incorrect reference flags (#5408) (Dunqing) - 0eb32a6 traverse: Invalid variable name generated by `generate_uid_based_on_node` (#5407) (Dunqing)- b96bea4 Add back lifetime (#5507) (IWANABETHATGUY) ### Performance - bfabd8f syntax: Further optimize `is_identifier_name` (#5426) (overlookmotel) - aeda84f syntax: Optimize `is_identifier_name` (#5425) (overlookmotel) - ed8937e transformer: Memoize rope instance (#5518) (Dunqing) - bfab091 transformer: Store needed options only on `RegExp` (#5484) (overlookmotel) - b4765af transformer: Pre-calculate if unsupported patterns in RegExp transform (#5483) (overlookmotel) - 182ab91 transformer: Pre-calculate unsupported flags in RegExp transform (#5482) (overlookmotel) ### Documentation - 64db1b4 ast: Clarify docs for `RegExpPattern` (#5497) (overlookmotel) - 3f204a9 span: Update docs about `ContentEq` `Vec` comparison speed (#5478) (overlookmotel)- 00511fd Use `oxc_index` instead of `index_vec` in doc comments (#5423) (IWANABETHATGUY) ### Refactor - 9f6e0ed ast: Simplify `ContentEq` trait definition. (#5468) (rzvxa) - a43e951 ast: Use loop instead of recursion (#5447) (overlookmotel) - 2224cc4 ast: Renumber `JSXMemberExpressionObject` discriminants (#5464) (overlookmotel) - a952c47 ast: Use loop not recursion (#5449) (overlookmotel) - d9d7e7c ast: Remove `IdentifierName` from `TSThisParameter` (#5327) (overlookmotel) - ccc8a27 ast, ast_tools: Use full method path for generated derives trait calls. (#5462) (rzvxa) - fdb8857 linter: Use "parsed pattern" in `no_div_regex` rule. (#5417) (rzvxa) - e7bd49d regular_expression: Correct typo (#5429) (overlookmotel) - e4ed41d semantic: Change the reference flag to `ReferenceFlags::Type` if it is used within a `TSTypeQuery` (#5444) (Dunqing) - 94a6ac6 span: Use `Hasher` from `std` (#5476) (overlookmotel) - b47aca0 syntax: Use `generate_derive` for `CloneIn` in types outside of `oxc_ast` crate. (#5280) (rzvxa) - a96866d transformer: Re-order imports (#5499) (overlookmotel) - 6abde0a transformer: Clarify match in RegExp transform (#5498) (overlookmotel) - 09c522a transformer: RegExp transform report pattern parsing errors (#5496) (overlookmotel) - dd19823 transformer: RegExp transform do not take ownership of `Pattern` then reallocate it (#5492) (overlookmotel) - 2514cc9 transformer/react: Move all entry points to implementation of Traverse trait (#5473) (Dunqing) - c984219 transformer/typescript: Move all entry points to implementation of Traverse trait (#5422) (Dunqing) ### Styling - 2a43fa4 linter: Introduce the writing style from PR #5491 and reduce the if nesting (#5512) (dalaoshu) ### Testing - 340b535 linter/no-unused-vars: Arrow functions in tagged templates (#5510) (Don Isaac) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com> --- Cargo.lock | 42 ++++++++++----------- Cargo.toml | 42 ++++++++++----------- crates/oxc/CHANGELOG.md | 6 +++ crates/oxc/Cargo.toml | 2 +- crates/oxc_allocator/CHANGELOG.md | 6 +++ crates/oxc_allocator/Cargo.toml | 2 +- crates/oxc_ast/CHANGELOG.md | 34 +++++++++++++++++ crates/oxc_ast/Cargo.toml | 2 +- crates/oxc_ast_macros/CHANGELOG.md | 12 ++++++ crates/oxc_ast_macros/Cargo.toml | 2 +- crates/oxc_cfg/Cargo.toml | 2 +- crates/oxc_codegen/CHANGELOG.md | 19 ++++++++++ crates/oxc_codegen/Cargo.toml | 2 +- crates/oxc_diagnostics/CHANGELOG.md | 10 +++++ crates/oxc_diagnostics/Cargo.toml | 2 +- crates/oxc_index/CHANGELOG.md | 9 +++++ crates/oxc_index/Cargo.toml | 2 +- crates/oxc_isolated_declarations/Cargo.toml | 2 +- crates/oxc_mangler/Cargo.toml | 2 +- crates/oxc_minifier/CHANGELOG.md | 6 +++ crates/oxc_minifier/Cargo.toml | 2 +- crates/oxc_module_lexer/Cargo.toml | 2 +- crates/oxc_parser/CHANGELOG.md | 13 +++++++ crates/oxc_parser/Cargo.toml | 2 +- crates/oxc_regular_expression/CHANGELOG.md | 18 +++++++++ crates/oxc_regular_expression/Cargo.toml | 2 +- crates/oxc_semantic/CHANGELOG.md | 28 ++++++++++++++ crates/oxc_semantic/Cargo.toml | 2 +- crates/oxc_sourcemap/Cargo.toml | 2 +- crates/oxc_span/CHANGELOG.md | 16 ++++++++ crates/oxc_span/Cargo.toml | 2 +- crates/oxc_syntax/CHANGELOG.md | 18 +++++++++ crates/oxc_syntax/Cargo.toml | 2 +- crates/oxc_transformer/CHANGELOG.md | 32 ++++++++++++++++ crates/oxc_transformer/Cargo.toml | 2 +- crates/oxc_traverse/CHANGELOG.md | 15 ++++++++ crates/oxc_traverse/Cargo.toml | 2 +- napi/transform/CHANGELOG.md | 6 +++ napi/transform/Cargo.toml | 2 +- npm/oxc-parser/package.json | 2 +- npm/oxc-transform/package.json | 2 +- wasm/parser/package.json | 2 +- 42 files changed, 314 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4b170790bb07e..99eb9c2d0f0735 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1391,7 +1391,7 @@ checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f" [[package]] name = "oxc" -version = "0.26.0" +version = "0.27.0" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1429,7 +1429,7 @@ dependencies = [ [[package]] name = "oxc_allocator" -version = "0.26.0" +version = "0.27.0" dependencies = [ "allocator-api2", "bumpalo", @@ -1439,7 +1439,7 @@ dependencies = [ [[package]] name = "oxc_ast" -version = "0.26.0" +version = "0.27.0" dependencies = [ "bitflags 2.6.0", "num-bigint", @@ -1456,7 +1456,7 @@ dependencies = [ [[package]] name = "oxc_ast_macros" -version = "0.26.0" +version = "0.27.0" dependencies = [ "proc-macro2", "quote", @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "oxc_cfg" -version = "0.26.0" +version = "0.27.0" dependencies = [ "bitflags 2.6.0", "itertools", @@ -1514,7 +1514,7 @@ dependencies = [ [[package]] name = "oxc_codegen" -version = "0.26.0" +version = "0.27.0" dependencies = [ "base64", "bitflags 2.6.0", @@ -1561,7 +1561,7 @@ dependencies = [ [[package]] name = "oxc_diagnostics" -version = "0.26.0" +version = "0.27.0" dependencies = [ "miette", "owo-colors", @@ -1571,7 +1571,7 @@ dependencies = [ [[package]] name = "oxc_index" -version = "0.26.0" +version = "0.27.0" dependencies = [ "rayon", "serde", @@ -1579,7 +1579,7 @@ dependencies = [ [[package]] name = "oxc_isolated_declarations" -version = "0.26.0" +version = "0.27.0" dependencies = [ "insta", "oxc_allocator", @@ -1671,7 +1671,7 @@ dependencies = [ [[package]] name = "oxc_mangler" -version = "0.26.0" +version = "0.27.0" dependencies = [ "itertools", "oxc_ast", @@ -1682,7 +1682,7 @@ dependencies = [ [[package]] name = "oxc_minifier" -version = "0.26.0" +version = "0.27.0" dependencies = [ "insta", "num-bigint", @@ -1716,7 +1716,7 @@ dependencies = [ [[package]] name = "oxc_module_lexer" -version = "0.26.0" +version = "0.27.0" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1726,7 +1726,7 @@ dependencies = [ [[package]] name = "oxc_parser" -version = "0.26.0" +version = "0.27.0" dependencies = [ "assert-unchecked", "bitflags 2.6.0", @@ -1800,7 +1800,7 @@ dependencies = [ [[package]] name = "oxc_regular_expression" -version = "0.26.0" +version = "0.27.0" dependencies = [ "oxc_allocator", "oxc_ast_macros", @@ -1834,7 +1834,7 @@ dependencies = [ [[package]] name = "oxc_semantic" -version = "0.26.0" +version = "0.27.0" dependencies = [ "assert-unchecked", "indexmap", @@ -1858,7 +1858,7 @@ dependencies = [ [[package]] name = "oxc_sourcemap" -version = "0.26.0" +version = "0.27.0" dependencies = [ "base64-simd", "cfg-if", @@ -1870,7 +1870,7 @@ dependencies = [ [[package]] name = "oxc_span" -version = "0.26.0" +version = "0.27.0" dependencies = [ "compact_str", "miette", @@ -1884,7 +1884,7 @@ dependencies = [ [[package]] name = "oxc_syntax" -version = "0.26.0" +version = "0.27.0" dependencies = [ "assert-unchecked", "bitflags 2.6.0", @@ -1927,7 +1927,7 @@ dependencies = [ [[package]] name = "oxc_transform_napi" -version = "0.26.0" +version = "0.27.0" dependencies = [ "napi", "napi-build", @@ -1946,7 +1946,7 @@ dependencies = [ [[package]] name = "oxc_transformer" -version = "0.26.0" +version = "0.27.0" dependencies = [ "dashmap 6.0.1", "indexmap", @@ -1970,7 +1970,7 @@ dependencies = [ [[package]] name = "oxc_traverse" -version = "0.26.0" +version = "0.27.0" dependencies = [ "compact_str", "memoffset", diff --git a/Cargo.toml b/Cargo.toml index 0ceb7b95ad3e3e..1d198f61d44d52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,27 +76,27 @@ doc_lazy_continuation = "allow" # FIXME [workspace.dependencies] # publish = true -oxc = { version = "0.26.0", path = "crates/oxc" } -oxc_allocator = { version = "0.26.0", path = "crates/oxc_allocator" } -oxc_ast = { version = "0.26.0", path = "crates/oxc_ast" } -oxc_codegen = { version = "0.26.0", path = "crates/oxc_codegen" } -oxc_diagnostics = { version = "0.26.0", path = "crates/oxc_diagnostics" } -oxc_index = { version = "0.26.0", path = "crates/oxc_index" } -oxc_minifier = { version = "0.26.0", path = "crates/oxc_minifier" } -oxc_mangler = { version = "0.26.0", path = "crates/oxc_mangler" } -oxc_parser = { version = "0.26.0", path = "crates/oxc_parser" } -oxc_semantic = { version = "0.26.0", path = "crates/oxc_semantic" } -oxc_span = { version = "0.26.0", path = "crates/oxc_span" } -oxc_syntax = { version = "0.26.0", path = "crates/oxc_syntax" } -oxc_transformer = { version = "0.26.0", path = "crates/oxc_transformer" } -oxc_sourcemap = { version = "0.26.0", path = "crates/oxc_sourcemap" } -oxc_ast_macros = { version = "0.26.0", path = "crates/oxc_ast_macros" } -oxc_traverse = { version = "0.26.0", path = "crates/oxc_traverse" } -oxc_module_lexer = { version = "0.26.0", path = "crates/oxc_module_lexer" } -oxc_cfg = { version = "0.26.0", path = "crates/oxc_cfg" } -oxc_isolated_declarations = { version = "0.26.0", path = "crates/oxc_isolated_declarations" } -oxc_regular_expression = { version = "0.26.0", path = "crates/oxc_regular_expression" } -oxc_transform_napi = { version = "0.26.0", path = "napi/transform" } +oxc = { version = "0.27.0", path = "crates/oxc" } +oxc_allocator = { version = "0.27.0", path = "crates/oxc_allocator" } +oxc_ast = { version = "0.27.0", path = "crates/oxc_ast" } +oxc_codegen = { version = "0.27.0", path = "crates/oxc_codegen" } +oxc_diagnostics = { version = "0.27.0", path = "crates/oxc_diagnostics" } +oxc_index = { version = "0.27.0", path = "crates/oxc_index" } +oxc_minifier = { version = "0.27.0", path = "crates/oxc_minifier" } +oxc_mangler = { version = "0.27.0", path = "crates/oxc_mangler" } +oxc_parser = { version = "0.27.0", path = "crates/oxc_parser" } +oxc_semantic = { version = "0.27.0", path = "crates/oxc_semantic" } +oxc_span = { version = "0.27.0", path = "crates/oxc_span" } +oxc_syntax = { version = "0.27.0", path = "crates/oxc_syntax" } +oxc_transformer = { version = "0.27.0", path = "crates/oxc_transformer" } +oxc_sourcemap = { version = "0.27.0", path = "crates/oxc_sourcemap" } +oxc_ast_macros = { version = "0.27.0", path = "crates/oxc_ast_macros" } +oxc_traverse = { version = "0.27.0", path = "crates/oxc_traverse" } +oxc_module_lexer = { version = "0.27.0", path = "crates/oxc_module_lexer" } +oxc_cfg = { version = "0.27.0", path = "crates/oxc_cfg" } +oxc_isolated_declarations = { version = "0.27.0", path = "crates/oxc_isolated_declarations" } +oxc_regular_expression = { version = "0.27.0", path = "crates/oxc_regular_expression" } +oxc_transform_napi = { version = "0.27.0", path = "napi/transform" } # publish = false oxc_macros = { path = "crates/oxc_macros" } diff --git a/crates/oxc/CHANGELOG.md b/crates/oxc/CHANGELOG.md index 4859a87c3fa84a..0625c954ba01a3 100644 --- a/crates/oxc/CHANGELOG.md +++ b/crates/oxc/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- ed8ab6d oxc: Conditional expose `oxc_cfg` in `oxc` crate (#5524) (IWANABETHATGUY) + ## [0.26.0] - 2024-09-03 ### Features diff --git a/crates/oxc/Cargo.toml b/crates/oxc/Cargo.toml index cb38d9945c9bc6..432549cfd82c4e 100644 --- a/crates/oxc/Cargo.toml +++ b/crates/oxc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_allocator/CHANGELOG.md b/crates/oxc_allocator/CHANGELOG.md index 43c16d48ae4285..be184199c17ef5 100644 --- a/crates/oxc_allocator/CHANGELOG.md +++ b/crates/oxc_allocator/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- e8bdd12 allocator: Add `AsMut` impl for `Box` (#5515) (overlookmotel) + ## [0.25.0] - 2024-08-23 ### Refactor diff --git a/crates/oxc_allocator/Cargo.toml b/crates/oxc_allocator/Cargo.toml index 678440a5494be1..e3ad2ea4ff5763 100644 --- a/crates/oxc_allocator/Cargo.toml +++ b/crates/oxc_allocator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_allocator" -version = "0.26.0" +version = "0.27.0" authors.workspace = true description.workspace = true edition.workspace = true diff --git a/crates/oxc_ast/CHANGELOG.md b/crates/oxc_ast/CHANGELOG.md index 266dc654b6abd9..865093da5d89f0 100644 --- a/crates/oxc_ast/CHANGELOG.md +++ b/crates/oxc_ast/CHANGELOG.md @@ -4,6 +4,40 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +- cba93f5 ast: [**BREAKING**] Add `ThisExpression` variants to `JSXElementName` and `JSXMemberExpressionObject` (#5466) (overlookmotel) + +- 87c5df2 ast: [**BREAKING**] Rename `Expression::without_parentheses` (#5448) (overlookmotel) + +### Features + +- 90facd3 ast: Add `ContentHash` trait; remove noop `Hash` implementation from `Span` (#5451) (rzvxa) +- 23285f4 ast: Add `ContentEq` trait. (#5427) (rzvxa) +- 59abf27 ast, parser: Add `oxc_regular_expression` types to the parser and AST. (#5256) (rzvxa) +- 68a1c01 ast_tools: Add dedicated `Derive` trait. (#5278) (rzvxa) +- 62f7fff semantic: Check for non-declared, non-abstract object accessors without bodies (#5461) (DonIsaac) +- 5407143 semantic: Check for non-declared, non-abstract class accessors without bodies (#5460) (DonIsaac) +- cedf7a4 xtask: Impl `as_ast_kind` method for each variant (#5491) (IWANABETHATGUY) + +### Bug Fixes + +- 0df1d9d ast, codegen, linter: Panics in fixers. (#5431) (rzvxa)- b96bea4 Add back lifetime (#5507) (IWANABETHATGUY) + +### Documentation + +- 64db1b4 ast: Clarify docs for `RegExpPattern` (#5497) (overlookmotel) + +### Refactor + +- a43e951 ast: Use loop instead of recursion (#5447) (overlookmotel) +- 2224cc4 ast: Renumber `JSXMemberExpressionObject` discriminants (#5464) (overlookmotel) +- a952c47 ast: Use loop not recursion (#5449) (overlookmotel) +- d9d7e7c ast: Remove `IdentifierName` from `TSThisParameter` (#5327) (overlookmotel) +- ccc8a27 ast, ast_tools: Use full method path for generated derives trait calls. (#5462) (rzvxa) +- fdb8857 linter: Use "parsed pattern" in `no_div_regex` rule. (#5417) (rzvxa) +- b47aca0 syntax: Use `generate_derive` for `CloneIn` in types outside of `oxc_ast` crate. (#5280) (rzvxa) + ## [0.26.0] - 2024-09-03 - 1aa49af ast: [**BREAKING**] Remove `JSXMemberExpressionObject::Identifier` variant (#5358) (Dunqing) diff --git a/crates/oxc_ast/Cargo.toml b/crates/oxc_ast/Cargo.toml index 32ee0eb2b00dcd..f0318135f5668f 100644 --- a/crates/oxc_ast/Cargo.toml +++ b/crates/oxc_ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_ast" -version = "0.26.0" +version = "0.27.0" authors.workspace = true description.workspace = true edition.workspace = true diff --git a/crates/oxc_ast_macros/CHANGELOG.md b/crates/oxc_ast_macros/CHANGELOG.md index 2febe874bec6dc..b436cf70c28f04 100644 --- a/crates/oxc_ast_macros/CHANGELOG.md +++ b/crates/oxc_ast_macros/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- 90facd3 ast: Add `ContentHash` trait; remove noop `Hash` implementation from `Span` (#5451) (rzvxa) +- 23285f4 ast: Add `ContentEq` trait. (#5427) (rzvxa) + +### Refactor + +- 9f6e0ed ast: Simplify `ContentEq` trait definition. (#5468) (rzvxa) +- b47aca0 syntax: Use `generate_derive` for `CloneIn` in types outside of `oxc_ast` crate. (#5280) (rzvxa) + ## [0.24.3] - 2024-08-18 ### Documentation diff --git a/crates/oxc_ast_macros/Cargo.toml b/crates/oxc_ast_macros/Cargo.toml index 3d03519367016c..d4bbda6db46134 100644 --- a/crates/oxc_ast_macros/Cargo.toml +++ b/crates/oxc_ast_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_ast_macros" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_cfg/Cargo.toml b/crates/oxc_cfg/Cargo.toml index 13b6e6baf51750..8a1feabd857fe8 100644 --- a/crates/oxc_cfg/Cargo.toml +++ b/crates/oxc_cfg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_cfg" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_codegen/CHANGELOG.md b/crates/oxc_codegen/CHANGELOG.md index 6ed759bbd72d92..8a04acc8bfee09 100644 --- a/crates/oxc_codegen/CHANGELOG.md +++ b/crates/oxc_codegen/CHANGELOG.md @@ -4,6 +4,25 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +- cba93f5 ast: [**BREAKING**] Add `ThisExpression` variants to `JSXElementName` and `JSXMemberExpressionObject` (#5466) (overlookmotel) + +- 87c5df2 ast: [**BREAKING**] Rename `Expression::without_parentheses` (#5448) (overlookmotel) + +### Features + +- 59abf27 ast, parser: Add `oxc_regular_expression` types to the parser and AST. (#5256) (rzvxa) +- c782916 codegen: Print `type_parameters` in `TaggedTemplateExpression` (#5438) (Dunqing) + +### Bug Fixes + +- 0df1d9d ast, codegen, linter: Panics in fixers. (#5431) (rzvxa) + +### Refactor + +- d9d7e7c ast: Remove `IdentifierName` from `TSThisParameter` (#5327) (overlookmotel) + ## [0.26.0] - 2024-09-03 - 1aa49af ast: [**BREAKING**] Remove `JSXMemberExpressionObject::Identifier` variant (#5358) (Dunqing) diff --git a/crates/oxc_codegen/Cargo.toml b/crates/oxc_codegen/Cargo.toml index 9e618271efce92..d1560ce1f0b84a 100644 --- a/crates/oxc_codegen/Cargo.toml +++ b/crates/oxc_codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_codegen" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_diagnostics/CHANGELOG.md b/crates/oxc_diagnostics/CHANGELOG.md index 828238d68c5a98..69336a119ec8a1 100644 --- a/crates/oxc_diagnostics/CHANGELOG.md +++ b/crates/oxc_diagnostics/CHANGELOG.md @@ -4,6 +4,16 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- 91b39c4 oxc_diagnostic: Impl DerefMut for OxcDiagnostic (#5474) (IWANABETHATGUY) + +### Bug Fixes + +- fce549e diagnostics: Ignore `Interrupted` and `BrokenPipe` errors while printing (#5526) (Boshen) + ## [0.26.0] - 2024-09-03 ### Features diff --git a/crates/oxc_diagnostics/Cargo.toml b/crates/oxc_diagnostics/Cargo.toml index bb5463c4a157fd..c536dcee2684fd 100644 --- a/crates/oxc_diagnostics/Cargo.toml +++ b/crates/oxc_diagnostics/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_diagnostics" -version = "0.26.0" +version = "0.27.0" authors.workspace = true description.workspace = true edition.workspace = true diff --git a/crates/oxc_index/CHANGELOG.md b/crates/oxc_index/CHANGELOG.md index 426258bf098fca..37c3c607f29808 100644 --- a/crates/oxc_index/CHANGELOG.md +++ b/crates/oxc_index/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- 4cb63fe index: Impl rayon related to trait for IndexVec (#5421) (IWANABETHATGUY) + +### Documentation +- 00511fd Use `oxc_index` instead of `index_vec` in doc comments (#5423) (IWANABETHATGUY) + ## [0.24.3] - 2024-08-18 ### Refactor diff --git a/crates/oxc_index/Cargo.toml b/crates/oxc_index/Cargo.toml index f726a86cba4548..e0056563363eb7 100644 --- a/crates/oxc_index/Cargo.toml +++ b/crates/oxc_index/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_index" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_isolated_declarations/Cargo.toml b/crates/oxc_isolated_declarations/Cargo.toml index e4387407141f8c..d3fa88beaa6f3b 100644 --- a/crates/oxc_isolated_declarations/Cargo.toml +++ b/crates/oxc_isolated_declarations/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_isolated_declarations" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_mangler/Cargo.toml b/crates/oxc_mangler/Cargo.toml index 39071acfa0846c..57b4ced6d90b93 100644 --- a/crates/oxc_mangler/Cargo.toml +++ b/crates/oxc_mangler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_mangler" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_minifier/CHANGELOG.md b/crates/oxc_minifier/CHANGELOG.md index eeddc4b661793c..62a4b23c76f058 100644 --- a/crates/oxc_minifier/CHANGELOG.md +++ b/crates/oxc_minifier/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- ba4b68c minifier: Remove parenthesized expression for dce (#5439) (Boshen) + ## [0.25.0] - 2024-08-23 - 78f135d ast: [**BREAKING**] Remove `ReferenceFlag` from `IdentifierReference` (#5077) (Boshen) diff --git a/crates/oxc_minifier/Cargo.toml b/crates/oxc_minifier/Cargo.toml index 2519fd05d78a5d..a6ddbb7b502ea5 100644 --- a/crates/oxc_minifier/Cargo.toml +++ b/crates/oxc_minifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_minifier" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_module_lexer/Cargo.toml b/crates/oxc_module_lexer/Cargo.toml index 6526e237718fef..2fd100f5bdfa60 100644 --- a/crates/oxc_module_lexer/Cargo.toml +++ b/crates/oxc_module_lexer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_module_lexer" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_parser/CHANGELOG.md b/crates/oxc_parser/CHANGELOG.md index f725d7b940e55a..b4a10df6bee4ec 100644 --- a/crates/oxc_parser/CHANGELOG.md +++ b/crates/oxc_parser/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +- cba93f5 ast: [**BREAKING**] Add `ThisExpression` variants to `JSXElementName` and `JSXMemberExpressionObject` (#5466) (overlookmotel) + +### Features + +- 59abf27 ast, parser: Add `oxc_regular_expression` types to the parser and AST. (#5256) (rzvxa) +- 10279f5 parser: Add syntax error for hyphen in `JSXMemberExpression` `` (#5440) (Boshen) + +### Refactor + +- d9d7e7c ast: Remove `IdentifierName` from `TSThisParameter` (#5327) (overlookmotel) + ## [0.26.0] - 2024-09-03 - 1aa49af ast: [**BREAKING**] Remove `JSXMemberExpressionObject::Identifier` variant (#5358) (Dunqing) diff --git a/crates/oxc_parser/Cargo.toml b/crates/oxc_parser/Cargo.toml index 898a0b9b0ec012..9e0d80164c1c0a 100644 --- a/crates/oxc_parser/Cargo.toml +++ b/crates/oxc_parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_parser" -version = "0.26.0" +version = "0.27.0" authors.workspace = true description.workspace = true edition.workspace = true diff --git a/crates/oxc_regular_expression/CHANGELOG.md b/crates/oxc_regular_expression/CHANGELOG.md index 2d205ff74d95ec..47f06bd8768a79 100644 --- a/crates/oxc_regular_expression/CHANGELOG.md +++ b/crates/oxc_regular_expression/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- 90facd3 ast: Add `ContentHash` trait; remove noop `Hash` implementation from `Span` (#5451) (rzvxa) +- 23285f4 ast: Add `ContentEq` trait. (#5427) (rzvxa) +- 59abf27 ast, parser: Add `oxc_regular_expression` types to the parser and AST. (#5256) (rzvxa) + +### Bug Fixes + +- 9b984b3 regex: Panic on displaying surrogated `UnicodeEscape` characters. (#5469) (rzvxa) +- 88b7ddb regular_expression: Handle unterminated character class (#5523) (leaysgur) + +### Refactor + +- ccc8a27 ast, ast_tools: Use full method path for generated derives trait calls. (#5462) (rzvxa) +- e7bd49d regular_expression: Correct typo (#5429) (overlookmotel) + ## [0.26.0] - 2024-09-03 ### Features diff --git a/crates/oxc_regular_expression/Cargo.toml b/crates/oxc_regular_expression/Cargo.toml index 3135408fd64b7d..3c979ab601bb09 100644 --- a/crates/oxc_regular_expression/Cargo.toml +++ b/crates/oxc_regular_expression/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_regular_expression" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true categories.workspace = true diff --git a/crates/oxc_semantic/CHANGELOG.md b/crates/oxc_semantic/CHANGELOG.md index e252090217639a..da9de3dbdf05a1 100644 --- a/crates/oxc_semantic/CHANGELOG.md +++ b/crates/oxc_semantic/CHANGELOG.md @@ -4,6 +4,34 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +- bd820f9 semantic: [**BREAKING**] Remove `SymbolTable::get_symbol_id_from_name` and `SymbolTable::get_scope_id_from_name` (#5480) (overlookmotel) + +### Features + +- 0f50b1e semantic: Check for initializers in ambient `VariableDeclaration`s (#5463) (DonIsaac) +- 62f7fff semantic: Check for non-declared, non-abstract object accessors without bodies (#5461) (DonIsaac) +- 5407143 semantic: Check for non-declared, non-abstract class accessors without bodies (#5460) (DonIsaac) +- 052e94c semantic: Check for parameter properties in constructor overloads (#5459) (DonIsaac) + +### Bug Fixes + +- 7a797ac semantic: Incorrect reference when `MemberExpression` used in `TSPropertySignature` (#5525) (Dunqing) +- d8b9909 semantic: `IdentifierReference` within `TSPropertySignature` cannot reference type-only import binding (#5441) (Dunqing) + +### Refactor + +- e4ed41d semantic: Change the reference flag to `ReferenceFlags::Type` if it is used within a `TSTypeQuery` (#5444) (Dunqing) + +### Styling + +- 2a43fa4 linter: Introduce the writing style from PR #5491 and reduce the if nesting (#5512) (dalaoshu) + +### Testing + +- 340b535 linter/no-unused-vars: Arrow functions in tagged templates (#5510) (Don Isaac) + ## [0.26.0] - 2024-09-03 - 01cc2ce semantic: [**BREAKING**] Add `ScopeTree:get_child_ids` API behind a runtime flag (#5403) (Boshen) diff --git a/crates/oxc_semantic/Cargo.toml b/crates/oxc_semantic/Cargo.toml index 267c452404c68b..67486f82dec792 100644 --- a/crates/oxc_semantic/Cargo.toml +++ b/crates/oxc_semantic/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_semantic" -version = "0.26.0" +version = "0.27.0" authors.workspace = true description.workspace = true edition.workspace = true diff --git a/crates/oxc_sourcemap/Cargo.toml b/crates/oxc_sourcemap/Cargo.toml index 727858ed889c33..0bebe7b4d5c524 100644 --- a/crates/oxc_sourcemap/Cargo.toml +++ b/crates/oxc_sourcemap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_sourcemap" -version = "0.26.0" +version = "0.27.0" authors.workspace = true description.workspace = true edition.workspace = true diff --git a/crates/oxc_span/CHANGELOG.md b/crates/oxc_span/CHANGELOG.md index c168ac3abe28ad..b37e6503b20b48 100644 --- a/crates/oxc_span/CHANGELOG.md +++ b/crates/oxc_span/CHANGELOG.md @@ -4,6 +4,22 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- 90facd3 ast: Add `ContentHash` trait; remove noop `Hash` implementation from `Span` (#5451) (rzvxa) +- 23285f4 ast: Add `ContentEq` trait. (#5427) (rzvxa) + +### Documentation + +- 3f204a9 span: Update docs about `ContentEq` `Vec` comparison speed (#5478) (overlookmotel) + +### Refactor + +- 9f6e0ed ast: Simplify `ContentEq` trait definition. (#5468) (rzvxa) +- 94a6ac6 span: Use `Hasher` from `std` (#5476) (overlookmotel) + ## [0.26.0] - 2024-09-03 ### Features diff --git a/crates/oxc_span/Cargo.toml b/crates/oxc_span/Cargo.toml index 2c0491b5cc438d..27a77cbec77197 100644 --- a/crates/oxc_span/Cargo.toml +++ b/crates/oxc_span/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_span" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_syntax/CHANGELOG.md b/crates/oxc_syntax/CHANGELOG.md index f96dcb57a224f0..4d23afb9f8bac7 100644 --- a/crates/oxc_syntax/CHANGELOG.md +++ b/crates/oxc_syntax/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Features + +- 90facd3 ast: Add `ContentHash` trait; remove noop `Hash` implementation from `Span` (#5451) (rzvxa) +- 23285f4 ast: Add `ContentEq` trait. (#5427) (rzvxa) + +### Performance + +- bfabd8f syntax: Further optimize `is_identifier_name` (#5426) (overlookmotel) +- aeda84f syntax: Optimize `is_identifier_name` (#5425) (overlookmotel) + +### Refactor + +- ccc8a27 ast, ast_tools: Use full method path for generated derives trait calls. (#5462) (rzvxa) +- e4ed41d semantic: Change the reference flag to `ReferenceFlags::Type` if it is used within a `TSTypeQuery` (#5444) (Dunqing) +- b47aca0 syntax: Use `generate_derive` for `CloneIn` in types outside of `oxc_ast` crate. (#5280) (rzvxa) + ## [0.25.0] - 2024-08-23 - d262a58 syntax: [**BREAKING**] Rename `ReferenceFlag` to `ReferenceFlags` (#5023) (overlookmotel) diff --git a/crates/oxc_syntax/Cargo.toml b/crates/oxc_syntax/Cargo.toml index 43cd4106833491..60ca7bd61824d8 100644 --- a/crates/oxc_syntax/Cargo.toml +++ b/crates/oxc_syntax/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_syntax" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_transformer/CHANGELOG.md b/crates/oxc_transformer/CHANGELOG.md index 6156b9f0639977..cdc3e2a2f363e1 100644 --- a/crates/oxc_transformer/CHANGELOG.md +++ b/crates/oxc_transformer/CHANGELOG.md @@ -4,6 +4,38 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +- cba93f5 ast: [**BREAKING**] Add `ThisExpression` variants to `JSXElementName` and `JSXMemberExpressionObject` (#5466) (overlookmotel) + +### Features + +- 32d4bbb transformer: Add `TransformOptions::enable_all` method (#5495) (Boshen) +- c59d8b3 transformer: Support all /regex/ to `new RegExp` transforms (#5387) (Dunqing) + +### Bug Fixes + +- 8f9627d transformer: RegExp transform do not transform invalid regexps (#5494) (overlookmotel) +- 2060efc transformer: RegExp transform don't transform all RegExps (#5486) (overlookmotel) +- cfe5497 transformer: Do not create double reference in JSX transform (#5414) (overlookmotel) +- 0617249 transformer/nullish-coalescing-operator: Incorrect reference flags (#5408) (Dunqing) + +### Performance + +- ed8937e transformer: Memoize rope instance (#5518) (Dunqing) +- bfab091 transformer: Store needed options only on `RegExp` (#5484) (overlookmotel) +- b4765af transformer: Pre-calculate if unsupported patterns in RegExp transform (#5483) (overlookmotel) +- 182ab91 transformer: Pre-calculate unsupported flags in RegExp transform (#5482) (overlookmotel) + +### Refactor + +- a96866d transformer: Re-order imports (#5499) (overlookmotel) +- 6abde0a transformer: Clarify match in RegExp transform (#5498) (overlookmotel) +- 09c522a transformer: RegExp transform report pattern parsing errors (#5496) (overlookmotel) +- dd19823 transformer: RegExp transform do not take ownership of `Pattern` then reallocate it (#5492) (overlookmotel) +- 2514cc9 transformer/react: Move all entry points to implementation of Traverse trait (#5473) (Dunqing) +- c984219 transformer/typescript: Move all entry points to implementation of Traverse trait (#5422) (Dunqing) + ## [0.26.0] - 2024-09-03 - 1aa49af ast: [**BREAKING**] Remove `JSXMemberExpressionObject::Identifier` variant (#5358) (Dunqing) diff --git a/crates/oxc_transformer/Cargo.toml b/crates/oxc_transformer/Cargo.toml index df5fc5f710dd01..21b96c16aef2a1 100644 --- a/crates/oxc_transformer/Cargo.toml +++ b/crates/oxc_transformer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_transformer" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/crates/oxc_traverse/CHANGELOG.md b/crates/oxc_traverse/CHANGELOG.md index 977c6597417b97..ceafe8e3f1aba9 100644 --- a/crates/oxc_traverse/CHANGELOG.md +++ b/crates/oxc_traverse/CHANGELOG.md @@ -4,6 +4,21 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +- cba93f5 ast: [**BREAKING**] Add `ThisExpression` variants to `JSXElementName` and `JSXMemberExpressionObject` (#5466) (overlookmotel) + +### Features + + +### Bug Fixes + +- 0eb32a6 traverse: Invalid variable name generated by `generate_uid_based_on_node` (#5407) (Dunqing) + +### Refactor + +- d9d7e7c ast: Remove `IdentifierName` from `TSThisParameter` (#5327) (overlookmotel) + ## [0.26.0] - 2024-09-03 - 1aa49af ast: [**BREAKING**] Remove `JSXMemberExpressionObject::Identifier` variant (#5358) (Dunqing) diff --git a/crates/oxc_traverse/Cargo.toml b/crates/oxc_traverse/Cargo.toml index 9e1fef6472c915..22239019991e21 100644 --- a/crates/oxc_traverse/Cargo.toml +++ b/crates/oxc_traverse/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_traverse" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/napi/transform/CHANGELOG.md b/napi/transform/CHANGELOG.md index ce079b6c7ae1e9..d1888d865f7086 100644 --- a/napi/transform/CHANGELOG.md +++ b/napi/transform/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0. +## [0.27.0] - 2024-09-06 + +### Bug Fixes + +- ea7a52f napi/transform: Fix test (Boshen) + ## [0.26.0] - 2024-09-03 - b1d0075 napi/transform: [**BREAKING**] Align output API `sourceText` -> `code` with babel (#5398) (Boshen) diff --git a/napi/transform/Cargo.toml b/napi/transform/Cargo.toml index accea59cff942f..e7212963e622a5 100644 --- a/napi/transform/Cargo.toml +++ b/napi/transform/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oxc_transform_napi" -version = "0.26.0" +version = "0.27.0" publish = true authors.workspace = true description.workspace = true diff --git a/npm/oxc-parser/package.json b/npm/oxc-parser/package.json index 56b77ef75e943c..c55343cf164c9b 100644 --- a/npm/oxc-parser/package.json +++ b/npm/oxc-parser/package.json @@ -1,6 +1,6 @@ { "name": "oxc-parser", - "version": "0.26.0", + "version": "0.27.0", "description": "Oxc Parser Node API", "keywords": [ "Parser" diff --git a/npm/oxc-transform/package.json b/npm/oxc-transform/package.json index d67c4a59137c16..61c321e6dfc56f 100644 --- a/npm/oxc-transform/package.json +++ b/npm/oxc-transform/package.json @@ -1,6 +1,6 @@ { "name": "oxc-transform", - "version": "0.26.0", + "version": "0.27.0", "description": "Oxc transform Node API", "keywords": [ "transform" diff --git a/wasm/parser/package.json b/wasm/parser/package.json index 7144830feae157..d49ecdae7372ed 100644 --- a/wasm/parser/package.json +++ b/wasm/parser/package.json @@ -1,6 +1,6 @@ { "name": "@oxc-parser/wasm", - "version": "0.26.0", + "version": "0.27.0", "description": "Wasm target for the oxc parser.", "packageManager": "pnpm@9.9.0", "keywords": [ From ff4ce21852d40e086b6a28afc0ccb0eebe59078c Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 6 Sep 2024 19:17:20 +0800 Subject: [PATCH 16/28] chore: rm editors/vscode/LICENSE --- editors/vscode/LICENSE | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 editors/vscode/LICENSE diff --git a/editors/vscode/LICENSE b/editors/vscode/LICENSE deleted file mode 100644 index c8a5d27fb28f74..00000000000000 --- a/editors/vscode/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023-present Bytedance Inc and its affiliates. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. From c35fd0c50d29643996be535a3ac31d0c0b9a6295 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 6 Sep 2024 19:17:49 +0800 Subject: [PATCH 17/28] chore: link editors/vscode/LICENSE to root LICENSE --- editors/vscode/LICENSE | 1 + 1 file changed, 1 insertion(+) create mode 120000 editors/vscode/LICENSE diff --git a/editors/vscode/LICENSE b/editors/vscode/LICENSE new file mode 120000 index 00000000000000..30cff7403da047 --- /dev/null +++ b/editors/vscode/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file From a540215c91d182590eb4f19cff8a50ff0794a5a1 Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Fri, 6 Sep 2024 19:23:06 +0800 Subject: [PATCH 18/28] docs(linter): update docs `Examples` for linter rules (#5513) --- .../eslint/no_unused_private_class_members.rs | 14 +++++++----- crates/oxc_linter/src/rules/import/no_amd.rs | 12 +++++++--- .../src/rules/import/no_default_export.rs | 17 ++++++-------- .../src/rules/jsdoc/check_access.rs | 19 ++++++++++------ .../src/rules/jsdoc/check_property_names.rs | 16 +++++++++----- .../src/rules/jsdoc/check_tag_names.rs | 15 ++++++++----- .../oxc_linter/src/rules/jsdoc/empty_tags.rs | 19 ++++++++++------ .../src/rules/jsdoc/implements_on_classes.rs | 21 +++++++++++------- .../oxc_linter/src/rules/jsdoc/no_defaults.rs | 18 ++++++++++----- .../src/rules/jsdoc/require_param.rs | 15 ++++++++----- .../rules/jsdoc/require_param_description.rs | 15 ++++++++----- .../src/rules/jsdoc/require_param_name.rs | 15 ++++++++----- .../src/rules/jsdoc/require_param_type.rs | 15 ++++++++----- .../src/rules/jsdoc/require_property.rs | 21 ++++++++++++------ .../jsdoc/require_property_description.rs | 15 ++++++++----- .../src/rules/jsdoc/require_property_name.rs | 15 ++++++++----- .../src/rules/jsdoc/require_property_type.rs | 15 ++++++++----- .../src/rules/jsdoc/require_returns.rs | 18 ++++++++++----- .../jsdoc/require_returns_description.rs | 15 ++++++++----- .../src/rules/jsdoc/require_returns_type.rs | 15 ++++++++----- .../src/rules/jsdoc/require_yields.rs | 16 +++++++++----- crates/oxc_linter/src/rules/jsx_a11y/lang.rs | 16 +++++++------- .../src/rules/oxc/bad_char_at_comparison.rs | 9 +++++--- .../src/rules/oxc/bad_replace_all_arg.rs | 9 +++++--- .../src/rules/oxc/no_accumulating_spread.rs | 22 ++++++++++--------- .../src/rules/oxc/only_used_in_recursion.rs | 9 +++++--- .../consistent_indexed_object_style.rs | 15 ++++++------- .../src/rules/unicorn/catch_error_name.rs | 13 ++++++----- .../src/rules/unicorn/error_message.rs | 13 ++++++----- .../src/rules/unicorn/escape_case.rs | 12 +++++++--- .../rules/unicorn/explicit_length_check.rs | 17 +++++++++----- .../src/rules/unicorn/new_for_builtins.rs | 9 +++++--- .../unicorn/no_abusive_eslint_disable.rs | 11 +++++++--- .../src/rules/unicorn/no_document_cookie.rs | 9 +++++--- .../src/rules/unicorn/no_hex_escape.rs | 11 +++++++--- .../src/rules/unicorn/no_nested_ternary.rs | 11 +++++++--- .../src/rules/unicorn/no_new_array.rs | 9 +++++--- .../src/rules/unicorn/no_this_assignment.rs | 9 +++++--- .../src/rules/unicorn/no_typeof_undefined.rs | 9 +++++--- .../src/rules/unicorn/no_unreadable_iife.rs | 11 +++++++--- .../unicorn/no_useless_fallback_in_spread.rs | 10 +++++---- .../no_useless_promise_resolve_reject.rs | 9 +++++--- .../rules/unicorn/no_useless_switch_case.rs | 10 ++++++--- .../src/rules/unicorn/no_useless_undefined.rs | 12 ++++++---- .../src/rules/unicorn/number_literal_case.rs | 11 +++++++--- .../unicorn/prefer_add_event_listener.rs | 9 +++++--- .../src/rules/unicorn/prefer_code_point.rs | 9 +++++--- .../src/rules/unicorn/prefer_date_now.rs | 9 ++++---- .../rules/unicorn/prefer_dom_node_append.rs | 11 +++++----- .../rules/unicorn/prefer_dom_node_remove.rs | 9 +++++--- .../src/rules/unicorn/prefer_includes.rs | 10 +++++---- .../prefer_native_coercion_functions.rs | 9 +++++--- .../rules/unicorn/prefer_number_properties.rs | 9 +++++--- .../rules/unicorn/prefer_prototype_methods.rs | 10 ++++++--- .../src/rules/unicorn/prefer_set_size.rs | 10 +++++---- .../src/rules/unicorn/prefer_spread.rs | 12 ++++++---- ...require_number_to_fixed_digits_argument.rs | 15 ++++++++----- .../src/rules/unicorn/throw_new_error.rs | 10 +++++---- 58 files changed, 484 insertions(+), 265 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs index 239d4ad97d741a..d25f3a09aad9e3 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs @@ -24,10 +24,10 @@ declare_oxc_lint!( /// /// Private class members that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such class members take up space in the code and can lead to confusion by readers. /// - /// ### Example - /// ```javascript + /// ### Examples /// - /// /// bad + /// Examples of **incorrect** code for this rule: + /// ```javascript /// class A { /// #unusedMember = 5; /// } @@ -54,15 +54,17 @@ declare_oxc_lint!( /// get #unusedAccessor() {} /// set #unusedAccessor(value) {} /// } + /// ``` /// - /// /// Good + /// Examples of **correct** code for this rule: + /// ```javascript /// class A { /// #usedMember = 42; /// method() { /// return this.#usedMember; /// } /// } - + /// /// class B { /// #usedMethod() { /// return 42; @@ -71,7 +73,7 @@ declare_oxc_lint!( /// return this.#usedMethod(); /// } /// } - + /// /// class C { /// get #usedAccessor() {} /// set #usedAccessor(value) {} diff --git a/crates/oxc_linter/src/rules/import/no_amd.rs b/crates/oxc_linter/src/rules/import/no_amd.rs index 18318715c7873e..2c5da588d825d6 100644 --- a/crates/oxc_linter/src/rules/import/no_amd.rs +++ b/crates/oxc_linter/src/rules/import/no_amd.rs @@ -22,12 +22,18 @@ declare_oxc_lint!( /// /// Forbid AMD `require` and `define` calls. /// - /// ### Example + /// ### Why is this bad? + /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// /// ```javascript - /// // fail /// require([a, b], function() {} ); - /// // pass + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript /// require('../name'); /// require(`../name`); /// ``` diff --git a/crates/oxc_linter/src/rules/import/no_default_export.rs b/crates/oxc_linter/src/rules/import/no_default_export.rs index d98d6b694d188d..6bb8b4edeab8da 100644 --- a/crates/oxc_linter/src/rules/import/no_default_export.rs +++ b/crates/oxc_linter/src/rules/import/no_default_export.rs @@ -18,23 +18,20 @@ declare_oxc_lint!( /// /// ### Examples /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad1.js - /// - /// // There is a default export. - /// export const foo = 'foo'; - /// const bar = 'bar'; /// export default 'bar'; - /// ``` - /// - /// ```javascript - /// // bad2.js /// - /// // There is a default export. /// const foo = 'foo'; /// export { foo as default } /// ``` /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// export const foo = 'foo'; + /// export const bar = 'bar'; + /// ``` + /// NoDefaultExport, restriction ); diff --git a/crates/oxc_linter/src/rules/jsdoc/check_access.rs b/crates/oxc_linter/src/rules/jsdoc/check_access.rs index 07ec0c0d9b7855..7d58e11855bb39 100644 --- a/crates/oxc_linter/src/rules/jsdoc/check_access.rs +++ b/crates/oxc_linter/src/rules/jsdoc/check_access.rs @@ -25,6 +25,7 @@ pub struct CheckAccess; declare_oxc_lint!( /// ### What it does + /// /// Checks that `@access` tags use one of the following values: /// - "package", "private", "protected", "public" /// @@ -33,20 +34,24 @@ declare_oxc_lint!( /// - Use of multiple instances of `@access` (or the `@public`, etc) on the same doc block. /// /// ### Why is this bad? - /// It is important to have a consistent way of specifying access levels. /// - /// ### Example - /// ```javascript - /// // Passing - /// /** @access private */ + /// It is important to have a consistent way of specifying access levels. /// - /// /** @private */ + /// ### Examples /// - /// // Failing + /// Examples of **incorrect** code for this rule: + /// ```javascript /// /** @access private @public */ /// /// /** @access invalidlevel */ /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @access private */ + /// + /// /** @private */ + /// ``` CheckAccess, restriction ); diff --git a/crates/oxc_linter/src/rules/jsdoc/check_property_names.rs b/crates/oxc_linter/src/rules/jsdoc/check_property_names.rs index 07e08ee78417e0..8290f8e18d6d73 100644 --- a/crates/oxc_linter/src/rules/jsdoc/check_property_names.rs +++ b/crates/oxc_linter/src/rules/jsdoc/check_property_names.rs @@ -20,33 +20,39 @@ pub struct CheckPropertyNames; declare_oxc_lint!( /// ### What it does + /// /// Ensures that property names in JSDoc are not duplicated on the same block and that nested properties have defined roots. /// /// ### Why is this bad? + /// /// `@property` tags with the same name can be confusing and may indicate a mistake. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing /// /** /// * @typedef {object} state /// * @property {number} foo + /// * @property {string} foo /// */ + /// /// /** /// * @typedef {object} state - /// * @property {object} foo /// * @property {number} foo.bar /// */ + /// ``` /// - /// // Failing + /// Examples of **correct** code for this rule: + /// ```javascript /// /** /// * @typedef {object} state /// * @property {number} foo - /// * @property {string} foo /// */ /// /// /** /// * @typedef {object} state + /// * @property {object} foo /// * @property {number} foo.bar /// */ /// ``` diff --git a/crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs b/crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs index 42e1865f359a33..a92d4fad1ce8ab 100644 --- a/crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs +++ b/crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs @@ -19,18 +19,18 @@ pub struct CheckTagNames(Box); declare_oxc_lint!( /// ### What it does + /// /// Reports invalid block tag names. /// Additionally checks for tag names that are redundant when using a type checker such as TypeScript. /// /// ### Why is this bad? + /// /// Using invalid tags can lead to confusion and make the documentation harder to read. /// - /// ### Example - /// ```javascript - /// // Passing - /// /** @param */ + /// ### Examples /// - /// // Failing + /// Examples of **incorrect** code for this rule: + /// ```javascript /// /** @Param */ /// /** @foo */ /// @@ -39,6 +39,11 @@ declare_oxc_lint!( /// * @type {string} /// */ /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @param */ + /// ``` CheckTagNames, correctness ); diff --git a/crates/oxc_linter/src/rules/jsdoc/empty_tags.rs b/crates/oxc_linter/src/rules/jsdoc/empty_tags.rs index 374820a5bdf2f5..a814d02045dae0 100644 --- a/crates/oxc_linter/src/rules/jsdoc/empty_tags.rs +++ b/crates/oxc_linter/src/rules/jsdoc/empty_tags.rs @@ -17,6 +17,7 @@ pub struct EmptyTags(Box); declare_oxc_lint!( /// ### What it does + /// /// Expects the following tags to be empty of any content: /// - `@abstract` /// - `@async` @@ -38,20 +39,24 @@ declare_oxc_lint!( /// - `@static` /// /// ### Why is this bad? - /// The void tags should be empty. /// - /// ### Example - /// ```javascript - /// // Passing - /// /** @async */ + /// The void tags should be empty. /// - /// /** @private */ + /// ### Examples /// - /// // Failing + /// Examples of **incorrect** code for this rule: + /// ```javascript /// /** @async foo */ /// /// /** @private bar */ /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @async */ + /// + /// /** @private */ + /// ``` EmptyTags, restriction ); diff --git a/crates/oxc_linter/src/rules/jsdoc/implements_on_classes.rs b/crates/oxc_linter/src/rules/jsdoc/implements_on_classes.rs index 0083b9a394685b..91d769a408c902 100644 --- a/crates/oxc_linter/src/rules/jsdoc/implements_on_classes.rs +++ b/crates/oxc_linter/src/rules/jsdoc/implements_on_classes.rs @@ -22,15 +22,26 @@ pub struct ImplementsOnClasses; declare_oxc_lint!( /// ### What it does + /// /// Reports an issue with any non-constructor function using `@implements`. /// /// ### Why is this bad? + /// /// Constructor functions should be /// whether marked with `@class`, `@constructs`, or being an ES6 class constructor. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: + /// ```javascript + /// /** + /// * @implements {SomeClass} + /// */ + /// function quux () {} + /// ``` + /// + /// Examples of **correct** code for this rule: /// ```javascript - /// // Passing /// class Foo { /// /** /// * @implements {SomeClass} @@ -42,12 +53,6 @@ declare_oxc_lint!( /// * @class /// */ /// function quux () {} - /// - /// // Failing - /// /** - /// * @implements {SomeClass} - /// */ - /// function quux () {} /// ``` ImplementsOnClasses, correctness diff --git a/crates/oxc_linter/src/rules/jsdoc/no_defaults.rs b/crates/oxc_linter/src/rules/jsdoc/no_defaults.rs index 885cccfbd4bf62..c1e65618472c2a 100644 --- a/crates/oxc_linter/src/rules/jsdoc/no_defaults.rs +++ b/crates/oxc_linter/src/rules/jsdoc/no_defaults.rs @@ -20,23 +20,29 @@ pub struct NoDefaults(Box); declare_oxc_lint!( /// ### What it does + /// /// This rule reports defaults being used on the relevant portion of `@param` or `@default`. /// It also optionally reports the presence of the square-bracketed optional arguments at all. /// /// ### Why is this bad? + /// /// The rule is intended to prevent the indication of defaults on tags /// where this would be redundant with ES6 default parameters. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** @param {number} foo */ + /// /** @param {number} [foo="7"] */ /// function quux (foo) {} - /// /** @param foo */ + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @param {number} foo */ /// function quux (foo) {} /// - /// // Failing - /// /** @param {number} [foo="7"] */ + /// /** @param foo */ /// function quux (foo) {} /// ``` NoDefaults, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_param.rs b/crates/oxc_linter/src/rules/jsdoc/require_param.rs index 8d669be3e3b28e..76f17aa91c2aef 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_param.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_param.rs @@ -23,20 +23,25 @@ pub struct RequireParam(Box); declare_oxc_lint!( /// ### What it does + /// /// Requires that all function parameters are documented with JSDoc `@param` tags. /// /// ### Why is this bad? + /// /// The rule is aimed at enforcing code quality and maintainability by requiring that all function parameters are documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing /// /** @param foo */ - /// function quux (foo) {} + /// function quux (foo, bar) {} + /// ``` /// - /// // Failing + /// Examples of **correct** code for this rule: + /// ```javascript /// /** @param foo */ - /// function quux (foo, bar) {} + /// function quux (foo) {} /// ``` RequireParam, pedantic, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_param_description.rs b/crates/oxc_linter/src/rules/jsdoc/require_param_description.rs index 85f43fb4d32ca5..bbc3660802f1d6 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_param_description.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_param_description.rs @@ -24,19 +24,24 @@ pub struct RequireParamDescription; declare_oxc_lint!( /// ### What it does + /// /// Requires that each `@param` tag has a description value. /// /// ### Why is this bad? + /// /// The description of a param should be documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** @param foo Foo. */ + /// /** @param foo */ /// function quux (foo) {} + /// ``` /// - /// // Failing - /// /** @param foo */ + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @param foo Foo. */ /// function quux (foo) {} /// ``` RequireParamDescription, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_param_name.rs b/crates/oxc_linter/src/rules/jsdoc/require_param_name.rs index e4a3116fa7f274..1e807a40a028bf 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_param_name.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_param_name.rs @@ -21,19 +21,24 @@ pub struct RequireParamName; declare_oxc_lint!( /// ### What it does + /// /// Requires that all `@param` tags have names. /// /// ### Why is this bad? + /// /// The name of a param should be documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** @param {SomeType} foo */ + /// /** @param {SomeType} */ /// function quux (foo) {} + /// ``` /// - /// // Failing - /// /** @param {SomeType} */ + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @param {SomeType} foo */ /// function quux (foo) {} /// ``` RequireParamName, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_param_type.rs b/crates/oxc_linter/src/rules/jsdoc/require_param_type.rs index 67804881b0398a..a464b5fb9c32f7 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_param_type.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_param_type.rs @@ -24,19 +24,24 @@ pub struct RequireParamType; declare_oxc_lint!( /// ### What it does + /// /// Requires that each `@param` tag has a type value (within curly brackets). /// /// ### Why is this bad? + /// /// The type of a parameter should be documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** @param {SomeType} foo */ + /// /** @param foo */ /// function quux (foo) {} + /// ``` /// - /// // Failing - /// /** @param foo */ + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @param {SomeType} foo */ /// function quux (foo) {} /// ``` RequireParamType, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_property.rs b/crates/oxc_linter/src/rules/jsdoc/require_property.rs index 58b5cf588d204e..709b4832f4c1d6 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_property.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_property.rs @@ -21,30 +21,37 @@ pub struct RequireProperty; declare_oxc_lint!( /// ### What it does + /// /// Requires that all `@typedef` and `@namespace` tags have `@property` tags /// when their type is a plain `object`, `Object`, or `PlainObject`. /// /// ### Why is this bad? + /// /// Object type should have properties defined. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing /// /** /// * @typedef {Object} SomeTypedef - /// * @property {SomeType} propName Prop description /// */ + /// /// /** - /// * @typedef {object} Foo - /// * @property someProp + /// * @namespace {Object} SomeNamesoace /// */ + /// ``` /// - /// // Failing + /// Examples of **correct** code for this rule: + /// ```javascript /// /** /// * @typedef {Object} SomeTypedef + /// * @property {SomeType} propName Prop description /// */ + /// /// /** - /// * @namespace {Object} SomeNamesoace + /// * @typedef {object} Foo + /// * @property someProp /// */ /// ``` RequireProperty, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_property_description.rs b/crates/oxc_linter/src/rules/jsdoc/require_property_description.rs index 2c0987d662eb9b..715561eed43223 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_property_description.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_property_description.rs @@ -19,23 +19,28 @@ pub struct RequirePropertyDescription; declare_oxc_lint!( /// ### What it does + /// /// Requires that all `@property` tags have descriptions. /// /// ### Why is this bad? + /// /// The description of a property should be documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing /// /** /// * @typedef {SomeType} SomeTypedef - /// * @property {number} foo Foo. + /// * @property {number} foo /// */ + /// ``` /// - /// // Failing + /// Examples of **correct** code for this rule: + /// ```javascript /// /** /// * @typedef {SomeType} SomeTypedef - /// * @property {number} foo + /// * @property {number} foo Foo. /// */ /// ``` RequirePropertyDescription, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_property_name.rs b/crates/oxc_linter/src/rules/jsdoc/require_property_name.rs index ac18791d799061..87ba362eb8ad7d 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_property_name.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_property_name.rs @@ -19,23 +19,28 @@ pub struct RequirePropertyName; declare_oxc_lint!( /// ### What it does + /// /// Requires that all `@property` tags have names. /// /// ### Why is this bad? + /// /// The name of a property type should be documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing /// /** /// * @typedef {SomeType} SomeTypedef - /// * @property {number} foo + /// * @property {number} /// */ + /// ``` /// - /// // Failing + /// Examples of **correct** code for this rule: + /// ```javascript /// /** /// * @typedef {SomeType} SomeTypedef - /// * @property {number} + /// * @property {number} foo /// */ /// ``` RequirePropertyName, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_property_type.rs b/crates/oxc_linter/src/rules/jsdoc/require_property_type.rs index 9715cb8b1e62b5..1ffb95a6a8d0bf 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_property_type.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_property_type.rs @@ -19,23 +19,28 @@ pub struct RequirePropertyType; declare_oxc_lint!( /// ### What it does + /// /// Requires that each `@property` tag has a type value (within curly brackets). /// /// ### Why is this bad? + /// /// The type of a property should be documented. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing /// /** /// * @typedef {SomeType} SomeTypedef - /// * @property {number} foo + /// * @property foo /// */ + /// ``` /// - /// // Failing + /// Examples of **correct** code for this rule: + /// ```javascript /// /** /// * @typedef {SomeType} SomeTypedef - /// * @property foo + /// * @property {number} foo /// */ /// ``` RequirePropertyType, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_returns.rs b/crates/oxc_linter/src/rules/jsdoc/require_returns.rs index ec47f26547c772..dc384438719695 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_returns.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_returns.rs @@ -35,27 +35,33 @@ pub struct RequireReturns(Box); declare_oxc_lint!( /// ### What it does + /// /// Requires that return statements are documented. /// Will also report if multiple `@returns` tags are present. /// /// ### Why is this bad? + /// /// The rule is intended to prevent the omission of `@returns` tag when necessary. /// - /// ### Example - /// ```javascript - /// // Passing - /// /** @returns Foo. */ - /// function quux () { return foo; } + /// ### Examples /// - /// // Failing + /// Examples of **incorrect** code for this rule: + /// ```javascript /// /** Foo. */ /// function quux () { return foo; } + /// /// /** /// * @returns Foo! /// * @returns Foo? /// */ /// function quux () { return foo; } /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @returns Foo. */ + /// function quux () { return foo; } + /// ``` RequireReturns, pedantic, ); diff --git a/crates/oxc_linter/src/rules/jsdoc/require_returns_description.rs b/crates/oxc_linter/src/rules/jsdoc/require_returns_description.rs index 6a498f5f2459f4..245aedf4e6a8ca 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_returns_description.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_returns_description.rs @@ -21,20 +21,25 @@ pub struct RequireReturnsDescription; declare_oxc_lint!( /// ### What it does + /// /// Requires that the `@returns` tag has a description value. /// The error will not be reported if the return value is `void `or `undefined` or if it is `Promise` or `Promise`. /// /// ### Why is this bad? + /// /// A `@returns` tag should have a description value. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** @returns Foo. */ + /// /** @returns */ /// function quux (foo) {} + /// ``` /// - /// // Failing - /// /** @returns */ + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @returns Foo. */ /// function quux (foo) {} /// ``` RequireReturnsDescription, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_returns_type.rs b/crates/oxc_linter/src/rules/jsdoc/require_returns_type.rs index f78c9a5cfce287..da0dc9ac652921 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_returns_type.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_returns_type.rs @@ -21,19 +21,24 @@ pub struct RequireReturnsType; declare_oxc_lint!( /// ### What it does + /// /// Requires that `@returns` tag has a type value (in curly brackets). /// /// ### Why is this bad? + /// /// A `@returns` tag should have a type value. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** @returns {string} */ + /// /** @returns */ /// function quux (foo) {} + /// ``` /// - /// // Failing - /// /** @returns */ + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** @returns {string} */ /// function quux (foo) {} /// ``` RequireReturnsType, diff --git a/crates/oxc_linter/src/rules/jsdoc/require_yields.rs b/crates/oxc_linter/src/rules/jsdoc/require_yields.rs index f99187ccb8b3e0..8a7bcc6dd87665 100644 --- a/crates/oxc_linter/src/rules/jsdoc/require_yields.rs +++ b/crates/oxc_linter/src/rules/jsdoc/require_yields.rs @@ -39,26 +39,32 @@ pub struct RequireYields(Box); declare_oxc_lint!( /// ### What it does + /// /// Requires that yields are documented. /// Will also report if multiple `@yields` tags are present. /// /// ### Why is this bad? + /// /// The rule is intended to prevent the omission of `@yields` tags when they are necessary. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Passing - /// /** * @yields Foo */ /// function * quux (foo) { yield foo; } /// - /// // Failing - /// function * quux (foo) { yield foo; } /// /** /// * @yields {undefined} /// * @yields {void} /// */ /// function * quux (foo) {} /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// /** * @yields Foo */ + /// function * quux (foo) { yield foo; } + /// ``` RequireYields, correctness ); diff --git a/crates/oxc_linter/src/rules/jsx_a11y/lang.rs b/crates/oxc_linter/src/rules/jsx_a11y/lang.rs index b9bd3406c89c3e..0cf7d34f41cbf1 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/lang.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/lang.rs @@ -36,20 +36,20 @@ declare_oxc_lint!( /// and access website in more than one language. /// /// - /// ### Example + /// ### Examples /// - /// // good - /// ```jsx - /// - /// - /// ``` - /// - /// // bad + /// Examples of **incorrect** code for this rule: /// ```jsx /// /// /// ```` /// + /// Examples of **correct** code for this rule: + /// ```jsx + /// + /// + /// ``` + /// /// ### Resources /// - [eslint-plugin-jsx-a11y/lang](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/lang.md) /// - [IANA Language Subtag Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry) diff --git a/crates/oxc_linter/src/rules/oxc/bad_char_at_comparison.rs b/crates/oxc_linter/src/rules/oxc/bad_char_at_comparison.rs index 694e28d0248fb7..4427c10645c718 100644 --- a/crates/oxc_linter/src/rules/oxc/bad_char_at_comparison.rs +++ b/crates/oxc_linter/src/rules/oxc/bad_char_at_comparison.rs @@ -31,13 +31,16 @@ declare_oxc_lint!( /// /// The `charAt` method returns a string of length 1. If the return value is compared with a string of length greater than 1, the comparison will always be false. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Bad: The return value of the `charAt` method is compared with a string of length greater than 1. /// a.charAt(4) === 'a2'; /// a.charAt(4) === '/n'; + /// ``` /// - /// // Good: The return value of the `charAt` method is compared with a string of length 1. + /// Examples of **correct** code for this rule: + /// ```javascript /// a.charAt(4) === 'a' /// a.charAt(4) === '\n'; /// ``` diff --git a/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs b/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs index 99ab0edc7de05c..10551620c86b25 100644 --- a/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs +++ b/crates/oxc_linter/src/rules/oxc/bad_replace_all_arg.rs @@ -34,12 +34,15 @@ declare_oxc_lint!( /// /// The `replaceAll` method replaces all occurrences of a string with another string. If the global flag (g) is not used in the regular expression, only the first occurrence of the string will be replaced. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Bad: The global flag (g) is missing in the regular expression. /// withSpaces.replaceAll(/\s+/, ','); + /// ``` /// - /// // Good: The global flag (g) is used in the regular expression. + /// Examples of **correct** code for this rule: + /// ```javascript /// withSpaces.replaceAll(/\s+/g, ','); /// ``` BadReplaceAllArg, diff --git a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs index 0e8525cace8dcb..0e38524104fbe3 100644 --- a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs @@ -76,9 +76,11 @@ pub struct NoAccumulatingSpread; declare_oxc_lint!( /// ### What it does + /// /// Prevents using object or array spreads on accumulators in `Array.prototype.reduce()` and in loops. /// /// ### Why is this bad? + /// /// Object and array spreads create a new object or array on each iteration. /// In the worst case, they also cause O(n) copies (both memory and time complexity). /// When used on an accumulator, this can lead to `O(n^2)` memory complexity and @@ -87,9 +89,17 @@ declare_oxc_lint!( /// For a more in-depth explanation, see this [blog post](https://prateeksurana.me/blog/why-using-object-spread-with-reduce-bad-idea/) /// by Prateek Surana. /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: + /// ```javascript + /// arr.reduce((acc, x) => ({ ...acc, [x]: fn(x) }), {}) + /// Object.keys(obj).reduce((acc, el) => ({ ...acc, [el]: fn(el) }), {}) + /// + /// let foo = []; for (let i = 0; i < 10; i++) { foo = [...foo, i]; } + /// ``` /// - /// ### Example - /// Pass + /// Examples of **correct** code for this rule: /// ```javascript /// function fn (x) { /// // ... @@ -108,14 +118,6 @@ declare_oxc_lint!( /// /// let foo = []; for (let i = 0; i < 10; i++) { foo.push(i); } /// ``` - /// - /// Fail - /// ```javascript - /// arr.reduce((acc, x) => ({ ...acc, [x]: fn(x) }), {}) - /// Object.keys(obj).reduce((acc, el) => ({ ...acc, [el]: fn(el) }), {}) - /// - /// let foo = []; for (let i = 0; i < 10; i++) { foo = [...foo, i]; } - /// ``` NoAccumulatingSpread, perf, ); diff --git a/crates/oxc_linter/src/rules/oxc/only_used_in_recursion.rs b/crates/oxc_linter/src/rules/oxc/only_used_in_recursion.rs index 6a181e73d70daf..30670602850291 100644 --- a/crates/oxc_linter/src/rules/oxc/only_used_in_recursion.rs +++ b/crates/oxc_linter/src/rules/oxc/only_used_in_recursion.rs @@ -36,9 +36,10 @@ declare_oxc_lint!( /// /// It increase cognitive complexity and may impact performance. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```ts - /// // Bad - the argument `b` is only used in recursive calls /// function f(a: number, b: number): number { /// if (a == 0) { /// return 1 @@ -46,8 +47,10 @@ declare_oxc_lint!( /// return f(a - 1, b + 1) /// } /// } + /// ``` /// - /// // Good - the argument `b` is omitted + /// Examples of **correct** code for this rule: + /// ```ts /// function f(a: number): number { /// if (a == 0) { /// return 1 diff --git a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs index aae2c657e5e1d7..21de5b2389df62 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs @@ -28,28 +28,27 @@ enum ConsistentIndexedObjectStyleConfig { declare_oxc_lint!( /// ### What it does + /// /// Require or disallow the `Record` type. /// /// ### Why is this bad? + /// /// Inconsistent style for indexed object types can harm readability in a project. /// - /// ### Example - /// With "record": + /// ### Examples /// + /// Examples of **incorrect** code for this rule: /// ```ts - /// // bad /// interface Foo { /// [key: string]: unknown; - ///} + /// } /// type Foo = { /// [key: string]: unknown; - ///}; + /// }; /// ``` /// - /// With "index-signature": - /// + /// Examples of **correct** code for this rule: /// ```ts - /// // bad /// type Foo = Record; /// ``` ConsistentIndexedObjectStyle, diff --git a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs index 103ee202981697..52971ada451dcc 100644 --- a/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs +++ b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs @@ -42,15 +42,18 @@ declare_oxc_lint!( /// /// This rule enforces naming conventions for catch statements. /// - /// ### Example - /// ```javascript + /// ### Why is this bad? + /// + /// ### Examples /// - /// // fail + /// Examples of **incorrect** code for this rule: + /// ```javascript /// try { } catch (foo) { } + /// ``` /// - /// // pass + /// Examples of **correct** code for this rule: + /// ```javascript /// try { } catch (error) { } - /// /// ``` CatchErrorName, style diff --git a/crates/oxc_linter/src/rules/unicorn/error_message.rs b/crates/oxc_linter/src/rules/unicorn/error_message.rs index 25dbcae6075f83..d71af0cfd1fd47 100644 --- a/crates/oxc_linter/src/rules/unicorn/error_message.rs +++ b/crates/oxc_linter/src/rules/unicorn/error_message.rs @@ -28,17 +28,20 @@ declare_oxc_lint!( /// /// This rule enforces a `message` value to be passed in when creating an instance of a built-in `Error` object, which leads to more readable and debuggable code. /// - /// ### Example + /// ### Why is this bad? + /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// throw Error() /// throw new TypeError() + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// throw new Error('Unexpected token') /// throw new TypeError('Number expected') - /// - /// /// ``` ErrorMessage, style diff --git a/crates/oxc_linter/src/rules/unicorn/escape_case.rs b/crates/oxc_linter/src/rules/unicorn/escape_case.rs index 89932557b9d694..4ddad1a9c4747f 100644 --- a/crates/oxc_linter/src/rules/unicorn/escape_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/escape_case.rs @@ -23,14 +23,20 @@ declare_oxc_lint!( /// /// Enforces defining escape sequence values with uppercase characters rather than lowercase ones. This promotes readability by making the escaped value more distinguishable from the identifier. /// - /// ### Example + /// ### Why is this bad? + /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // fail /// const foo = '\xa9'; /// const foo = '\ud834'; /// const foo = '\u{1d306}'; /// const foo = '\ca'; - /// // pass + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript /// const foo = '\xA9'; /// const foo = '\uD834'; /// const foo = '\u{1D306}'; diff --git a/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs b/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs index 2d0ae5f31c9929..017bf8ac9ddedd 100644 --- a/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs +++ b/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs @@ -61,19 +61,26 @@ declare_oxc_lint!( /// Enforces non-zero to be checked with: foo.length > 0 /// not-equal /// Enforces non-zero to be checked with: foo.length !== 0 - /// ### Example + /// + /// ### Why is this bad? + /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // fail - /// const isEmpty = !foo.length; /// const isEmpty = foo.length == 0; /// const isEmpty = foo.length < 1; /// const isEmpty = 0 === foo.length; /// const isEmpty = 0 == foo.length; /// const isEmpty = 1 > foo.length; - /// // Negative style is disallowed too + /// + /// const isEmpty = !foo.length; /// const isEmpty = !(foo.length > 0); /// const isEmptySet = !foo.size; - /// // pass + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript /// const isEmpty = foo.length === 0; /// ``` ExplicitLengthCheck, diff --git a/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs b/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs index 1175915e36f422..e0d9683fd7d63e 100644 --- a/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs +++ b/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs @@ -35,13 +35,16 @@ declare_oxc_lint!( /// They work the same, but `new` should be preferred for consistency with other constructors. /// /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const foo = new String('hello world'); /// const bar = Array(1, 2, 3); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// const foo = String('hello world'); /// const bar = new Array(1, 2, 3); /// ``` diff --git a/crates/oxc_linter/src/rules/unicorn/no_abusive_eslint_disable.rs b/crates/oxc_linter/src/rules/unicorn/no_abusive_eslint_disable.rs index e2f6849934da3b..eed4973266ef55 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_abusive_eslint_disable.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_abusive_eslint_disable.rs @@ -17,14 +17,17 @@ pub struct NoAbusiveEslintDisable; declare_oxc_lint!( /// ### What it does + /// /// This rule disallows `eslint-disable` comments that do not specify any rules to disable. /// /// ### Why is this bad? + /// /// When only one rule should be disabled but the `eslint-disable` comment does not specify any rules, other useful errors will also be silently ignored. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// /* eslint-disable */ /// console.log(message); /// @@ -32,8 +35,10 @@ declare_oxc_lint!( /// /// // eslint-disable-next-line /// console.log(message); + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// /* eslint-disable no-console */ /// console.log(message); /// diff --git a/crates/oxc_linter/src/rules/unicorn/no_document_cookie.rs b/crates/oxc_linter/src/rules/unicorn/no_document_cookie.rs index bf21cb429cfd9e..6dc12930dff836 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_document_cookie.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_document_cookie.rs @@ -35,17 +35,20 @@ declare_oxc_lint!( /// API](https://developer.mozilla.org/en-US/docs/Web/API/Cookie_Store_API) /// or a [cookie library](https://www.npmjs.com/search?q=cookie). /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// document.cookie = /// 'foo=bar' + /// '; Path=/' + /// '; Domain=example.com' + /// '; expires=Fri, 31 Dec 9999 23:59:59 GMT' + /// '; Secure'; + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// async function storeCookies() { /// await cookieStore.set({ /// name: 'foo', diff --git a/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs b/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs index 1531b9e59f70ee..9f7449aa0727ed 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs @@ -20,13 +20,18 @@ declare_oxc_lint!( /// /// Enforces a convention of using [Unicode escapes](https://mathiasbynens.be/notes/javascript-escapes#unicode) instead of [hexadecimal escapes](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) for consistency and clarity. /// - /// ### Example + /// ### Why is this bad? + /// + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // fail /// const foo = '\x1B'; /// const foo = `\x1B${bar}`; + /// ``` /// - /// // pass + /// Examples of **correct** code for this rule: + /// ```javascript /// const foo = '\u001B'; /// const foo = `\u001B${bar}`; /// ``` diff --git a/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs b/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs index d4af6ae4705e11..737ffff6f53668 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs @@ -22,19 +22,24 @@ pub struct NoNestedTernary; declare_oxc_lint!( /// ### What it does + /// /// This rule disallows deeply nested ternary expressions. /// Nested ternary expressions that are only one level deep and wrapped in parentheses are allowed. /// /// ### Why is this bad? + /// /// Nesting ternary expressions can make code more difficult to understand. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// const foo = i > 5 ? i < 100 ? true : false : true; /// const foo = i > 5 ? true : (i < 100 ? true : (i < 1000 ? true : false)); + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// const foo = i > 5 ? (i < 100 ? true : false) : true; /// const foo = i > 5 ? (i < 100 ? true : false) : (i < 100 ? true : false); /// ``` diff --git a/crates/oxc_linter/src/rules/unicorn/no_new_array.rs b/crates/oxc_linter/src/rules/unicorn/no_new_array.rs index 9b12f87927dbe5..fef71df4c35fae 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_new_array.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_new_array.rs @@ -21,14 +21,17 @@ declare_oxc_lint!( /// /// When using the `Array` constructor with one argument, it's not clear whether the argument is meant to be the length of the array or the only element. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const array = new Array(1); /// const array = new Array(42); /// const array = new Array(foo); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// const array = Array.from({ length: 42 }); /// const array = [42]; /// ``` diff --git a/crates/oxc_linter/src/rules/unicorn/no_this_assignment.rs b/crates/oxc_linter/src/rules/unicorn/no_this_assignment.rs index 2875e47023f250..fd934822f68cbe 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_this_assignment.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_this_assignment.rs @@ -26,9 +26,10 @@ declare_oxc_lint!( /// /// Assigning `this` to a variable is unnecessary and confusing. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // fail /// const foo = this; /// class Bar { /// method() { @@ -37,8 +38,10 @@ declare_oxc_lint!( /// } /// /// new Bar().method(); + /// ``` /// - /// // pass + /// Examples of **correct** code for this rule: + /// ```javascript /// class Bar { /// constructor(fooInstance) { /// this.fooInstance = fooInstance; diff --git a/crates/oxc_linter/src/rules/unicorn/no_typeof_undefined.rs b/crates/oxc_linter/src/rules/unicorn/no_typeof_undefined.rs index 74b9ccdd2caa76..b4aa5a61e97fb4 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_typeof_undefined.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_typeof_undefined.rs @@ -26,12 +26,15 @@ declare_oxc_lint!( /// Checking if a value is `undefined` by using `typeof value === 'undefined'` is needlessly verbose. It's generally better to compare against `undefined` directly. The only time `typeof` is needed is when a global variable potentially does not exists, in which case, using `globalThis.value === undefined` may be better. /// /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// typeof foo === 'undefined'; + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// foo === undefined; /// ``` NoTypeofUndefined, diff --git a/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs b/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs index c5648fc822dca7..3e85318960151a 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_unreadable_iife.rs @@ -19,19 +19,24 @@ pub struct NoUnreadableIife; declare_oxc_lint!( /// ### What it does + /// /// This rule disallows IIFEs with a parenthesized arrow function body. /// /// ### Why is this bad? + /// /// IIFEs with a parenthesized arrow function body are unreadable. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// const foo = (bar => (bar ? bar.baz : baz))(getBar()); /// /// const foo = ((bar, baz) => ({bar, baz}))(bar, baz); + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// const bar = getBar(); /// const foo = bar ? bar.baz : baz; /// diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs index 4443816b0cde0c..08f22767e9b269 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs @@ -24,15 +24,17 @@ declare_oxc_lint!( /// /// Spreading [falsy values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) in object literals won't add any unexpected properties, so it's unnecessary to add an empty object as fallback. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const object = { ...(foo || {}) } + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// const object = { ...foo } /// const object = { ...(foo || { not: "empty" }) } - /// /// ``` NoUselessFallbackInSpread, correctness, diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs index 36c1c3084b78e4..d92ab7a38e9ea5 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs @@ -38,12 +38,15 @@ declare_oxc_lint!( /// /// Wrapping a return value in `Promise.resolve` in an async function or a `Promise#then`/`catch`/`finally` callback is unnecessary as all return values in async functions and promise callback functions are already wrapped in a `Promise`. Similarly, returning an error wrapped in `Promise.reject` is equivalent to simply `throw`ing the error. This is the same for `yield`ing in async generators as well. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// async () => Promise.resolve(bar); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// async () => bar; /// ``` NoUselessPromiseResolveReject, diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs index 8973007aecdd01..409490ef080e7d 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_switch_case.rs @@ -23,16 +23,20 @@ declare_oxc_lint!( /// /// An empty case before the last default case is useless. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// switch (foo) { /// case 1: /// default: /// handleDefaultCase(); /// break; /// } - /// // good: + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript /// switch (foo) { /// case 1: /// case 2: diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs index 84a32efcb04393..56a01a718b7ce6 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs @@ -33,17 +33,21 @@ impl Default for NoUselessUndefined { declare_oxc_lint!( /// ### What it does + /// /// Do not use useless `undefined`. /// /// ### Why is this bad? - /// `undefined` is the default value for new variables, parameters, return statements, etc… so specifying it doesn't make any difference. /// + /// `undefined` is the default value for new variables, parameters, return statements, etc… so specifying it doesn't make any difference. /// - /// ### Example + /// ### Examples + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// let foo = undefined; - /// // good: + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript /// let foo; /// ``` NoUselessUndefined, diff --git a/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs b/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs index afad10c468e0b9..83edd6f140a605 100644 --- a/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs @@ -38,14 +38,17 @@ pub struct NumberLiteralCase; declare_oxc_lint!( /// ### What it does + /// /// This rule enforces proper case for numeric literals. /// /// ### Why is this bad? + /// /// When both an identifier and a number literal are in lower case, it can be hard to differentiate between them. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// const foo = 0XFF; /// const foo = 0xff; /// const foo = 0Xff; @@ -58,8 +61,10 @@ declare_oxc_lint!( /// const foo = 0O76n; /// /// const foo = 2E-5; + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// const foo = 0xFF; /// const foo = 0b10; /// const foo = 0o76; diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs b/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs index 323b25e4c9bd48..c252b43e2027ee 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_add_event_listener.rs @@ -24,12 +24,15 @@ declare_oxc_lint!( /// /// There are [numerous advantages of using `addEventListener`](https://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick/35093997#35093997). Some of these advantages include registering unlimited event handlers and optionally having the event handler invoked only once. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// foo.onclick = () => {}; + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// foo.addEventListener('click', () => {}); /// ``` PreferAddEventListener, diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs b/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs index ac11c8334ba82d..bf0a32a8dff0ad 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs @@ -26,13 +26,16 @@ declare_oxc_lint!( /// /// [Difference between `String.fromCodePoint()` and `String.fromCharCode()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint#compared_to_fromcharcode) /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// '🦄'.charCodeAt(0); /// String.fromCharCode(0x1f984); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// '🦄'.codePointAt(0); /// String.fromCodePoint(0x1f984); /// ``` diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs b/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs index acdea4b256932c..14b45fd0accdb8 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs @@ -39,14 +39,15 @@ declare_oxc_lint!( /// /// Using `Date.now()` is shorter and nicer than `new Date().getTime()`, and avoids unnecessary instantiation of `Date` objects. /// - /// - /// ### Example + /// ### Examples + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const ts = new Date().getTime(); /// const ts = new Date().valueOf(); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// const ts = Date.now(); /// ``` PreferDateNow, diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs index d9d5512c43b087..b146287259fd31 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs @@ -17,20 +17,21 @@ pub struct PreferDomNodeAppend; declare_oxc_lint!( /// ### What it does /// - ///Enforces the use of, for example, `document.body.append(div);` over `document.body.appendChild(div);` for DOM nodes. + /// Enforces the use of, for example, `document.body.append(div);` over `document.body.appendChild(div);` for DOM nodes. /// /// ### Why is this bad? /// /// There are [some advantages of using `Node#append()`](https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append), like the ability to append multiple nodes and to append both [`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString) and DOM node objects. /// - /// ### Example + /// ### Examples + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// foo.appendChild(bar); + /// ``` /// - // // good + /// Examples of **correct** code for this rule: + /// ```javascript /// foo.append(bar); - // /// ``` PreferDomNodeAppend, pedantic, diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs index 5529eef104262b..0719e83576daa5 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_remove.rs @@ -28,12 +28,15 @@ declare_oxc_lint!( /// /// The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild). /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// parentNode.removeChild(childNode); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// childNode.remove(); /// ``` PreferDomNodeRemove, diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_includes.rs b/crates/oxc_linter/src/rules/unicorn/prefer_includes.rs index ad02f1ed691d16..8cc8516bae1c9b 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_includes.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_includes.rs @@ -25,19 +25,21 @@ declare_oxc_lint!( /// ### What it does /// /// Prefer `includes()` over `indexOf()` when checking for existence or non-existence. - /// /// All built-ins have `.includes()` in addition to `.indexOf()`. /// /// ### Why is this bad? /// /// The `.includes()` method is more readable and less error-prone than `.indexOf()`. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// if (str.indexOf('foo') !== -1) { } + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// if (str.includes('foo')) { } /// ``` PreferIncludes, diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs index 227bc5ce7a2e3e..3121b04251d5d8 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs @@ -32,15 +32,18 @@ declare_oxc_lint!( /// If a function is equivalent to [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean), or [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), you should use the built-in one directly. /// Wrapping the built-in in a function is moot. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const foo = v => String(v); /// foo(1); /// const foo = v => Number(v); /// array.some((v, ) => /* comment */ v) + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// String(1); /// Number(1); /// array.some(Boolean); diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs b/crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs index 391f79cb702031..2e127631f4f756 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs @@ -34,13 +34,16 @@ declare_oxc_lint!( /// - [`Number.POSITIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY) over [`Infinity`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity) /// - [`Number.NEGATIVE_INFINITY`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY) over [`-Infinity`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity) /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const foo = parseInt('10', 2); /// const bar = parseFloat('10.5'); + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// const foo = Number.parseInt('10', 2); /// const bar = Number.parseFloat('10.5'); /// ``` diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs b/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs index 8c29c27934fcb7..7da10aa6453d31 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs @@ -28,16 +28,20 @@ declare_oxc_lint!( /// This rule prefers borrowing methods from the prototype instead of the instance. /// /// ### Why is this bad? + /// /// “Borrowing” a method from an instance of `Array` or `Object` is less clear than getting it from the corresponding prototype. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// const array = [].slice.apply(bar); /// const type = {}.toString.call(foo); /// Reflect.apply([].forEach, arrayLike, [callback]); + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// const array = Array.prototype.slice.apply(bar); /// const type = Object.prototype.toString.call(foo); /// Reflect.apply(Array.prototype.forEach, arrayLike, [callback]); diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_set_size.rs b/crates/oxc_linter/src/rules/unicorn/prefer_set_size.rs index 984375185a4feb..f379ba70b95434 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_set_size.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_set_size.rs @@ -29,14 +29,16 @@ declare_oxc_lint!( /// /// Using `Set#size` is more readable and performant. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const length = [...new Set([1, 2, 3])].length; + /// ``` /// - /// // good + /// Examples of **correct** code for this rule: + /// ```javascript /// const size = new Set([1, 2, 3]).size; - /// /// ``` PreferSetSize, correctness, diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs b/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs index a7a4b2e278b88a..1c05c74a5f58b4 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs @@ -27,14 +27,18 @@ declare_oxc_lint!( /// /// Using the spread operator is more concise and readable. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // bad /// const foo = Array.from(set); /// const foo = Array.from(new Set([1, 2])); + /// ``` /// - /// // good - /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// [...set].map(() => {}); + /// Array.from(...argumentsArray); /// ``` PreferSpread, style, diff --git a/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs b/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs index bcdc83c54d2cbf..eb31915aeaf91d 100644 --- a/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs +++ b/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs @@ -16,20 +16,25 @@ pub struct RequireNumberToFixedDigitsArgument; declare_oxc_lint!( /// ### What it does + /// /// Enforce using the digits argument with Number.toFixed() /// /// ### Why is this bad? + /// /// It's better to make it clear what the value of the digits argument is when calling Number.toFixed(), /// instead of relying on the default value of 0. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: + /// ```javascript + /// number.toFixed(); + /// ``` + /// + /// Examples of **correct** code for this rule: /// ```javascript - /// // Pass /// number.toFixed(0); /// number.toFixed(2); - /// - /// // Fail: - /// number.toFixed(); /// ``` RequireNumberToFixedDigitsArgument, pedantic, diff --git a/crates/oxc_linter/src/rules/unicorn/throw_new_error.rs b/crates/oxc_linter/src/rules/unicorn/throw_new_error.rs index 3187513c7b4ddc..7d0aedc0f0ff64 100644 --- a/crates/oxc_linter/src/rules/unicorn/throw_new_error.rs +++ b/crates/oxc_linter/src/rules/unicorn/throw_new_error.rs @@ -33,18 +33,20 @@ declare_oxc_lint!( /// /// While it's possible to create a new error without using the `new` keyword, it's better to be explicit. /// - /// ### Example + /// ### Examples + /// + /// Examples of **incorrect** code for this rule: /// ```javascript - /// // Fail /// throw Error('🦄'); /// throw TypeError('unicorn'); /// throw lib.TypeError('unicorn'); + /// ``` /// - /// // Pass + /// Examples of **correct** code for this rule: + /// ```javascript /// throw new Error('🦄'); /// throw new TypeError('unicorn'); /// throw new lib.TypeError('unicorn'); - /// /// ``` ThrowNewError, style, From 0c43d0cf8d2a31a30cd324ce2f59daa082ad7a66 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 6 Sep 2024 19:27:13 +0800 Subject: [PATCH 19/28] build: fix wasm publish --- .github/workflows/release_wasm.yml | 6 +- package.json | 3 +- pnpm-lock.yaml | 172 +++++++++++++++++++++++++++++ pnpm-workspace.yaml | 1 + wasm/parser/package.json | 5 +- 5 files changed, 181 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release_wasm.yml b/.github/workflows/release_wasm.yml index efba750a3079cd..e09b14b4740e4a 100644 --- a/.github/workflows/release_wasm.yml +++ b/.github/workflows/release_wasm.yml @@ -45,6 +45,11 @@ jobs: steps: - uses: taiki-e/checkout-action@v1 + - name: Install pnpm + uses: pnpm/action-setup@v4.0.0 + with: + package_json_file: ./wasm/parser/package.json + - name: Install Node.js uses: actions/setup-node@v4 with: @@ -59,7 +64,6 @@ jobs: working-directory: wasm/parser run: | rustup target add wasm32-unknown-unknown - corepack enable pnpm install pnpm run build pnpm run test diff --git a/package.json b/package.json index b7037b3948bdbe..f020be53b77ae7 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "devDependencies": { "@napi-rs/cli": "3.0.0-alpha.61", "es-module-lexer": "^1.4.1", - "tinybench": "^2.6.0" + "tinybench": "^2.6.0", + "wasm-pack": "^0.13.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b0e0e99ebbd009..135509a9e495a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: tinybench: specifier: ^2.6.0 version: 2.9.0 + wasm-pack: + specifier: ^0.13.0 + version: 0.13.0 napi/parser: {} @@ -34,6 +37,8 @@ importers: specifier: ^7.2.0 version: 7.4.3 + wasm/parser: {} + packages: '@emnapi/core@1.2.0': @@ -516,6 +521,9 @@ packages: asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + axios@0.26.1: + resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==} + axios@1.7.7: resolution: {integrity: sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==} @@ -525,10 +533,17 @@ packages: before-after-hook@3.0.2: resolution: {integrity: sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==} + binary-install@1.1.0: + resolution: {integrity: sha512-rkwNGW+3aQVSZoD0/o3mfPN6Yxh3Id0R/xzTVBVVpGNlVz8EGwusksxRlbk/A5iKTZt9zkMn3qIqmAt3vpfbzg==} + engines: {node: '>=10'} + body-parser@1.20.2: resolution: {integrity: sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==} engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} + brace-expansion@1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} @@ -543,6 +558,10 @@ packages: chardet@0.7.0: resolution: {integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==} + chownr@2.0.0: + resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==} + engines: {node: '>=10'} + chownr@3.0.0: resolution: {integrity: sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==} engines: {node: '>=18'} @@ -574,6 +593,9 @@ packages: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} + concat-map@0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + content-disposition@0.5.4: resolution: {integrity: sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==} engines: {node: '>= 0.6'} @@ -697,6 +719,13 @@ packages: resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==} engines: {node: '>= 0.6'} + fs-minipass@2.1.0: + resolution: {integrity: sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==} + engines: {node: '>= 8'} + + fs.realpath@1.0.0: + resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} + function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} @@ -708,6 +737,10 @@ packages: resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} hasBin: true + glob@7.2.3: + resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} + deprecated: Glob versions prior to v9 are no longer supported + gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} @@ -734,6 +767,10 @@ packages: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} + inflight@1.0.6: + resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. + inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -789,18 +826,38 @@ packages: engines: {node: '>=4'} hasBin: true + minimatch@3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} + minimatch@9.0.5: resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} engines: {node: '>=16 || 14 >=14.17'} + minipass@3.3.6: + resolution: {integrity: sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==} + engines: {node: '>=8'} + + minipass@5.0.0: + resolution: {integrity: sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==} + engines: {node: '>=8'} + minipass@7.1.2: resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} engines: {node: '>=16 || 14 >=14.17'} + minizlib@2.1.2: + resolution: {integrity: sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==} + engines: {node: '>= 8'} + minizlib@3.0.1: resolution: {integrity: sha512-umcy022ILvb5/3Djuu8LWeqUa8D68JaBzlttKeMWen48SjabqS3iY5w/vzeMzMUNhLDifyhbOwKDSznB1vvrwg==} engines: {node: '>= 18'} + mkdirp@1.0.4: + resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==} + engines: {node: '>=10'} + hasBin: true + mkdirp@3.0.1: resolution: {integrity: sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==} engines: {node: '>=10'} @@ -831,6 +888,9 @@ packages: resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} engines: {node: '>= 0.8'} + once@1.4.0: + resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} + os-tmpdir@1.0.2: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} @@ -842,6 +902,10 @@ packages: resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==} engines: {node: '>= 0.8'} + path-is-absolute@1.0.1: + resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} + engines: {node: '>=0.10.0'} + path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} @@ -872,6 +936,11 @@ packages: resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==} engines: {node: '>= 0.8'} + rimraf@3.0.2: + resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} + deprecated: Rimraf versions prior to v4 are no longer supported + hasBin: true + rimraf@5.0.10: resolution: {integrity: sha512-l0OE8wL34P4nJH/H2ffoaniAokM2qSmrtXHmlpvYr5AVVX8msAyW0l8NVJFDxlSK4u3Uh/f41cQheDVdnYijwQ==} hasBin: true @@ -945,6 +1014,10 @@ packages: resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} engines: {node: '>=12'} + tar@6.2.1: + resolution: {integrity: sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==} + engines: {node: '>=10'} + tar@7.4.3: resolution: {integrity: sha512-5S7Va8hKfV7W5U6g3aYxXmlPoZVAwUMy9AOKyF2fVuZa2UD3qZjg578OrLRt8PcNN1PleVaL/5/yYATNL0ICUw==} engines: {node: '>=18'} @@ -995,6 +1068,10 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + wasm-pack@0.13.0: + resolution: {integrity: sha512-AmboGZEnZoIcVCzSlkLEmNFEqJN+IwgshJ5S7pi30uNUTce4LvWkifQzsQRxnWj47G8gkqZxlyGlyQplsnIS7w==} + hasBin: true + wasm-sjlj@1.0.5: resolution: {integrity: sha512-Z/MHJeOkAvJJVWnGX3/YZGYldGaawZbYHX4ldYG9kLhcdB8H31F5x66M7Zc4BP/7pg0aLsusQj1629m2B3Rilg==} @@ -1015,6 +1092,12 @@ packages: resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} engines: {node: '>=12'} + wrappy@1.0.2: + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} + + yallist@4.0.0: + resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + yallist@5.0.0: resolution: {integrity: sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==} engines: {node: '>=18'} @@ -1483,6 +1566,12 @@ snapshots: asynckit@0.4.0: {} + axios@0.26.1: + dependencies: + follow-redirects: 1.15.6 + transitivePeerDependencies: + - debug + axios@1.7.7: dependencies: follow-redirects: 1.15.6 @@ -1495,6 +1584,14 @@ snapshots: before-after-hook@3.0.2: {} + binary-install@1.1.0: + dependencies: + axios: 0.26.1 + rimraf: 3.0.2 + tar: 6.2.1 + transitivePeerDependencies: + - debug + body-parser@1.20.2: dependencies: bytes: 3.1.2 @@ -1512,6 +1609,11 @@ snapshots: transitivePeerDependencies: - supports-color + brace-expansion@1.1.11: + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + brace-expansion@2.0.1: dependencies: balanced-match: 1.0.2 @@ -1528,6 +1630,8 @@ snapshots: chardet@0.7.0: {} + chownr@2.0.0: {} + chownr@3.0.0: {} cli-spinners@2.9.2: {} @@ -1550,6 +1654,8 @@ snapshots: dependencies: delayed-stream: 1.0.0 + concat-map@0.0.1: {} + content-disposition@0.5.4: dependencies: safe-buffer: 5.2.1 @@ -1679,6 +1785,12 @@ snapshots: fresh@0.5.2: {} + fs-minipass@2.1.0: + dependencies: + minipass: 3.3.6 + + fs.realpath@1.0.0: {} + function-bind@1.1.2: {} get-intrinsic@1.2.4: @@ -1698,6 +1810,15 @@ snapshots: package-json-from-dist: 1.0.0 path-scurry: 1.11.1 + glob@7.2.3: + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 3.1.2 + once: 1.4.0 + path-is-absolute: 1.0.1 + gopd@1.0.1: dependencies: get-intrinsic: 1.2.4 @@ -1726,6 +1847,11 @@ snapshots: dependencies: safer-buffer: 2.1.2 + inflight@1.0.6: + dependencies: + once: 1.4.0 + wrappy: 1.0.2 + inherits@2.0.4: {} inquirer@10.2.0: @@ -1772,17 +1898,34 @@ snapshots: mime@1.6.0: {} + minimatch@3.1.2: + dependencies: + brace-expansion: 1.1.11 + minimatch@9.0.5: dependencies: brace-expansion: 2.0.1 + minipass@3.3.6: + dependencies: + yallist: 4.0.0 + + minipass@5.0.0: {} + minipass@7.1.2: {} + minizlib@2.1.2: + dependencies: + minipass: 3.3.6 + yallist: 4.0.0 + minizlib@3.0.1: dependencies: minipass: 7.1.2 rimraf: 5.0.10 + mkdirp@1.0.4: {} + mkdirp@3.0.1: {} ms@2.0.0: {} @@ -1801,12 +1944,18 @@ snapshots: dependencies: ee-first: 1.1.1 + once@1.4.0: + dependencies: + wrappy: 1.0.2 + os-tmpdir@1.0.2: {} package-json-from-dist@1.0.0: {} parseurl@1.3.3: {} + path-is-absolute@1.0.1: {} + path-key@3.1.1: {} path-scurry@1.11.1: @@ -1836,6 +1985,10 @@ snapshots: iconv-lite: 0.4.24 unpipe: 1.0.0 + rimraf@3.0.2: + dependencies: + glob: 7.2.3 + rimraf@5.0.10: dependencies: glob: 10.4.5 @@ -1927,6 +2080,15 @@ snapshots: dependencies: ansi-regex: 6.0.1 + tar@6.2.1: + dependencies: + chownr: 2.0.0 + fs-minipass: 2.1.0 + minipass: 5.0.0 + minizlib: 2.1.2 + mkdirp: 1.0.4 + yallist: 4.0.0 + tar@7.4.3: dependencies: '@isaacs/fs-minipass': 4.0.1 @@ -1967,6 +2129,12 @@ snapshots: vary@1.1.2: {} + wasm-pack@0.13.0: + dependencies: + binary-install: 1.1.0 + transitivePeerDependencies: + - debug + wasm-sjlj@1.0.5: {} which@2.0.2: @@ -1991,6 +2159,10 @@ snapshots: string-width: 5.1.2 strip-ansi: 7.1.0 + wrappy@1.0.2: {} + + yallist@4.0.0: {} + yallist@5.0.0: {} yoctocolors-cjs@2.1.2: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index d54d64bb0f614d..3f24834b52ce0f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,4 @@ packages: - 'napi/**' + - 'wasm/**' - 'tasks/benchmark/codspeed' diff --git a/wasm/parser/package.json b/wasm/parser/package.json index d49ecdae7372ed..37bbd57699eb0f 100644 --- a/wasm/parser/package.json +++ b/wasm/parser/package.json @@ -34,8 +34,5 @@ "copy-files": "cp ./package.json ../../npm/parser-wasm/package.json && cp ./README.md ../../npm/parser-wasm/README.md", "clean-files": "rm ../../npm/parser-wasm/*/.gitignore", "test": "node ./test-node.mjs" - }, - "devDependencies": { - "wasm-pack": "^0.13.0" } -} \ No newline at end of file +} From d1ece197c4713dd8ef5e2c7be90b8c518b2168d4 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:51:35 +0000 Subject: [PATCH 20/28] fix(transformer): RegExp transform handle `Term::Quantifier` (#5501) `Term::Quantifier` contains a nested `Term` so we need to recurse into that `Term` to check if it contains any unsupported syntax. --- crates/oxc_transformer/src/regexp/mod.rs | 28 +++++++++++-------- .../input.js | 3 ++ .../output.js | 3 ++ .../input.js | 1 + .../output.js | 3 +- .../transform-unicode-property-regex/input.js | 3 +- .../output.js | 3 +- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 31c3b26a6f3438..d8942b270980e7 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -197,27 +197,33 @@ impl<'a> RegExp<'a> { /// /// Based on parsed regular expression pattern. fn has_unsupported_regular_expression_pattern(&self, pattern: &Pattern<'a>) -> bool { - let terms_contains_unsupported = |terms: &[Term]| { - terms.iter().any(|term| match term { - Term::CapturingGroup(_) => self.named_capture_groups, - Term::UnicodePropertyEscape(_) => self.unicode_property_escapes, + pattern.body.body.iter().any(|alternative| { + alternative.body.iter().any(|term| self.term_contains_unsupported(term)) + }) + } + + fn term_contains_unsupported(&self, mut term: &Term) -> bool { + // Loop because `Term::Quantifier` contains a nested `Term` + loop { + match term { + Term::CapturingGroup(_) => return self.named_capture_groups, + Term::UnicodePropertyEscape(_) => return self.unicode_property_escapes, Term::CharacterClass(character_class) => { - self.unicode_property_escapes + return self.unicode_property_escapes && character_class_has_unicode_property_escape(character_class) } Term::LookAroundAssertion(assertion) => { - self.look_behind_assertions + return self.look_behind_assertions && matches!( assertion.kind, LookAroundAssertionKind::Lookbehind | LookAroundAssertionKind::NegativeLookbehind ) } - _ => false, - }) - }; - - pattern.body.body.iter().any(|alternative| terms_contains_unsupported(&alternative.body)) + Term::Quantifier(quantifier) => term = &quantifier.body, + _ => return false, + } + } } } diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/input.js b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/input.js index baef065c1caf0d..450f6d384ba545 100644 --- a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/input.js +++ b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/input.js @@ -9,8 +9,11 @@ a1 = /a.b/s // RegExpLookbehindAssertions b1 = /(?b)/ +c2 = /((?d)){4}/; // RegExpUnicodePropertyEscapes d1 = /\p{Emoji}/u // ES2022 diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/output.js b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/output.js index 03c4967db48e5d..8226e9420d3b4e 100644 --- a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/output.js +++ b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/output.js @@ -3,7 +3,10 @@ x2 = new RegExp(".", "u"); a1 = new RegExp("a.b", "s"); b1 = new RegExp("(?b)", ""); +c2 = new RegExp("((?d)){4}", ""); d1 = new RegExp("\\p{Emoji}", "u"); f1 = new RegExp("y", "d"); g1 = new RegExp("[\\p{White_Space}&&\\p{ASCII}]", "v"); \ No newline at end of file diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/input.js b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/input.js index b16d24951898b0..9b29e8fd659040 100644 --- a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/input.js +++ b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/input.js @@ -1 +1,2 @@ c1 = /(?b)/ +c2 = /((?b)){2}/ diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/output.js b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/output.js index 8e12f01100f116..9ab527d8f46a2e 100644 --- a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/output.js +++ b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/output.js @@ -1 +1,2 @@ -c1 = new RegExp("(?b)", ""); \ No newline at end of file +c1 = new RegExp("(?b)", ""); +c2 = new RegExp("((?b)){2}", ""); diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/input.js b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/input.js index 06ab375088ef11..aa457fff8875b9 100644 --- a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/input.js +++ b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/input.js @@ -1 +1,2 @@ -d1 = /\p{Emoji}/u \ No newline at end of file +d1 = /\p{Emoji}/u +d2 = /\p{Emoji}{2}/u diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/output.js b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/output.js index 10074f71c555e1..51870f2d8d8ddc 100644 --- a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/output.js +++ b/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/output.js @@ -1 +1,2 @@ -d1 = new RegExp("\\p{Emoji}", "u"); \ No newline at end of file +d1 = new RegExp("\\p{Emoji}", "u"); +d2 = new RegExp("\\p{Emoji}{2}", "u"); From fad0a0548b6da2e842efa3c6712f7e58acfc42b5 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:51:37 +0000 Subject: [PATCH 21/28] refactor(transformer): RegExp transform unbox early (#5504) Unbox the `RegExpLiteral` early to avoid all lookups thereafter going through the indirection of a `Box`. --- crates/oxc_transformer/src/regexp/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index d8942b270980e7..68aac4ffafe457 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -113,9 +113,10 @@ impl<'a> Traverse<'a> for RegExp<'a> { expr: &mut Expression<'a>, ctx: &mut oxc_traverse::TraverseCtx<'a>, ) { - let Expression::RegExpLiteral(ref mut regexp) = expr else { + let Expression::RegExpLiteral(regexp) = expr else { return; }; + let regexp = regexp.as_mut(); let flags = regexp.regex.flags; let has_unsupported_flags = flags.intersects(self.unsupported_flags); From bb9d9d1481c26b4d3f76da9cccd85f6629a484e7 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 6 Sep 2024 19:55:10 +0800 Subject: [PATCH 22/28] feat(oxc): raise MSRV to v1.76.0 (Minimum Supported Rust Version) --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1d198f61d44d52..9b79f50107760d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://oxc.rs" keywords = ["JavaScript", "TypeScript", "linter", "minifier", "parser"] license = "MIT" repository = "https://github.com/oxc-project/oxc" -rust-version = "1.74" +rust-version = "1.76" # Support last 6 minor versions. # [workspace.lints.rust] @@ -64,6 +64,7 @@ too_many_lines = "allow" must_use_candidate = "allow" # used_underscore_binding= "allow" doc_markdown = "allow" +ref_as_ptr = "allow" # FIXME or give a reason # nursery # `const` functions do not make sense for our project because this is not a `const` library. # This rule also confuses newcomers and forces them to add `const` blindlessly without any reason. From 9b7ecc7ee7d4ceb0b92c7d1f7788210902433968 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:02:43 +0000 Subject: [PATCH 23/28] fix(transformer): RegExp transform only set span on final expression (#5508) --- crates/oxc_transformer/src/regexp/mod.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 68aac4ffafe457..64cd91e12396c9 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -48,7 +48,7 @@ use oxc_regular_expression::ast::{ CharacterClass, CharacterClassContents, LookAroundAssertionKind, Pattern, Term, }; use oxc_semantic::ReferenceFlags; -use oxc_span::Atom; +use oxc_span::{Atom, SPAN}; use oxc_traverse::{Traverse, TraverseCtx}; use crate::context::Ctx; @@ -164,7 +164,7 @@ impl<'a> Traverse<'a> for RegExp<'a> { let callee = { let symbol_id = ctx.scopes().find_binding(ctx.current_scope_id(), "RegExp"); let ident = ctx.create_reference_id( - regexp.span, + SPAN, Atom::from("RegExp"), symbol_id, ReferenceFlags::read(), @@ -174,14 +174,11 @@ impl<'a> Traverse<'a> for RegExp<'a> { let mut arguments = ctx.ast.vec_with_capacity(2); arguments.push( - ctx.ast.argument_expression( - ctx.ast.expression_string_literal(regexp.span, pattern_source), - ), + ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, pattern_source)), ); let flags = regexp.regex.flags.to_string(); - let flags = - ctx.ast.argument_expression(ctx.ast.expression_string_literal(regexp.span, flags)); + let flags = ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, flags)); arguments.push(flags); *expr = ctx.ast.expression_new( From 758a10c515d30e65968ad79d2ec6e0789ee6762f Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:02:44 +0000 Subject: [PATCH 24/28] refactor(transformer): RegExp transform reuse var (#5527) Nit. Use local `flags` var instead of `regexp.regex.flags`. --- crates/oxc_transformer/src/regexp/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 64cd91e12396c9..8d0b63352d8788 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -177,9 +177,10 @@ impl<'a> Traverse<'a> for RegExp<'a> { ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, pattern_source)), ); - let flags = regexp.regex.flags.to_string(); - let flags = ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, flags)); - arguments.push(flags); + let flags_str = flags.to_string(); + let flags_str = + ctx.ast.argument_expression(ctx.ast.expression_string_literal(SPAN, flags_str)); + arguments.push(flags_str); *expr = ctx.ast.expression_new( regexp.span, From 9282647e6ce47d521dc81f01a1813baf2d96a5f7 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:02:44 +0000 Subject: [PATCH 25/28] docs(transformer): comment on RegExp transform for potential improvement (#5514) I think it's correct that we could do better here. Or is there some difference in behavior between `RegExp(...)` and `new RegExp(...)`? --- crates/oxc_transformer/src/regexp/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 8d0b63352d8788..53a992bfc555ab 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -39,6 +39,10 @@ //! #### Set notation + properties of strings (`v`) //! - @babel/plugin-transform-unicode-sets-regex: //! - TC39 Proposal: +//! +//! TODO(improve-on-babel): We could convert to plain `RegExp(...)` instead of `new RegExp(...)`. +//! TODO(improve-on-babel): When flags is empty, we could output `RegExp("(?<=x)")` instead of `RegExp("(?<=x)", "")`. +//! (actually these would be improvements on ESBuild, not Babel) use std::borrow::Cow; From e18c2edfcbae5238c60b0bca804ee878f72172f7 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:02:45 +0000 Subject: [PATCH 26/28] test(transformer): move RegExp transform conformance tests (#5536) Rename transform conformance RegExp test fixtures folder from "esbuild-tests" to "regexp", to reflect that not all these tests are copied from ESBuild. --- tasks/transform_conformance/oxc.snap.md | 2 +- tasks/transform_conformance/src/constants.rs | 4 ++-- .../fixtures}/all-regex-plugins-enabled-by-targets/input.js | 0 .../all-regex-plugins-enabled-by-targets/options.json | 0 .../fixtures}/all-regex-plugins-enabled-by-targets/output.js | 0 .../fixtures/regexp => regexp/test/fixtures}/igm/input.js | 0 .../fixtures/regexp => regexp/test/fixtures}/igm/options.json | 0 .../fixtures/regexp => regexp/test/fixtures}/igm/output.js | 0 .../test/fixtures}/transform-dotall-regex/input.js | 0 .../test/fixtures}/transform-dotall-regex/options.json | 0 .../test/fixtures}/transform-dotall-regex/output.js | 0 .../fixtures}/transform-named-capturing-groups-regex/input.js | 0 .../transform-named-capturing-groups-regex/options.json | 0 .../transform-named-capturing-groups-regex/output.js | 0 .../test/fixtures}/transform-sticky-regex/input.js | 0 .../test/fixtures}/transform-sticky-regex/options.json | 0 .../test/fixtures}/transform-sticky-regex/output.js | 0 .../test/fixtures}/transform-unicode-property-regex/input.js | 0 .../fixtures}/transform-unicode-property-regex/options.json | 0 .../test/fixtures}/transform-unicode-property-regex/output.js | 0 .../test/fixtures}/transform-unicode-regex/input.js | 0 .../test/fixtures}/transform-unicode-regex/options.json | 0 .../test/fixtures}/transform-unicode-regex/output.js | 0 .../test/fixtures}/transform-unicode-sets-regex/input.js | 0 .../test/fixtures}/transform-unicode-sets-regex/options.json | 0 .../test/fixtures}/transform-unicode-sets-regex/output.js | 0 26 files changed, 3 insertions(+), 3 deletions(-) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/all-regex-plugins-enabled-by-targets/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/all-regex-plugins-enabled-by-targets/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/all-regex-plugins-enabled-by-targets/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/igm/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/igm/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/igm/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-dotall-regex/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-dotall-regex/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-dotall-regex/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-named-capturing-groups-regex/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-named-capturing-groups-regex/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-named-capturing-groups-regex/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-sticky-regex/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-sticky-regex/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-sticky-regex/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-property-regex/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-property-regex/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-property-regex/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-regex/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-regex/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-regex/output.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-sets-regex/input.js (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-sets-regex/options.json (100%) rename tasks/transform_conformance/tests/{esbuild-tests/test/fixtures/regexp => regexp/test/fixtures}/transform-unicode-sets-regex/output.js (100%) diff --git a/tasks/transform_conformance/oxc.snap.md b/tasks/transform_conformance/oxc.snap.md index 40ce7d8c8d547d..742ab0f03fd86a 100644 --- a/tasks/transform_conformance/oxc.snap.md +++ b/tasks/transform_conformance/oxc.snap.md @@ -6,7 +6,7 @@ Passed: 21/49 * babel-plugin-transform-nullish-coalescing-operator * babel-plugin-transform-optional-catch-binding * babel-preset-typescript -* esbuild-tests +* regexp # babel-plugin-transform-arrow-functions (1/2) diff --git a/tasks/transform_conformance/src/constants.rs b/tasks/transform_conformance/src/constants.rs index 9d9cb81564a59c..d4b1400c3b3449 100644 --- a/tasks/transform_conformance/src/constants.rs +++ b/tasks/transform_conformance/src/constants.rs @@ -57,8 +57,8 @@ pub(crate) const PLUGINS: &[&str] = &[ // // Proposal // "babel-plugin-proposal-decorators", - // Tests port from esbuild - "esbuild-tests", + // RegExp tests ported from esbuild + a few additions + "regexp", ]; pub(crate) const PLUGINS_NOT_SUPPORTED_YET: &[&str] = &[ diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/all-regex-plugins-enabled-by-targets/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/igm/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/igm/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/igm/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/igm/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/igm/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/igm/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/igm/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/igm/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/igm/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-dotall-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-dotall-regex/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-dotall-regex/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-dotall-regex/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-dotall-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-dotall-regex/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-named-capturing-groups-regex/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-named-capturing-groups-regex/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-named-capturing-groups-regex/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-named-capturing-groups-regex/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-named-capturing-groups-regex/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-named-capturing-groups-regex/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-named-capturing-groups-regex/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-sticky-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-sticky-regex/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-sticky-regex/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-sticky-regex/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-sticky-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-sticky-regex/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-property-regex/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-property-regex/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-property-regex/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-property-regex/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-property-regex/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-property-regex/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-property-regex/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-regex/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-regex/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-regex/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-regex/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/output.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-sets-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/input.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-sets-regex/input.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/input.js diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-sets-regex/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/options.json similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-sets-regex/options.json rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/options.json diff --git a/tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-sets-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/output.js similarity index 100% rename from tasks/transform_conformance/tests/esbuild-tests/test/fixtures/regexp/transform-unicode-sets-regex/output.js rename to tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/output.js From 87a79d9cd056413b7691962868be201b4ee7b9a5 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:02:46 +0000 Subject: [PATCH 27/28] test(transformer): add trailing line breaks to conformance fixtures (#5537) Currently whether conformance fixture files have trailing line breaks is inconsistent - some have them, some don't. Make all of them have a trailing line break. --- .../test/fixtures/use-this-inside-blocks/input.js | 2 +- .../test/fixtures/use-this-inside-blocks/output.js | 2 +- .../test/fixtures/try-catch-shadow/input.js | 2 +- .../test/fixtures/try-catch-shadow/output.js | 2 +- .../refresh/can-handle-implicit-arrow-returns/input.jsx | 2 +- .../refresh/can-handle-implicit-arrow-returns/output.js | 2 +- .../does-not-consider-require-like-methods-to-be-hocs/input.jsx | 2 +- .../fixtures/refresh/does-not-get-tripped-by-iifes/input.jsx | 2 +- .../input.jsx | 2 +- .../input.jsx | 2 +- .../output.js | 2 +- .../input.jsx | 2 +- .../test/fixtures/refresh/ignores-complex-definitions/input.jsx | 2 +- .../ignores-higher-order-functions-that-are-not-hocs/input.jsx | 2 +- .../test/fixtures/refresh/ignores-hoc-definitions/input.jsx | 2 +- .../refresh/ignores-unnamed-function-declarations/input.jsx | 2 +- .../refresh/ignores-unnamed-function-declarations/output.js | 2 +- .../input.jsx | 2 +- .../options.json | 2 +- .../refresh/includes-custom-hooks-into-the-signatures/input.jsx | 2 +- .../refresh/only-registers-pascal-case-functions/input.jsx | 2 +- .../refresh/only-registers-pascal-case-functions/output.js | 2 +- .../registers-capitalized-identifiers-in-hoc-calls/input.jsx | 2 +- .../input.jsx | 2 +- .../input.jsx | 2 +- .../output.js | 2 +- .../registers-likely-hocs-with-inline-functions-1/input.jsx | 2 +- .../registers-likely-hocs-with-inline-functions-2/input.jsx | 2 +- .../registers-likely-hocs-with-inline-functions-2/output.js | 2 +- .../registers-likely-hocs-with-inline-functions-3/input.jsx | 2 +- .../input.jsx | 2 +- .../output.js | 2 +- .../input.jsx | 2 +- .../refresh/registers-top-level-function-declarations/input.jsx | 2 +- .../refresh/registers-top-level-function-declarations/output.js | 2 +- .../input.jsx | 2 +- .../input.jsx | 2 +- .../refresh/supports-typescript-namespace-syntax/input.tsx | 2 +- .../refresh/supports-typescript-namespace-syntax/output.ts | 2 +- .../input.jsx | 2 +- .../input.jsx | 2 +- .../test/fixtures/computed-constant-value/output.js | 2 +- .../test/fixtures/elimination-declare/input.ts | 2 +- .../test/fixtures/elimination-declare/output.js | 2 +- .../test/fixtures/enum-member-reference/output.js | 2 +- .../test/fixtures/export-elimination/input.ts | 2 +- .../test/fixtures/export-elimination/output.ts | 2 +- .../test/fixtures/redeclarations/input.ts | 2 +- .../test/fixtures/redeclarations/output.js | 1 - .../test/fixtures/all-regex-plugins-enabled-by-targets/input.js | 2 +- .../fixtures/all-regex-plugins-enabled-by-targets/output.js | 2 +- .../tests/regexp/test/fixtures/igm/input.js | 2 +- .../tests/regexp/test/fixtures/igm/options.json | 2 +- .../tests/regexp/test/fixtures/igm/output.js | 2 +- .../tests/regexp/test/fixtures/transform-dotall-regex/input.js | 2 +- .../tests/regexp/test/fixtures/transform-dotall-regex/output.js | 2 +- .../tests/regexp/test/fixtures/transform-sticky-regex/input.js | 2 +- .../tests/regexp/test/fixtures/transform-unicode-regex/input.js | 2 +- .../regexp/test/fixtures/transform-unicode-sets-regex/output.js | 2 +- 59 files changed, 58 insertions(+), 59 deletions(-) diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/input.js b/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/input.js index 56bbc2c6851bcf..ad9f1332c9e54d 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/input.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/input.js @@ -1,4 +1,4 @@ function foo() { { let f = () => this; } { let f2 = () => this; } -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/output.js index 189f758562f1a7..081da1e1183b03 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-arrow-functions/test/fixtures/use-this-inside-blocks/output.js @@ -10,4 +10,4 @@ function foo() { return _this; }; } -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js index 41ada5aa087650..91738a17357ac8 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/input.js @@ -3,4 +3,4 @@ try { throw 0; } catch { console.log(_unused); -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js index 2c90680df6d8dd..5b4b775938524a 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-optional-catch-binding/test/fixtures/try-catch-shadow/output.js @@ -3,4 +3,4 @@ try { throw 0; } catch (_unused2) { console.log(_unused); -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/input.jsx index b45dbe76835534..ce54d010ffbad7 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/input.jsx @@ -3,4 +3,4 @@ export const Foo = () => useContext(X); module.exports = () => useContext(X); const Bar = () => useContext(X); const Baz = memo(() => useContext(X)); -const Qux = () => (0, useContext(X)); \ No newline at end of file +const Qux = () => (0, useContext(X)); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/output.js index 51263c7e327b21..bf2d4b49ca4f18 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/can-handle-implicit-arrow-returns/output.js @@ -35,4 +35,4 @@ $RefreshReg$(_c, "Foo"); $RefreshReg$(_c2, "Bar"); $RefreshReg$(_c3, "Baz$memo"); $RefreshReg$(_c4, "Baz"); -$RefreshReg$(_c5, "Qux"); \ No newline at end of file +$RefreshReg$(_c5, "Qux"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-consider-require-like-methods-to-be-hocs/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-consider-require-like-methods-to-be-hocs/input.jsx index d55ce48f47911e..6489fd2d682c8a 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-consider-require-like-methods-to-be-hocs/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-consider-require-like-methods-to-be-hocs/input.jsx @@ -18,4 +18,4 @@ export default function App() { ); -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-get-tripped-by-iifes/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-get-tripped-by-iifes/input.jsx index 089c6647006533..95bb0f1604e362 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-get-tripped-by-iifes/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/does-not-get-tripped-by-iifes/input.jsx @@ -2,4 +2,4 @@ while (item) { (item => { useFoo(); })(item); -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-declarations-calling-hooks/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-declarations-calling-hooks/input.jsx index 4a8b072c8b3075..0afdc8ac877dd0 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-declarations-calling-hooks/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-declarations-calling-hooks/input.jsx @@ -2,4 +2,4 @@ export default function App() { const [foo, setFoo] = useState(0); React.useEffect(() => {}); return

{foo}

; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx index 95c88048f02d1a..681bb28c9459f6 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/input.jsx @@ -24,4 +24,4 @@ function hoc() { }; } -export let C = hoc(); \ No newline at end of file +export let C = hoc(); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/output.js index dba04069c62363..3a8f74e62c7749 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-signatures-for-function-expressions-calling-hooks/output.js @@ -39,4 +39,4 @@ $RefreshReg$(_c2, "A$React.memo"); $RefreshReg$(_c3, "A"); $RefreshReg$(_c4, "B$React.memo$React.forwardRef"); $RefreshReg$(_c5, "B$React.memo"); -$RefreshReg$(_c6, "B"); \ No newline at end of file +$RefreshReg$(_c6, "B"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx index ae402c002909ba..d06e653ec6bc4f 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/generates-valid-signature-for-exotic-ways-to-call-hooks/input.jsx @@ -11,4 +11,4 @@ export default function App() { React.useState(); useThePlatform(); return

{bar}{baz}

; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-complex-definitions/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-complex-definitions/input.jsx index bd4daf1e61b18e..c66bc3cc3405de 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-complex-definitions/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-complex-definitions/input.jsx @@ -9,4 +9,4 @@ let C = () => () => { }; let D = bar && (() => { return

Hi

; -}); \ No newline at end of file +}); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-higher-order-functions-that-are-not-hocs/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-higher-order-functions-that-are-not-hocs/input.jsx index 1697a276ca95cb..9ee945c95e465b 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-higher-order-functions-that-are-not-hocs/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-higher-order-functions-that-are-not-hocs/input.jsx @@ -4,4 +4,4 @@ const throttledAlert = throttle(function() { const TooComplex = (function() { return hello })(() => {}); if (cond) { const Foo = thing(() => {}); -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-hoc-definitions/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-hoc-definitions/input.jsx index c08c8660ac999b..c9028bf5ce9b89 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-hoc-definitions/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-hoc-definitions/input.jsx @@ -14,4 +14,4 @@ function withRouter() { const handleClick = () => {}; return

Hi

; } -}; \ No newline at end of file +}; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/input.jsx index 421474fe3c0e75..6ab80bc8d76f77 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/input.jsx @@ -1 +1 @@ -export default function() {} \ No newline at end of file +export default function() {} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/output.js index 421474fe3c0e75..6ab80bc8d76f77 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/ignores-unnamed-function-declarations/output.js @@ -1 +1 @@ -export default function() {} \ No newline at end of file +export default function() {} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/input.jsx index 2adf1cfda72fe3..8cef8d8eebe394 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/input.jsx @@ -5,4 +5,4 @@ import {useFancyState} from './hooks'; export default function App() { const bar = useFancyState(); return

{bar}

; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/options.json b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/options.json index 41d36d77150ed2..c4115d11d670b8 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/options.json +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures-when-commonjs-target-is-used/options.json @@ -10,4 +10,4 @@ "transform-modules-commonjs" ] ] -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures/input.jsx index a7274ad7eef5e5..abcbe68531df06 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/includes-custom-hooks-into-the-signatures/input.jsx @@ -11,4 +11,4 @@ const useFancyEffect = () => { export default function App() { const bar = useFancyState(); return

{bar}

; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/input.jsx index 5206a2ea763781..490c7f8fc59079 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/input.jsx @@ -1,3 +1,3 @@ function hello() { return 2 * 2; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/output.js index 5206a2ea763781..490c7f8fc59079 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/only-registers-pascal-case-functions/output.js @@ -1,3 +1,3 @@ function hello() { return 2 * 2; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx index 7929fdb34ab5e6..bb6b54835535c4 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-capitalized-identifiers-in-hoc-calls/input.jsx @@ -4,4 +4,4 @@ function Foo() { export default hoc(Foo); export const A = hoc(Foo); -const B = hoc(Foo); \ No newline at end of file +const B = hoc(Foo); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx index 9208808c6ce4c1..ab226b6a2f0679 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx @@ -27,4 +27,4 @@ function Foo() { const B = hoc(A); // This is currently registered as a false positive: const NotAComponent = wow(A); -// We could avoid it but it also doesn't hurt. \ No newline at end of file +// We could avoid it but it also doesn't hurt. diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx index 12b02ebb14cbe4..f745fbd903cea6 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx @@ -37,4 +37,4 @@ React.createContext(Store); const B = hoc(A); // This is currently registered as a false positive: const NotAComponent = wow(A); -// We could avoid it but it also doesn't hurt. \ No newline at end of file +// We could avoid it but it also doesn't hurt. diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/output.js index f731e51d6bb09f..77b8130cde4fe2 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-identifiers-used-in-react-create-element-at-definition-site/output.js @@ -29,4 +29,4 @@ $RefreshReg$(_c3, "StyledFactory2"); $RefreshReg$(_c4, "StyledFactory3"); $RefreshReg$(_c5, "Foo"); $RefreshReg$(_c6, "B"); -$RefreshReg$(_c7, "NotAComponent"); \ No newline at end of file +$RefreshReg$(_c7, "NotAComponent"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-1/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-1/input.jsx index 0f68d2db05e135..2412f36b52e75e 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-1/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-1/input.jsx @@ -6,4 +6,4 @@ const B = memo(React.forwardRef(() => { })); export default React.memo(forwardRef((props, ref) => { return

Foo

; -})); \ No newline at end of file +})); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/input.jsx index 20aa196d47bb6c..ca0283401bb9fe 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/input.jsx @@ -1,3 +1,3 @@ export default React.memo(forwardRef(function (props, ref) { return

Foo

; -})); \ No newline at end of file +})); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/output.js index 6148fce4645c61..06bd3733528043 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-2/output.js @@ -5,4 +5,4 @@ export default _c3 = React.memo(_c2 = forwardRef(_c = function(props, ref) { var _c, _c2, _c3; $RefreshReg$(_c, "%default%$React.memo$forwardRef"); $RefreshReg$(_c2, "%default%$React.memo"); -$RefreshReg$(_c3, "%default%"); \ No newline at end of file +$RefreshReg$(_c3, "%default%"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-3/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-3/input.jsx index bc646b5b624aa8..6a0c013be64eb8 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-3/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-likely-hocs-with-inline-functions-3/input.jsx @@ -1,3 +1,3 @@ export default React.memo(forwardRef(function Named(props, ref) { return

Foo

; -})); \ No newline at end of file +})); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/input.jsx index f76b06ca29de4a..5e600909423412 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/input.jsx @@ -15,4 +15,4 @@ const NotAComp = 'hi'; export { Baz, NotAComp }; export function sum() {} -export const Bad = 42; \ No newline at end of file +export const Bad = 42; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/output.js index f81fa11b93d66c..438d336371d2e4 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-function-declarations/output.js @@ -24,4 +24,4 @@ var _c, _c2, _c3; $RefreshReg$(_c, "Hello"); $RefreshReg$(_c2, "Bar"); -$RefreshReg$(_c3, "Baz"); \ No newline at end of file +$RefreshReg$(_c3, "Baz"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-named-arrow-functions/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-named-arrow-functions/input.jsx index 5913c23561eec1..9b300ec517b16e 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-named-arrow-functions/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-exported-named-arrow-functions/input.jsx @@ -9,4 +9,4 @@ export default () => { // This one should be ignored. // You should name your components. return ; -}; \ No newline at end of file +}; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/input.jsx index 62e99f5afdce57..05414dc6a33bd7 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/input.jsx @@ -5,4 +5,4 @@ function Hello() { function Bar() { return ; -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/output.js index be4ca90c059500..806a74bac5d940 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-function-declarations/output.js @@ -20,4 +20,4 @@ _c2 = Bar; var _c, _c2; $RefreshReg$(_c, "Hello"); -$RefreshReg$(_c2, "Bar"); \ No newline at end of file +$RefreshReg$(_c2, "Bar"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-arrow-functions/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-arrow-functions/input.jsx index 11f8cd8285b038..8f621564847a05 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-arrow-functions/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-arrow-functions/input.jsx @@ -7,4 +7,4 @@ const Bar = () => { return ; }; var Baz = () =>
; -var sum = () => {}; \ No newline at end of file +var sum = () => {}; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-function-expressions/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-function-expressions/input.jsx index 03ad5077ccca00..2de72c0233053a 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-function-expressions/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/registers-top-level-variable-declarations-with-function-expressions/input.jsx @@ -9,4 +9,4 @@ const Bar = function Baz() { }; function sum() {} let Baz = 10; -var Qux; \ No newline at end of file +var Qux; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx index dcd54f8394dd3c..24305cb96927d8 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/input.tsx @@ -12,4 +12,4 @@ namespace Foo { namespace NotExported { export const E = () => {}; } -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/output.ts b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/output.ts index 9669ed9bc8676a..aa983f96406ea0 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/output.ts +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/supports-typescript-namespace-syntax/output.ts @@ -22,4 +22,4 @@ var _c, _c2, _c3, _c4; $RefreshReg$(_c, "Foo$Bar$A"); $RefreshReg$(_c2, "Foo$Bar$B"); $RefreshReg$(_c3, "Foo$C"); -$RefreshReg$(_c4, "Foo$D"); \ No newline at end of file +$RefreshReg$(_c4, "Foo$D"); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-custom-identifiers-for-refresh-reg-and-refresh-sig/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-custom-identifiers-for-refresh-reg-and-refresh-sig/input.jsx index 7e871cb8dc04d0..c7476d92142efb 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-custom-identifiers-for-refresh-reg-and-refresh-sig/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-custom-identifiers-for-refresh-reg-and-refresh-sig/input.jsx @@ -1,4 +1,4 @@ export default function Bar () { useContext(X) return -}; \ No newline at end of file +}; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-original-function-declaration-if-it-get-reassigned/input.jsx b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-original-function-declaration-if-it-get-reassigned/input.jsx index 82a86d5fbd52de..f714958503472a 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-original-function-declaration-if-it-get-reassigned/input.jsx +++ b/tasks/transform_conformance/tests/babel-plugin-transform-react-jsx/test/fixtures/refresh/uses-original-function-declaration-if-it-get-reassigned/input.jsx @@ -1,4 +1,4 @@ function Hello() { return

Hi

; } -Hello = connect(Hello); \ No newline at end of file +Hello = connect(Hello); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/output.js index 58f370ac797a22..a5ad2e50262679 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/computed-constant-value/output.js @@ -25,4 +25,4 @@ var D = /*#__PURE__*/function (D) { D[D["b"] = NaN] = "b"; D[D["c"] = -1] = "c"; return D; -}(D || {}); \ No newline at end of file +}(D || {}); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/input.ts b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/input.ts index 3ef5553b39053f..31ec41c8736329 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/input.ts +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/input.ts @@ -4,4 +4,4 @@ export declare class ReactiveMarker { private [ReactiveMarkerSymbol]?: void } -export declare const A = 1 \ No newline at end of file +export declare const A = 1 diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/output.js index 8cec2e9ced0d35..cb0ff5c3b541f6 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-declare/output.js @@ -1 +1 @@ -export {}; \ No newline at end of file +export {}; diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-member-reference/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-member-reference/output.js index 8dcfa9feeba4ba..a963366508ed9b 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-member-reference/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-member-reference/output.js @@ -4,4 +4,4 @@ var Foo = function(Foo) { Foo[Foo['b'] = 10] = 'b'; Foo[Foo['c'] = Foo.b + x] = 'c'; return Foo; -}(Foo || {}); \ No newline at end of file +}(Foo || {}); diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts index 65b1e6efb0b52a..ea0cd8d051f990 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/input.ts @@ -14,4 +14,4 @@ type T = number; function T(): T { return 123; } -export { T } \ No newline at end of file +export { T } diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/output.ts b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/output.ts index 6e60c70871b10f..c15ddb40633e6d 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/output.ts +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/export-elimination/output.ts @@ -12,4 +12,4 @@ export { Im, Ok, Foo, Bar, Func, Name }; function T() { return 123; } -export { T } \ No newline at end of file +export { T } diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/input.ts b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/input.ts index 71e25715aa5522..353b051df45200 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/input.ts +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/input.ts @@ -12,4 +12,4 @@ export { T } import { B } from './b'; const B: B = 0; type B = number; -export { B } \ No newline at end of file +export { B } diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/output.js index cd77114c9598b2..7917f4efd4c9e5 100644 --- a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/output.js +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/redeclarations/output.js @@ -9,4 +9,3 @@ export { T }; // CASE 3: redeclaration of VariableDeclaration and TypeAlias const B = 0; export { B }; - diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/input.js index 450f6d384ba545..31519d315e94c8 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/input.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/input.js @@ -21,4 +21,4 @@ d1 = /\p{Emoji}/u f1 = /y/d // ES2024 // RegExpSetNotation -g1 = /[\p{White_Space}&&\p{ASCII}]/v \ No newline at end of file +g1 = /[\p{White_Space}&&\p{ASCII}]/v diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/output.js index 8226e9420d3b4e..c430be659e84f0 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/output.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/all-regex-plugins-enabled-by-targets/output.js @@ -9,4 +9,4 @@ c1 = new RegExp("(?
b)", ""); c2 = new RegExp("((?d)){4}", ""); d1 = new RegExp("\\p{Emoji}", "u"); f1 = new RegExp("y", "d"); -g1 = new RegExp("[\\p{White_Space}&&\\p{ASCII}]", "v"); \ No newline at end of file +g1 = new RegExp("[\\p{White_Space}&&\\p{ASCII}]", "v"); diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/igm/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/input.js index c994ef95d528c6..2bcf92fdf30f8f 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/igm/input.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/input.js @@ -1 +1 @@ -a1 = /a.b/igm; \ No newline at end of file +a1 = /a.b/igm; diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/igm/options.json b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/options.json index c871da605e38c1..ec3370903d9ee9 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/igm/options.json +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/options.json @@ -6,4 +6,4 @@ } }] ] -} \ No newline at end of file +} diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/igm/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/output.js index c994ef95d528c6..2bcf92fdf30f8f 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/igm/output.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/igm/output.js @@ -1 +1 @@ -a1 = /a.b/igm; \ No newline at end of file +a1 = /a.b/igm; diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/input.js index e529a74bf2ac9f..e18925a75bb4d1 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/input.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/input.js @@ -1 +1 @@ -a1 = /a.b/s \ No newline at end of file +a1 = /a.b/s diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/output.js index 15fdf4bdc57e9a..d8e8983d266d41 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/output.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-dotall-regex/output.js @@ -1 +1 @@ -a1 = new RegExp("a.b", "s"); \ No newline at end of file +a1 = new RegExp("a.b", "s"); diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/input.js index 5ef23ff8beb045..697f1c9e30862e 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/input.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-sticky-regex/input.js @@ -1 +1 @@ -x1 = /./y \ No newline at end of file +x1 = /./y diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/input.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/input.js index eb14085e948a9f..b7f15eee860d3f 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/input.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-regex/input.js @@ -1 +1 @@ -x2 = /./u \ No newline at end of file +x2 = /./u diff --git a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/output.js b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/output.js index de413b03d2c086..ffd632c5f4abf8 100644 --- a/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/output.js +++ b/tasks/transform_conformance/tests/regexp/test/fixtures/transform-unicode-sets-regex/output.js @@ -1 +1 @@ -g1 = new RegExp("[\\p{White_Space}&&\\p{ASCII}]", "v"); \ No newline at end of file +g1 = new RegExp("[\\p{White_Space}&&\\p{ASCII}]", "v"); From 7414ff89b6751e9b47af72d1a4530e81b5570fff Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:23:15 +0000 Subject: [PATCH 28/28] style(editors): add trailing newline to `.prettierignore` (#5540) For consistency with our `.editorconfig`. --- editors/vscode/.prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/vscode/.prettierignore b/editors/vscode/.prettierignore index 60ffc01773a89b..bf9f44c436eb48 100644 --- a/editors/vscode/.prettierignore +++ b/editors/vscode/.prettierignore @@ -2,4 +2,4 @@ target/ **/.git **/.svn **/.hg -**/node_modules \ No newline at end of file +**/node_modules