diff --git a/.rustfmt.toml b/.rustfmt.toml index fcb76e1e00f3af..6862d534ce1c6d 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -5,9 +5,11 @@ use_small_heuristics = "Max" # Use field initialize shorthand if possible use_field_init_shorthand = true +reorder_modules = true + # All unstable features that we wish for # unstable_features = true -# version = "Two" +# style_edition = "2024" # Provide a cleaner impl order # reorder_impl_items = true # Provide a cleaner import sort order diff --git a/apps/oxlint/src/command/lint.rs b/apps/oxlint/src/command/lint.rs index 70dc0e76d17f02..68ba5eb0178919 100644 --- a/apps/oxlint/src/command/lint.rs +++ b/apps/oxlint/src/command/lint.rs @@ -368,9 +368,10 @@ impl EnablePlugins { #[cfg(test)] mod plugins { - use super::{EnablePlugins, OverrideToggle}; use oxc_linter::LintPlugins; + use super::{EnablePlugins, OverrideToggle}; + #[test] fn test_override_default() { let mut plugins = LintPlugins::default(); diff --git a/crates/oxc_ast/src/ast_builder_impl.rs b/crates/oxc_ast/src/ast_builder_impl.rs index 8cbefde5f77a5a..6badb10c008117 100644 --- a/crates/oxc_ast/src/ast_builder_impl.rs +++ b/crates/oxc_ast/src/ast_builder_impl.rs @@ -12,8 +12,7 @@ use oxc_allocator::{Allocator, Box, FromIn, String, Vec}; use oxc_span::{Atom, GetSpan, Span, SPAN}; use oxc_syntax::{number::NumberBase, operator::UnaryOperator, scope::ScopeId}; -use crate::ast::*; -use crate::AstBuilder; +use crate::{ast::*, AstBuilder}; /// Type that can be used in any AST builder method call which requires an `IntoIn<'a, Anything<'a>>`. /// Pass `NONE` instead of `None::>`. diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index 1ff48973fa5f12..98ac44e7c6c7ea 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -779,6 +779,7 @@ impl<'a> Declaration<'a> { _ => true, } } + /// Get the identifier bound by this declaration. /// /// ## Example diff --git a/crates/oxc_ast/src/serialize.rs b/crates/oxc_ast/src/serialize.rs index df79e26a61940d..7242b2dd1708f7 100644 --- a/crates/oxc_ast/src/serialize.rs +++ b/crates/oxc_ast/src/serialize.rs @@ -1,7 +1,6 @@ use cow_utils::CowUtils; use num_bigint::BigInt; use num_traits::Num; - use oxc_allocator::Box; use oxc_span::{Atom, Span}; use oxc_syntax::number::BigintBase; diff --git a/crates/oxc_codegen/src/comment.rs b/crates/oxc_codegen/src/comment.rs index 9260aa2974f437..8ec0c4d7dc31be 100644 --- a/crates/oxc_codegen/src/comment.rs +++ b/crates/oxc_codegen/src/comment.rs @@ -1,7 +1,6 @@ -use rustc_hash::FxHashMap; - use oxc_ast::{Comment, CommentKind}; use oxc_syntax::identifier::is_line_terminator; +use rustc_hash::FxHashMap; use crate::{Codegen, LegalComment}; diff --git a/crates/oxc_codegen/tests/integration/esbuild.rs b/crates/oxc_codegen/tests/integration/esbuild.rs index 9ae5e68b17ecce..444205e38744a1 100644 --- a/crates/oxc_codegen/tests/integration/esbuild.rs +++ b/crates/oxc_codegen/tests/integration/esbuild.rs @@ -210,8 +210,10 @@ fn test_new() { "new Worker(/* webpackFoo: 1 */ 'path', /* webpackBar:2 */ );", "new Worker(\n\t/* webpackFoo: 1 */\n\t\"path\"\n\t/* webpackBar:2 */\n);\n", ); - test( "new Worker(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))", - "new Worker(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n"); + test( + "new Worker(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))", + "new Worker(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n", + ); // non-webpack comments test("new Worker(/* before */ foo)", "new Worker(\n\t/* before */\n\tfoo\n);\n"); @@ -252,14 +254,18 @@ fn test_call() { "require(// webpackFoo: 1\n // webpackBar: 2\n 'path');", "require(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\"\n);\n", ); - test( "require(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});", - "require(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n"); + test( + "require(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});", + "require(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n", + ); test( "require(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path');", "require(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\"\n);\n", ); - test( "require(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});", - "require(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n"); + test( + "require(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});", + "require(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n", + ); test( "require(\n /* multi\n * line\n * webpackBar: */ 'path');", "require(\n\t/* multi\n\t* line\n\t* webpackBar: */\n\t\"path\"\n);\n", @@ -276,7 +282,10 @@ fn test_call() { "require(/* webpackFoo: 1 */ 'path', /* webpackBar:2 */ );", "require(\n\t/* webpackFoo: 1 */\n\t\"path\"\n\t/* webpackBar:2 */\n);\n", ); - test( "require(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );", "require(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n"); + test( + "require(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );", + "require(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n", + ); // non-webpack comments test("require(/* before */ foo)", "require(\n\t/* before */\n\tfoo\n);\n"); @@ -668,13 +677,18 @@ fn test_import() { "import(// webpackFoo: 1\n // webpackBar: 2\n 'path');", "import(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\"\n);\n", ); - test( "import(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});", "import(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n"); + test( + "import(// webpackFoo: 1\n // webpackBar: 2\n 'path', {type: 'module'});", + "import(\n\t// webpackFoo: 1\n\t// webpackBar: 2\n\t\"path\",\n\t{ type: \"module\" }\n);\n", + ); test( "import(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path');", "import(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\"\n);\n", ); - test( "import(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});", - "import(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n"); + test( + "import(/* webpackFoo: 1 */ /* webpackBar: 2 */ 'path', {type: 'module'});", + "import(\n\t/* webpackFoo: 1 */\n\t/* webpackBar: 2 */\n\t\"path\",\n\t{ type: \"module\" }\n);\n", + ); test( "import(\n /* multi\n * line\n * webpackBar: */ 'path');", "import(\n\t/* multi\n\t* line\n\t* webpackBar: */\n\t\"path\"\n);\n", @@ -691,9 +705,14 @@ fn test_import() { "import(/* webpackFoo: 1 */ 'path', /* webpackBar:2 */ );", "import(\n\t/* webpackFoo: 1 */\n\t\"path\"\n\t/* webpackBar:2 */\n);\n", ); - test( "import(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );", "import(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n"); - test( "import(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))", - "import(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n"); + test( + "import(/* webpackFoo: 1 */ 'path', { type: 'module' } /* webpackBar:2 */ );", + "import(\n\t/* webpackFoo: 1 */\n\t\"path\",\n\t{ type: \"module\" }\n\t/* webpackBar:2 */\n);\n", + ); + test( + "import(new URL('path', /* webpackFoo: these can go anywhere */ import.meta.url))", + "import(new URL(\n\t\"path\",\n\t/* webpackFoo: these can go anywhere */\n\timport.meta.url\n));\n", + ); // non-webpack comments test("import(/* before */ foo)", "import(\n\t/* before */\n\tfoo\n);\n"); diff --git a/crates/oxc_codegen/tests/integration/ts.rs b/crates/oxc_codegen/tests/integration/ts.rs index b036da602d720a..ca06641ef4ffb4 100644 --- a/crates/oxc_codegen/tests/integration/ts.rs +++ b/crates/oxc_codegen/tests/integration/ts.rs @@ -1,6 +1,7 @@ -use crate::{snapshot, snapshot_options}; use oxc_codegen::CodegenOptions; +use crate::{snapshot, snapshot_options}; + #[test] fn ts() { let cases = [ @@ -52,10 +53,10 @@ export type Component< | ConcreteComponent | ComponentPublicInstanceConstructor ", -"(a || b) as any", -"(a ** b) as any", -"(function g() {}) as any", -r#" + "(a || b) as any", + "(a ** b) as any", + "(function g() {}) as any", + r#" import defaultExport from "module-name"; import * as name from "module-name"; import { export1 } from "module-name"; @@ -88,7 +89,7 @@ export { name12, /* …, */ nameN } from "module-name"; export { import1 as name13, import2 as name14, /* …, */ name15 } from "module-name"; export { default, /* …, */ } from "module-name"; export { default as name16 } from "module-name"; -"# +"#, ]; snapshot("ts", &cases); diff --git a/crates/oxc_data_structures/src/stack/sparse.rs b/crates/oxc_data_structures/src/stack/sparse.rs index ab9cc468e393de..92e0f1bbc744a5 100644 --- a/crates/oxc_data_structures/src/stack/sparse.rs +++ b/crates/oxc_data_structures/src/stack/sparse.rs @@ -37,11 +37,6 @@ impl Default for SparseStack { } impl SparseStack { - /// Maximum capacity for entries (either `Some` or `None`). - /// - /// Effectively unlimited on 64-bit systems. - pub const MAX_TOTAL_CAPACITY: usize = NonEmptyStack::::MAX_CAPACITY; - /// Maximum capacity for filled entries (`Some`). /// /// Unless `size_of::() == 1`, `MAX_FILLED_CAPACITY` is lower than [`MAX_TOTAL_CAPACITY`]. @@ -50,6 +45,10 @@ impl SparseStack { /// /// [`MAX_TOTAL_CAPACITY`]: Self::MAX_TOTAL_CAPACITY pub const MAX_FILLED_CAPACITY: usize = Stack::::MAX_CAPACITY; + /// Maximum capacity for entries (either `Some` or `None`). + /// + /// Effectively unlimited on 64-bit systems. + pub const MAX_TOTAL_CAPACITY: usize = NonEmptyStack::::MAX_CAPACITY; /// Create new `SparseStack`. /// diff --git a/crates/oxc_diagnostics/src/reporter/checkstyle.rs b/crates/oxc_diagnostics/src/reporter/checkstyle.rs index 9ecbf4cc3e8bcd..ba8ba813af3944 100644 --- a/crates/oxc_diagnostics/src/reporter/checkstyle.rs +++ b/crates/oxc_diagnostics/src/reporter/checkstyle.rs @@ -1,8 +1,9 @@ use std::borrow::Cow; +use rustc_hash::FxHashMap; + use super::{DiagnosticReporter, Info}; use crate::{Error, Severity}; -use rustc_hash::FxHashMap; #[derive(Default)] pub struct CheckstyleReporter { diff --git a/crates/oxc_ecmascript/src/array_join.rs b/crates/oxc_ecmascript/src/array_join.rs index d2b42476f09ac5..e19c0463dbd707 100644 --- a/crates/oxc_ecmascript/src/array_join.rs +++ b/crates/oxc_ecmascript/src/array_join.rs @@ -1,6 +1,7 @@ -use crate::ToJsString; use oxc_ast::ast::*; +use crate::ToJsString; + pub trait ArrayJoin<'a> { /// `Array.prototype.join ( separator )` /// diff --git a/crates/oxc_ecmascript/src/constant_evaluation/mod.rs b/crates/oxc_ecmascript/src/constant_evaluation/mod.rs index 7c3d4b47bebc71..bf7c88fcde8de1 100644 --- a/crates/oxc_ecmascript/src/constant_evaluation/mod.rs +++ b/crates/oxc_ecmascript/src/constant_evaluation/mod.rs @@ -6,12 +6,10 @@ use std::{borrow::Cow, cmp::Ordering}; use num_bigint::BigInt; use num_traits::Zero; - use oxc_ast::ast::*; -use crate::{side_effects::MayHaveSideEffects, ToBigInt, ToBoolean, ToInt32, ToJsString, ToNumber}; - pub use self::{is_literal_value::IsLiteralValue, value::ConstantValue, value_type::ValueType}; +use crate::{side_effects::MayHaveSideEffects, ToBigInt, ToBoolean, ToInt32, ToJsString, ToNumber}; pub trait ConstantEvaluation<'a> { fn is_global_reference(&self, ident: &IdentifierReference<'a>) -> bool { diff --git a/crates/oxc_ecmascript/src/string_to_big_int.rs b/crates/oxc_ecmascript/src/string_to_big_int.rs index 2fd1b0d30b493f..36295819e5629c 100644 --- a/crates/oxc_ecmascript/src/string_to_big_int.rs +++ b/crates/oxc_ecmascript/src/string_to_big_int.rs @@ -1,6 +1,5 @@ -use num_traits::Zero; - use num_bigint::BigInt; +use num_traits::Zero; /// `StringToBigInt` /// diff --git a/crates/oxc_ecmascript/src/to_big_int.rs b/crates/oxc_ecmascript/src/to_big_int.rs index 6db17ec00c7572..c34348a551cf54 100644 --- a/crates/oxc_ecmascript/src/to_big_int.rs +++ b/crates/oxc_ecmascript/src/to_big_int.rs @@ -1,6 +1,5 @@ use num_bigint::BigInt; use num_traits::{One, Zero}; - use oxc_ast::ast::{BigIntLiteral, Expression}; use oxc_syntax::operator::UnaryOperator; @@ -35,15 +34,8 @@ impl<'a> ToBigInt<'a> for Expression<'a> { } Expression::UnaryExpression(unary_expr) => match unary_expr.operator { UnaryOperator::LogicalNot => { - self.to_boolean().map( - |boolean| { - if boolean { - BigInt::one() - } else { - BigInt::zero() - } - }, - ) + self.to_boolean() + .map(|boolean| if boolean { BigInt::one() } else { BigInt::zero() }) } UnaryOperator::UnaryNegation => { unary_expr.argument.to_big_int().map(std::ops::Neg::neg) diff --git a/crates/oxc_ecmascript/src/to_string.rs b/crates/oxc_ecmascript/src/to_string.rs index 08d958beba4bb4..f3f23817fffc0f 100644 --- a/crates/oxc_ecmascript/src/to_string.rs +++ b/crates/oxc_ecmascript/src/to_string.rs @@ -1,10 +1,10 @@ use std::borrow::Cow; -use crate::array_join::ArrayJoin; -use crate::ToBoolean; use oxc_ast::ast::*; use oxc_syntax::operator::UnaryOperator; +use crate::{array_join::ArrayJoin, ToBoolean}; + /// `ToString` /// /// diff --git a/crates/oxc_isolated_declarations/src/declaration.rs b/crates/oxc_isolated_declarations/src/declaration.rs index 731f47d19a4f80..f46f3074b088ad 100644 --- a/crates/oxc_isolated_declarations/src/declaration.rs +++ b/crates/oxc_isolated_declarations/src/declaration.rs @@ -1,17 +1,15 @@ use std::cell::Cell; use oxc_allocator::{Box, CloneIn, Vec}; -use oxc_ast::ast::*; -use oxc_ast::visit::walk_mut::walk_ts_signatures; -use oxc_ast::{Visit, VisitMut}; +use oxc_ast::{ast::*, visit::walk_mut::walk_ts_signatures, Visit, VisitMut}; use oxc_ecmascript::BoundNames; use oxc_span::{GetSpan, SPAN}; use oxc_syntax::scope::ScopeFlags; -use crate::diagnostics::accessor_must_have_explicit_return_type; use crate::{ diagnostics::{ - binding_element_export, inferred_type_of_expression, signature_computed_property_name, + accessor_must_have_explicit_return_type, binding_element_export, + inferred_type_of_expression, signature_computed_property_name, variable_must_have_explicit_type, }, IsolatedDeclarations, diff --git a/crates/oxc_isolated_declarations/src/enum.rs b/crates/oxc_isolated_declarations/src/enum.rs index d9a844d459bd33..b885500de8478e 100644 --- a/crates/oxc_isolated_declarations/src/enum.rs +++ b/crates/oxc_isolated_declarations/src/enum.rs @@ -1,5 +1,3 @@ -use rustc_hash::FxHashMap; - use oxc_allocator::CloneIn; use oxc_ast::ast::*; use oxc_ecmascript::ToInt32; @@ -8,6 +6,7 @@ use oxc_syntax::{ number::{NumberBase, ToJsString}, operator::{BinaryOperator, UnaryOperator}, }; +use rustc_hash::FxHashMap; use crate::{diagnostics::enum_member_initializers, IsolatedDeclarations}; diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index f962f74bcfd4c1..7dfe8c64eaeda5 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -21,6 +21,7 @@ mod types; use std::{cell::RefCell, mem}; +use diagnostics::function_with_assigning_properties; use oxc_allocator::{Allocator, CloneIn}; use oxc_ast::{ast::*, AstBuilder, Visit, NONE}; use oxc_diagnostics::OxcDiagnostic; @@ -28,7 +29,6 @@ use oxc_span::{Atom, GetSpan, SourceType, SPAN}; use rustc_hash::{FxHashMap, FxHashSet}; use crate::scope::ScopeTree; -use diagnostics::function_with_assigning_properties; #[derive(Debug, Default, Clone, Copy)] pub struct IsolatedDeclarationsOptions { diff --git a/crates/oxc_isolated_declarations/src/module.rs b/crates/oxc_isolated_declarations/src/module.rs index 061aad0ebf512e..2dfb5b5e99cdb2 100644 --- a/crates/oxc_isolated_declarations/src/module.rs +++ b/crates/oxc_isolated_declarations/src/module.rs @@ -1,6 +1,4 @@ -use oxc_allocator::Box; -use oxc_allocator::CloneIn; -use oxc_allocator::Vec; +use oxc_allocator::{Box, CloneIn, Vec}; use oxc_ast::{ast::*, NONE}; use oxc_span::{Atom, GetSpan, SPAN}; diff --git a/crates/oxc_isolated_declarations/src/scope.rs b/crates/oxc_isolated_declarations/src/scope.rs index 344b4bc3ac0ff1..c0e1fd53391a8c 100644 --- a/crates/oxc_isolated_declarations/src/scope.rs +++ b/crates/oxc_isolated_declarations/src/scope.rs @@ -1,12 +1,10 @@ -use bitflags::bitflags; -use rustc_hash::FxHashMap; - use std::cell::Cell; -use oxc_ast::ast::*; -use oxc_ast::{visit::walk::*, Visit}; +use bitflags::bitflags; +use oxc_ast::{ast::*, visit::walk::*, Visit}; use oxc_span::Atom; use oxc_syntax::scope::{ScopeFlags, ScopeId}; +use rustc_hash::FxHashMap; bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/oxc_isolated_declarations/src/signatures.rs b/crates/oxc_isolated_declarations/src/signatures.rs index 562d5a40e7fc4b..35ffd361be8d13 100644 --- a/crates/oxc_isolated_declarations/src/signatures.rs +++ b/crates/oxc_isolated_declarations/src/signatures.rs @@ -1,8 +1,7 @@ -use rustc_hash::FxHashMap; - use oxc_allocator::{CloneIn, Vec}; use oxc_ast::ast::{TSMethodSignatureKind, TSSignature}; use oxc_span::GetSpan; +use rustc_hash::FxHashMap; use crate::IsolatedDeclarations; diff --git a/crates/oxc_language_server/src/linter.rs b/crates/oxc_language_server/src/linter.rs index e1d91b8ccc9d2a..b0450b9bb83d35 100644 --- a/crates/oxc_language_server/src/linter.rs +++ b/crates/oxc_language_server/src/linter.rs @@ -8,23 +8,21 @@ use std::{ use cow_utils::CowUtils; use log::debug; -use rustc_hash::FxHashSet; -use tower_lsp::lsp_types::{ - self, CodeDescription, DiagnosticRelatedInformation, DiagnosticSeverity, NumberOrString, - Position, Range, Url, -}; - use oxc_allocator::Allocator; use oxc_data_structures::rope::{get_line_column, Rope}; use oxc_diagnostics::{Error, NamedSource, Severity}; -use oxc_linter::loader::LINT_PARTIAL_LOADER_EXT; use oxc_linter::{ - loader::{JavaScriptSource, Loader}, + loader::{JavaScriptSource, Loader, LINT_PARTIAL_LOADER_EXT}, FixKind, Linter, ModuleRecord, }; use oxc_parser::{ParseOptions, Parser}; use oxc_semantic::SemanticBuilder; use oxc_span::VALID_EXTENSIONS; +use rustc_hash::FxHashSet; +use tower_lsp::lsp_types::{ + self, CodeDescription, DiagnosticRelatedInformation, DiagnosticSeverity, NumberOrString, + Position, Range, Url, +}; const LINT_DOC_LINK_PREFIX: &str = "https://oxc.rs/docs/guide/usage/linter/rules"; #[derive(Debug)] diff --git a/crates/oxc_language_server/src/main.rs b/crates/oxc_language_server/src/main.rs index 993707c0b933b7..38e9aaa8d7a0ce 100644 --- a/crates/oxc_language_server/src/main.rs +++ b/crates/oxc_language_server/src/main.rs @@ -2,7 +2,6 @@ mod linter; use std::{fmt::Debug, path::PathBuf, str::FromStr}; -use crate::linter::{DiagnosticReport, ServerLinter}; use dashmap::DashMap; use futures::future::join_all; use globset::Glob; @@ -12,7 +11,6 @@ use oxc_linter::{FixKind, LinterBuilder, Oxlintrc}; use rustc_hash::FxBuildHasher; use serde::{Deserialize, Serialize}; use tokio::sync::{Mutex, OnceCell, RwLock, SetError}; -use tower_lsp::lsp_types::{NumberOrString, Position, Range}; use tower_lsp::{ jsonrpc::{Error, ErrorCode, Result}, lsp_types::{ @@ -20,14 +18,16 @@ use tower_lsp::{ CodeActionProviderCapability, CodeActionResponse, ConfigurationItem, Diagnostic, DidChangeConfigurationParams, DidChangeTextDocumentParams, DidChangeWatchedFilesParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, DidSaveTextDocumentParams, - InitializeParams, InitializeResult, InitializedParams, OneOf, ServerCapabilities, - ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url, - WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities, + InitializeParams, InitializeResult, InitializedParams, NumberOrString, OneOf, Position, + Range, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, TextDocumentSyncKind, + TextEdit, Url, WorkDoneProgressOptions, WorkspaceEdit, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities, }, Client, LanguageServer, LspService, Server, }; +use crate::linter::{DiagnosticReport, ServerLinter}; + type FxDashMap = DashMap; struct Backend { diff --git a/crates/oxc_linter/src/ast_util.rs b/crates/oxc_linter/src/ast_util.rs index 166ea6603b3b7c..76828fb33d8502 100644 --- a/crates/oxc_linter/src/ast_util.rs +++ b/crates/oxc_linter/src/ast_util.rs @@ -1,11 +1,12 @@ -use oxc_ast::{ast::BindingIdentifier, AstKind}; +use oxc_ast::{ + ast::{BindingIdentifier, *}, + AstKind, +}; use oxc_ecmascript::ToBoolean; use oxc_semantic::{AstNode, IsGlobalReference, NodeId, ReferenceId, Semantic, SymbolId}; use oxc_span::{GetSpan, Span}; use oxc_syntax::operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator}; -use oxc_ast::ast::*; - /// Test if an AST node is a boolean value that never changes. Specifically we /// test for: /// 1. Literal booleans (`true` or `false`) diff --git a/crates/oxc_linter/src/builder.rs b/crates/oxc_linter/src/builder.rs index 92ca3410e459ce..768236b68f76ca 100644 --- a/crates/oxc_linter/src/builder.rs +++ b/crates/oxc_linter/src/builder.rs @@ -507,7 +507,10 @@ mod test { builder .with_filters([LintFilter::new(AllowWarnDeny::Deny, filter_string).unwrap()]); let rule_count_after_deny = builder.rules.len(); - assert_eq!(initial_rule_count, rule_count_after_deny, "Changing a single rule from warn to deny should not add a new one, just modify what's already there."); + assert_eq!( + initial_rule_count, rule_count_after_deny, + "Changing a single rule from warn to deny should not add a new one, just modify what's already there." + ); let no_const_assign = builder .rules @@ -571,7 +574,11 @@ mod test { let initial_rule_count = builder.rules.len(); let builder = builder.and_plugins(LintPlugins::IMPORT, true); - assert_eq!(initial_rule_count, builder.rules.len(), "Enabling a plugin should not add any rules, since we don't know which categories to turn on."); + assert_eq!( + initial_rule_count, + builder.rules.len(), + "Enabling a plugin should not add any rules, since we don't know which categories to turn on." + ); } #[test] diff --git a/crates/oxc_linter/src/config/flat.rs b/crates/oxc_linter/src/config/flat.rs index 4fe6d183e308cb..28e8bd3c8fc068 100644 --- a/crates/oxc_linter/src/config/flat.rs +++ b/crates/oxc_linter/src/config/flat.rs @@ -1,18 +1,17 @@ -use crate::LintPlugins; -use crate::{rules::RULES, RuleWithSeverity}; -use rustc_hash::FxHashSet; use std::{ hash::{BuildHasher, Hash, Hasher}, path::Path, sync::Arc, }; +use dashmap::DashMap; +use rustc_hash::{FxBuildHasher, FxHashSet}; + use super::{ overrides::{OverrideId, OxlintOverrides}, LintConfig, }; -use dashmap::DashMap; -use rustc_hash::FxBuildHasher; +use crate::{rules::RULES, LintPlugins, RuleWithSeverity}; type AppliedOverrideHash = u64; type FxDashMap = DashMap; diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index 54f012be7b769c..31daa7193802ef 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -18,8 +18,7 @@ pub use self::{ overrides::OxlintOverrides, oxlintrc::Oxlintrc, plugins::LintPlugins, - rules::ESLintRule, - rules::OxlintRules, + rules::{ESLintRule, OxlintRules}, settings::{jsdoc::JSDocPluginSettings, OxlintSettings}, }; diff --git a/crates/oxc_linter/src/config/overrides.rs b/crates/oxc_linter/src/config/overrides.rs index 6a64222584aa07..394c66bed94ed8 100644 --- a/crates/oxc_linter/src/config/overrides.rs +++ b/crates/oxc_linter/src/config/overrides.rs @@ -1,11 +1,10 @@ use std::{borrow::Cow, ops::Deref, path::Path}; use nonmax::NonMaxU32; +use oxc_index::{Idx, IndexVec}; use schemars::{gen, schema::Schema, JsonSchema}; use serde::{de, ser, Deserialize, Serialize}; -use oxc_index::{Idx, IndexVec}; - use crate::{config::OxlintRules, LintPlugins}; #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] @@ -30,6 +29,7 @@ pub struct OxlintOverrides(IndexVec); impl Deref for OxlintOverrides { type Target = IndexVec; + fn deref(&self) -> &Self::Target { &self.0 } @@ -155,9 +155,10 @@ impl JsonSchema for GlobSet { mod test { #[test] fn test_globset() { - use super::*; use serde_json::{from_value, json}; + use super::*; + let config: OxlintOverride = from_value(json!({ "files": ["*.tsx",], })) @@ -175,9 +176,10 @@ mod test { #[test] fn test_parsing_plugins() { - use super::*; use serde_json::{from_value, json}; + use super::*; + let config: OxlintOverride = from_value(json!({ "files": ["*.tsx"], })) diff --git a/crates/oxc_linter/src/config/oxlintrc.rs b/crates/oxc_linter/src/config/oxlintrc.rs index 190d06fc96c6ce..652360f913171b 100644 --- a/crates/oxc_linter/src/config/oxlintrc.rs +++ b/crates/oxc_linter/src/config/oxlintrc.rs @@ -8,7 +8,6 @@ use super::{ categories::OxlintCategories, env::OxlintEnv, globals::OxlintGlobals, overrides::OxlintOverrides, plugins::LintPlugins, rules::OxlintRules, settings::OxlintSettings, }; - use crate::utils::read_to_string; /// Oxlint Configuration File @@ -137,9 +136,10 @@ impl Oxlintrc { #[cfg(test)] mod test { - use super::*; use serde_json::json; + use super::*; + #[test] fn test_oxlintrc_de_empty() { let config: Oxlintrc = serde_json::from_value(json!({})).unwrap(); diff --git a/crates/oxc_linter/src/config/plugins.rs b/crates/oxc_linter/src/config/plugins.rs index 794745411a584f..a562f84c1bc76c 100644 --- a/crates/oxc_linter/src/config/plugins.rs +++ b/crates/oxc_linter/src/config/plugins.rs @@ -212,9 +212,11 @@ impl JsonSchema for LintPlugins { fn schema_name() -> String { "LintPlugins".to_string() } + fn schema_id() -> std::borrow::Cow<'static, str> { std::borrow::Cow::Borrowed("LintPlugins") } + fn json_schema(gen: &mut SchemaGenerator) -> Schema { gen.subschema_for::>() } diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs index a4084f93d81c6e..bbac4fd01138e2 100644 --- a/crates/oxc_linter/src/config/rules.rs +++ b/crates/oxc_linter/src/config/rules.rs @@ -341,14 +341,14 @@ impl ESLintRule { #[cfg(test)] #[allow(clippy::default_trait_access)] mod test { - use crate::{ - rules::{RuleEnum, RULES}, - AllowWarnDeny, RuleWithSeverity, - }; use serde::Deserialize; use serde_json::{json, Value}; use super::{OxlintRules, RuleSet}; + use crate::{ + rules::{RuleEnum, RULES}, + AllowWarnDeny, RuleWithSeverity, + }; #[test] fn test_parse_rules() { @@ -425,10 +425,22 @@ mod test { rules.clear(); r#override(&mut rules, &config); - assert_eq!(rules.len(), 1, "eslint rules should be configurable by their typescript-eslint reimplementations: {config:?}"); + assert_eq!( + rules.len(), + 1, + "eslint rules should be configurable by their typescript-eslint reimplementations: {config:?}" + ); let rule = rules.iter().next().unwrap(); - assert_eq!(rule.name(), "no-console", "eslint rules should be configurable by their typescript-eslint reimplementations: {config:?}"); - assert_eq!(rule.severity, AllowWarnDeny::Deny, "eslint rules should be configurable by their typescript-eslint reimplementations: {config:?}"); + assert_eq!( + rule.name(), + "no-console", + "eslint rules should be configurable by their typescript-eslint reimplementations: {config:?}" + ); + assert_eq!( + rule.severity, + AllowWarnDeny::Deny, + "eslint rules should be configurable by their typescript-eslint reimplementations: {config:?}" + ); } #[test] diff --git a/crates/oxc_linter/src/context/host.rs b/crates/oxc_linter/src/context/host.rs index d44590447af2d3..cb6fa2b304042f 100644 --- a/crates/oxc_linter/src/context/host.rs +++ b/crates/oxc_linter/src/context/host.rs @@ -3,6 +3,7 @@ use std::{cell::RefCell, path::Path, rc::Rc, sync::Arc}; use oxc_semantic::Semantic; use oxc_span::SourceType; +use super::{plugin_name_to_prefix, LintContext}; use crate::{ config::{LintConfig, LintPlugins}, disable_directives::{DisableDirectives, DisableDirectivesBuilder}, @@ -13,8 +14,6 @@ use crate::{ utils, FrameworkFlags, RuleWithSeverity, }; -use super::{plugin_name_to_prefix, LintContext}; - /// Stores shared information about a file being linted. /// /// When linting a file, there are a number of shared resources that are diff --git a/crates/oxc_linter/src/context/mod.rs b/crates/oxc_linter/src/context/mod.rs index 2a891195a41bf5..3f18057fa6e2f5 100644 --- a/crates/oxc_linter/src/context/mod.rs +++ b/crates/oxc_linter/src/context/mod.rs @@ -3,6 +3,7 @@ mod host; use std::{ops::Deref, path::Path, rc::Rc}; +pub(crate) use host::ContextHost; use oxc_cfg::ControlFlowGraph; use oxc_diagnostics::{OxcDiagnostic, Severity}; use oxc_semantic::Semantic; @@ -17,8 +18,6 @@ use crate::{ AllowWarnDeny, FrameworkFlags, ModuleRecord, OxlintEnv, OxlintGlobals, OxlintSettings, }; -pub(crate) use host::ContextHost; - #[derive(Clone)] #[must_use] /// Contains all of the state and context specific to this lint rule. Includes information diff --git a/crates/oxc_linter/src/fixer/mod.rs b/crates/oxc_linter/src/fixer/mod.rs index d3c1b4f6563402..61ee49daff57e4 100644 --- a/crates/oxc_linter/src/fixer/mod.rs +++ b/crates/oxc_linter/src/fixer/mod.rs @@ -329,9 +329,9 @@ impl<'a> Fixer<'a> { #[cfg(test)] mod test { - use cow_utils::CowUtils; use std::borrow::Cow; + use cow_utils::CowUtils; use oxc_diagnostics::OxcDiagnostic; use oxc_span::Span; diff --git a/crates/oxc_linter/src/loader/mod.rs b/crates/oxc_linter/src/loader/mod.rs index f11f1f55969ac8..07742211eb458d 100644 --- a/crates/oxc_linter/src/loader/mod.rs +++ b/crates/oxc_linter/src/loader/mod.rs @@ -4,7 +4,6 @@ mod source; use std::{error::Error, fmt, path::Path}; use oxc_span::SourceType; - pub use partial_loader::{PartialLoader, LINT_PARTIAL_LOADER_EXT}; pub use source::JavaScriptSource; diff --git a/crates/oxc_linter/src/module_record.rs b/crates/oxc_linter/src/module_record.rs index 439b7c5524494d..4ad65174fc5ffb 100644 --- a/crates/oxc_linter/src/module_record.rs +++ b/crates/oxc_linter/src/module_record.rs @@ -7,11 +7,10 @@ use std::{ }; use dashmap::DashMap; -use rustc_hash::{FxBuildHasher, FxHashMap}; - use oxc_semantic::Semantic; use oxc_span::{CompactStr, Span}; pub use oxc_syntax::module_record::RequestedModule; +use rustc_hash::{FxBuildHasher, FxHashMap}; type FxDashMap = DashMap; diff --git a/crates/oxc_linter/src/options/allow_warn_deny.rs b/crates/oxc_linter/src/options/allow_warn_deny.rs index b72e1cade8a001..23b882ce57a444 100644 --- a/crates/oxc_linter/src/options/allow_warn_deny.rs +++ b/crates/oxc_linter/src/options/allow_warn_deny.rs @@ -78,6 +78,7 @@ fn invalid_int_severity(value: D) -> OxcDiagnostic { impl TryFrom for AllowWarnDeny { type Error = OxcDiagnostic; + fn try_from(value: u64) -> Result { match value { 0 => Ok(Self::Allow), diff --git a/crates/oxc_linter/src/options/filter.rs b/crates/oxc_linter/src/options/filter.rs index 6ac054ba2287f5..6010c394678be5 100644 --- a/crates/oxc_linter/src/options/filter.rs +++ b/crates/oxc_linter/src/options/filter.rs @@ -1,8 +1,7 @@ -use crate::RuleCategory; +use std::{borrow::Cow, fmt}; use super::AllowWarnDeny; -use crate::LintPlugins; -use std::{borrow::Cow, fmt}; +use crate::{LintPlugins, RuleCategory}; /// Enables, disables, and sets the severity of lint rules. /// diff --git a/crates/oxc_linter/src/rule.rs b/crates/oxc_linter/src/rule.rs index cd4b06aa2cbb5a..12529b150293a1 100644 --- a/crates/oxc_linter/src/rule.rs +++ b/crates/oxc_linter/src/rule.rs @@ -129,6 +129,7 @@ impl RuleCategory { impl TryFrom<&str> for RuleCategory { type Error = (); + fn try_from(value: &str) -> Result { match value { "correctness" => Ok(Self::Correctness), diff --git a/crates/oxc_linter/src/rules/eslint/no_array_constructor.rs b/crates/oxc_linter/src/rules/eslint/no_array_constructor.rs index 420497766f46dc..f987a471ce58fd 100644 --- a/crates/oxc_linter/src/rules/eslint/no_array_constructor.rs +++ b/crates/oxc_linter/src/rules/eslint/no_array_constructor.rs @@ -1,5 +1,4 @@ -use oxc_ast::ast::Expression; -use oxc_ast::AstKind; +use oxc_ast::{ast::Expression, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::IsGlobalReference; diff --git a/crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs b/crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs index 31ba280c12dc31..002f4020739d88 100644 --- a/crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs +++ b/crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs @@ -4,8 +4,7 @@ use oxc_ast::{ }; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::cmp::ContentEq; -use oxc_span::{GetSpan, Span}; +use oxc_span::{cmp::ContentEq, GetSpan, Span}; use oxc_syntax::operator::LogicalOperator; use crate::{context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs b/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs index 69a994d34520ad..2206f5c1b63704 100644 --- a/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs @@ -1,8 +1,7 @@ -use rustc_hash::FxHashMap; - use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::{CompactStr, Span}; +use rustc_hash::FxHashMap; use crate::{ context::LintContext, diff --git a/crates/oxc_linter/src/rules/eslint/no_else_return.rs b/crates/oxc_linter/src/rules/eslint/no_else_return.rs index 178acbf1c1b9f6..0490c4c66fb46d 100644 --- a/crates/oxc_linter/src/rules/eslint/no_else_return.rs +++ b/crates/oxc_linter/src/rules/eslint/no_else_return.rs @@ -1,10 +1,11 @@ -use crate::{context::LintContext, rule::Rule, AstNode}; use oxc_ast::{ast::Statement, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::{ScopeId, ScopeTree}; use oxc_span::{GetSpan, Span}; +use crate::{context::LintContext, rule::Rule, AstNode}; + #[derive(Debug, Default, Clone)] pub struct NoElseReturn { allow_else_if: bool, @@ -401,167 +402,436 @@ fn test() { let pass = vec![ ("function foo() { if (true) { if (false) { return x; } } else { return y; } }", None), -("function foo() { if (true) { return x; } return y; }", None), -("function foo() { if (true) { for (;;) { return x; } } else { return y; } }", None), -("function foo() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", None), -("function foo() { if (true) notAReturn(); else return y; }", None), -("function foo() {if (x) { notAReturn(); } else if (y) { return true; } else { notAReturn(); } }", None), -("function foo() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", None), -("if (0) { if (0) {} else {} } else {}", None), -(" + ("function foo() { if (true) { return x; } return y; }", None), + ("function foo() { if (true) { for (;;) { return x; } } else { return y; } }", None), + ( + "function foo() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", + None, + ), + ("function foo() { if (true) notAReturn(); else return y; }", None), + ( + "function foo() {if (x) { notAReturn(); } else if (y) { return true; } else { notAReturn(); } }", + None, + ), + ( + "function foo() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", + None, + ), + ("if (0) { if (0) {} else {} } else {}", None), + ( + " function foo() { if (foo) if (bar) return; else baz; else qux; } - ", None), -(" + ", + None, + ), + ( + " function foo() { while (foo) if (bar) return; else baz; } - ", None), -("function foo19() { if (true) { return x; } else if (false) { return y; } }", Some(serde_json::json!([{ "allowElseIf": true }]))), -("function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", Some(serde_json::json!([{ "allowElseIf": true }]))), -("function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", Some(serde_json::json!([{ "allowElseIf": true }]))) + ", + None, + ), + ( + "function foo19() { if (true) { return x; } else if (false) { return y; } }", + Some(serde_json::json!([{ "allowElseIf": true }])), + ), + ( + "function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", + Some(serde_json::json!([{ "allowElseIf": true }])), + ), + ( + "function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", + Some(serde_json::json!([{ "allowElseIf": true }])), + ), ]; let fail = vec![ ("if(0)return;else r", None), ("function foo1() { if (true) { return x; } else { return y; } }", None), -("function foo2() { if (true) { var x = bar; return x; } else { var y = baz; return y; } }", None), -("function foo3() { if (true) return x; else return y; }", None), -("function foo4() { if (true) { if (false) return x; else return y; } else { return z; } }", None), -("function foo5() { if (true) { if (false) { if (true) return x; else { w = y; } } else { w = x; } } else { return z; } }", None), -("function foo6() { if (true) { if (false) { if (true) return x; else return y; } } else { return z; } }", None), -("function foo7() { if (true) { if (false) { if (true) return x; else return y; } return w; } else { return z; } }", None), -("function foo8() { if (true) { if (false) { if (true) return x; else return y; } else { w = x; } } else { return z; } }", None), -("function foo9() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", None), -("function foo9a() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo9b() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo10() { if (foo) return bar; else (foo).bar(); }", None), -("function foo11() { if (foo) return bar - else { [1, 2, 3].map(foo) } }", None), -("function foo12() { if (foo) return bar + ( + "function foo2() { if (true) { var x = bar; return x; } else { var y = baz; return y; } }", + None, + ), + ("function foo3() { if (true) return x; else return y; }", None), + ( + "function foo4() { if (true) { if (false) return x; else return y; } else { return z; } }", + None, + ), + ( + "function foo5() { if (true) { if (false) { if (true) return x; else { w = y; } } else { w = x; } } else { return z; } }", + None, + ), + ( + "function foo6() { if (true) { if (false) { if (true) return x; else return y; } } else { return z; } }", + None, + ), + ( + "function foo7() { if (true) { if (false) { if (true) return x; else return y; } return w; } else { return z; } }", + None, + ), + ( + "function foo8() { if (true) { if (false) { if (true) return x; else return y; } else { w = x; } } else { return z; } }", + None, + ), + ( + "function foo9() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", + None, + ), + ( + "function foo9a() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo9b() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ("function foo10() { if (foo) return bar; else (foo).bar(); }", None), + ( + "function foo11() { if (foo) return bar + else { [1, 2, 3].map(foo) } }", + None, + ), + ( + "function foo12() { if (foo) return bar else { baz() } - [1, 2, 3].map(foo) }", None), -("function foo13() { if (foo) return bar; - else { [1, 2, 3].map(foo) } }", None), -("function foo14() { if (foo) return bar + [1, 2, 3].map(foo) }", + None, + ), + ( + "function foo13() { if (foo) return bar; + else { [1, 2, 3].map(foo) } }", + None, + ), + ( + "function foo14() { if (foo) return bar else { baz(); } - [1, 2, 3].map(foo) }", None), -("function foo15() { if (foo) return bar; else { baz() } qaz() }", None), -("function foo16() { if (foo) return bar - else { baz() } qaz() }", None), -("function foo17() { if (foo) return bar + [1, 2, 3].map(foo) }", + None, + ), + ("function foo15() { if (foo) return bar; else { baz() } qaz() }", None), + ( + "function foo16() { if (foo) return bar + else { baz() } qaz() }", + None, + ), + ( + "function foo17() { if (foo) return bar else { baz() } - qaz() }", None), -("function foo18() { if (foo) return function() {} - else [1, 2, 3].map(bar) }", None), -("function foo19() { if (true) { return x; } else if (false) { return y; } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo() { var a; if (bar) { return true; } else { var a; } }", None), -("function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", None), -("function foo() { var a; if (bar) { return true; } else { var a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { let a; if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("class foo { bar() { let a; if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { let a; if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() {let a; if (bar) { if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { const a = 1; if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { const a = 1; if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { let a; if (bar) { return true; } else { const a = 1 } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { let a; if (baz) { return true; } else { const a = 1; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { class a {}; if (bar) { return true; } else { const a = 1; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { class a {}; if (baz) { return true; } else { const a = 1; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { const a = 1; if (bar) { return true; } else { class a {} } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { const a = 1; if (baz) { return true; } else { class a {} } } }", None), // { "ecmaVersion": 6 }, -("function foo() { var a; if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { var a; return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let a; } while (baz) { var a; } }", None), // { "ecmaVersion": 6 }, -("function foo(a) { if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function foo(a = 1) { if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function foo(a, b = a) { if (bar) { return true; } else { let a; } if (bar) { return true; } else { let b; }}", None), // { "ecmaVersion": 6 }, -("function foo(...args) { if (bar) { return true; } else { let args; } }", None), // { "ecmaVersion": 6 }, -("function foo() { try {} catch (a) { if (bar) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } else { let a; } } } }", None), // { "ecmaVersion": 6 }, -("function foo() { try {} catch ({bar, a = 1}) { if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let arguments; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let arguments; } return arguments[0]; }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let arguments; } if (baz) { return arguments[0]; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let arguments; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let a; } a; }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let a; } if (baz) { a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } a; }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { a; } } }", None), // { "ecmaVersion": 6 }, -("function a() { if (foo) { return true; } else { let a; } a(); }", None), // { "ecmaVersion": 6 }, -("function a() { if (a) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function a() { if (foo) { return a; } else { let a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let a; } function baz() { a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } (() => a) } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let a; } var a; }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } var a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } var { a } = {}; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { var a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { var a; } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else { let a; } function a(){} }", None), // { "ecmaVersion": 6 }, -("function foo() { if (baz) { if (bar) { return true; } else { let a; } function a(){} } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { function a(){} } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } function a(){} }", None), // { "ecmaVersion": 6 }, -("function foo() { let a; if (bar) { return true; } else { function a(){} } }", None), // { "ecmaVersion": 6 }, -("function foo() { var a; if (bar) { return true; } else { function a(){} } }", None), // { "ecmaVersion": 6 }, -("function foo() { if (bar) { return true; } else function baz() {} };", None), -("if (foo) { return true; } else { let a; }", None), // { "ecmaVersion": 6, "sourceType": "commonjs" }, -("let a; if (foo) { return true; } else { let a; }", None), // { "ecmaVersion": 6, "sourceType": "commonjs" } + qaz() }", + None, + ), + ( + "function foo18() { if (foo) return function() {} + else [1, 2, 3].map(bar) }", + None, + ), + ( + "function foo19() { if (true) { return x; } else if (false) { return y; } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ("function foo() { var a; if (bar) { return true; } else { var a; } }", None), + ("function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", None), + ("function foo() { var a; if (bar) { return true; } else { var a; } }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", None), // { "ecmaVersion": 6 }, + ("function foo() { let a; if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ("class foo { bar() { let a; if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { let a; if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, + ("function foo() {let a; if (bar) { if (baz) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, + ("function foo() { const a = 1; if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { const a = 1; if (baz) { return true; } else { let a; } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { let a; if (bar) { return true; } else { const a = 1 } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { let a; if (baz) { return true; } else { const a = 1; } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { class a {}; if (bar) { return true; } else { const a = 1; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { class a {}; if (baz) { return true; } else { const a = 1; } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { const a = 1; if (bar) { return true; } else { class a {} } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { const a = 1; if (baz) { return true; } else { class a {} } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { var a; if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { var a; return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { return true; } else { let a; } while (baz) { var a; } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo(a) { if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ("function foo(a = 1) { if (bar) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo(a, b = a) { if (bar) { return true; } else { let a; } if (bar) { return true; } else { let b; }}", + None, + ), // { "ecmaVersion": 6 }, + ("function foo(...args) { if (bar) { return true; } else { let args; } }", None), // { "ecmaVersion": 6 }, + ("function foo() { try {} catch (a) { if (bar) { return true; } else { let a; } } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } else { let a; } } } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { try {} catch ({bar, a = 1}) { if (baz) { return true; } else { let a; } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { return true; } else { let arguments; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { return true; } else { let arguments; } return arguments[0]; }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { return true; } else { let arguments; } if (baz) { return arguments[0]; } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { if (baz) { return true; } else { let arguments; } } }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { return true; } else { let a; } a; }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { return true; } else { let a; } if (baz) { a; } }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { if (baz) { return true; } else { let a; } } a; }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { if (baz) { return true; } else { let a; } a; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { a; } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function a() { if (foo) { return true; } else { let a; } a(); }", None), // { "ecmaVersion": 6 }, + ("function a() { if (a) { return true; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ("function a() { if (foo) { return a; } else { let a; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { return true; } else { let a; } function baz() { a; } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } (() => a) } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { return true; } else { let a; } var a; }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { if (baz) { return true; } else { let a; } var a; } }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } var { a } = {}; } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } if (quux) { var a; } } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { var a; } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } else { let a; } } }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { return true; } else { let a; } function a(){} }", None), // { "ecmaVersion": 6 }, + ( + "function foo() { if (baz) { if (bar) { return true; } else { let a; } function a(){} } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { function a(){} } }", + None, + ), // { "ecmaVersion": 6 }, + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } function a(){} }", + None, + ), // { "ecmaVersion": 6 }, + ("function foo() { let a; if (bar) { return true; } else { function a(){} } }", None), // { "ecmaVersion": 6 }, + ("function foo() { var a; if (bar) { return true; } else { function a(){} } }", None), // { "ecmaVersion": 6 }, + ("function foo() { if (bar) { return true; } else function baz() {} };", None), + ("if (foo) { return true; } else { let a; }", None), // { "ecmaVersion": 6, "sourceType": "commonjs" }, + ("let a; if (foo) { return true; } else { let a; }", None), // { "ecmaVersion": 6, "sourceType": "commonjs" } ]; let fix = vec![ ("if(0)return;else r", "if(0)return; r", None), - ("function foo1() { if (true) { return x; } else { return y; } }", "function foo1() { if (true) { return x; } return y; }", None), - ("function foo1() { if(true){ return x; }else{ return y; } }", "function foo1() { if(true){ return x; } return y; }", None), -("function foo2() { if (true) { var x = bar; return x; } else { var y = baz; return y; } }", "function foo2() { if (true) { var x = bar; return x; } var y = baz; return y; }", None), -("function foo3() { if (true) return x; else return y; }", "function foo3() { if (true) return x; return y; }", None), -("function foo4() { if (true) { if (false) return x; else return y; } else { return z; } }", "function foo4() { if (true) { if (false) return x; return y; } return z; }", None), -("function foo5() { if (true) { if (false) { if (true) return x; else { w = y; } } else { w = x; } } else { return z; } }", "function foo5() { if (true) { if (false) { if (true) return x; w = y; } else { w = x; } } else { return z; } }", None), -("function foo6() { if (true) { if (false) { if (true) return x; else return y; } } else { return z; } }", "function foo6() { if (true) { if (false) { if (true) return x; return y; } } else { return z; } }", None), -("function foo7() { if (true) { if (false) { if (true) return x; else return y; } return w; } else { return z; } }", "function foo7() { if (true) { if (false) { if (true) return x; return y; } return w; } return z; }", None), -("function foo8() { if (true) { if (false) { if (true) return x; else return y; } else { w = x; } } else { return z; } }", "function foo8() { if (true) { if (false) { if (true) return x; return y; } w = x; } else { return z; } }", None), -("function foo9() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", "function foo9() {if (x) { return true; } else if (y) { return true; } notAReturn(); }", None), -("function foo9a() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", "function foo9a() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo9b() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", "function foo9b() {if (x) { return true; } if (y) { return true; } notAReturn(); }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo10() { if (foo) return bar; else (foo).bar(); }", "function foo10() { if (foo) return bar; (foo).bar(); }", None), -("function foo13() { if (foo) return bar; - else { [1, 2, 3].map(foo) } }", "function foo13() { if (foo) return bar; [1, 2, 3].map(foo) }", None), -("function foo14() { if (foo) return bar + ( + "function foo1() { if (true) { return x; } else { return y; } }", + "function foo1() { if (true) { return x; } return y; }", + None, + ), + ( + "function foo1() { if(true){ return x; }else{ return y; } }", + "function foo1() { if(true){ return x; } return y; }", + None, + ), + ( + "function foo2() { if (true) { var x = bar; return x; } else { var y = baz; return y; } }", + "function foo2() { if (true) { var x = bar; return x; } var y = baz; return y; }", + None, + ), + ( + "function foo3() { if (true) return x; else return y; }", + "function foo3() { if (true) return x; return y; }", + None, + ), + ( + "function foo4() { if (true) { if (false) return x; else return y; } else { return z; } }", + "function foo4() { if (true) { if (false) return x; return y; } return z; }", + None, + ), + ( + "function foo5() { if (true) { if (false) { if (true) return x; else { w = y; } } else { w = x; } } else { return z; } }", + "function foo5() { if (true) { if (false) { if (true) return x; w = y; } else { w = x; } } else { return z; } }", + None, + ), + ( + "function foo6() { if (true) { if (false) { if (true) return x; else return y; } } else { return z; } }", + "function foo6() { if (true) { if (false) { if (true) return x; return y; } } else { return z; } }", + None, + ), + ( + "function foo7() { if (true) { if (false) { if (true) return x; else return y; } return w; } else { return z; } }", + "function foo7() { if (true) { if (false) { if (true) return x; return y; } return w; } return z; }", + None, + ), + ( + "function foo8() { if (true) { if (false) { if (true) return x; else return y; } else { w = x; } } else { return z; } }", + "function foo8() { if (true) { if (false) { if (true) return x; return y; } w = x; } else { return z; } }", + None, + ), + ( + "function foo9() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", + "function foo9() {if (x) { return true; } else if (y) { return true; } notAReturn(); }", + None, + ), + ( + "function foo9a() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", + "function foo9a() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo9b() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", + "function foo9b() {if (x) { return true; } if (y) { return true; } notAReturn(); }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo10() { if (foo) return bar; else (foo).bar(); }", + "function foo10() { if (foo) return bar; (foo).bar(); }", + None, + ), + ( + "function foo13() { if (foo) return bar; + else { [1, 2, 3].map(foo) } }", + "function foo13() { if (foo) return bar; [1, 2, 3].map(foo) }", + None, + ), + ( + "function foo14() { if (foo) return bar else { baz(); } - [1, 2, 3].map(foo) }", "function foo14() { if (foo) return bar\n baz(); - [1, 2, 3].map(foo) }", None), -("function foo17() { if (foo) return bar + [1, 2, 3].map(foo) }", + "function foo14() { if (foo) return bar\n baz(); + [1, 2, 3].map(foo) }", + None, + ), + ( + "function foo17() { if (foo) return bar else { baz() } - qaz() }", "function foo17() { if (foo) return bar\n baz() - qaz() }", None), -("function foo19() { if (true) { return x; } else if (false) { return y; } }", "function foo19() { if (true) { return x; } if (false) { return y; } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", "function foo20() {if (x) { return true; } if (y) { notAReturn() } else { notAReturn(); } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", "function foo21() { var x = true; if (x) { return x; } if (x === false) { return false; } }", Some(serde_json::json!([{ "allowElseIf": false }]))), -("function foo() { var a; if (bar) { return true; } else { var a; } }", "function foo() { var a; if (bar) { return true; } var a; }", None), -("function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", "function foo() { if (bar) { var a; if (baz) { return true; } var a; } }", None), -("function foo() { var a; if (bar) { return true; } else { var a; } }", "function foo() { var a; if (bar) { return true; } var a; }", None), -("function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", "function foo() { if (bar) { var a; if (baz) { return true; } var a; } }", None), -("function foo() {let a; if (bar) { if (baz) { return true; } else { let a; } } }", "function foo() {let a; if (bar) { if (baz) { return true; } let a; } }", None), -("function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } else { let a; } } } }", "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } let a; } } }", None), -("function foo() { if (bar) { return true; } else { let arguments; } }", "function foo() { if (bar) { return true; } let arguments; }", None), -("function foo() { if (bar) { if (baz) { return true; } else { let arguments; } } }", "function foo() { if (bar) { if (baz) { return true; } let arguments; } }", None), -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } a; }", "function foo() { if (bar) { if (baz) { return true; } let a; } a; }", None), -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { var a; } }", "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { var a; } }", None), -("function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } else { let a; } } }", "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } let a; } }", None), -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { function a(){} } }", "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { function a(){} } }", None), -("function foo() { if (bar) { if (baz) { return true; } else { let a; } } function a(){} }", "function foo() { if (bar) { if (baz) { return true; } let a; } function a(){} }", None), -("if (foo) { return true; } else { let a; }", "if (foo) { return true; } let a;", None) + qaz() }", + "function foo17() { if (foo) return bar\n baz() + qaz() }", + None, + ), + ( + "function foo19() { if (true) { return x; } else if (false) { return y; } }", + "function foo19() { if (true) { return x; } if (false) { return y; } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", + "function foo20() {if (x) { return true; } if (y) { notAReturn() } else { notAReturn(); } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", + "function foo21() { var x = true; if (x) { return x; } if (x === false) { return false; } }", + Some(serde_json::json!([{ "allowElseIf": false }])), + ), + ( + "function foo() { var a; if (bar) { return true; } else { var a; } }", + "function foo() { var a; if (bar) { return true; } var a; }", + None, + ), + ( + "function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", + "function foo() { if (bar) { var a; if (baz) { return true; } var a; } }", + None, + ), + ( + "function foo() { var a; if (bar) { return true; } else { var a; } }", + "function foo() { var a; if (bar) { return true; } var a; }", + None, + ), + ( + "function foo() { if (bar) { var a; if (baz) { return true; } else { var a; } } }", + "function foo() { if (bar) { var a; if (baz) { return true; } var a; } }", + None, + ), + ( + "function foo() {let a; if (bar) { if (baz) { return true; } else { let a; } } }", + "function foo() {let a; if (bar) { if (baz) { return true; } let a; } }", + None, + ), + ( + "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } else { let a; } } } }", + "function foo() { try {} catch (a) { if (bar) { if (baz) { return true; } let a; } } }", + None, + ), + ( + "function foo() { if (bar) { return true; } else { let arguments; } }", + "function foo() { if (bar) { return true; } let arguments; }", + None, + ), + ( + "function foo() { if (bar) { if (baz) { return true; } else { let arguments; } } }", + "function foo() { if (bar) { if (baz) { return true; } let arguments; } }", + None, + ), + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } a; }", + "function foo() { if (bar) { if (baz) { return true; } let a; } a; }", + None, + ), + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { var a; } }", + "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { var a; } }", + None, + ), + ( + "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } else { let a; } } }", + "function foo() { if (quux) { var a; } if (bar) { if (baz) { return true; } let a; } }", + None, + ), + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } if (quux) { function a(){} } }", + "function foo() { if (bar) { if (baz) { return true; } let a; } if (quux) { function a(){} } }", + None, + ), + ( + "function foo() { if (bar) { if (baz) { return true; } else { let a; } } function a(){} }", + "function foo() { if (bar) { if (baz) { return true; } let a; } function a(){} }", + None, + ), + ("if (foo) { return true; } else { let a; }", "if (foo) { return true; } let a;", None), ]; Tester::new(NoElseReturn::NAME, NoElseReturn::CATEGORY, pass, fail) .expect_fix(fix) diff --git a/crates/oxc_linter/src/rules/eslint/no_extend_native.rs b/crates/oxc_linter/src/rules/eslint/no_extend_native.rs index 6f1b3c50d7e7b8..7b8392b4d346db 100644 --- a/crates/oxc_linter/src/rules/eslint/no_extend_native.rs +++ b/crates/oxc_linter/src/rules/eslint/no_extend_native.rs @@ -1,9 +1,10 @@ -use oxc_ast::ast::{CallExpression, ChainElement, Expression}; -use oxc_ast::{ast::MemberExpression, AstKind}; +use oxc_ast::{ + ast::{CallExpression, ChainElement, Expression, MemberExpression}, + AstKind, +}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::cmp::ContentEq; -use oxc_span::{CompactStr, GetSpan}; +use oxc_span::{cmp::ContentEq, CompactStr, GetSpan}; use crate::{context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs index 0b0b37dbcda04d..45a9ce45c04e65 100644 --- a/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs +++ b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs @@ -289,6 +289,7 @@ impl Rule for NoMagicNumbers { fn from_configuration(value: serde_json::Value) -> Self { Self(Box::new(NoMagicNumbersConfig::try_from(&value).unwrap())) } + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { if !matches!(node.kind(), AstKind::NumericLiteral(_) | AstKind::BigIntLiteral(_)) { return; diff --git a/crates/oxc_linter/src/rules/eslint/no_object_constructor.rs b/crates/oxc_linter/src/rules/eslint/no_object_constructor.rs index a4e1a522ab50dd..36c6beda52281b 100644 --- a/crates/oxc_linter/src/rules/eslint/no_object_constructor.rs +++ b/crates/oxc_linter/src/rules/eslint/no_object_constructor.rs @@ -1,5 +1,4 @@ -use oxc_ast::ast::Expression; -use oxc_ast::AstKind; +use oxc_ast::{ast::Expression, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::IsGlobalReference; diff --git a/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs b/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs index 0e58d0d6fcc074..80895db6d4929a 100644 --- a/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs +++ b/crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs @@ -143,6 +143,7 @@ impl<'a> Visit<'a> for ConsecutiveSpaceFinder { self.depth += 1; } } + fn leave_node(&mut self, kind: RegExpAstKind<'a>) { if let RegExpAstKind::Quantifier(_) | RegExpAstKind::CharacterClass(_) = kind { self.depth -= 1; diff --git a/crates/oxc_linter/src/rules/eslint/no_self_compare.rs b/crates/oxc_linter/src/rules/eslint/no_self_compare.rs index b200e1ac1c6999..b59c598117b6e1 100644 --- a/crates/oxc_linter/src/rules/eslint/no_self_compare.rs +++ b/crates/oxc_linter/src/rules/eslint/no_self_compare.rs @@ -1,8 +1,7 @@ use oxc_ast::AstKind; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::cmp::ContentEq; -use oxc_span::{GetSpan, Span}; +use oxc_span::{cmp::ContentEq, GetSpan, Span}; use crate::{context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/rules/eslint/no_undef.rs b/crates/oxc_linter/src/rules/eslint/no_undef.rs index 67f4095264fe1c..7f0edf3ac48135 100644 --- a/crates/oxc_linter/src/rules/eslint/no_undef.rs +++ b/crates/oxc_linter/src/rules/eslint/no_undef.rs @@ -160,7 +160,7 @@ fn test() { "String;Array;Boolean;", "function resolve(path: string): T { return { path } as T; }", "let xyz: NodeListOf", - "type Foo = Record;" + "type Foo = Record;", ]; let fail = vec![ 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 af8848cd8402d3..504bbaec705536 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 @@ -2,7 +2,6 @@ use oxc_ast::ast::*; use oxc_semantic::{Semantic, SymbolId}; use super::{symbol::Symbol, NoUnusedVars}; - use crate::ModuleRecord; #[derive(Clone, Copy)] 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 874913733ac7e0..88a020885fdca1 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 @@ -501,6 +501,7 @@ fn parse_unicode_rule(value: Option<&Value>, name: &str) -> IgnorePattern impl TryFrom for NoUnusedVarsOptions { type Error = OxcDiagnostic; + fn try_from(value: Value) -> Result { let Some(config) = value.get(0) else { return Ok(Self::default()) }; match config { @@ -509,36 +510,24 @@ impl TryFrom for NoUnusedVarsOptions { Ok(Self { vars, ..Default::default() }) } Value::Object(config) => { - let vars = config - .get("vars") - .map(|vars| { - vars.try_into() - }) - .transpose()? - .unwrap_or_default(); + let vars = + config.get("vars").map(|vars| vars.try_into()).transpose()?.unwrap_or_default(); // NOTE: when a configuration object is provided, do not provide // a default ignore pattern here. They've opted into configuring // this rule, and we'll give them full control over it. - let vars_ignore_pattern= + let vars_ignore_pattern = parse_unicode_rule(config.get("varsIgnorePattern"), "varsIgnorePattern"); - let args: ArgsOption = config - .get("args") - .map(|args| { - args.try_into() - }) - .transpose()? - .unwrap_or_default(); + let args: ArgsOption = + config.get("args").map(|args| args.try_into()).transpose()?.unwrap_or_default(); - let args_ignore_pattern = + let args_ignore_pattern = parse_unicode_rule(config.get("argsIgnorePattern"), "argsIgnorePattern"); let caught_errors: CaughtErrors = config .get("caughtErrors") - .map(|caught_errors| { - caught_errors.try_into() - }) + .map(|caught_errors| caught_errors.try_into()) .transpose()? .unwrap_or_default(); @@ -582,7 +571,7 @@ impl TryFrom for NoUnusedVarsOptions { } Value::Null => Ok(Self::default()), _ => Err(OxcDiagnostic::error( - "Invalid 'vars' option for no-unused-vars: Expected a string or an object, got {config}" + "Invalid 'vars' option for no-unused-vars: Expected a string or an object, got {config}", )), } } 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 6135b1706dcfcd..e32393dabe5497 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 @@ -52,10 +52,7 @@ fn test() { }", None, ), - ( - "for (let prop in box) { box[prop] = parseInt(box[prop]); }", - None, - ), // { "ecmaVersion": 6 }, + ("for (let prop in box) { box[prop] = parseInt(box[prop]); }", None), // { "ecmaVersion": 6 }, ( "var box = {a: 2}; for (var prop in box) { 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 c4ff0c45fdfb15..1e2123c79066df 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 @@ -583,7 +583,7 @@ fn test_functions() { console.log(message, interpolations); } ", - "declare function func(strings: any, ...values: any[]): object" + "declare function func(strings: any, ...values: any[]): object", ]; let fail = vec![ diff --git a/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs b/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs index 18bd8a700b97e1..187d8d8f34ddc8 100644 --- a/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs +++ b/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs @@ -324,6 +324,7 @@ impl<'a> Visit<'a> for UselessEscapeFinder<'a> { self.character_classes.push(class); } } + fn leave_node(&mut self, kind: RegExpAstKind<'a>) { if let RegExpAstKind::CharacterClass(_) = kind { self.character_classes.pop(); @@ -566,9 +567,9 @@ fn test() { // spellchecker:on // Carets r"/[^\^]/", - r"/[^\^]/u", // { "ecmaVersion": 2015 }, + r"/[^\^]/u", // { "ecmaVersion": 2015 }, // ES2024 - r"/[\$]/v", // { "ecmaVersion": 2024 }, + r"/[\$]/v", // { "ecmaVersion": 2024 }, r"/[\&\&]/v", // { "ecmaVersion": 2024 }, r"/[\!\!]/v", // { "ecmaVersion": 2024 }, r"/[\#\#]/v", // { "ecmaVersion": 2024 }, @@ -584,17 +585,17 @@ fn test() { r"/[\>\>]/v", // { "ecmaVersion": 2024 }, r"/[\?\?]/v", // { "ecmaVersion": 2024 }, r"/[\@\@]/v", // { "ecmaVersion": 2024 }, - "/[\\`\\`]/v", // { "ecmaVersion": 2024 }, + "/[\\`\\`]/v", // { "ecmaVersion": 2024 }, r"/[\~\~]/v", // { "ecmaVersion": 2024 }, r"/[^\^\^]/v", // { "ecmaVersion": 2024 }, r"/[_\^\^]/v", // { "ecmaVersion": 2024 }, - r"/[\&\&&\&]/v", // { "ecmaVersion": 2024 }, + r"/[\&\&&\&]/v", // { "ecmaVersion": 2024 }, r"/[\p{ASCII}--\.]/v", // { "ecmaVersion": 2024 }, r"/[\p{ASCII}&&\.]/v", // { "ecmaVersion": 2024 }, - r"/[\.--[.&]]/v", // { "ecmaVersion": 2024 }, - r"/[\.&&[.&]]/v", // { "ecmaVersion": 2024 }, - r"/[\.--\.--\.]/v", // { "ecmaVersion": 2024 }, - r"/[\.&&\.&&\.]/v", // { "ecmaVersion": 2024 }, + r"/[\.--[.&]]/v", // { "ecmaVersion": 2024 }, + r"/[\.&&[.&]]/v", // { "ecmaVersion": 2024 }, + r"/[\.--\.--\.]/v", // { "ecmaVersion": 2024 }, + r"/[\.&&\.&&\.]/v", // { "ecmaVersion": 2024 }, r"/[[\.&]--[\.&]]/v", // { "ecmaVersion": 2024 }, r"/[[\.&]&&[\.&]]/v", // { "ecmaVersion": 2024 } ]; diff --git a/crates/oxc_linter/src/rules/eslint/sort_keys.rs b/crates/oxc_linter/src/rules/eslint/sort_keys.rs index b2641c0ca58a2d..d60a741e121504 100644 --- a/crates/oxc_linter/src/rules/eslint/sort_keys.rs +++ b/crates/oxc_linter/src/rules/eslint/sort_keys.rs @@ -1,11 +1,8 @@ -use std::cmp::Ordering; -use std::str::Chars; +use std::{cmp::Ordering, str::Chars}; use cow_utils::CowUtils; use itertools::all; - -use oxc_ast::ast::ObjectPropertyKind; -use oxc_ast::AstKind; +use oxc_ast::{ast::ObjectPropertyKind, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::{GetSpan, Span}; @@ -129,6 +126,7 @@ impl Rule for SortKeys { allow_line_separated_groups, })) } + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { if let AstKind::ObjectExpression(dec) = node.kind() { if dec.properties.len() < self.min_keys { @@ -220,18 +218,18 @@ fn natural_sort(arr: &mut [String]) { (Some(a_char), Some(b_char)) if a_char.is_alphanumeric() && !b_char.is_alphanumeric() => { - return Ordering::Greater + return Ordering::Greater; } (Some(a_char), Some(b_char)) if !a_char.is_alphanumeric() && b_char.is_alphanumeric() => { - return Ordering::Less + return Ordering::Less; } (Some(a_char), Some(b_char)) if a_char == '[' && b_char.is_alphanumeric() => { - return Ordering::Greater + return Ordering::Greater; } (Some(a_char), Some(b_char)) if a_char.is_alphanumeric() && b_char == '[' => { - return Ordering::Less + return Ordering::Less; } (Some(a_char), Some(b_char)) => return a_char.cmp(&b_char), (None, None) => return Ordering::Equal, diff --git a/crates/oxc_linter/src/rules/import/export.rs b/crates/oxc_linter/src/rules/import/export.rs index 96f87fb7d31ec0..df7d50e87b1df7 100644 --- a/crates/oxc_linter/src/rules/import/export.rs +++ b/crates/oxc_linter/src/rules/import/export.rs @@ -1,10 +1,9 @@ use std::path::PathBuf; -use rustc_hash::{FxHashMap, FxHashSet}; - use oxc_diagnostics::{LabeledSpan, OxcDiagnostic}; use oxc_macros::declare_oxc_lint; use oxc_span::{CompactStr, Span}; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{context::LintContext, rule::Rule, ModuleRecord}; diff --git a/crates/oxc_linter/src/rules/import/first.rs b/crates/oxc_linter/src/rules/import/first.rs index 70672c689e22bd..7c14a659448427 100644 --- a/crates/oxc_linter/src/rules/import/first.rs +++ b/crates/oxc_linter/src/rules/import/first.rs @@ -1,3 +1,5 @@ +use std::convert::From; + use oxc_ast::{ ast::{Statement, TSModuleReference}, AstKind, @@ -5,7 +7,6 @@ use oxc_ast::{ use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::Span; -use std::convert::From; use crate::{context::LintContext, rule::Rule}; diff --git a/crates/oxc_linter/src/rules/import/no_commonjs.rs b/crates/oxc_linter/src/rules/import/no_commonjs.rs index b9b16eb12a3c56..71ea54a0d669cb 100644 --- a/crates/oxc_linter/src/rules/import/no_commonjs.rs +++ b/crates/oxc_linter/src/rules/import/no_commonjs.rs @@ -1,11 +1,10 @@ -use oxc_diagnostics::OxcDiagnostic; -use oxc_macros::declare_oxc_lint; -use oxc_span::{GetSpan, Span}; - use oxc_ast::{ ast::{Argument, Expression}, AstKind, }; +use oxc_diagnostics::OxcDiagnostic; +use oxc_macros::declare_oxc_lint; +use oxc_span::{GetSpan, Span}; use crate::{context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/rules/import/no_namespace.rs b/crates/oxc_linter/src/rules/import/no_namespace.rs index 165a57d9ac8b6c..51eb1593312986 100644 --- a/crates/oxc_linter/src/rules/import/no_namespace.rs +++ b/crates/oxc_linter/src/rules/import/no_namespace.rs @@ -1,6 +1,5 @@ use fast_glob::glob_match; use oxc_diagnostics::OxcDiagnostic; - use oxc_macros::declare_oxc_lint; use oxc_span::{CompactStr, Span}; diff --git a/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs b/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs index 1566bd185866b6..4271ce04acc6d3 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs @@ -1,6 +1,4 @@ use lazy_static::lazy_static; -use phf::phf_map; - use oxc_ast::{ ast::{JSXAttributeItem, JSXAttributeValue}, AstKind, @@ -8,6 +6,7 @@ use oxc_ast::{ use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::Span; +use phf::phf_map; use crate::{ context::LintContext, diff --git a/crates/oxc_linter/src/rules/oxc/no_map_spread.rs b/crates/oxc_linter/src/rules/oxc/no_map_spread.rs index 73a6d89a268d53..54b839e6b3d366 100644 --- a/crates/oxc_linter/src/rules/oxc/no_map_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_map_spread.rs @@ -1,5 +1,3 @@ -use oxc_semantic::{ReferenceId, ScopeId, SymbolId}; -use serde::{Deserialize, Serialize}; use std::ops::Deref; use oxc_ast::{ @@ -11,7 +9,9 @@ use oxc_ast::{ }; use oxc_diagnostics::{LabeledSpan, OxcDiagnostic}; use oxc_macros::declare_oxc_lint; +use oxc_semantic::{ReferenceId, ScopeId, SymbolId}; use oxc_span::{GetSpan, Span}; +use serde::{Deserialize, Serialize}; use crate::{ ast_util::{is_method_call, leftmost_identifier_reference}, @@ -726,9 +726,10 @@ where #[test] fn test() { - use crate::tester::Tester; use serde_json::json; + use crate::tester::Tester; + let pass = vec![ ("let a = b.map(x => x)", None), ("let b = []; let a = b.map(x => ({ ...x })); console.log(b)", None), diff --git a/crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs b/crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs index cda25c1ef3b83e..92ad7887180c8e 100644 --- a/crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs +++ b/crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs @@ -1,11 +1,9 @@ -use oxc_ast::ast::FormalParameters; -use oxc_ast::AstKind; +use oxc_ast::{ast::FormalParameters, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::{GetSpan, Span}; -use crate::utils::is_promise; -use crate::{context::LintContext, rule::Rule, AstNode}; +use crate::{context::LintContext, rule::Rule, utils::is_promise, AstNode}; fn no_promise_in_callback_diagnostic(span: Span) -> OxcDiagnostic { OxcDiagnostic::warn("Avoid using promises inside of callbacks.") diff --git a/crates/oxc_linter/src/rules/react/exhaustive_deps.rs b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs index 826598796ea41f..08531b72a3acf2 100644 --- a/crates/oxc_linter/src/rules/react/exhaustive_deps.rs +++ b/crates/oxc_linter/src/rules/react/exhaustive_deps.rs @@ -1,11 +1,6 @@ -use itertools::Itertools; -use oxc_semantic::{ReferenceId, ScopeId, Semantic, SymbolId}; -use oxc_span::GetSpan; -use rustc_hash::FxHashSet; use std::hash::Hash; -use oxc_diagnostics::OxcDiagnostic; - +use itertools::Itertools; use oxc_ast::{ ast::{ Argument, ArrayExpressionElement, ArrowFunctionExpression, BindingPatternKind, @@ -16,9 +11,12 @@ use oxc_ast::{ visit::walk::walk_function_body, AstKind, Visit, }; +use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::{Atom, Span}; +use oxc_semantic::{ReferenceId, ScopeId, Semantic, SymbolId}; +use oxc_span::{Atom, GetSpan, Span}; use phf::phf_set; +use rustc_hash::FxHashSet; use crate::{ ast_util::{ @@ -1001,6 +999,7 @@ impl<'a> Visit<'a> for ExhaustiveDepsVisitor<'a, '_> { fn enter_node(&mut self, kind: AstKind<'a>) { self.stack.push(kind); } + fn leave_node(&mut self, _kind: AstKind<'a>) { self.stack.pop(); } @@ -1008,9 +1007,11 @@ impl<'a> Visit<'a> for ExhaustiveDepsVisitor<'a, '_> { fn visit_ts_type_annotation(&mut self, _it: &oxc_ast::ast::TSTypeAnnotation<'a>) { // noop } + fn visit_ts_type_reference(&mut self, _it: &oxc_ast::ast::TSTypeReference<'a>) { // noop } + fn visit_ts_type_parameters( &mut self, _it: &oxc_allocator::Vec<'a, oxc_ast::ast::TSTypeParameter<'a>>, diff --git a/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs b/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs index 82cdf42ffb8890..7d3ec3b0fe6515 100644 --- a/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs +++ b/crates/oxc_linter/src/rules/react/iframe_missing_sandbox.rs @@ -1,16 +1,22 @@ -use oxc_ast::ast::{ - Argument, Expression, JSXAttributeItem, JSXAttributeValue, JSXElementName, ObjectProperty, - ObjectPropertyKind, StringLiteral, +use oxc_ast::{ + ast::{ + Argument, Expression, JSXAttributeItem, JSXAttributeValue, JSXElementName, ObjectProperty, + ObjectPropertyKind, StringLiteral, + }, + AstKind, }; -use oxc_ast::AstKind; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::Span; use phf::{phf_set, Set}; -use crate::ast_util::is_method_call; -use crate::utils::{get_prop_value, has_jsx_prop_ignore_case, is_create_element_call}; -use crate::{context::LintContext, rule::Rule, AstNode}; +use crate::{ + ast_util::is_method_call, + context::LintContext, + rule::Rule, + utils::{get_prop_value, has_jsx_prop_ignore_case, is_create_element_call}, + AstNode, +}; fn missing_sandbox_prop(span: Span) -> OxcDiagnostic { OxcDiagnostic::warn("An iframe element is missing a sandbox attribute") diff --git a/crates/oxc_linter/src/rules/react/jsx_no_script_url.rs b/crates/oxc_linter/src/rules/react/jsx_no_script_url.rs index 1c8be8295afa9b..963866ab240ff3 100644 --- a/crates/oxc_linter/src/rules/react/jsx_no_script_url.rs +++ b/crates/oxc_linter/src/rules/react/jsx_no_script_url.rs @@ -1,8 +1,5 @@ -use crate::context::ContextHost; -use crate::{context::LintContext, rule::Rule, AstNode}; use lazy_static::lazy_static; -use oxc_ast::ast::JSXAttributeItem; -use oxc_ast::AstKind; +use oxc_ast::{ast::JSXAttributeItem, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::{CompactStr, GetSpan, Span}; @@ -10,6 +7,12 @@ use regex::Regex; use rustc_hash::FxHashMap; use serde_json::Value; +use crate::{ + context::{ContextHost, LintContext}, + rule::Rule, + AstNode, +}; + fn jsx_no_script_url_diagnostic(span: Span) -> OxcDiagnostic { // See for details OxcDiagnostic::warn("A future version of React will block javascript: URLs as a security precaution.") diff --git a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs index 05587b7c8ff269..12c1bc5f91fe6f 100644 --- a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs +++ b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use oxc_ast::{ ast::{TSInterfaceDeclaration, TSTypeLiteral}, AstKind, @@ -6,7 +8,6 @@ use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::NodeId; use oxc_span::Span; -use std::borrow::Cow; use crate::{context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/rules/typescript/no_inferrable_types.rs b/crates/oxc_linter/src/rules/typescript/no_inferrable_types.rs index 1bee690328d3e5..8f0b5c8b9cd516 100644 --- a/crates/oxc_linter/src/rules/typescript/no_inferrable_types.rs +++ b/crates/oxc_linter/src/rules/typescript/no_inferrable_types.rs @@ -1,4 +1,3 @@ -use crate::{context::LintContext, rule::Rule, AstNode}; use oxc_ast::{ ast::{ BindingPatternKind, ChainElement, Expression, FormalParameter, TSLiteral, TSType, @@ -8,8 +7,9 @@ use oxc_ast::{ }; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_span::GetSpan; -use oxc_span::Span; +use oxc_span::{GetSpan, Span}; + +use crate::{context::LintContext, rule::Rule, AstNode}; fn no_inferrable_types_diagnostic(span: Span) -> OxcDiagnostic { OxcDiagnostic::warn("Type can be trivially inferred from the initializer") diff --git a/crates/oxc_linter/src/rules/typescript/no_require_imports.rs b/crates/oxc_linter/src/rules/typescript/no_require_imports.rs index 3ac6fb4e07df5a..8f8b296fc7b455 100644 --- a/crates/oxc_linter/src/rules/typescript/no_require_imports.rs +++ b/crates/oxc_linter/src/rules/typescript/no_require_imports.rs @@ -2,12 +2,11 @@ use oxc_ast::{ ast::{Argument, TSModuleReference}, AstKind, }; -use oxc_semantic::IsGlobalReference; -use regex::Regex; - use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; +use oxc_semantic::IsGlobalReference; use oxc_span::{CompactStr, Span}; +use regex::Regex; use crate::{context::LintContext, rule::Rule, AstNode}; diff --git a/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs b/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs index d05d4e6d957f12..fcc62fe66bb92b 100644 --- a/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs +++ b/crates/oxc_linter/src/rules/unicorn/consistent_existence_index_check.rs @@ -2,7 +2,6 @@ use oxc_ast::{ ast::{BinaryOperator, Expression, UnaryOperator, VariableDeclarationKind}, AstKind, }; - use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_semantic::AstNode; 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 c6b73acc93e0d6..90e8d636e0e9da 100644 --- a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs +++ b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs @@ -642,7 +642,7 @@ fn test() { function outer() { inner = function inner() {} - }", + }", None, ), // end of cases that eslint-plugin-unicorn passes, but we fail. diff --git a/crates/oxc_linter/src/rules/vitest/prefer_to_be_falsy.rs b/crates/oxc_linter/src/rules/vitest/prefer_to_be_falsy.rs index 5d129057e072bf..4d658851a5d88d 100644 --- a/crates/oxc_linter/src/rules/vitest/prefer_to_be_falsy.rs +++ b/crates/oxc_linter/src/rules/vitest/prefer_to_be_falsy.rs @@ -1,8 +1,7 @@ use oxc_macros::declare_oxc_lint; -use crate::{context::LintContext, rule::Rule}; - use super::prefer_to_be_truthy::prefer_to_be_simply_bool; +use crate::{context::LintContext, rule::Rule}; #[derive(Debug, Default, Clone)] pub struct PreferToBeFalsy; diff --git a/crates/oxc_linter/src/rules/vitest/prefer_to_be_truthy.rs b/crates/oxc_linter/src/rules/vitest/prefer_to_be_truthy.rs index d15d8f6b933654..17ed20b06f2a9c 100644 --- a/crates/oxc_linter/src/rules/vitest/prefer_to_be_truthy.rs +++ b/crates/oxc_linter/src/rules/vitest/prefer_to_be_truthy.rs @@ -2,7 +2,9 @@ use oxc_ast::{ ast::{Argument, Expression}, AstKind, }; +use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; +use oxc_span::Span; use crate::{ context::LintContext, @@ -10,9 +12,6 @@ use crate::{ utils::{is_equality_matcher, parse_expect_and_typeof_vitest_fn_call, PossibleJestNode}, }; -use oxc_diagnostics::OxcDiagnostic; -use oxc_span::Span; - pub fn prefer_to_be_simply_bool<'a>( possible_vitest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>, diff --git a/crates/oxc_linter/src/service/mod.rs b/crates/oxc_linter/src/service/mod.rs index b9b6726c8d749b..991c5b2656872f 100644 --- a/crates/oxc_linter/src/service/mod.rs +++ b/crates/oxc_linter/src/service/mod.rs @@ -8,11 +8,10 @@ use std::{ use oxc_diagnostics::DiagnosticSender; use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; +use runtime::Runtime; use crate::Linter; -use runtime::Runtime; - pub struct LintServiceOptions { /// Current working directory cwd: Box, diff --git a/crates/oxc_linter/src/service/runtime.rs b/crates/oxc_linter/src/service/runtime.rs index 8014df9f582fcf..28231c73789b4d 100644 --- a/crates/oxc_linter/src/service/runtime.rs +++ b/crates/oxc_linter/src/service/runtime.rs @@ -7,16 +7,19 @@ use std::{ sync::Arc, }; -use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; -use rustc_hash::FxHashSet; - use oxc_allocator::Allocator; use oxc_diagnostics::{DiagnosticSender, DiagnosticService, Error, OxcDiagnostic}; use oxc_parser::{ParseOptions, Parser}; use oxc_resolver::Resolver; use oxc_semantic::SemanticBuilder; use oxc_span::{SourceType, VALID_EXTENSIONS}; +use rayon::{iter::ParallelBridge, prelude::ParallelIterator}; +use rustc_hash::FxHashSet; +use super::{ + module_cache::{ModuleCache, ModuleState}, + LintServiceOptions, +}; use crate::{ loader::{JavaScriptSource, PartialLoader, LINT_PARTIAL_LOADER_EXT}, module_record::ModuleRecord, @@ -24,11 +27,6 @@ use crate::{ Fixer, Linter, Message, }; -use super::{ - module_cache::{ModuleCache, ModuleState}, - LintServiceOptions, -}; - pub struct Runtime { cwd: Box, /// All paths to lint diff --git a/crates/oxc_linter/src/tester.rs b/crates/oxc_linter/src/tester.rs index fb619fc225d85d..ff2e789779d26b 100644 --- a/crates/oxc_linter/src/tester.rs +++ b/crates/oxc_linter/src/tester.rs @@ -407,7 +407,12 @@ impl Tester { // If auto-fixes are reported, make sure some fix test cases are provided let rule = self.find_rule(); let Some(fix_test_cases) = self.expect_fix.clone() else { - assert!(!rule.fix().has_fix(), "'{}/{}' reports that it can auto-fix violations, but no fix cases were provided. Please add fixer test cases with `tester.expect_fix()`", rule.plugin_name(), rule.name()); + assert!( + !rule.fix().has_fix(), + "'{}/{}' reports that it can auto-fix violations, but no fix cases were provided. Please add fixer test cases with `tester.expect_fix()`", + rule.plugin_name(), + rule.name() + ); return; }; diff --git a/crates/oxc_minifier/src/ast_passes/mod.rs b/crates/oxc_minifier/src/ast_passes/mod.rs index 1db4468f53b544..49c5d13fe83143 100644 --- a/crates/oxc_minifier/src/ast_passes/mod.rs +++ b/crates/oxc_minifier/src/ast_passes/mod.rs @@ -10,6 +10,9 @@ mod statement_fusion; pub use collapse_variable_declarations::CollapseVariableDeclarations; pub use exploit_assigns::ExploitAssigns; +use oxc_allocator::Vec; +use oxc_ast::ast::*; +use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx}; pub use peephole_fold_constants::PeepholeFoldConstants; pub use peephole_minimize_conditions::PeepholeMinimizeConditions; pub use peephole_remove_dead_code::PeepholeRemoveDeadCode; @@ -18,10 +21,6 @@ pub use peephole_substitute_alternate_syntax::PeepholeSubstituteAlternateSyntax; pub use remove_syntax::RemoveSyntax; pub use statement_fusion::StatementFusion; -use oxc_allocator::Vec; -use oxc_ast::ast::*; -use oxc_traverse::{traverse_mut_with_ctx, ReusableTraverseCtx, Traverse, TraverseCtx}; - pub trait CompressorPass<'a>: Traverse<'a> { fn build(&mut self, program: &mut Program<'a>, ctx: &mut ReusableTraverseCtx<'a>); } diff --git a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs index 7213b31fad2fd8..06fb924a887db0 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs @@ -260,7 +260,7 @@ impl<'a, 'b> PeepholeFoldConstants { | BinaryOperator::GreaterThan | BinaryOperator::LessEqualThan | BinaryOperator::GreaterEqualThan => { - return ctx.eval_binary_expression(e).map(|v| ctx.value_to_expr(e.span, v)) + return ctx.eval_binary_expression(e).map(|v| ctx.value_to_expr(e.span, v)); } BinaryOperator::Equality => Self::try_abstract_equality_comparison(left, right, ctx), BinaryOperator::Inequality => { diff --git a/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs b/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs index 26719d224b179d..55a1dd10f45958 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs @@ -4,8 +4,7 @@ use oxc_ecmascript::constant_evaluation::{ConstantEvaluation, IsLiteralValue}; use oxc_span::SPAN; use oxc_traverse::{traverse_mut_with_ctx, Ancestor, ReusableTraverseCtx, Traverse, TraverseCtx}; -use crate::node_util::Ctx; -use crate::{keep_var::KeepVar, CompressorPass}; +use crate::{keep_var::KeepVar, node_util::Ctx, CompressorPass}; /// Remove Dead Code from the AST. /// diff --git a/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs b/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs index dde3a40b3f821a..8da3dfe56a8ab7 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_replace_known_methods.rs @@ -216,6 +216,7 @@ impl PeepholeReplaceKnownMethods { #[expect(clippy::cast_lossless)] Some(ctx.ast.expression_numeric_literal(span, result as f64, None, NumberBase::Decimal)) } + fn try_fold_string_replace_or_string_replace_all<'a>( span: Span, call_expr: &CallExpression<'a>, diff --git a/crates/oxc_minifier/src/node_util/mod.rs b/crates/oxc_minifier/src/node_util/mod.rs index db2c93098cd1a2..a3c62f6d084808 100644 --- a/crates/oxc_minifier/src/node_util/mod.rs +++ b/crates/oxc_minifier/src/node_util/mod.rs @@ -10,6 +10,7 @@ pub struct Ctx<'a, 'b>(pub &'b TraverseCtx<'a>); impl<'a, 'b> Deref for Ctx<'a, 'b> { type Target = &'b TraverseCtx<'a>; + fn deref(&self) -> &Self::Target { &self.0 } diff --git a/crates/oxc_minifier/src/tester.rs b/crates/oxc_minifier/src/tester.rs index e0bcd85d5d8000..0ae6dcaa875d02 100644 --- a/crates/oxc_minifier/src/tester.rs +++ b/crates/oxc_minifier/src/tester.rs @@ -5,7 +5,10 @@ use oxc_semantic::SemanticBuilder; use oxc_span::SourceType; use oxc_traverse::ReusableTraverseCtx; -use crate::{ast_passes::CompressorPass, ast_passes::RemoveSyntax, CompressOptions}; +use crate::{ + ast_passes::{CompressorPass, RemoveSyntax}, + CompressOptions, +}; pub fn test<'a, P: CompressorPass<'a>>( allocator: &'a Allocator, diff --git a/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs b/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs index f366e3fc60ae0a..666b1faae585bb 100644 --- a/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs +++ b/crates/oxc_minifier/tests/ast_passes/dead_code_elimination.rs @@ -1,5 +1,4 @@ use cow_utils::CowUtils; - use oxc_minifier::CompressOptions; fn test(source_text: &str, expected: &str) { diff --git a/crates/oxc_napi/src/lib.rs b/crates/oxc_napi/src/lib.rs index db11f25eb7a5c0..aacf4770b12c81 100644 --- a/crates/oxc_napi/src/lib.rs +++ b/crates/oxc_napi/src/lib.rs @@ -1,5 +1,4 @@ use napi_derive::napi; - use oxc_diagnostics::{LabeledSpan, OxcDiagnostic}; #[napi(object)] diff --git a/crates/oxc_parser/src/lexer/trivia_builder.rs b/crates/oxc_parser/src/lexer/trivia_builder.rs index ec1df541d8494e..1bf2705924a60e 100644 --- a/crates/oxc_parser/src/lexer/trivia_builder.rs +++ b/crates/oxc_parser/src/lexer/trivia_builder.rs @@ -132,11 +132,12 @@ impl TriviaBuilder { #[cfg(test)] mod test { - use crate::Parser; use oxc_allocator::Allocator; use oxc_ast::{Comment, CommentKind, CommentPosition}; use oxc_span::{SourceType, Span}; + use crate::Parser; + fn get_comments(source_text: &str) -> Vec { let allocator = Allocator::default(); let source_type = SourceType::default(); diff --git a/crates/oxc_parser/src/state.rs b/crates/oxc_parser/src/state.rs index bb8e193ce94263..463a90232c9a35 100644 --- a/crates/oxc_parser/src/state.rs +++ b/crates/oxc_parser/src/state.rs @@ -1,6 +1,5 @@ -use rustc_hash::{FxHashMap, FxHashSet}; - use oxc_ast::ast::{AssignmentExpression, Decorator}; +use rustc_hash::{FxHashMap, FxHashSet}; #[derive(Default)] pub struct ParserState<'a> { diff --git a/crates/oxc_prettier/src/comments/print.rs b/crates/oxc_prettier/src/comments/print.rs index 317f70c7d1c116..1c6b2c2ff2ece0 100644 --- a/crates/oxc_prettier/src/comments/print.rs +++ b/crates/oxc_prettier/src/comments/print.rs @@ -1,9 +1,8 @@ use oxc_allocator::Vec; use oxc_span::Span; -use crate::{ir::Doc, Prettier}; - use super::{CommentFlags, DanglingCommentsPrintOptions}; +use crate::{ir::Doc, Prettier}; impl<'a> Prettier<'a> { #[must_use] diff --git a/crates/oxc_prettier/src/needs_parens.rs b/crates/oxc_prettier/src/needs_parens.rs index d37981da018974..5931d5e12b3726 100644 --- a/crates/oxc_prettier/src/needs_parens.rs +++ b/crates/oxc_prettier/src/needs_parens.rs @@ -394,7 +394,7 @@ impl<'a> Prettier<'a> { let parent_kind = self.parent_kind(); match parent_kind { AstKind::TSAsExpression(_) | AstKind::TSSatisfiesExpression(_) => { - return !self.is_binary_cast_expression(span) + return !self.is_binary_cast_expression(span); } AstKind::ConditionalExpression(_) => return self.is_binary_cast_expression(span), AstKind::NewExpression(new_expr) => return new_expr.callee.span() == span, diff --git a/crates/oxc_regular_expression/src/ast_impl/display.rs b/crates/oxc_regular_expression/src/ast_impl/display.rs index 444476ac18d94f..e33806c2f55045 100644 --- a/crates/oxc_regular_expression/src/ast_impl/display.rs +++ b/crates/oxc_regular_expression/src/ast_impl/display.rs @@ -4,8 +4,10 @@ use std::{ iter::Peekable, }; -use crate::ast::*; -use crate::surrogate_pair::{combine_surrogate_pair, is_lead_surrogate, is_trail_surrogate}; +use crate::{ + ast::*, + surrogate_pair::{combine_surrogate_pair, is_lead_surrogate, is_trail_surrogate}, +}; impl Display for Pattern<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -410,9 +412,10 @@ where #[cfg(test)] mod test { - use crate::{LiteralParser, Options}; use oxc_allocator::Allocator; + use crate::{LiteralParser, Options}; + type Case<'a> = ( &'a str, /* expected display, None means expect the same as original */ Option<&'a str>, diff --git a/crates/oxc_regular_expression/src/ast_impl/visit.rs b/crates/oxc_regular_expression/src/ast_impl/visit.rs index a3b6ea052a56e8..492618f2cbc8d3 100644 --- a/crates/oxc_regular_expression/src/ast_impl/visit.rs +++ b/crates/oxc_regular_expression/src/ast_impl/visit.rs @@ -2,7 +2,7 @@ // But like `oxc_ast`, this should be generated by `tasks/ast_tools` in the future. use oxc_span::{GetSpan, Span}; -use walk::walk_pattern; +use walk::{walk_pattern, *}; use crate::ast::{ Alternative, BoundaryAssertion, CapturingGroup, Character, CharacterClass, @@ -10,7 +10,6 @@ use crate::ast::{ ClassStringDisjunction, Disjunction, Dot, IgnoreGroup, IndexedReference, LookAroundAssertion, NamedReference, Pattern, Quantifier, Term, UnicodePropertyEscape, }; -use walk::*; #[derive(Copy, Clone, Debug)] pub enum RegExpAstKind<'a> { diff --git a/crates/oxc_regular_expression/src/generated/derive_clone_in.rs b/crates/oxc_regular_expression/src/generated/derive_clone_in.rs index 62f9e4ef10fde6..ba9b2e1ac9c089 100644 --- a/crates/oxc_regular_expression/src/generated/derive_clone_in.rs +++ b/crates/oxc_regular_expression/src/generated/derive_clone_in.rs @@ -9,6 +9,7 @@ use crate::ast::*; impl<'new_alloc> CloneIn<'new_alloc> for Pattern<'_> { type Cloned = Pattern<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { Pattern { span: CloneIn::clone_in(&self.span, allocator), @@ -19,6 +20,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Pattern<'_> { impl<'new_alloc> CloneIn<'new_alloc> for Disjunction<'_> { type Cloned = Disjunction<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { Disjunction { span: CloneIn::clone_in(&self.span, allocator), @@ -29,6 +31,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Disjunction<'_> { impl<'new_alloc> CloneIn<'new_alloc> for Alternative<'_> { type Cloned = Alternative<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { Alternative { span: CloneIn::clone_in(&self.span, allocator), @@ -39,6 +42,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Alternative<'_> { impl<'new_alloc> CloneIn<'new_alloc> for Term<'_> { type Cloned = Term<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { match self { Self::BoundaryAssertion(it) => { @@ -67,6 +71,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Term<'_> { impl<'alloc> CloneIn<'alloc> for BoundaryAssertion { type Cloned = BoundaryAssertion; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { BoundaryAssertion { span: CloneIn::clone_in(&self.span, allocator), @@ -77,6 +82,7 @@ impl<'alloc> CloneIn<'alloc> for BoundaryAssertion { impl<'alloc> CloneIn<'alloc> for BoundaryAssertionKind { type Cloned = BoundaryAssertionKind; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Start => BoundaryAssertionKind::Start, @@ -89,6 +95,7 @@ impl<'alloc> CloneIn<'alloc> for BoundaryAssertionKind { impl<'new_alloc> CloneIn<'new_alloc> for LookAroundAssertion<'_> { type Cloned = LookAroundAssertion<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { LookAroundAssertion { span: CloneIn::clone_in(&self.span, allocator), @@ -100,6 +107,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for LookAroundAssertion<'_> { impl<'alloc> CloneIn<'alloc> for LookAroundAssertionKind { type Cloned = LookAroundAssertionKind; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Lookahead => LookAroundAssertionKind::Lookahead, @@ -112,6 +120,7 @@ impl<'alloc> CloneIn<'alloc> for LookAroundAssertionKind { impl<'new_alloc> CloneIn<'new_alloc> for Quantifier<'_> { type Cloned = Quantifier<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { Quantifier { span: CloneIn::clone_in(&self.span, allocator), @@ -125,6 +134,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for Quantifier<'_> { impl<'alloc> CloneIn<'alloc> for Character { type Cloned = Character; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { Character { span: CloneIn::clone_in(&self.span, allocator), @@ -136,6 +146,7 @@ impl<'alloc> CloneIn<'alloc> for Character { impl<'alloc> CloneIn<'alloc> for CharacterKind { type Cloned = CharacterKind; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::ControlLetter => CharacterKind::ControlLetter, @@ -154,6 +165,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterKind { impl<'alloc> CloneIn<'alloc> for CharacterClassEscape { type Cloned = CharacterClassEscape; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { CharacterClassEscape { span: CloneIn::clone_in(&self.span, allocator), @@ -164,6 +176,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassEscape { impl<'alloc> CloneIn<'alloc> for CharacterClassEscapeKind { type Cloned = CharacterClassEscapeKind; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::D => CharacterClassEscapeKind::D, @@ -178,6 +191,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassEscapeKind { impl<'new_alloc> CloneIn<'new_alloc> for UnicodePropertyEscape<'_> { type Cloned = UnicodePropertyEscape<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { UnicodePropertyEscape { span: CloneIn::clone_in(&self.span, allocator), @@ -191,6 +205,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for UnicodePropertyEscape<'_> { impl<'alloc> CloneIn<'alloc> for Dot { type Cloned = Dot; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { Dot { span: CloneIn::clone_in(&self.span, allocator) } } @@ -198,6 +213,7 @@ impl<'alloc> CloneIn<'alloc> for Dot { impl<'new_alloc> CloneIn<'new_alloc> for CharacterClass<'_> { type Cloned = CharacterClass<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { CharacterClass { span: CloneIn::clone_in(&self.span, allocator), @@ -211,6 +227,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for CharacterClass<'_> { impl<'alloc> CloneIn<'alloc> for CharacterClassContentsKind { type Cloned = CharacterClassContentsKind; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Union => CharacterClassContentsKind::Union, @@ -222,6 +239,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassContentsKind { impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassContents<'_> { type Cloned = CharacterClassContents<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { match self { Self::CharacterClassRange(it) => { @@ -248,6 +266,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassContents<'_> { impl<'alloc> CloneIn<'alloc> for CharacterClassRange { type Cloned = CharacterClassRange; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { CharacterClassRange { span: CloneIn::clone_in(&self.span, allocator), @@ -259,6 +278,7 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassRange { impl<'new_alloc> CloneIn<'new_alloc> for ClassStringDisjunction<'_> { type Cloned = ClassStringDisjunction<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { ClassStringDisjunction { span: CloneIn::clone_in(&self.span, allocator), @@ -270,6 +290,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for ClassStringDisjunction<'_> { impl<'new_alloc> CloneIn<'new_alloc> for ClassString<'_> { type Cloned = ClassString<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { ClassString { span: CloneIn::clone_in(&self.span, allocator), @@ -281,6 +302,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for ClassString<'_> { impl<'new_alloc> CloneIn<'new_alloc> for CapturingGroup<'_> { type Cloned = CapturingGroup<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { CapturingGroup { span: CloneIn::clone_in(&self.span, allocator), @@ -292,6 +314,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for CapturingGroup<'_> { impl<'new_alloc> CloneIn<'new_alloc> for IgnoreGroup<'_> { type Cloned = IgnoreGroup<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { IgnoreGroup { span: CloneIn::clone_in(&self.span, allocator), @@ -303,6 +326,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for IgnoreGroup<'_> { impl<'alloc> CloneIn<'alloc> for Modifiers { type Cloned = Modifiers; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { Modifiers { span: CloneIn::clone_in(&self.span, allocator), @@ -314,6 +338,7 @@ impl<'alloc> CloneIn<'alloc> for Modifiers { impl<'alloc> CloneIn<'alloc> for Modifier { type Cloned = Modifier; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { Modifier { ignore_case: CloneIn::clone_in(&self.ignore_case, allocator), @@ -325,6 +350,7 @@ impl<'alloc> CloneIn<'alloc> for Modifier { impl<'alloc> CloneIn<'alloc> for IndexedReference { type Cloned = IndexedReference; + fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned { IndexedReference { span: CloneIn::clone_in(&self.span, allocator), @@ -335,6 +361,7 @@ impl<'alloc> CloneIn<'alloc> for IndexedReference { impl<'new_alloc> CloneIn<'new_alloc> for NamedReference<'_> { type Cloned = NamedReference<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { NamedReference { span: CloneIn::clone_in(&self.span, allocator), diff --git a/crates/oxc_regular_expression/src/parser/mod.rs b/crates/oxc_regular_expression/src/parser/mod.rs index c53684cdbb4c93..9ec8bdf035a437 100644 --- a/crates/oxc_regular_expression/src/parser/mod.rs +++ b/crates/oxc_regular_expression/src/parser/mod.rs @@ -8,9 +8,10 @@ pub use parser_impl::{ConstructorParser, LiteralParser}; #[cfg(test)] mod test { - use crate::{ConstructorParser, LiteralParser, Options}; use oxc_allocator::Allocator; + use crate::{ConstructorParser, LiteralParser, Options}; + #[test] fn should_pass() { let allocator = Allocator::default(); diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 129968ffdf45a5..16a782aae20a1e 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -2,8 +2,6 @@ use std::cell::{Cell, RefCell}; -use rustc_hash::FxHashMap; - use oxc_ast::{ast::*, AstKind, Visit}; use oxc_cfg::{ ControlFlowGraphBuilder, CtxCursor, CtxFlags, EdgeType, ErrorEdgeKind, InstructionKind, @@ -11,6 +9,7 @@ use oxc_cfg::{ }; use oxc_diagnostics::OxcDiagnostic; use oxc_span::{Atom, CompactStr, SourceType, Span}; +use rustc_hash::FxHashMap; use crate::{ binder::Binder, diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index 7c5fe941a5f49b..6aca8107e04bbd 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -1,6 +1,3 @@ -use phf::{phf_set, Set}; -use rustc_hash::FxHashMap; - use oxc_ast::{ast::*, AstKind}; use oxc_diagnostics::{LabeledSpan, OxcDiagnostic}; use oxc_ecmascript::{IsSimpleParameterList, PropName}; @@ -9,6 +6,8 @@ use oxc_syntax::{ number::NumberBase, operator::{AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator}, }; +use phf::{phf_set, Set}; +use rustc_hash::FxHashMap; use crate::{builder::SemanticBuilder, diagnostics::redeclaration, scope::ScopeFlags, AstNode}; diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index 343d18c1ac7e13..4ab6be5c561c21 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -1,11 +1,10 @@ use std::borrow::Cow; -use rustc_hash::FxHashMap; - use oxc_ast::{ast::*, AstKind}; use oxc_diagnostics::OxcDiagnostic; use oxc_ecmascript::{BoundNames, PropName}; use oxc_span::{Atom, GetSpan, Span}; +use rustc_hash::FxHashMap; use crate::{builder::SemanticBuilder, diagnostics::redeclaration}; diff --git a/crates/oxc_semantic/src/class/builder.rs b/crates/oxc_semantic/src/class/builder.rs index c0419d2940a402..74b58111b888d7 100644 --- a/crates/oxc_semantic/src/class/builder.rs +++ b/crates/oxc_semantic/src/class/builder.rs @@ -8,12 +8,11 @@ use oxc_ast::{ use oxc_span::GetSpan; use oxc_syntax::class::{ClassId, ElementKind}; -use crate::{AstNodes, NodeId}; - use super::{ table::{Element, PrivateIdentifierReference}, ClassTable, }; +use crate::{AstNodes, NodeId}; #[derive(Debug, Default)] pub struct ClassTableBuilder { diff --git a/crates/oxc_semantic/src/class/table.rs b/crates/oxc_semantic/src/class/table.rs index e1901541325976..a3c868ef375200 100644 --- a/crates/oxc_semantic/src/class/table.rs +++ b/crates/oxc_semantic/src/class/table.rs @@ -1,8 +1,7 @@ -use rustc_hash::FxHashMap; - use oxc_index::IndexVec; use oxc_span::{CompactStr, Span}; use oxc_syntax::class::{ClassId, ElementId, ElementKind}; +use rustc_hash::FxHashMap; use crate::node::NodeId; diff --git a/crates/oxc_semantic/src/jsdoc/builder.rs b/crates/oxc_semantic/src/jsdoc/builder.rs index 82be8c41bb8bb3..10cc40c5510c58 100644 --- a/crates/oxc_semantic/src/jsdoc/builder.rs +++ b/crates/oxc_semantic/src/jsdoc/builder.rs @@ -1,11 +1,9 @@ -use rustc_hash::FxHashMap; - use oxc_ast::{ast::Comment, AstKind}; use oxc_span::{GetSpan, Span}; - -use crate::jsdoc::JSDocFinder; +use rustc_hash::FxHashMap; use super::parser::JSDoc; +use crate::jsdoc::JSDocFinder; #[derive(Default)] pub struct JSDocBuilder<'a> { diff --git a/crates/oxc_semantic/src/jsdoc/finder.rs b/crates/oxc_semantic/src/jsdoc/finder.rs index 5fc3bee4b3dfdf..a871fc7715742b 100644 --- a/crates/oxc_semantic/src/jsdoc/finder.rs +++ b/crates/oxc_semantic/src/jsdoc/finder.rs @@ -1,10 +1,8 @@ -use rustc_hash::FxHashMap; - use oxc_span::{GetSpan, Span}; - -use crate::AstNode; +use rustc_hash::FxHashMap; use super::parser::JSDoc; +use crate::AstNode; #[derive(Debug, Default)] pub struct JSDocFinder<'a> { diff --git a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs index 6f309d4ee756db..3068659abce4ae 100644 --- a/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs +++ b/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs @@ -1,10 +1,9 @@ use oxc_span::Span; -use crate::jsdoc::parser::utils; - use super::jsdoc_parts::{ JSDocCommentPart, JSDocTagKindPart, JSDocTagTypeNamePart, JSDocTagTypePart, }; +use crate::jsdoc::parser::utils; // Initially, I attempted to parse into specific structures such as: // - `@param {type} name comment`: `JSDocParameterTag { type, name, comment }` diff --git a/crates/oxc_semantic/src/lib.rs b/crates/oxc_semantic/src/lib.rs index 88205849214c7b..591d7622308209 100644 --- a/crates/oxc_semantic/src/lib.rs +++ b/crates/oxc_semantic/src/lib.rs @@ -33,6 +33,8 @@ mod stats; mod symbol; mod unresolved_stack; +use class::ClassTable; + pub use crate::{ builder::{SemanticBuilder, SemanticBuilderReturn}, jsdoc::{JSDoc, JSDocFinder, JSDocTag}, @@ -42,7 +44,6 @@ pub use crate::{ stats::Stats, symbol::{IsGlobalReference, SymbolTable}, }; -use class::ClassTable; /// Semantic analysis of a JavaScript/TypeScript program. /// diff --git a/crates/oxc_semantic/src/node.rs b/crates/oxc_semantic/src/node.rs index 38283508795bf3..24bb70dcddf05c 100644 --- a/crates/oxc_semantic/src/node.rs +++ b/crates/oxc_semantic/src/node.rs @@ -280,8 +280,8 @@ impl<'a> AstNodes<'a> { } impl<'a, 'n> IntoIterator for &'n AstNodes<'a> { - type Item = &'n AstNode<'a>; type IntoIter = std::slice::Iter<'n, AstNode<'a>>; + type Item = &'n AstNode<'a>; fn into_iter(self) -> Self::IntoIter { self.nodes.iter() diff --git a/crates/oxc_semantic/src/reference.rs b/crates/oxc_semantic/src/reference.rs index 12ac10ecd6b60c..1e2eed8802f748 100644 --- a/crates/oxc_semantic/src/reference.rs +++ b/crates/oxc_semantic/src/reference.rs @@ -1,10 +1,9 @@ +pub use oxc_syntax::reference::{ReferenceFlags, ReferenceId}; #[cfg(feature = "serialize")] use serde::Serialize; #[cfg(feature = "serialize")] use tsify::Tsify; -pub use oxc_syntax::reference::{ReferenceFlags, ReferenceId}; - use crate::{symbol::SymbolId, NodeId}; /// Describes where and how a Symbol is used in the AST. diff --git a/crates/oxc_semantic/src/scope.rs b/crates/oxc_semantic/src/scope.rs index 38944a1a1a7ee8..3bcf62391ef0b0 100644 --- a/crates/oxc_semantic/src/scope.rs +++ b/crates/oxc_semantic/src/scope.rs @@ -1,12 +1,11 @@ use std::mem; use indexmap::IndexMap; -use rustc_hash::{FxBuildHasher, FxHashMap}; - use oxc_index::IndexVec; use oxc_span::CompactStr; use oxc_syntax::reference::ReferenceId; pub use oxc_syntax::scope::{ScopeFlags, ScopeId}; +use rustc_hash::{FxBuildHasher, FxHashMap}; use crate::{symbol::SymbolId, NodeId}; diff --git a/crates/oxc_semantic/src/symbol.rs b/crates/oxc_semantic/src/symbol.rs index 0e5274a1b87b87..9986540a470092 100644 --- a/crates/oxc_semantic/src/symbol.rs +++ b/crates/oxc_semantic/src/symbol.rs @@ -1,10 +1,5 @@ use std::mem; -#[cfg(feature = "serialize")] -use serde::Serialize; -#[cfg(feature = "serialize")] -use tsify::Tsify; - use oxc_ast::ast::{Expression, IdentifierReference}; use oxc_index::IndexVec; use oxc_span::{CompactStr, Span}; @@ -12,6 +7,10 @@ pub use oxc_syntax::{ scope::ScopeId, symbol::{RedeclarationId, SymbolFlags, SymbolId}, }; +#[cfg(feature = "serialize")] +use serde::Serialize; +#[cfg(feature = "serialize")] +use tsify::Tsify; use crate::{ node::NodeId, diff --git a/crates/oxc_semantic/src/unresolved_stack.rs b/crates/oxc_semantic/src/unresolved_stack.rs index ebba979791c9c8..70f40d0bdd9c6f 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 rustc_hash::FxHashMap; - use oxc_span::Atom; 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>; diff --git a/crates/oxc_semantic/tests/conformance/mod.rs b/crates/oxc_semantic/tests/conformance/mod.rs index dcbcc19746dfbd..10d3c1a896c5ff 100644 --- a/crates/oxc_semantic/tests/conformance/mod.rs +++ b/crates/oxc_semantic/tests/conformance/mod.rs @@ -3,12 +3,13 @@ //! Since these cases are a contract-as-code, they _must be well documented_. When adding a new //! test, please describe what behavior it guarantees in as plain language as possible. -use crate::TestContext; use std::{borrow::Cow, sync::Arc}; use oxc_diagnostics::{GraphicalReportHandler, GraphicalTheme, NamedSource, OxcDiagnostic}; use oxc_semantic::{AstNode, Semantic, SymbolId}; +use crate::TestContext; + mod test_identifier_reference; mod test_symbol_declaration; diff --git a/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs b/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs index 3cb7aae33db882..307b1da10537cd 100644 --- a/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs +++ b/crates/oxc_semantic/tests/conformance/test_symbol_declaration.rs @@ -1,5 +1,7 @@ -use oxc_ast::ast::BindingPattern; -use oxc_ast::{ast::BindingIdentifier, AstKind}; +use oxc_ast::{ + ast::{BindingIdentifier, BindingPattern}, + AstKind, +}; use oxc_diagnostics::OxcDiagnostic; use oxc_span::{GetSpan, Span}; use oxc_syntax::symbol::SymbolId; diff --git a/crates/oxc_span/src/compact_str.rs b/crates/oxc_span/src/compact_str.rs index 10752a2b7f30fb..87dec9cc263168 100644 --- a/crates/oxc_span/src/compact_str.rs +++ b/crates/oxc_span/src/compact_str.rs @@ -281,9 +281,8 @@ macro_rules! format_compact_str { mod test { use compact_str::CompactString; - use crate::format_compact_str; - use super::CompactStr; + use crate::format_compact_str; #[test] fn test_compactstr_eq() { diff --git a/crates/oxc_span/src/generated/derive_estree.rs b/crates/oxc_span/src/generated/derive_estree.rs index de9824d1c34131..ce6e08dd1260dc 100644 --- a/crates/oxc_span/src/generated/derive_estree.rs +++ b/crates/oxc_span/src/generated/derive_estree.rs @@ -5,9 +5,7 @@ use serde::{ser::SerializeMap, Serialize, Serializer}; -use crate::source_type::*; - -use crate::span::types::*; +use crate::{source_type::*, span::types::*}; impl Serialize for Span { fn serialize(&self, serializer: S) -> Result { diff --git a/crates/oxc_span/src/source_type/mod.rs b/crates/oxc_span/src/source_type/mod.rs index f4e2241e7c3c54..e25636fe31684e 100644 --- a/crates/oxc_span/src/source_type/mod.rs +++ b/crates/oxc_span/src/source_type/mod.rs @@ -2,12 +2,12 @@ mod error; use std::{hash::Hash, path::Path}; +pub use error::UnknownExtension; use oxc_allocator::{Allocator, CloneIn}; use oxc_ast_macros::ast; use oxc_estree::ESTree; use crate::{cmp::ContentEq, hash::ContentHash}; -pub use error::UnknownExtension; /// Source Type for JavaScript vs TypeScript / Script vs Module / JSX #[ast] diff --git a/crates/oxc_syntax/src/generated/derive_clone_in.rs b/crates/oxc_syntax/src/generated/derive_clone_in.rs index d0a01e2b57a0ee..05bd573b6fb7e6 100644 --- a/crates/oxc_syntax/src/generated/derive_clone_in.rs +++ b/crates/oxc_syntax/src/generated/derive_clone_in.rs @@ -5,12 +5,11 @@ use oxc_allocator::{Allocator, CloneIn}; -use crate::number::*; - -use crate::operator::*; +use crate::{number::*, operator::*}; impl<'alloc> CloneIn<'alloc> for NumberBase { type Cloned = NumberBase; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Float => NumberBase::Float, @@ -24,6 +23,7 @@ impl<'alloc> CloneIn<'alloc> for NumberBase { impl<'alloc> CloneIn<'alloc> for BigintBase { type Cloned = BigintBase; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Decimal => BigintBase::Decimal, @@ -36,6 +36,7 @@ impl<'alloc> CloneIn<'alloc> for BigintBase { impl<'alloc> CloneIn<'alloc> for AssignmentOperator { type Cloned = AssignmentOperator; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Assign => AssignmentOperator::Assign, @@ -60,6 +61,7 @@ impl<'alloc> CloneIn<'alloc> for AssignmentOperator { impl<'alloc> CloneIn<'alloc> for BinaryOperator { type Cloned = BinaryOperator; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Equality => BinaryOperator::Equality, @@ -90,6 +92,7 @@ impl<'alloc> CloneIn<'alloc> for BinaryOperator { impl<'alloc> CloneIn<'alloc> for LogicalOperator { type Cloned = LogicalOperator; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Or => LogicalOperator::Or, @@ -101,6 +104,7 @@ impl<'alloc> CloneIn<'alloc> for LogicalOperator { impl<'alloc> CloneIn<'alloc> for UnaryOperator { type Cloned = UnaryOperator; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::UnaryPlus => UnaryOperator::UnaryPlus, @@ -116,6 +120,7 @@ impl<'alloc> CloneIn<'alloc> for UnaryOperator { impl<'alloc> CloneIn<'alloc> for UpdateOperator { type Cloned = UpdateOperator; + fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { Self::Increment => UpdateOperator::Increment, diff --git a/crates/oxc_syntax/src/generated/derive_content_eq.rs b/crates/oxc_syntax/src/generated/derive_content_eq.rs index d8bce369ae880e..51b405c21e4cf9 100644 --- a/crates/oxc_syntax/src/generated/derive_content_eq.rs +++ b/crates/oxc_syntax/src/generated/derive_content_eq.rs @@ -5,9 +5,7 @@ use oxc_span::cmp::ContentEq; -use crate::number::*; - -use crate::operator::*; +use crate::{number::*, operator::*}; impl ContentEq for NumberBase { fn content_eq(&self, other: &Self) -> bool { diff --git a/crates/oxc_syntax/src/generated/derive_content_hash.rs b/crates/oxc_syntax/src/generated/derive_content_hash.rs index 15d7242ff322b9..4772f29bac2395 100644 --- a/crates/oxc_syntax/src/generated/derive_content_hash.rs +++ b/crates/oxc_syntax/src/generated/derive_content_hash.rs @@ -7,9 +7,7 @@ use std::{hash::Hasher, mem::discriminant}; use oxc_span::hash::ContentHash; -use crate::number::*; - -use crate::operator::*; +use crate::{number::*, operator::*}; impl ContentHash for NumberBase { fn content_hash(&self, state: &mut H) { diff --git a/crates/oxc_syntax/src/module_record.rs b/crates/oxc_syntax/src/module_record.rs index 6af51578682753..ef06f49e935cfe 100644 --- a/crates/oxc_syntax/src/module_record.rs +++ b/crates/oxc_syntax/src/module_record.rs @@ -2,7 +2,6 @@ use oxc_allocator::{Allocator, Vec}; use oxc_span::{Atom, Span}; - use rustc_hash::FxHashMap; /// ESM Module Record diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index 92dcb1fb1857c0..986e7460b08a10 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -89,8 +89,6 @@ use compact_str::CompactString; use indexmap::IndexMap; -use rustc_hash::{FxBuildHasher, FxHashSet}; - use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec}; use oxc_ast::{ast::*, NONE}; use oxc_data_structures::stack::{NonEmptyStack, SparseStack}; @@ -101,6 +99,7 @@ use oxc_syntax::{ symbol::SymbolFlags, }; use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx}; +use rustc_hash::{FxBuildHasher, FxHashSet}; use crate::EnvOptions; diff --git a/crates/oxc_transformer/src/common/helper_loader.rs b/crates/oxc_transformer/src/common/helper_loader.rs index 2d50fb76c7f90d..16ecf286edf5df 100644 --- a/crates/oxc_transformer/src/common/helper_loader.rs +++ b/crates/oxc_transformer/src/common/helper_loader.rs @@ -67,9 +67,6 @@ use std::{borrow::Cow, cell::RefCell}; -use rustc_hash::FxHashMap; -use serde::Deserialize; - use oxc_allocator::{String as ArenaString, Vec as ArenaVec}; use oxc_ast::{ ast::{Argument, CallExpression, Expression}, @@ -78,6 +75,8 @@ use oxc_ast::{ use oxc_semantic::{ReferenceFlags, SymbolFlags}; use oxc_span::{Atom, Span, SPAN}; use oxc_traverse::{BoundIdentifier, TraverseCtx}; +use rustc_hash::FxHashMap; +use serde::Deserialize; use crate::TransformCtx; diff --git a/crates/oxc_transformer/src/common/module_imports.rs b/crates/oxc_transformer/src/common/module_imports.rs index 76f1bbc0bee309..51d2fbbd64bd68 100644 --- a/crates/oxc_transformer/src/common/module_imports.rs +++ b/crates/oxc_transformer/src/common/module_imports.rs @@ -35,7 +35,6 @@ use std::cell::RefCell; use indexmap::{map::Entry as IndexMapEntry, IndexMap}; - use oxc_ast::{ast::*, NONE}; use oxc_semantic::ReferenceFlags; use oxc_span::{Atom, SPAN}; diff --git a/crates/oxc_transformer/src/common/statement_injector.rs b/crates/oxc_transformer/src/common/statement_injector.rs index dbcd1f8bf42d7b..ed4104fc79fc5e 100644 --- a/crates/oxc_transformer/src/common/statement_injector.rs +++ b/crates/oxc_transformer/src/common/statement_injector.rs @@ -15,7 +15,6 @@ use std::cell::RefCell; use oxc_allocator::{Address, GetAddress, Vec as ArenaVec}; - use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; use rustc_hash::FxHashMap; diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index a6ae357f2c2b02..a0c28167136319 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -125,9 +125,8 @@ //! * Babel plugin implementation: //! * Arrow function specification: -use serde::Deserialize; - use oxc_traverse::Traverse; +use serde::Deserialize; use crate::context::TransformCtx; diff --git a/crates/oxc_transformer/src/es2017/mod.rs b/crates/oxc_transformer/src/es2017/mod.rs index 105b6c325f6fda..8e8beb9a922526 100644 --- a/crates/oxc_transformer/src/es2017/mod.rs +++ b/crates/oxc_transformer/src/es2017/mod.rs @@ -1,13 +1,12 @@ pub(crate) mod async_to_generator; mod options; +pub use async_to_generator::AsyncGeneratorExecutor; +pub use options::ES2017Options; use oxc_ast::ast::{Expression, Function, Statement}; use oxc_traverse::{Traverse, TraverseCtx}; use crate::{es2017::async_to_generator::AsyncToGenerator, TransformCtx}; -pub use async_to_generator::AsyncGeneratorExecutor; - -pub use options::ES2017Options; #[allow(dead_code)] pub struct ES2017<'a, 'ctx> { diff --git a/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs b/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs index 3fbe4f2ca73849..7381c4591e39fb 100644 --- a/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs +++ b/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs @@ -65,7 +65,9 @@ impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> { // If it's a labeled statement, we need to wrap the ForStatement with a labeled statement. if let Some(label) = label { let Statement::TryStatement(try_statement) = &mut new_stmt else { - unreachable!("The last statement should be a try statement, please see the `build_for_await` function"); + unreachable!( + "The last statement should be a try statement, please see the `build_for_await` function" + ); }; let try_statement_block_body = &mut try_statement.block.body; let for_statement = try_statement_block_body.pop().unwrap(); diff --git a/crates/oxc_transformer/src/es2018/mod.rs b/crates/oxc_transformer/src/es2018/mod.rs index 74af7d249bb76c..49d2af88e63ede 100644 --- a/crates/oxc_transformer/src/es2018/mod.rs +++ b/crates/oxc_transformer/src/es2018/mod.rs @@ -2,15 +2,14 @@ pub(crate) mod async_generator_functions; mod object_rest_spread; mod options; +use async_generator_functions::AsyncGeneratorFunctions; +pub use object_rest_spread::{ObjectRestSpread, ObjectRestSpreadOptions}; +pub use options::ES2018Options; use oxc_ast::ast::*; use oxc_traverse::{Traverse, TraverseCtx}; use crate::context::TransformCtx; -use async_generator_functions::AsyncGeneratorFunctions; -pub use object_rest_spread::{ObjectRestSpread, ObjectRestSpreadOptions}; -pub use options::ES2018Options; - pub struct ES2018<'a, 'ctx> { options: ES2018Options, diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread.rs b/crates/oxc_transformer/src/es2018/object_rest_spread.rs index b425ad526a6307..00aae8a41f8ca0 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread.rs @@ -29,8 +29,6 @@ use std::mem; -use serde::Deserialize; - use oxc_allocator::{CloneIn, GetAddress, Vec as ArenaVec}; use oxc_ast::{ast::*, NONE}; use oxc_diagnostics::OxcDiagnostic; @@ -38,6 +36,7 @@ use oxc_ecmascript::{BoundNames, ToJsString}; use oxc_semantic::{ScopeFlags, ScopeId, SymbolFlags}; use oxc_span::{GetSpan, SPAN}; use oxc_traverse::{Ancestor, MaybeBoundIdentifier, Traverse, TraverseCtx}; +use serde::Deserialize; use crate::{common::helper_loader::Helper, TransformCtx}; diff --git a/crates/oxc_transformer/src/es2020/mod.rs b/crates/oxc_transformer/src/es2020/mod.rs index 92cfe88e840f7d..a90d86bd647940 100644 --- a/crates/oxc_transformer/src/es2020/mod.rs +++ b/crates/oxc_transformer/src/es2020/mod.rs @@ -2,13 +2,12 @@ mod nullish_coalescing_operator; mod optional_chaining; mod options; -use oxc_ast::ast::*; -use oxc_diagnostics::OxcDiagnostic; -use oxc_traverse::{Traverse, TraverseCtx}; - pub use nullish_coalescing_operator::NullishCoalescingOperator; pub use optional_chaining::OptionalChaining; pub use options::ES2020Options; +use oxc_ast::ast::*; +use oxc_diagnostics::OxcDiagnostic; +use oxc_traverse::{Traverse, TraverseCtx}; use crate::TransformCtx; diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index 1904964503a153..849f4ec8cfda52 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -12,18 +12,17 @@ use oxc_syntax::{ }; use oxc_traverse::{BoundIdentifier, TraverseCtx}; -use crate::common::helper_loader::Helper; - -use super::{super::ClassStaticBlock, ClassBindings}; use super::{ + super::ClassStaticBlock, constructor::InstanceInitsInsertLocation, private_props::{PrivateProp, PrivateProps}, utils::{ create_assignment, create_underscore_ident_name, create_variable_declaration, exprs_into_stmts, }, - ClassProperties, FxIndexMap, + ClassBindings, ClassProperties, FxIndexMap, }; +use crate::common::helper_loader::Helper; impl<'a, 'ctx> ClassProperties<'a, 'ctx> { /// Transform class expression. diff --git a/crates/oxc_transformer/src/es2022/class_properties/mod.rs b/crates/oxc_transformer/src/es2022/class_properties/mod.rs index ca2e661afded92..74d693eeaefb22 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/mod.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/mod.rs @@ -145,14 +145,13 @@ //! * Class properties TC39 proposal: use indexmap::IndexMap; -use rustc_hash::FxBuildHasher; -use serde::Deserialize; - use oxc_allocator::{Address, GetAddress}; use oxc_ast::ast::*; use oxc_data_structures::stack::NonEmptyStack; use oxc_syntax::scope::ScopeId; use oxc_traverse::{Traverse, TraverseCtx}; +use rustc_hash::FxBuildHasher; +use serde::Deserialize; use crate::TransformCtx; diff --git a/crates/oxc_transformer/src/es2022/class_properties/private.rs b/crates/oxc_transformer/src/es2022/class_properties/private.rs index 6bab35d7bd3ea6..21da7c861228a7 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/private.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/private.rs @@ -11,8 +11,6 @@ use oxc_traverse::{ ast_operations::get_var_name_from_node, Ancestor, BoundIdentifier, TraverseCtx, }; -use crate::{common::helper_loader::Helper, TransformCtx}; - use super::{ private_props::ResolvedPrivateProp, utils::{ @@ -21,6 +19,7 @@ use super::{ }, ClassProperties, }; +use crate::{common::helper_loader::Helper, TransformCtx}; impl<'a, 'ctx> ClassProperties<'a, 'ctx> { /// Transform private field expression. diff --git a/crates/oxc_transformer/src/es2022/class_properties/supers.rs b/crates/oxc_transformer/src/es2022/class_properties/supers.rs index 1f57ffb7e21d66..dac4aec66481ed 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/supers.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/supers.rs @@ -6,9 +6,8 @@ use oxc_ast::ast::*; use oxc_span::SPAN; use oxc_traverse::TraverseCtx; -use crate::Helper; - use super::ClassProperties; +use crate::Helper; impl<'a, 'ctx> ClassProperties<'a, 'ctx> { /// Transform static member expression where object is `super`. diff --git a/crates/oxc_transformer/src/es2022/class_static_block.rs b/crates/oxc_transformer/src/es2022/class_static_block.rs index d4877584a9fd83..e50b4dc00d7d9e 100644 --- a/crates/oxc_transformer/src/es2022/class_static_block.rs +++ b/crates/oxc_transformer/src/es2022/class_static_block.rs @@ -40,7 +40,6 @@ //! * Class static initialization blocks TC39 proposal: use itoa::Buffer as ItoaBuffer; - use oxc_allocator::String as ArenaString; use oxc_ast::{ast::*, NONE}; use oxc_span::SPAN; diff --git a/crates/oxc_transformer/src/es2022/mod.rs b/crates/oxc_transformer/src/es2022/mod.rs index e6c08043f1c0b9..1008eaa7e56fca 100644 --- a/crates/oxc_transformer/src/es2022/mod.rs +++ b/crates/oxc_transformer/src/es2022/mod.rs @@ -10,7 +10,6 @@ mod options; use class_properties::ClassProperties; pub use class_properties::ClassPropertiesOptions; use class_static_block::ClassStaticBlock; - pub use options::ES2022Options; pub struct ES2022<'a, 'ctx> { diff --git a/crates/oxc_transformer/src/jsx/comments.rs b/crates/oxc_transformer/src/jsx/comments.rs index db488a63736b0a..75413292cc3f3f 100644 --- a/crates/oxc_transformer/src/jsx/comments.rs +++ b/crates/oxc_transformer/src/jsx/comments.rs @@ -327,10 +327,11 @@ pub fn cold_branch T, T>(f: F) -> T { #[cfg(test)] mod tests { - use super::*; use oxc_ast::CommentPosition; use oxc_span::Span; + use super::*; + static PRE_AND_POSTFIX: &[(&str, &str)] = &[ ("", ""), ("\n\n\n", "\n"), diff --git a/crates/oxc_transformer/src/jsx/jsx_impl.rs b/crates/oxc_transformer/src/jsx/jsx_impl.rs index e85cad1047e611..ab2840201068e2 100644 --- a/crates/oxc_transformer/src/jsx/jsx_impl.rs +++ b/crates/oxc_transformer/src/jsx/jsx_impl.rs @@ -100,18 +100,16 @@ use oxc_syntax::{ }; use oxc_traverse::{BoundIdentifier, Traverse, TraverseCtx}; -use crate::{ - es2018::{ObjectRestSpread, ObjectRestSpreadOptions}, - TransformCtx, -}; - use super::diagnostics; - pub use super::{ jsx_self::JsxSelf, jsx_source::JsxSource, options::{JsxOptions, JsxRuntime}, }; +use crate::{ + es2018::{ObjectRestSpread, ObjectRestSpreadOptions}, + TransformCtx, +}; pub struct JsxImpl<'a, 'ctx> { options: JsxOptions, @@ -1112,9 +1110,8 @@ mod test { use oxc_syntax::{node::NodeId, scope::ScopeFlags}; use oxc_traverse::ReusableTraverseCtx; - use crate::{TransformCtx, TransformOptions}; - use super::Pragma; + use crate::{TransformCtx, TransformOptions}; macro_rules! setup { ($traverse_ctx:ident, $transform_ctx:ident) => { diff --git a/crates/oxc_transformer/src/jsx/jsx_source.rs b/crates/oxc_transformer/src/jsx/jsx_source.rs index 3c2180972ec148..dfc208391253bd 100644 --- a/crates/oxc_transformer/src/jsx/jsx_source.rs +++ b/crates/oxc_transformer/src/jsx/jsx_source.rs @@ -33,9 +33,8 @@ //! //! * Babel plugin implementation: -use oxc_data_structures::rope::{get_line_column, Rope}; - use oxc_ast::ast::*; +use oxc_data_structures::rope::{get_line_column, Rope}; use oxc_diagnostics::OxcDiagnostic; use oxc_span::{Span, SPAN}; use oxc_syntax::{number::NumberBase, symbol::SymbolFlags}; diff --git a/crates/oxc_transformer/src/jsx/mod.rs b/crates/oxc_transformer/src/jsx/mod.rs index f216ab6c0f6ace..815ceff766952f 100644 --- a/crates/oxc_transformer/src/jsx/mod.rs +++ b/crates/oxc_transformer/src/jsx/mod.rs @@ -11,14 +11,12 @@ mod jsx_self; mod jsx_source; mod options; mod refresh; -use refresh::ReactRefresh; - +pub(crate) use comments::update_options_with_comments; pub use display_name::ReactDisplayName; pub use jsx_impl::JsxImpl; use jsx_self::JsxSelf; pub use options::{JsxOptions, JsxRuntime, ReactRefreshOptions}; - -pub(crate) use comments::update_options_with_comments; +use refresh::ReactRefresh; /// [Preset React](https://babel.dev/docs/babel-preset-react) /// diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index 3287cf5286f44d..7448e447af26b6 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -1,17 +1,15 @@ use base64::prelude::{Engine, BASE64_STANDARD}; -use rustc_hash::FxHashMap; -use sha1::{Digest, Sha1}; - use oxc_allocator::{Address, CloneIn, GetAddress, Vec as ArenaVec}; use oxc_ast::{ast::*, match_expression, AstBuilder, NONE}; use oxc_semantic::{Reference, ReferenceFlags, ScopeFlags, ScopeId, SymbolFlags}; use oxc_span::{Atom, GetSpan, SPAN}; use oxc_syntax::operator::AssignmentOperator; use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx}; - -use crate::TransformCtx; +use rustc_hash::FxHashMap; +use sha1::{Digest, Sha1}; use super::options::ReactRefreshOptions; +use crate::TransformCtx; /// Parse a string into a `RefreshIdentifierResolver` and convert it into an `Expression` #[derive(Debug)] diff --git a/crates/oxc_transformer/src/options/babel/env/mod.rs b/crates/oxc_transformer/src/options/babel/env/mod.rs index 06a6350990ade1..4e2e5d95e08166 100644 --- a/crates/oxc_transformer/src/options/babel/env/mod.rs +++ b/crates/oxc_transformer/src/options/babel/env/mod.rs @@ -3,7 +3,6 @@ mod targets; use serde::Deserialize; pub use self::targets::BabelTargets; - use crate::{options::EngineTargets, Module}; fn default_as_true() -> bool { diff --git a/crates/oxc_transformer/src/options/babel/env/targets.rs b/crates/oxc_transformer/src/options/babel/env/targets.rs index b044f627f9d8ff..c35805b3e59224 100644 --- a/crates/oxc_transformer/src/options/babel/env/targets.rs +++ b/crates/oxc_transformer/src/options/babel/env/targets.rs @@ -1,10 +1,9 @@ use std::str::FromStr; +pub use browserslist::Version; use rustc_hash::FxHashMap; use serde::Deserialize; -pub use browserslist::Version; - use crate::options::{BrowserslistQuery, Engine, EngineTargets}; /// @@ -34,6 +33,7 @@ pub enum BabelTargetsValue { impl TryFrom for EngineTargets { type Error = String; + fn try_from(value: BabelTargets) -> Result { match value { BabelTargets::String(s) => BrowserslistQuery::Single(s).exec(), @@ -71,7 +71,7 @@ impl TryFrom for EngineTargets { engine_targets.insert(engine, version); } Err(err) => { - return Err(format!("Failed to parse `{v}` for `{key}`\n{err:?}")) + return Err(format!("Failed to parse `{v}` for `{key}`\n{err:?}")); } } } diff --git a/crates/oxc_transformer/src/options/babel/mod.rs b/crates/oxc_transformer/src/options/babel/mod.rs index 00ff26f6d6a73e..c8da314e16c6aa 100644 --- a/crates/oxc_transformer/src/options/babel/mod.rs +++ b/crates/oxc_transformer/src/options/babel/mod.rs @@ -6,10 +6,9 @@ use std::path::{Path, PathBuf}; use serde::{de::DeserializeOwned, Deserialize}; -use crate::CompilerAssumptions; - pub use self::env::{BabelEnvOptions, BabelModule, BabelTargets}; pub(crate) use self::{plugins::BabelPlugins, presets::BabelPresets}; +use crate::CompilerAssumptions; /// Babel options /// diff --git a/crates/oxc_transformer/src/options/babel/plugins.rs b/crates/oxc_transformer/src/options/babel/plugins.rs index ffd4bffc95d48a..a9eb20f8010395 100644 --- a/crates/oxc_transformer/src/options/babel/plugins.rs +++ b/crates/oxc_transformer/src/options/babel/plugins.rs @@ -1,12 +1,11 @@ use serde::Deserialize; +use super::PluginPresetEntries; use crate::{ es2015::ArrowFunctionsOptions, es2018::ObjectRestSpreadOptions, es2022::ClassPropertiesOptions, jsx::JsxOptions, TypeScriptOptions, }; -use super::PluginPresetEntries; - #[derive(Debug, Default, Clone, Copy, Deserialize)] pub struct SyntaxTypeScriptOptions { #[serde(default)] diff --git a/crates/oxc_transformer/src/options/babel/presets.rs b/crates/oxc_transformer/src/options/babel/presets.rs index 60687b2be1c8ae..1dbeaa2855efde 100644 --- a/crates/oxc_transformer/src/options/babel/presets.rs +++ b/crates/oxc_transformer/src/options/babel/presets.rs @@ -1,7 +1,6 @@ use serde::Deserialize; use super::PluginPresetEntries; - use crate::{EnvOptions, JsxOptions, TypeScriptOptions}; #[derive(Debug, Default, Clone, Deserialize)] diff --git a/crates/oxc_transformer/src/options/engine_targets.rs b/crates/oxc_transformer/src/options/engine_targets.rs index d5724b29655f89..6f7abd6cf3d18c 100644 --- a/crates/oxc_transformer/src/options/engine_targets.rs +++ b/crates/oxc_transformer/src/options/engine_targets.rs @@ -22,6 +22,7 @@ pub struct EngineTargets(FxHashMap); impl Deref for EngineTargets { type Target = FxHashMap; + fn deref(&self) -> &Self::Target { &self.0 } @@ -37,6 +38,7 @@ impl EngineTargets { pub fn new(map: FxHashMap) -> Self { Self(map) } + /// # Errors /// /// * Query is invalid. diff --git a/crates/oxc_transformer/src/options/env.rs b/crates/oxc_transformer/src/options/env.rs index eee0aa45861156..8e5a8a39b5f40e 100644 --- a/crates/oxc_transformer/src/options/env.rs +++ b/crates/oxc_transformer/src/options/env.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use serde::Deserialize; +use super::{babel::BabelEnvOptions, ESFeature, ESTarget, Engine, Module}; use crate::{ es2015::{ArrowFunctionsOptions, ES2015Options}, es2016::ES2016Options, @@ -15,8 +16,6 @@ use crate::{ EngineTargets, }; -use super::{babel::BabelEnvOptions, ESFeature, ESTarget, Engine, Module}; - #[derive(Debug, Default, Clone, Copy, Deserialize)] #[serde(try_from = "BabelEnvOptions")] pub struct EnvOptions { diff --git a/crates/oxc_transformer/src/options/es_features.rs b/crates/oxc_transformer/src/options/es_features.rs index cabac4aaca09ad..7f02375edfa037 100644 --- a/crates/oxc_transformer/src/options/es_features.rs +++ b/crates/oxc_transformer/src/options/es_features.rs @@ -1,9 +1,11 @@ // Auto generated by `tasks/compat_data/src/lib.rs`. #![allow(clippy::enum_glob_use, clippy::match_same_arms)] -use super::{Engine, EngineTargets}; +use std::sync::OnceLock; + use browserslist::Version; use rustc_hash::FxHashMap; -use std::sync::OnceLock; + +use super::{Engine, EngineTargets}; #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] pub enum ESFeature { ES5MemberExpressionLiterals, diff --git a/crates/oxc_transformer/src/options/mod.rs b/crates/oxc_transformer/src/options/mod.rs index aa2963c035d490..41cb1e7f766f5b 100644 --- a/crates/oxc_transformer/src/options/mod.rs +++ b/crates/oxc_transformer/src/options/mod.rs @@ -10,6 +10,11 @@ mod module; use std::path::PathBuf; +use self::babel::BabelOptions; +pub use self::{ + browserslist_query::BrowserslistQuery, engine::Engine, engine_targets::EngineTargets, + env::EnvOptions, es_features::ESFeature, es_target::ESTarget, module::Module, +}; use crate::{ common::helper_loader::{HelperLoaderMode, HelperLoaderOptions}, compiler_assumptions::CompilerAssumptions, @@ -27,13 +32,6 @@ use crate::{ ReactRefreshOptions, }; -pub use self::{ - browserslist_query::BrowserslistQuery, engine::Engine, engine_targets::EngineTargets, - env::EnvOptions, es_features::ESFeature, es_target::ESTarget, module::Module, -}; - -use self::babel::BabelOptions; - /// #[derive(Debug, Default, Clone)] pub struct TransformOptions { diff --git a/crates/oxc_transformer/src/options/module.rs b/crates/oxc_transformer/src/options/module.rs index 6e888258b4f661..9c56321a222752 100644 --- a/crates/oxc_transformer/src/options/module.rs +++ b/crates/oxc_transformer/src/options/module.rs @@ -34,6 +34,7 @@ impl Module { impl TryFrom for Module { type Error = Error; + fn try_from(value: BabelModule) -> Result { match value { BabelModule::Commonjs => Ok(Self::CommonJS), @@ -45,6 +46,7 @@ impl TryFrom for Module { impl TryFrom<&BabelPlugins> for Module { type Error = Error; + fn try_from(value: &BabelPlugins) -> Result { if value.modules_commonjs { Ok(Self::CommonJS) diff --git a/crates/oxc_transformer/src/plugins/inject_global_variables.rs b/crates/oxc_transformer/src/plugins/inject_global_variables.rs index f4e5a6129f4cce..12cce4078f618f 100644 --- a/crates/oxc_transformer/src/plugins/inject_global_variables.rs +++ b/crates/oxc_transformer/src/plugins/inject_global_variables.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use cow_utils::CowUtils; - use oxc_allocator::Allocator; use oxc_ast::{ast::*, AstBuilder, NONE}; use oxc_semantic::{ScopeTree, SymbolTable}; diff --git a/crates/oxc_transformer/src/regexp/mod.rs b/crates/oxc_transformer/src/regexp/mod.rs index 7bdf29ad04fb9c..f694e8151e9410 100644 --- a/crates/oxc_transformer/src/regexp/mod.rs +++ b/crates/oxc_transformer/src/regexp/mod.rs @@ -210,7 +210,7 @@ impl<'a, 'ctx> RegExp<'a, 'ctx> { Term::UnicodePropertyEscape(_) => return self.unicode_property_escapes, Term::CharacterClass(character_class) => { return self.unicode_property_escapes - && character_class_has_unicode_property_escape(character_class) + && character_class_has_unicode_property_escape(character_class); } Term::LookAroundAssertion(assertion) => { return self.look_behind_assertions @@ -218,7 +218,7 @@ impl<'a, 'ctx> RegExp<'a, 'ctx> { assertion.kind, LookAroundAssertionKind::Lookbehind | LookAroundAssertionKind::NegativeLookbehind - ) + ); } Term::Quantifier(quantifier) => term = &quantifier.body, _ => return false, diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index d321921602d685..9abe3a283ab3fa 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -1,5 +1,3 @@ -use rustc_hash::FxHashSet; - use oxc_allocator::Vec as ArenaVec; use oxc_ast::ast::*; use oxc_diagnostics::OxcDiagnostic; @@ -12,6 +10,7 @@ use oxc_syntax::{ symbol::SymbolId, }; use oxc_traverse::{Traverse, TraverseCtx}; +use rustc_hash::FxHashSet; use crate::{TransformCtx, TypeScriptOptions}; diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index 71f24e6451f0aa..3000eca41cb7f2 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -1,5 +1,3 @@ -use rustc_hash::FxHashMap; - use oxc_allocator::Vec as ArenaVec; use oxc_ast::{ast::*, visit::walk_mut, VisitMut, NONE}; use oxc_ecmascript::ToInt32; @@ -11,6 +9,7 @@ use oxc_syntax::{ symbol::SymbolFlags, }; use oxc_traverse::{BoundIdentifier, Traverse, TraverseCtx}; +use rustc_hash::FxHashMap; pub struct TypeScriptEnum<'a> { enums: FxHashMap, FxHashMap, ConstantValue>>, diff --git a/crates/oxc_transformer/src/typescript/mod.rs b/crates/oxc_transformer/src/typescript/mod.rs index f53b75926f0eaf..d841ae35119311 100644 --- a/crates/oxc_transformer/src/typescript/mod.rs +++ b/crates/oxc_transformer/src/typescript/mod.rs @@ -15,11 +15,10 @@ mod rewrite_extensions; use annotations::TypeScriptAnnotations; use module::TypeScriptModule; use namespace::TypeScriptNamespace; +pub use options::{RewriteExtensionsMode, TypeScriptOptions}; use r#enum::TypeScriptEnum; use rewrite_extensions::TypeScriptRewriteExtensions; -pub use options::{RewriteExtensionsMode, TypeScriptOptions}; - /// [Preset TypeScript](https://babeljs.io/docs/babel-preset-typescript) /// /// This preset includes the following plugins: diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index 581732f1007cb3..903697319720b6 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -1,5 +1,3 @@ -use rustc_hash::FxHashSet; - use oxc_allocator::{Box as ArenaBox, Vec as ArenaVec}; use oxc_ast::{ast::*, NONE}; use oxc_ecmascript::BoundNames; @@ -10,13 +8,13 @@ use oxc_syntax::{ symbol::SymbolFlags, }; use oxc_traverse::{Traverse, TraverseCtx}; - -use crate::TransformCtx; +use rustc_hash::FxHashSet; use super::{ diagnostics::{ambient_module_nested, namespace_exporting_non_const, namespace_not_supported}, TypeScriptOptions, }; +use crate::TransformCtx; pub struct TypeScriptNamespace<'a, 'ctx> { ctx: &'ctx TransformCtx<'a>, diff --git a/crates/oxc_transformer/src/typescript/rewrite_extensions.rs b/crates/oxc_transformer/src/typescript/rewrite_extensions.rs index 5951e8dd36a9e0..139f1d2b88cc1e 100644 --- a/crates/oxc_transformer/src/typescript/rewrite_extensions.rs +++ b/crates/oxc_transformer/src/typescript/rewrite_extensions.rs @@ -10,9 +10,8 @@ use oxc_ast::ast::{ }; use oxc_traverse::{Traverse, TraverseCtx}; -use crate::TypeScriptOptions; - use super::options::RewriteExtensionsMode; +use crate::TypeScriptOptions; pub struct TypeScriptRewriteExtensions { mode: RewriteExtensionsMode, diff --git a/crates/oxc_transformer/tests/integrations/es_target.rs b/crates/oxc_transformer/tests/integrations/es_target.rs index 7300070ba47e68..e02e3b59d5a0f2 100644 --- a/crates/oxc_transformer/tests/integrations/es_target.rs +++ b/crates/oxc_transformer/tests/integrations/es_target.rs @@ -1,9 +1,10 @@ use std::str::FromStr; -use crate::{codegen, test}; use oxc_span::SourceType; use oxc_transformer::{ESTarget, TransformOptions}; +use crate::{codegen, test}; + #[test] fn es_target() { use std::fmt::Write; @@ -77,7 +78,10 @@ fn target_list_fail() { ("asdf", "Invalid target 'asdf'."), ("es2020,es2020", "'es2020' is already specified."), ("chrome1,chrome1", "'chrome1' is already specified."), - ("chromeXXX", "All version numbers must be in the format \"X\", \"X.Y\", or \"X.Y.Z\" where X, Y, and Z are non-negative integers."), + ( + "chromeXXX", + "All version numbers must be in the format \"X\", \"X.Y\", or \"X.Y.Z\" where X, Y, and Z are non-negative integers.", + ), ]; for (target, expected) in targets { diff --git a/crates/oxc_transformer/tests/integrations/targets.rs b/crates/oxc_transformer/tests/integrations/targets.rs index 7ea88e0bfa101e..75a680b7b90e0f 100644 --- a/crates/oxc_transformer/tests/integrations/targets.rs +++ b/crates/oxc_transformer/tests/integrations/targets.rs @@ -1,7 +1,8 @@ -use crate::{codegen, test}; use oxc_span::SourceType; use oxc_transformer::{ESTarget, EnvOptions, TransformOptions}; +use crate::{codegen, test}; + #[test] fn targets() { let cases = [ diff --git a/crates/oxc_traverse/src/context/bound_identifier.rs b/crates/oxc_traverse/src/context/bound_identifier.rs index 793fe6603a842a..a5d1ed76f0bf8f 100644 --- a/crates/oxc_traverse/src/context/bound_identifier.rs +++ b/crates/oxc_traverse/src/context/bound_identifier.rs @@ -8,9 +8,8 @@ use oxc_ast::{ use oxc_span::{Atom, Span, SPAN}; use oxc_syntax::{reference::ReferenceFlags, symbol::SymbolId}; -use crate::TraverseCtx; - use super::MaybeBoundIdentifier; +use crate::TraverseCtx; /// Info about a binding, from which one can create a `BindingIdentifier` or `IdentifierReference`s. /// diff --git a/crates/oxc_traverse/src/context/maybe_bound_identifier.rs b/crates/oxc_traverse/src/context/maybe_bound_identifier.rs index 623b7ef2e1fb1f..9f34720ac01de9 100644 --- a/crates/oxc_traverse/src/context/maybe_bound_identifier.rs +++ b/crates/oxc_traverse/src/context/maybe_bound_identifier.rs @@ -2,9 +2,8 @@ use oxc_ast::ast::{AssignmentTarget, Expression, IdentifierReference, SimpleAssi use oxc_span::{Atom, Span, SPAN}; use oxc_syntax::{reference::ReferenceFlags, symbol::SymbolId}; -use crate::TraverseCtx; - use super::BoundIdentifier; +use crate::TraverseCtx; /// A factory for generating `IdentifierReference`s. /// diff --git a/crates/oxc_traverse/src/context/scoping.rs b/crates/oxc_traverse/src/context/scoping.rs index c90f805f8359db..60c2da041924c8 100644 --- a/crates/oxc_traverse/src/context/scoping.rs +++ b/crates/oxc_traverse/src/context/scoping.rs @@ -2,8 +2,6 @@ use std::str; use compact_str::CompactString; use itoa::Buffer as ItoaBuffer; -use rustc_hash::FxHashSet; - use oxc_ast::{ast::*, visit::Visit}; use oxc_semantic::{NodeId, Reference, ScopeTree, SymbolTable}; use oxc_span::{CompactStr, SPAN}; @@ -12,6 +10,7 @@ use oxc_syntax::{ scope::{ScopeFlags, ScopeId}, symbol::{SymbolFlags, SymbolId}, }; +use rustc_hash::FxHashSet; use crate::{scopes_collector::ChildScopeCollector, BoundIdentifier}; diff --git a/crates/oxc_wasm/src/lib.rs b/crates/oxc_wasm/src/lib.rs index 5417a514ba461b..ed212c5358ef4d 100644 --- a/crates/oxc_wasm/src/lib.rs +++ b/crates/oxc_wasm/src/lib.rs @@ -5,10 +5,6 @@ use std::{ sync::Arc, }; -use serde::Serialize; -use tsify::Tsify; -use wasm_bindgen::prelude::*; - use oxc::{ allocator::Allocator, ast::{ast::Program, Comment as OxcComment, CommentKind, Visit}, @@ -25,6 +21,9 @@ use oxc::{ use oxc_index::Idx; use oxc_linter::{Linter, ModuleRecord}; use oxc_prettier::{Prettier, PrettierOptions}; +use serde::Serialize; +use tsify::Tsify; +use wasm_bindgen::prelude::*; use crate::options::{OxcOptions, OxcRunOptions}; diff --git a/napi/minify/src/lib.rs b/napi/minify/src/lib.rs index 61156f360f351d..ebaf75d03ce4f3 100644 --- a/napi/minify/src/lib.rs +++ b/napi/minify/src/lib.rs @@ -1,5 +1,4 @@ use napi_derive::napi; - use oxc_allocator::Allocator; use oxc_codegen::{Codegen, CodegenOptions}; use oxc_minifier::{CompressOptions, Minifier, MinifierOptions}; diff --git a/napi/parser/src/convert.rs b/napi/parser/src/convert.rs index 4bfb1f5a6a0328..8d71ccfab14e1c 100644 --- a/napi/parser/src/convert.rs +++ b/napi/parser/src/convert.rs @@ -1,6 +1,5 @@ -use rustc_hash::FxHashMap; - use oxc::syntax::module_record::{self, ModuleRecord}; +use rustc_hash::FxHashMap; use crate::types::{ EcmaScriptModule, ExportExportName, ExportExportNameKind, ExportImportName, diff --git a/napi/parser/src/lib.rs b/napi/parser/src/lib.rs index bf9c6e22274670..02f6e7ee165791 100644 --- a/napi/parser/src/lib.rs +++ b/napi/parser/src/lib.rs @@ -10,7 +10,6 @@ use std::mem; use napi::{bindgen_prelude::AsyncTask, Task}; use napi_derive::napi; - use oxc::{ allocator::Allocator, ast::CommentKind, diff --git a/napi/parser/src/magic_string.rs b/napi/parser/src/magic_string.rs index 35b87c091767a8..e958a4facd7892 100644 --- a/napi/parser/src/magic_string.rs +++ b/napi/parser/src/magic_string.rs @@ -3,7 +3,6 @@ use napi_derive::napi; use oxc_data_structures::rope::{get_line_column, Rope}; - // use oxc_sourcemap::napi::SourceMap; use self_cell::self_cell; use string_wizard::MagicString as MS; diff --git a/napi/parser/src/types.rs b/napi/parser/src/types.rs index be6ef3abb96e7b..4c4b73ca923de5 100644 --- a/napi/parser/src/types.rs +++ b/napi/parser/src/types.rs @@ -1,6 +1,6 @@ -use napi_derive::napi; use std::mem; +use napi_derive::napi; use oxc_napi::OxcError; use crate::magic_string::MagicString; diff --git a/napi/transform/src/isolated_declaration.rs b/napi/transform/src/isolated_declaration.rs index ffbaf37263fb0a..bdba5e28d76d17 100644 --- a/napi/transform/src/isolated_declaration.rs +++ b/napi/transform/src/isolated_declaration.rs @@ -1,7 +1,6 @@ use std::path::Path; use napi_derive::napi; - use oxc::{ allocator::Allocator, codegen::{CodeGenerator, CodegenOptions}, diff --git a/napi/transform/src/transformer.rs b/napi/transform/src/transformer.rs index 0f64a7b2060b83..ba886442b1b4ba 100644 --- a/napi/transform/src/transformer.rs +++ b/napi/transform/src/transformer.rs @@ -8,8 +8,6 @@ use std::{ use napi::Either; use napi_derive::napi; -use rustc_hash::FxHashMap; - use oxc::{ codegen::CodegenReturn, diagnostics::OxcDiagnostic, @@ -22,6 +20,7 @@ use oxc::{ }; use oxc_napi::OxcError; use oxc_sourcemap::napi::SourceMap; +use rustc_hash::FxHashMap; use crate::IsolatedDeclarationsOptions; @@ -629,7 +628,7 @@ pub fn transform( return TransformResult { errors: vec![OxcError::new(format!("Incorrect lang '{lang}'"))], ..Default::default() - } + }; } None => { let mut source_type = SourceType::from_path(source_path).unwrap_or_default(); @@ -649,7 +648,7 @@ pub fn transform( return TransformResult { errors: errors.into_iter().map(OxcError::from).collect(), ..Default::default() - } + }; } }; diff --git a/tasks/ast_tools/src/derives/clone_in.rs b/tasks/ast_tools/src/derives/clone_in.rs index 48e6b20669c9b0..a9bcfea9ac13b7 100644 --- a/tasks/ast_tools/src/derives/clone_in.rs +++ b/tasks/ast_tools/src/derives/clone_in.rs @@ -3,13 +3,12 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use syn::Ident; +use super::{define_derive, Derive}; use crate::{ markers::CloneInAttribute, schema::{EnumDef, GetIdent, Schema, StructDef, TypeDef}, }; -use super::{define_derive, Derive}; - pub struct DeriveCloneIn; define_derive!(DeriveCloneIn); diff --git a/tasks/ast_tools/src/derives/content_eq.rs b/tasks/ast_tools/src/derives/content_eq.rs index 496a870403cfde..483be783ae4edf 100644 --- a/tasks/ast_tools/src/derives/content_eq.rs +++ b/tasks/ast_tools/src/derives/content_eq.rs @@ -2,13 +2,12 @@ use itertools::Itertools; use proc_macro2::TokenStream; use quote::quote; +use super::{define_derive, Derive}; use crate::{ schema::{EnumDef, GetGenerics, Schema, StructDef, ToType, TypeDef}, util::ToIdent, }; -use super::{define_derive, Derive}; - pub struct DeriveContentEq; define_derive!(DeriveContentEq); diff --git a/tasks/ast_tools/src/derives/content_hash.rs b/tasks/ast_tools/src/derives/content_hash.rs index d44c1ea645690c..dce774c1b780ee 100644 --- a/tasks/ast_tools/src/derives/content_hash.rs +++ b/tasks/ast_tools/src/derives/content_hash.rs @@ -2,13 +2,12 @@ use itertools::Itertools; use proc_macro2::TokenStream; use quote::quote; +use super::{define_derive, Derive}; use crate::{ schema::{EnumDef, GetGenerics, Schema, StructDef, ToType, TypeDef}, util::ToIdent, }; -use super::{define_derive, Derive}; - pub struct DeriveContentHash; define_derive!(DeriveContentHash); diff --git a/tasks/ast_tools/src/derives/estree.rs b/tasks/ast_tools/src/derives/estree.rs index 48de37d1994096..232b123e829275 100644 --- a/tasks/ast_tools/src/derives/estree.rs +++ b/tasks/ast_tools/src/derives/estree.rs @@ -3,6 +3,7 @@ use proc_macro2::TokenStream; use quote::quote; use rustc_hash::FxHashMap; +use super::{define_derive, Derive}; use crate::{ markers::ESTreeStructTagMode, schema::{ @@ -11,8 +12,6 @@ use crate::{ }, }; -use super::{define_derive, Derive}; - pub struct DeriveESTree; define_derive!(DeriveESTree); diff --git a/tasks/ast_tools/src/derives/get_address.rs b/tasks/ast_tools/src/derives/get_address.rs index c3ddd6674c52bd..c1a12946008dac 100644 --- a/tasks/ast_tools/src/derives/get_address.rs +++ b/tasks/ast_tools/src/derives/get_address.rs @@ -1,13 +1,12 @@ use proc_macro2::TokenStream; use quote::quote; +use super::{define_derive, Derive}; use crate::{ schema::{EnumDef, Schema, ToType, TypeDef}, util::TypeWrapper, }; -use super::{define_derive, Derive}; - pub struct DeriveGetAddress; define_derive!(DeriveGetAddress); diff --git a/tasks/ast_tools/src/derives/get_span.rs b/tasks/ast_tools/src/derives/get_span.rs index 3f9d0d206b4e49..0183e7a30606a2 100644 --- a/tasks/ast_tools/src/derives/get_span.rs +++ b/tasks/ast_tools/src/derives/get_span.rs @@ -2,13 +2,12 @@ use proc_macro2::TokenStream; use quote::quote; use syn::Ident; +use super::{define_derive, Derive}; use crate::{ schema::{EnumDef, GetGenerics, Schema, StructDef, ToType, TypeDef}, util::{ToIdent, TypeWrapper}, }; -use super::{define_derive, Derive}; - pub struct DeriveGetSpan; define_derive!(DeriveGetSpan); diff --git a/tasks/ast_tools/src/generators/assert_layouts.rs b/tasks/ast_tools/src/generators/assert_layouts.rs index b7edfe115562d1..590c8f54631951 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::{ output::{output_path, Output}, schema::{FieldDef, Schema, ToType, TypeDef}, @@ -9,8 +10,6 @@ use crate::{ Generator, }; -use super::define_generator; - pub struct AssertLayouts; define_generator!(AssertLayouts); diff --git a/tasks/ast_tools/src/generators/ast_builder.rs b/tasks/ast_tools/src/generators/ast_builder.rs index bebe0185d2bd2a..a63b7af8a1c650 100644 --- a/tasks/ast_tools/src/generators/ast_builder.rs +++ b/tasks/ast_tools/src/generators/ast_builder.rs @@ -6,6 +6,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote, ToTokens}; use syn::{parse_quote, Ident, Type}; +use super::define_generator; use crate::{ output::{output_path, Output}, schema::{ @@ -15,8 +16,6 @@ use crate::{ Generator, }; -use super::define_generator; - pub const BLACK_LIST: [&str; 1] = ["Span"]; pub struct AstBuilderGenerator; diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index 154b8a393f12d5..f6553d239358f5 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -3,14 +3,13 @@ use itertools::Itertools; use quote::{format_ident, quote}; use syn::{parse_quote, Arm, ImplItemFn, Variant}; +use super::define_generator; use crate::{ output::{output_path, Output}, schema::{GetIdent, Schema, ToType}, Generator, }; -use super::define_generator; - pub struct AstKindGenerator; define_generator!(AstKindGenerator); diff --git a/tasks/ast_tools/src/generators/get_id.rs b/tasks/ast_tools/src/generators/get_id.rs index e487f8c01dcbe7..e478957bf60c59 100644 --- a/tasks/ast_tools/src/generators/get_id.rs +++ b/tasks/ast_tools/src/generators/get_id.rs @@ -6,6 +6,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; +use super::define_generator; use crate::{ output::{output_path, Output}, schema::{Schema, TypeDef}, @@ -13,8 +14,6 @@ use crate::{ Generator, }; -use super::define_generator; - pub struct GetIdGenerator; define_generator!(GetIdGenerator); diff --git a/tasks/ast_tools/src/generators/typescript.rs b/tasks/ast_tools/src/generators/typescript.rs index ff4c67afd2173e..4408c8dd099fd0 100644 --- a/tasks/ast_tools/src/generators/typescript.rs +++ b/tasks/ast_tools/src/generators/typescript.rs @@ -2,6 +2,7 @@ use convert_case::{Case, Casing}; use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; +use super::define_generator; use crate::{ output::Output, schema::{ @@ -11,8 +12,6 @@ use crate::{ Generator, TypeId, }; -use super::define_generator; - const CUSTOM_TYPESCRIPT: &str = include_str!("../../../../crates/oxc_ast/custom_types.d.ts"); pub struct TypescriptGenerator; diff --git a/tasks/ast_tools/src/generators/visit.rs b/tasks/ast_tools/src/generators/visit.rs index 97b64535573417..ba81ba55e91ac7 100644 --- a/tasks/ast_tools/src/generators/visit.rs +++ b/tasks/ast_tools/src/generators/visit.rs @@ -7,6 +7,7 @@ use quote::{format_ident, quote, ToTokens}; use rustc_hash::FxHashMap; use syn::{parse_quote, Ident}; +use super::define_generator; use crate::{ generators::ast_kind::BLACK_LIST as KIND_BLACK_LIST, markers::VisitArg, @@ -16,8 +17,6 @@ use crate::{ Generator, }; -use super::define_generator; - pub struct VisitGenerator; define_generator!(VisitGenerator); diff --git a/tasks/ast_tools/src/logger.rs b/tasks/ast_tools/src/logger.rs index 056408892cc850..875532ce5ff072 100644 --- a/tasks/ast_tools/src/logger.rs +++ b/tasks/ast_tools/src/logger.rs @@ -44,4 +44,7 @@ macro_rules! log_result { }; } -pub(crate) use {log, log_failed, log_result, log_success}; +pub(crate) use log; +pub(crate) use log_failed; +pub(crate) use log_result; +pub(crate) use log_success; diff --git a/tasks/ast_tools/src/passes/calc_layout.rs b/tasks/ast_tools/src/passes/calc_layout.rs index d113caef693d99..45c8ddeacf07eb 100644 --- a/tasks/ast_tools/src/passes/calc_layout.rs +++ b/tasks/ast_tools/src/passes/calc_layout.rs @@ -7,6 +7,7 @@ use quote::ToTokens; use rustc_hash::FxHashMap; use syn::Type; +use super::{define_pass, Pass}; use crate::{ codegen::EarlyCtx, layout::{KnownLayout, Layout}, @@ -15,8 +16,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 247c52cfa11243..0be7ad08606f29 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; diff --git a/tasks/ast_tools/src/schema/defs.rs b/tasks/ast_tools/src/schema/defs.rs index 433d5f05be2f01..1eed746c92f22d 100644 --- a/tasks/ast_tools/src/schema/defs.rs +++ b/tasks/ast_tools/src/schema/defs.rs @@ -1,6 +1,7 @@ use serde::Serialize; use syn::Ident; +use super::TypeName; use crate::{ markers::{ DeriveAttributes, ESTreeEnumAttribute, ESTreeStructAttribute, ScopeAttribute, ScopeMarkers, @@ -10,8 +11,6 @@ use crate::{ TypeId, }; -use super::TypeName; - #[derive(Debug, Serialize)] #[serde(untagged)] #[expect(clippy::large_enum_variant)] diff --git a/tasks/ast_tools/src/schema/get_ident.rs b/tasks/ast_tools/src/schema/get_ident.rs index 1f1f5f8769085c..03fb62e964f953 100644 --- a/tasks/ast_tools/src/schema/get_ident.rs +++ b/tasks/ast_tools/src/schema/get_ident.rs @@ -1,8 +1,7 @@ use syn::Ident; -use crate::util::ToIdent; - use super::defs::{EnumDef, StructDef, TypeDef}; +use crate::util::ToIdent; pub trait GetIdent { fn ident(&self) -> Ident; diff --git a/tasks/ast_tools/src/schema/serialize.rs b/tasks/ast_tools/src/schema/serialize.rs index 8f83219c0207c1..517c41d0be4ee5 100644 --- a/tasks/ast_tools/src/schema/serialize.rs +++ b/tasks/ast_tools/src/schema/serialize.rs @@ -1,9 +1,8 @@ use convert_case::{Case, Casing}; use rustc_hash::FxHashSet; -use crate::{markers::ESTreeStructTagMode, schema::GetIdent, Schema, TypeId}; - use super::{EnumDef, StructDef, TypeDef, VariantDef}; +use crate::{markers::ESTreeStructTagMode, schema::GetIdent, Schema, TypeId}; pub fn enum_variant_name(var: &VariantDef, enm: &EnumDef) -> String { match var.markers.derive_attributes.estree.rename.as_ref() { diff --git a/tasks/compat_data/src/lib.rs b/tasks/compat_data/src/lib.rs index 4bde4cad0a3165..7a24cde2e47694 100644 --- a/tasks/compat_data/src/lib.rs +++ b/tasks/compat_data/src/lib.rs @@ -2,7 +2,6 @@ use std::{fs, str::FromStr}; use oxc_tasks_common::project_root; use oxc_transformer::EngineTargets; - use quote::quote; use serde::Deserialize; use syn::Ident; diff --git a/tasks/coverage/src/driver.rs b/tasks/coverage/src/driver.rs index bec0b0bbfa5114..17bc9857b1ed01 100644 --- a/tasks/coverage/src/driver.rs +++ b/tasks/coverage/src/driver.rs @@ -1,7 +1,5 @@ use std::{ops::ControlFlow, path::PathBuf}; -use rustc_hash::FxHashSet; - use oxc::{ allocator::Allocator, ast::{ast::Program, Comment}, @@ -16,6 +14,7 @@ use oxc::{ CompilerInterface, }; use oxc_tasks_transform_checker::{check_semantic_after_transform, check_semantic_ids}; +use rustc_hash::FxHashSet; use crate::suite::TestResult; diff --git a/tasks/coverage/src/runtime/mod.rs b/tasks/coverage/src/runtime/mod.rs index 38b9f16316af85..b4976b3c86a707 100644 --- a/tasks/coverage/src/runtime/mod.rs +++ b/tasks/coverage/src/runtime/mod.rs @@ -16,6 +16,7 @@ use oxc::{ }; use oxc_tasks_common::agent; use serde_json::json; +use test262_status::get_v8_test262_failure_paths; use crate::{ suite::{Case, TestResult}, @@ -23,8 +24,6 @@ use crate::{ workspace_root, }; -use test262_status::get_v8_test262_failure_paths; - static SKIP_FEATURES: &[&str] = &[ // Node's version of V8 doesn't implement these "hashbang", diff --git a/tasks/coverage/src/typescript/meta.rs b/tasks/coverage/src/typescript/meta.rs index 25e3b4aaa673db..d43b1d8d92d74f 100644 --- a/tasks/coverage/src/typescript/meta.rs +++ b/tasks/coverage/src/typescript/meta.rs @@ -1,6 +1,5 @@ //! -use rustc_hash::FxHashMap; use std::{fs, path::Path, sync::Arc}; use oxc::{ @@ -11,6 +10,7 @@ use oxc::{ span::SourceType, }; use regex::Regex; +use rustc_hash::FxHashMap; use crate::workspace_root; diff --git a/tasks/prettier_conformance/src/ignore_list.rs b/tasks/prettier_conformance/src/ignore_list.rs index 1e831867cf5aed..1441c9f9cc2bba 100644 --- a/tasks/prettier_conformance/src/ignore_list.rs +++ b/tasks/prettier_conformance/src/ignore_list.rs @@ -79,7 +79,6 @@ pub const IGNORE_TESTS: &[&str] = &[ "typescript/as/as-const-embedded.ts", // Syntax recovery "typescript/error-recovery/", - // + Not yet supported by OXC // Some items may be already declared in the above // ---------------------------------------------------------------------------------------------------------------------------------- diff --git a/tasks/transform_checker/src/lib.rs b/tasks/transform_checker/src/lib.rs index 9b7c5aef92684d..368f2c814eb527 100644 --- a/tasks/transform_checker/src/lib.rs +++ b/tasks/transform_checker/src/lib.rs @@ -92,8 +92,6 @@ use std::{ }; use indexmap::IndexMap; -use rustc_hash::FxBuildHasher; - use oxc_allocator::{Allocator, CloneIn}; use oxc_ast::{ast::*, visit::walk, Visit}; use oxc_diagnostics::OxcDiagnostic; @@ -104,6 +102,7 @@ use oxc_syntax::{ scope::{ScopeFlags, ScopeId}, symbol::SymbolId, }; +use rustc_hash::FxBuildHasher; type FxIndexMap = IndexMap; diff --git a/tasks/transform_conformance/src/constants.rs b/tasks/transform_conformance/src/constants.rs index effeab3409625c..94770bb4c1aacd 100644 --- a/tasks/transform_conformance/src/constants.rs +++ b/tasks/transform_conformance/src/constants.rs @@ -103,5 +103,5 @@ pub const SKIP_TESTS: &[&str] = &[ "babel-plugin-transform-object-rest-spread/test/fixtures/assumption", "babel-plugin-transform-object-rest-spread/test/fixtures/object-spread-loose", "babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/remove-unused-excluded-keys-loose", - "babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/regression/gh-8323" + "babel-plugin-transform-object-rest-spread/test/fixtures/object-rest/regression/gh-8323", ]; diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 2011bbbc7f2529..0494cdeb1877e9 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -4,12 +4,11 @@ use std::{ }; use cow_utils::CowUtils; -use oxc::parser::ParseOptions; use oxc::{ allocator::Allocator, codegen::{CodeGenerator, CodegenOptions}, diagnostics::{NamedSource, OxcDiagnostic}, - parser::Parser, + parser::{ParseOptions, Parser}, span::{SourceType, VALID_EXTENSIONS}, transformer::{BabelOptions, HelperLoaderMode, TransformOptions}, };