diff --git a/Cargo.toml b/Cargo.toml index a2ce59c7f4cca..26d7b306260f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,15 +68,28 @@ wildcard_imports = "allow" # used_underscore_binding= "allow" doc_markdown = "allow" # nursery +nursery = { level = "warn", priority = -1 } # `const` functions do not make sense for our project because this is not a `const` library. # This rule also confuses newcomers and forces them to add `const` blindlessly without any reason. missing_const_for_fn = "allow" +option_if_let_else = "allow" +or_fun_call = "allow" +cognitive_complexity = "allow" +non_send_fields_in_send_ty = "allow" +use_self = "allow" +significant_drop_tightening = "allow" +branches_sharing_code = "allow" +fallible_impl_from = "allow" +useless_let_if_seq = "allow" significant_drop_in_scrutinee = "warn" iter_on_single_items = "warn" unused_peekable = "warn" too_long_first_doc_paragraph = "warn" suspicious_operation_groupings = "warn" redundant_clone = "warn" +redundant_pub_crate = "allow" # FIXME +debug_assert_with_mut_call = "allow" # FIXME +needless_pass_by_ref_mut = "allow" # FIXME # cargo cargo = { level = "warn", priority = -1 } multiple_crate_versions = "allow" diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 3bdb2bc9017b3..ea0523c57ee5e 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -209,7 +209,7 @@ impl Runner for LintRunner { if fs::write(Self::DEFAULT_OXLINTRC, configuration).is_ok() { stdout - .write_all("Configuration file created\n".as_bytes()) + .write_all(b"Configuration file created\n") .or_else(Self::check_for_writer_error) .unwrap(); stdout.flush().unwrap(); diff --git a/apps/oxlint/src/output_formatter/junit.rs b/apps/oxlint/src/output_formatter/junit.rs index fe64e7158383d..956964f70cfe5 100644 --- a/apps/oxlint/src/output_formatter/junit.rs +++ b/apps/oxlint/src/output_formatter/junit.rs @@ -53,7 +53,7 @@ fn format_junit(diagnostics: &[Error]) -> String { let rule = diagnostic.code().map_or_else(String::new, |code| code.to_string()); let Info { message, start, .. } = Info::new(diagnostic); - let severity = if let Some(Severity::Error) = diagnostic.severity() { + let severity = if diagnostic.severity() == Some(Severity::Error) { total_errors += 1; error += 1; "error" diff --git a/apps/oxlint/src/tester.rs b/apps/oxlint/src/tester.rs index b4a252b23400f..8d48377c05de3 100644 --- a/apps/oxlint/src/tester.rs +++ b/apps/oxlint/src/tester.rs @@ -53,17 +53,17 @@ impl Tester { let options = lint_command().run_inner(*args).unwrap(); let args_string = args.join(" "); - output.extend_from_slice("########## \n".as_bytes()); + output.extend_from_slice(b"########## \n"); output.extend_from_slice(format!("arguments: {args_string}\n").as_bytes()); output.extend_from_slice( format!("working directory: {}\n", relative_dir.to_str().unwrap()).as_bytes(), ); - output.extend_from_slice("----------\n".as_bytes()); + output.extend_from_slice(b"----------\n"); let result = LintRunner::new(options).with_cwd(self.cwd.clone()).run(&mut output); - output.extend_from_slice("----------\n".as_bytes()); + output.extend_from_slice(b"----------\n"); output.extend_from_slice(format!("CLI result: {result:?}\n").as_bytes()); - output.extend_from_slice("----------\n".as_bytes()); + output.extend_from_slice(b"----------\n"); output.push(b'\n'); } diff --git a/crates/oxc_cfg/src/lib.rs b/crates/oxc_cfg/src/lib.rs index bb162fe54acfd..36e51efc0c751 100644 --- a/crates/oxc_cfg/src/lib.rs +++ b/crates/oxc_cfg/src/lib.rs @@ -205,15 +205,19 @@ impl ControlFlowGraph { // if there is exactly one and it is a condition instruction we are in a loop so we // check the condition to infer if it is always true. - if let EvalConstConditionResult::Eval(true) = try_eval_const_condition(only_instruction) { + if matches!( + try_eval_const_condition(only_instruction), + EvalConstConditionResult::Eval(true) + ) { get_jump_target(&self.graph, node).map(|it| (it, node)) - } else if let EvalConstConditionResult::Eval(true) = self - .basic_block(backedge.source()) - .instructions() - .iter() - .exactly_one() - .map_or_else(|_| EvalConstConditionResult::NotFound, try_eval_const_condition) - { + } else if matches!( + self.basic_block(backedge.source()) + .instructions() + .iter() + .exactly_one() + .map_or_else(|_| EvalConstConditionResult::NotFound, try_eval_const_condition), + EvalConstConditionResult::Eval(true) + ) { get_jump_target(&self.graph, node).map(|it| (node, it)) } else { None diff --git a/crates/oxc_codegen/src/binary_expr_visitor.rs b/crates/oxc_codegen/src/binary_expr_visitor.rs index b779344dd6d62..26770069002f4 100644 --- a/crates/oxc_codegen/src/binary_expr_visitor.rs +++ b/crates/oxc_codegen/src/binary_expr_visitor.rs @@ -12,7 +12,7 @@ use oxc_syntax::{ use crate::{gen::GenExpr, Codegen, Context, Operator}; #[derive(Clone, Copy)] -pub(crate) enum Binaryish<'a> { +pub enum Binaryish<'a> { Binary(&'a BinaryExpression<'a>), Logical(&'a LogicalExpression<'a>), } diff --git a/crates/oxc_codegen/src/comment.rs b/crates/oxc_codegen/src/comment.rs index 5dee019925bfb..dc43723f0b154 100644 --- a/crates/oxc_codegen/src/comment.rs +++ b/crates/oxc_codegen/src/comment.rs @@ -5,7 +5,7 @@ use oxc_syntax::identifier::is_line_terminator; use crate::{Codegen, LegalComment}; -pub(crate) type CommentsMap = FxHashMap>; +pub type CommentsMap = FxHashMap>; impl Codegen<'_> { pub(crate) fn build_comments(&mut self, comments: &[Comment]) { diff --git a/crates/oxc_codegen/src/operator.rs b/crates/oxc_codegen/src/operator.rs index d30f36dded9bb..8c5fb8089fe87 100644 --- a/crates/oxc_codegen/src/operator.rs +++ b/crates/oxc_codegen/src/operator.rs @@ -1,7 +1,7 @@ use oxc_syntax::operator::{BinaryOperator, UnaryOperator, UpdateOperator}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(crate) enum Operator { +pub enum Operator { Binary(BinaryOperator), Unary(UnaryOperator), Update(UpdateOperator), diff --git a/crates/oxc_codegen/src/sourcemap_builder.rs b/crates/oxc_codegen/src/sourcemap_builder.rs index 6b6d6e09b08c5..4edb5e3c24b9a 100644 --- a/crates/oxc_codegen/src/sourcemap_builder.rs +++ b/crates/oxc_codegen/src/sourcemap_builder.rs @@ -537,7 +537,7 @@ mod test { #[test] fn add_source_mapping_for_name() { - let output = "ac".as_bytes(); + let output = b"ac"; let mut builder = SourcemapBuilder::new(Path::new("x.js"), "ab"); builder.add_source_mapping_for_name(output, Span::new(0, 1), "a"); builder.add_source_mapping_for_name(output, Span::new(1, 2), "c"); @@ -556,7 +556,7 @@ mod test { #[test] fn add_source_mapping_for_unordered_position() { - let output = "".as_bytes(); + let output = b""; let mut builder = SourcemapBuilder::new(Path::new("x.js"), "ab"); builder.add_source_mapping(output, 1, None); builder.add_source_mapping(output, 0, None); diff --git a/crates/oxc_ecmascript/src/to_primitive.rs b/crates/oxc_ecmascript/src/to_primitive.rs index 4a72215c550a7..355391de42806 100644 --- a/crates/oxc_ecmascript/src/to_primitive.rs +++ b/crates/oxc_ecmascript/src/to_primitive.rs @@ -81,7 +81,7 @@ impl ToPrimitive<'_> for Expression<'_> { } } -pub(crate) fn maybe_object_with_to_primitive_related_properties_overridden( +pub fn maybe_object_with_to_primitive_related_properties_overridden( obj: &ObjectExpression<'_>, ) -> bool { obj.properties.iter().any(|prop| match prop { diff --git a/crates/oxc_linter/src/config/config_store.rs b/crates/oxc_linter/src/config/config_store.rs index 3fe2e2fcdead3..c0f76ca0d0115 100644 --- a/crates/oxc_linter/src/config/config_store.rs +++ b/crates/oxc_linter/src/config/config_store.rs @@ -7,7 +7,7 @@ use crate::{rules::RULES, RuleWithSeverity}; // TODO: support `categories` et. al. in overrides. #[derive(Debug)] -pub(crate) struct ResolvedLinterState { +pub struct ResolvedLinterState { // TODO: Arc + Vec -> SyncVec? It would save a pointer dereference. pub rules: Arc<[RuleWithSeverity]>, pub config: Arc, diff --git a/crates/oxc_linter/src/config/env.rs b/crates/oxc_linter/src/config/env.rs index cab011440a433..19ae8f39efb2b 100644 --- a/crates/oxc_linter/src/config/env.rs +++ b/crates/oxc_linter/src/config/env.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; /// list of /// environments](https://eslint.org/docs/v8.x/use/configure/language-options#specifying-environments) /// for what environments are available and what each one provides. -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)] pub struct OxlintEnv(FxHashMap); impl FromIterator for OxlintEnv { diff --git a/crates/oxc_linter/src/config/globals.rs b/crates/oxc_linter/src/config/globals.rs index 0aaf0ed2dea87..672b499392845 100644 --- a/crates/oxc_linter/src/config/globals.rs +++ b/crates/oxc_linter/src/config/globals.rs @@ -30,7 +30,7 @@ use serde::{de::Visitor, Deserialize, Serialize}; /// You may also use `"readable"` or `false` to represent `"readonly"`, and /// `"writeable"` or `true` to represent `"writable"`. // -#[derive(Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema, Clone)] +#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize, JsonSchema, Clone)] pub struct OxlintGlobals(FxHashMap); impl Deref for OxlintGlobals { diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index 61f5c0afef265..862d3319ff6bd 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -12,7 +12,7 @@ mod rules; mod settings; pub use config_builder::{ConfigBuilderError, ConfigStoreBuilder}; pub use config_store::ConfigStore; -pub(crate) use config_store::ResolvedLinterState; +pub use config_store::ResolvedLinterState; pub use env::OxlintEnv; pub use globals::{GlobalValue, OxlintGlobals}; pub use overrides::OxlintOverrides; diff --git a/crates/oxc_linter/src/config/plugins.rs b/crates/oxc_linter/src/config/plugins.rs index e6ad6bf39c144..155d3b8a93b59 100644 --- a/crates/oxc_linter/src/config/plugins.rs +++ b/crates/oxc_linter/src/config/plugins.rs @@ -8,7 +8,7 @@ use serde::{ bitflags! { // NOTE: may be increased to a u32 if needed - #[derive(Debug, Clone, Copy, PartialEq, Hash)] + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct LintPlugins: u16 { /// Not really a plugin. Included for completeness. const ESLINT = 0; diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs index a4b36d951c103..b46a27b2aa66d 100644 --- a/crates/oxc_linter/src/config/rules.rs +++ b/crates/oxc_linter/src/config/rules.rs @@ -23,8 +23,7 @@ type RuleSet = FxHashSet; // - type RuleConf = SeverityConf | [SeverityConf, ...any[]]; // // Note: when update document comment, also update `DummyRuleMap`'s description in this file. -#[derive(Debug, Clone, Default)] -#[cfg_attr(test, derive(PartialEq))] +#[derive(Debug, Clone, Default, Eq, PartialEq)] pub struct OxlintRules { /// List of all configured rules pub(crate) rules: Vec, @@ -46,8 +45,7 @@ impl OxlintRules { /// e.g. `eslint/no-console` or `react/rule-of-hooks`. /// Includes the plugin name, the rule name, and the configuration for the rule (if any). /// This does not imply the rule is known to the linter as that, only that it is configured. -#[derive(Debug, Clone)] -#[cfg_attr(test, derive(PartialEq))] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct ESLintRule { /// Name of the plugin: `eslint`, `react`, etc. pub plugin_name: String, diff --git a/crates/oxc_linter/src/config/settings/jsx_a11y.rs b/crates/oxc_linter/src/config/settings/jsx_a11y.rs index 96038b9d4a397..e4f1203218484 100644 --- a/crates/oxc_linter/src/config/settings/jsx_a11y.rs +++ b/crates/oxc_linter/src/config/settings/jsx_a11y.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; /// [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s /// configuration for a full reference. #[derive(Debug, Clone, Deserialize, Default, Serialize, JsonSchema)] -#[cfg_attr(test, derive(PartialEq))] +#[cfg_attr(test, derive(PartialEq, Eq))] pub struct JSXA11yPluginSettings { /// An optional setting that define the prop your code uses to create polymorphic components. /// This setting will be used to determine the element type in rules that diff --git a/crates/oxc_linter/src/context/host.rs b/crates/oxc_linter/src/context/host.rs index ad8ad0a3b1680..f47b7947799ff 100644 --- a/crates/oxc_linter/src/context/host.rs +++ b/crates/oxc_linter/src/context/host.rs @@ -35,7 +35,7 @@ use super::{plugin_name_to_prefix, LintContext}; /// - [Flyweight Pattern](https://en.wikipedia.org/wiki/Flyweight_pattern) #[must_use] #[non_exhaustive] -pub(crate) struct ContextHost<'a> { +pub struct ContextHost<'a> { /// Shared semantic information about the file being linted, which includes scopes, symbols /// and AST nodes. See [`Semantic`]. pub(super) semantic: Rc>, @@ -106,7 +106,6 @@ impl<'a> ContextHost<'a> { /// Set the linter configuration for this context. #[inline] - #[expect(dead_code)] // will be used in up-stack PR pub fn with_config(mut self, config: &Arc) -> Self { let plugins = config.plugins; self.config = Arc::clone(config); diff --git a/crates/oxc_linter/src/context/mod.rs b/crates/oxc_linter/src/context/mod.rs index 76b305b30f35c..c3014d38b8139 100644 --- a/crates/oxc_linter/src/context/mod.rs +++ b/crates/oxc_linter/src/context/mod.rs @@ -19,7 +19,7 @@ use crate::{ }; mod host; -pub(crate) use host::ContextHost; +pub use host::ContextHost; /// Contains all of the state and context specific to this lint rule. /// diff --git a/crates/oxc_linter/src/frameworks.rs b/crates/oxc_linter/src/frameworks.rs index 67705ed40d0ef..1fcba314becaa 100644 --- a/crates/oxc_linter/src/frameworks.rs +++ b/crates/oxc_linter/src/frameworks.rs @@ -72,7 +72,7 @@ impl FrameworkFlags { } /// -pub(crate) fn is_jestlike_file(path: &Path) -> bool { +pub fn is_jestlike_file(path: &Path) -> bool { use std::ffi::OsStr; if path.components().any(|c| match c { @@ -88,10 +88,10 @@ pub(crate) fn is_jestlike_file(path: &Path) -> bool { .is_some_and(|name_or_first_ext| name_or_first_ext == "test" || name_or_first_ext == "spec") } -pub(crate) fn has_vitest_imports(module_record: &ModuleRecord) -> bool { +pub fn has_vitest_imports(module_record: &ModuleRecord) -> bool { module_record.import_entries.iter().any(|entry| entry.module_request.name() == "vitest") } -pub(crate) fn has_jest_imports(module_record: &ModuleRecord) -> bool { +pub fn has_jest_imports(module_record: &ModuleRecord) -> bool { module_record.import_entries.iter().any(|entry| entry.module_request.name() == "@jest/globals") } diff --git a/crates/oxc_linter/src/loader/partial_loader/astro.rs b/crates/oxc_linter/src/loader/partial_loader/astro.rs index 2cc63d68df577..c97eeec530883 100644 --- a/crates/oxc_linter/src/loader/partial_loader/astro.rs +++ b/crates/oxc_linter/src/loader/partial_loader/astro.rs @@ -74,7 +74,7 @@ impl<'a> AstroPartialLoader<'a> { break; }; // check for the / of a self closing script tag - if let Some('/') = self.source_text.chars().nth(js_start - 2) { + if self.source_text.chars().nth(js_start - 2) == Some('/') { js_end = pointer; // find "" if no self closing tag was found } else if let Some(offset) = diff --git a/crates/oxc_linter/src/options/filter.rs b/crates/oxc_linter/src/options/filter.rs index 80c8fc08ddb9a..b832ae2a83366 100644 --- a/crates/oxc_linter/src/options/filter.rs +++ b/crates/oxc_linter/src/options/filter.rs @@ -11,8 +11,7 @@ use super::AllowWarnDeny; /// 2. Filter an entire category: `correctness` /// 3. Some unknow filter. This is a fallback used when parsing a filter string, /// and is interpreted uniquely by the linter. -#[derive(Debug, Clone)] -#[cfg_attr(test, derive(PartialEq))] +#[derive(Debug, Clone, Eq, PartialEq)] pub struct LintFilter { severity: AllowWarnDeny, kind: LintFilterKind, @@ -77,8 +76,7 @@ impl<'a> From<&'a LintFilter> for (AllowWarnDeny, &'a LintFilterKind) { } } -#[derive(Debug, Clone)] -#[cfg_attr(test, derive(PartialEq))] +#[derive(Debug, Clone, Eq, PartialEq)] pub enum LintFilterKind { Generic(Cow<'static, str>), /// e.g. `no-const-assign` or `eslint/no-const-assign` diff --git a/crates/oxc_linter/src/options/mod.rs b/crates/oxc_linter/src/options/mod.rs index 0c5056a5c986f..767960b68e436 100644 --- a/crates/oxc_linter/src/options/mod.rs +++ b/crates/oxc_linter/src/options/mod.rs @@ -8,7 +8,7 @@ use crate::{fixer::FixKind, FrameworkFlags}; /// Subset of options used directly by the linter. #[derive(Debug, Default, Clone, Copy)] -#[cfg_attr(test, derive(PartialEq))] +#[cfg_attr(test, derive(PartialEq, Eq))] pub struct LintOptions { pub fix: FixKind, pub framework_hints: FrameworkFlags, diff --git a/crates/oxc_linter/src/rules/eslint/for_direction.rs b/crates/oxc_linter/src/rules/eslint/for_direction.rs index ffd251f9bc5b5..cf29c8d8f5ccd 100644 --- a/crates/oxc_linter/src/rules/eslint/for_direction.rs +++ b/crates/oxc_linter/src/rules/eslint/for_direction.rs @@ -130,9 +130,9 @@ impl Rule for ForDirection { span.end = update.argument.span().start; } - if let UpdateOperator::Increment = update.operator { + if update.operator == UpdateOperator::Increment { new_operator_str = "--"; - } else if let UpdateOperator::Decrement = update.operator { + } else if update.operator == UpdateOperator::Decrement { new_operator_str = "++"; } } @@ -140,9 +140,9 @@ impl Rule for ForDirection { span.start = update.left.span().end; span.end = update.right.span().start; - if let AssignmentOperator::Addition = update.operator { + if update.operator == AssignmentOperator::Addition { new_operator_str = "-="; - } else if let AssignmentOperator::Subtraction = update.operator { + } else if update.operator == AssignmentOperator::Subtraction { new_operator_str = "+="; } } diff --git a/crates/oxc_linter/src/rules/eslint/func_style.rs b/crates/oxc_linter/src/rules/eslint/func_style.rs index 5430ff5ae0858..99434d6ec6be8 100644 --- a/crates/oxc_linter/src/rules/eslint/func_style.rs +++ b/crates/oxc_linter/src/rules/eslint/func_style.rs @@ -251,10 +251,10 @@ impl Rule for FuncStyle { } } - if let Some(NamedExports::Expression) = self.named_exports { - if matches!(parent.kind(), AstKind::ExportNamedDeclaration(_)) { - ctx.diagnostic(func_style_diagnostic(func.span, self.style)); - } + if self.named_exports == Some(NamedExports::Expression) + && matches!(parent.kind(), AstKind::ExportNamedDeclaration(_)) + { + ctx.diagnostic(func_style_diagnostic(func.span, self.style)); } } FunctionType::FunctionExpression => { @@ -266,12 +266,10 @@ impl Rule for FuncStyle { ctx.diagnostic(func_style_diagnostic(decl.span, self.style)); } - if let Some(NamedExports::Declaration) = self.named_exports { - if is_ancestor_export { - ctx.diagnostic(func_style_diagnostic( - decl.span, self.style, - )); - } + if self.named_exports == Some(NamedExports::Declaration) + && is_ancestor_export + { + ctx.diagnostic(func_style_diagnostic(decl.span, self.style)); } } } @@ -310,10 +308,8 @@ impl Rule for FuncStyle { ctx.diagnostic(func_style_diagnostic(decl.span, self.style)); } - if let Some(NamedExports::Declaration) = self.named_exports { - if is_ancestor_export { - ctx.diagnostic(func_style_diagnostic(decl.span, self.style)); - } + if self.named_exports == Some(NamedExports::Declaration) && is_ancestor_export { + ctx.diagnostic(func_style_diagnostic(decl.span, self.style)); } } } diff --git a/crates/oxc_linter/src/rules/eslint/getter_return.rs b/crates/oxc_linter/src/rules/eslint/getter_return.rs index 9b1c23ac82212..ee27d7b66cfda 100644 --- a/crates/oxc_linter/src/rules/eslint/getter_return.rs +++ b/crates/oxc_linter/src/rules/eslint/getter_return.rs @@ -271,10 +271,10 @@ impl GetterReturn { }); let does_return = return_instruction.is_some_and(|ret| { - !matches! { ret.kind, + !matches!( ret.kind, InstructionKind::Return(ReturnInstructionKind::ImplicitUndefined) if !self.allow_implicit - } + ) }); // Return true as the second argument to signify we should diff --git a/crates/oxc_linter/src/rules/eslint/init_declarations.rs b/crates/oxc_linter/src/rules/eslint/init_declarations.rs index e3c46e80b311b..1bd253ff566af 100644 --- a/crates/oxc_linter/src/rules/eslint/init_declarations.rs +++ b/crates/oxc_linter/src/rules/eslint/init_declarations.rs @@ -171,7 +171,7 @@ impl Rule for InitDeclarations { )); } Mode::Never if is_initialized && !self.ignore_for_loop_init => { - if let VariableDeclarationKind::Const = &v.kind { + if matches!(&v.kind, VariableDeclarationKind::Const) { continue; } ctx.diagnostic(init_declarations_diagnostic( diff --git a/crates/oxc_linter/src/rules/eslint/no_unreachable.rs b/crates/oxc_linter/src/rules/eslint/no_unreachable.rs index c41c482f5a79a..c82b9e85a7f26 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unreachable.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unreachable.rs @@ -157,11 +157,11 @@ impl Rule for NoUnreachable { continue; } - if matches! { + if matches!( node.kind(), AstKind::VariableDeclaration(decl) if matches!(decl.kind, VariableDeclarationKind::Var) && !decl.has_init() - } { + ) { // Skip `var` declarations without any initialization, // These work because of the JavaScript hoisting rules. continue; diff --git a/crates/oxc_linter/src/rules/jest/no_large_snapshots.rs b/crates/oxc_linter/src/rules/jest/no_large_snapshots.rs index 125a5063e2d55..19377cb37ea09 100644 --- a/crates/oxc_linter/src/rules/jest/no_large_snapshots.rs +++ b/crates/oxc_linter/src/rules/jest/no_large_snapshots.rs @@ -167,7 +167,7 @@ impl Rule for NoLargeSnapshots { }); if is_snap { - for node in ctx.nodes().iter().collect::>() { + for node in ctx.nodes().iter() { if let AstKind::ExpressionStatement(expr_stmt) = node.kind() { self.report_in_expr_stmt(expr_stmt, ctx); } 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 7728b2f81163d..0d43e7bc4291b 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 @@ -153,7 +153,7 @@ fn check_interface_declaration( allow_interfaces: AllowInterfaces, allow_with_name: &str, ) { - if let AllowInterfaces::Always = allow_interfaces { + if matches!(allow_interfaces, AllowInterfaces::Always) { return; }; if interface.id.name.as_str() == allow_with_name { @@ -190,7 +190,7 @@ fn check_type_literal( allow_object_types: AllowObjectTypes, allow_with_name: &str, ) { - if let AllowObjectTypes::Always = allow_object_types { + if matches!(allow_object_types, AllowObjectTypes::Always) { return; }; let Some(parent_node) = ctx.nodes().parent_node(node_id) else { 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 a43f144345b58..ca7be72fb12f4 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 @@ -224,7 +224,7 @@ fn get_replacement(right: &Expression, operator: BinaryOperator) -> Option bool { if let Expression::UnaryExpression(unary_expression) = expression { - if let UnaryOperator::UnaryNegation = unary_expression.operator { + if unary_expression.operator == UnaryOperator::UnaryNegation { if let Expression::NumericLiteral(value) = &unary_expression.argument.get_inner_expression() { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_set_has.rs b/crates/oxc_linter/src/rules/unicorn/prefer_set_has.rs index 6e10202615a8d..a71e50e1467d2 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_set_has.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_set_has.rs @@ -132,7 +132,7 @@ impl Rule for PreferSetHas { return; }; - if let VariableDeclarationKind::Var = declarator.kind { + if declarator.kind == VariableDeclarationKind::Var { return; } diff --git a/crates/oxc_linter/src/utils/react.rs b/crates/oxc_linter/src/utils/react.rs index bb768613846c5..08028f69fec31 100644 --- a/crates/oxc_linter/src/utils/react.rs +++ b/crates/oxc_linter/src/utils/react.rs @@ -330,10 +330,10 @@ pub fn is_react_function_call(call: &CallExpression, expected_call: &str) -> boo } if let Some(member) = call.callee.as_member_expression() { - matches! { + matches!( member.object().get_identifier_reference(), Some(ident) if ident.name.as_str() == PRAGMA - } + ) } else { true } diff --git a/crates/oxc_linter/src/utils/react_perf.rs b/crates/oxc_linter/src/utils/react_perf.rs index 407d72cae0ea1..5bab52774906a 100644 --- a/crates/oxc_linter/src/utils/react_perf.rs +++ b/crates/oxc_linter/src/utils/react_perf.rs @@ -37,7 +37,7 @@ fn react_perf_reference_diagnostic( diagnostic.and_label(attr_span.label("And used here")) } -pub(crate) trait ReactPerfRule: Sized + Default + fmt::Debug { +pub trait ReactPerfRule: Sized + Default + fmt::Debug { const MESSAGE: &'static str; /// Check if an [`Expression`] violates a react perf rule. If it does, diff --git a/crates/oxc_macros/src/declare_oxc_lint.rs b/crates/oxc_macros/src/declare_oxc_lint.rs index 30c5662970822..644c3d0e5f77d 100644 --- a/crates/oxc_macros/src/declare_oxc_lint.rs +++ b/crates/oxc_macros/src/declare_oxc_lint.rs @@ -55,7 +55,7 @@ impl Parse for LintRuleMeta { } } -pub(crate) fn rule_name_converter() -> Converter { +pub fn rule_name_converter() -> Converter { Converter::new().remove_boundary(Boundary::LOWER_DIGIT).to_case(Case::Kebab) } diff --git a/crates/oxc_minifier/src/peephole/replace_known_methods.rs b/crates/oxc_minifier/src/peephole/replace_known_methods.rs index ddea9da67877f..bbdb795cd2391 100644 --- a/crates/oxc_minifier/src/peephole/replace_known_methods.rs +++ b/crates/oxc_minifier/src/peephole/replace_known_methods.rs @@ -464,7 +464,7 @@ impl<'a> PeepholeOptimizations { // In Rust, when facing `.5`, it may follow `half-away-from-zero` instead of round to upper bound. // So we need to handle it manually. let frac_part = arg_val.fract(); - let epsilon = 2f64.powf(-52f64); + let epsilon = 2f64.powi(-52); if (frac_part.abs() - 0.5).abs() < epsilon { // We should ceil it. arg_val.ceil() @@ -831,7 +831,7 @@ impl<'a> PeepholeOptimizations { "NaN" => num(span, f64::NAN), "MAX_SAFE_INTEGER" => { if self.target < ESTarget::ES2016 { - num(span, 2.0f64.powf(53.0) - 1.0) + num(span, 2.0f64.powi(53) - 1.0) } else { // 2**53 - 1 pow_with_expr(span, 2.0, 53.0, BinaryOperator::Subtraction, 1.0) @@ -839,7 +839,7 @@ impl<'a> PeepholeOptimizations { } "MIN_SAFE_INTEGER" => { if self.target < ESTarget::ES2016 { - num(span, -(2.0f64.powf(53.0) - 1.0)) + num(span, -(2.0f64.powi(53) - 1.0)) } else { // -(2**53 - 1) ctx.ast.expression_unary( diff --git a/crates/oxc_parser/src/lib.rs b/crates/oxc_parser/src/lib.rs index b33a4b9e51d52..d3df1fdd2ad02 100644 --- a/crates/oxc_parser/src/lib.rs +++ b/crates/oxc_parser/src/lib.rs @@ -268,7 +268,7 @@ mod parser_parse { /// /// `UniquePromise::new_for_tests_and_benchmarks` is a backdoor for tests/benchmarks, so they can /// create a `ParserImpl` or `Lexer`, and manipulate it directly, for testing/benchmarking purposes. - pub(crate) struct UniquePromise(()); + pub struct UniquePromise(()); impl UniquePromise { #[inline] diff --git a/crates/oxc_regular_expression/src/ast.rs b/crates/oxc_regular_expression/src/ast.rs index 8d3689425b4c1..c651a1ada4de7 100644 --- a/crates/oxc_regular_expression/src/ast.rs +++ b/crates/oxc_regular_expression/src/ast.rs @@ -83,7 +83,7 @@ pub struct BoundaryAssertion { } #[ast] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ESTree)] pub enum BoundaryAssertionKind { Start = 0, @@ -104,7 +104,7 @@ pub struct LookAroundAssertion<'a> { } #[ast] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ESTree)] pub enum LookAroundAssertionKind { Lookahead = 0, @@ -140,7 +140,7 @@ pub struct Character { } #[ast] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ESTree)] pub enum CharacterKind { ControlLetter = 0, @@ -167,7 +167,7 @@ pub struct CharacterClassEscape { } #[ast] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ESTree)] pub enum CharacterClassEscapeKind { D = 0, @@ -217,7 +217,7 @@ pub struct CharacterClass<'a> { } #[ast] -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] #[generate_derive(CloneIn, ContentEq, ESTree)] pub enum CharacterClassContentsKind { Union = 0, diff --git a/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/ast.rs b/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/ast.rs index 2a060a9c57416..a763a497ccf75 100644 --- a/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/ast.rs +++ b/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/ast.rs @@ -9,7 +9,7 @@ pub struct StringLiteral { pub body: Vec, } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum StringLiteralKind { Double, Single, diff --git a/crates/oxc_semantic/src/binder.rs b/crates/oxc_semantic/src/binder.rs index bfceda4d3d44a..aa37303bf81f1 100644 --- a/crates/oxc_semantic/src/binder.rs +++ b/crates/oxc_semantic/src/binder.rs @@ -12,7 +12,7 @@ use oxc_syntax::{ use crate::SemanticBuilder; -pub(crate) trait Binder<'a> { +pub trait Binder<'a> { #[expect(unused_variables)] fn bind(&self, builder: &mut SemanticBuilder<'a>) {} } diff --git a/crates/oxc_semantic/src/scope.rs b/crates/oxc_semantic/src/scope.rs index 19fe9e1c0420f..8f05412b2d0e1 100644 --- a/crates/oxc_semantic/src/scope.rs +++ b/crates/oxc_semantic/src/scope.rs @@ -11,7 +11,7 @@ use oxc_syntax::{ use crate::SymbolTable; -pub(crate) type Bindings<'a> = ArenaHashMap<'a, &'a str, SymbolId>; +pub type Bindings<'a> = ArenaHashMap<'a, &'a str, SymbolId>; pub type UnresolvedReferences<'a> = ArenaHashMap<'a, &'a str, ArenaVec<'a, ReferenceId>>; /// Scope Tree @@ -69,7 +69,7 @@ self_cell::self_cell!( } ); -pub(crate) struct ScopeTreeInner<'cell> { +pub struct ScopeTreeInner<'cell> { /// Symbol bindings in a scope. /// /// A binding is a mapping from an identifier name to its [`SymbolId`] diff --git a/crates/oxc_semantic/src/unresolved_stack.rs b/crates/oxc_semantic/src/unresolved_stack.rs index 34df37475c719..344802c8ac223 100644 --- a/crates/oxc_semantic/src/unresolved_stack.rs +++ b/crates/oxc_semantic/src/unresolved_stack.rs @@ -13,7 +13,7 @@ type TempUnresolvedReferences<'a> = FxHashMap, Vec>; // to reduce allocations, so the stack grows to maximum scope depth, but never shrinks. // See: // This stack abstraction uses the invariant that stack only grows to avoid bounds checks. -pub(crate) struct UnresolvedReferencesStack<'a> { +pub struct UnresolvedReferencesStack<'a> { stack: Vec>, /// Current scope depth. /// 0 is global scope. 1 is `Program`. diff --git a/crates/oxc_syntax/src/class.rs b/crates/oxc_syntax/src/class.rs index dc003f1834e7a..c8638d494739a 100644 --- a/crates/oxc_syntax/src/class.rs +++ b/crates/oxc_syntax/src/class.rs @@ -11,7 +11,7 @@ define_index_type! { } bitflags! { - #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)] pub struct ElementKind: u8 { const Accessor = 1 << 0; const Method = 1 << 1; diff --git a/crates/oxc_syntax/src/scope.rs b/crates/oxc_syntax/src/scope.rs index 37e7731fcd95e..b779f5e304d1c 100644 --- a/crates/oxc_syntax/src/scope.rs +++ b/crates/oxc_syntax/src/scope.rs @@ -65,7 +65,7 @@ export type ScopeId = number; "#; bitflags! { - #[derive(Debug, Clone, Copy, PartialEq)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ScopeFlags: u16 { const StrictMode = 1 << 0; const Top = 1 << 1; diff --git a/crates/oxc_transformer/src/jsx/comments.rs b/crates/oxc_transformer/src/jsx/comments.rs index 75413292cc3f3..51b97d92918f8 100644 --- a/crates/oxc_transformer/src/jsx/comments.rs +++ b/crates/oxc_transformer/src/jsx/comments.rs @@ -16,7 +16,7 @@ use crate::{JsxOptions, JsxRuntime, TransformCtx, TypeScriptOptions}; /// otherwise `JSDoc` could be used instead. /// /// This behavior is aligned with Babel. -pub(crate) fn update_options_with_comments( +pub fn update_options_with_comments( comments: &[Comment], typescript: &mut TypeScriptOptions, jsx: &mut JsxOptions, diff --git a/crates/oxc_transformer/src/jsx/mod.rs b/crates/oxc_transformer/src/jsx/mod.rs index 3a3e938aac485..ce3c5e14ea122 100644 --- a/crates/oxc_transformer/src/jsx/mod.rs +++ b/crates/oxc_transformer/src/jsx/mod.rs @@ -11,7 +11,7 @@ mod jsx_self; mod jsx_source; mod options; mod refresh; -pub(crate) use comments::update_options_with_comments; +pub use comments::update_options_with_comments; use display_name::ReactDisplayName; use jsx_impl::JsxImpl; use jsx_self::JsxSelf; diff --git a/crates/oxc_transformer/src/options/babel/mod.rs b/crates/oxc_transformer/src/options/babel/mod.rs index 3b1dab2b53849..b8412f8068f64 100644 --- a/crates/oxc_transformer/src/options/babel/mod.rs +++ b/crates/oxc_transformer/src/options/babel/mod.rs @@ -8,8 +8,8 @@ mod env; mod plugins; mod presets; pub use env::{BabelEnvOptions, BabelModule, BabelTargets}; -pub(crate) use plugins::BabelPlugins; -pub(crate) use presets::BabelPresets; +pub use plugins::BabelPlugins; +pub use presets::BabelPresets; /// Babel options /// diff --git a/crates/oxc_transformer/src/utils/ast_builder.rs b/crates/oxc_transformer/src/utils/ast_builder.rs index d91ba62a31d00..b24568cd401e4 100644 --- a/crates/oxc_transformer/src/utils/ast_builder.rs +++ b/crates/oxc_transformer/src/utils/ast_builder.rs @@ -5,7 +5,7 @@ use oxc_span::{GetSpan, SPAN}; use oxc_traverse::TraverseCtx; /// `object` -> `object.call`. -pub(crate) fn create_member_callee<'a>( +pub fn create_member_callee<'a>( object: Expression<'a>, property: &'static str, ctx: &mut TraverseCtx<'a>, @@ -15,7 +15,7 @@ pub(crate) fn create_member_callee<'a>( } /// `object` -> `object.bind(this)`. -pub(crate) fn create_bind_call<'a>( +pub fn create_bind_call<'a>( callee: Expression<'a>, this: Expression<'a>, span: Span, @@ -27,7 +27,7 @@ pub(crate) fn create_bind_call<'a>( } /// `object` -> `object.call(...arguments)`. -pub(crate) fn create_call_call<'a>( +pub fn create_call_call<'a>( callee: Expression<'a>, this: Expression<'a>, span: Span, @@ -42,7 +42,7 @@ pub(crate) fn create_call_call<'a>( /// with a body block. /// /// `expr` -> `(() => { return expr; })()` -pub(crate) fn wrap_expression_in_arrow_function_iife<'a>( +pub fn wrap_expression_in_arrow_function_iife<'a>( expr: Expression<'a>, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { @@ -56,7 +56,7 @@ pub(crate) fn wrap_expression_in_arrow_function_iife<'a>( /// Wrap statements in an IIFE (immediately invoked function expression). /// /// `x; y; z;` -> `(() => { x; y; z; })()` -pub(crate) fn wrap_statements_in_arrow_function_iife<'a>( +pub fn wrap_statements_in_arrow_function_iife<'a>( stmts: ArenaVec<'a, Statement<'a>>, scope_id: ScopeId, span: Span, @@ -73,7 +73,7 @@ pub(crate) fn wrap_statements_in_arrow_function_iife<'a>( } /// `object` -> `object.prototype`. -pub(crate) fn create_prototype_member<'a>( +pub fn create_prototype_member<'a>( object: Expression<'a>, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { @@ -83,7 +83,7 @@ pub(crate) fn create_prototype_member<'a>( } /// `object` -> `object.a`. -pub(crate) fn create_property_access<'a>( +pub fn create_property_access<'a>( object: Expression<'a>, property: &str, ctx: &mut TraverseCtx<'a>, diff --git a/crates/oxc_transformer/src/utils/mod.rs b/crates/oxc_transformer/src/utils/mod.rs index 964d1297d035c..dca0fb0f720e4 100644 --- a/crates/oxc_transformer/src/utils/mod.rs +++ b/crates/oxc_transformer/src/utils/mod.rs @@ -1 +1 @@ -pub(crate) mod ast_builder; +pub mod ast_builder; diff --git a/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs b/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs index 140c8642ea52f..e80547e078d21 100644 --- a/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs +++ b/crates/oxc_transformer/tests/integrations/plugins/inject_global_variables.rs @@ -11,7 +11,7 @@ use oxc_transformer::{InjectGlobalVariables, InjectGlobalVariablesConfig, Inject use crate::codegen; -pub(crate) fn test(source_text: &str, expected: &str, config: InjectGlobalVariablesConfig) { +pub fn test(source_text: &str, expected: &str, config: InjectGlobalVariablesConfig) { let source_type = SourceType::default(); let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); diff --git a/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs b/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs index 3554982e63e5c..f68ef525b8f21 100644 --- a/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs +++ b/crates/oxc_transformer/tests/integrations/plugins/replace_global_defines.rs @@ -8,7 +8,7 @@ use oxc_transformer::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig}; use crate::codegen; -pub(crate) fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefinesConfig) { +pub fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefinesConfig) { let source_type = SourceType::default(); let allocator = Allocator::default(); let ret = Parser::new(&allocator, source_text, source_type).parse(); diff --git a/crates/oxc_traverse/src/context/ancestry.rs b/crates/oxc_traverse/src/context/ancestry.rs index dcf483c133652..caba1c265e375 100644 --- a/crates/oxc_traverse/src/context/ancestry.rs +++ b/crates/oxc_traverse/src/context/ancestry.rs @@ -203,4 +203,4 @@ impl<'a> TraverseAncestry<'a> { /// It is not `Clone` or `Copy`, so no way to obtain one except in this file. /// Only method which generates a `PopToken` is `push_stack`, and `pop_stack` consumes one, /// which guarantees you can't have more pops than pushes. -pub(crate) struct PopToken(()); +pub struct PopToken(()); diff --git a/crates/oxc_traverse/src/lib.rs b/crates/oxc_traverse/src/lib.rs index 92775567b2a9e..17994b4e01d90 100644 --- a/crates/oxc_traverse/src/lib.rs +++ b/crates/oxc_traverse/src/lib.rs @@ -75,9 +75,9 @@ pub use context::{ mod generated { pub mod ancestor; - pub(super) mod scopes_collector; + pub mod scopes_collector; pub mod traverse; - pub(super) mod walk; + pub mod walk; } pub use generated::{ancestor, ancestor::Ancestor, traverse::Traverse}; use generated::{scopes_collector, walk::walk_ast}; diff --git a/tasks/ast_tools/src/logger.rs b/tasks/ast_tools/src/logger.rs index be85004396134..d99e68acf800e 100644 --- a/tasks/ast_tools/src/logger.rs +++ b/tasks/ast_tools/src/logger.rs @@ -3,11 +3,11 @@ use std::sync::OnceLock; static LOG: OnceLock = OnceLock::new(); /// Disable logging. -pub(super) fn quiet() { +pub fn quiet() { LOG.set(false).expect("Failed to disable logger"); } -pub(super) fn __internal_log_enable() -> bool { +pub fn __internal_log_enable() -> bool { *LOG.get_or_init(|| true) } diff --git a/tasks/coverage/src/suite.rs b/tasks/coverage/src/suite.rs index d9bd2703a5b69..3075dccb7d37a 100644 --- a/tasks/coverage/src/suite.rs +++ b/tasks/coverage/src/suite.rs @@ -22,7 +22,7 @@ use walkdir::WalkDir; use crate::{snap_root, workspace_root, AppArgs, Driver}; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum TestResult { ToBeRun, Passed, diff --git a/tasks/website/src/linter/rules/html.rs b/tasks/website/src/linter/rules/html.rs index e8e95dc6f7d09..759561f068d24 100644 --- a/tasks/website/src/linter/rules/html.rs +++ b/tasks/website/src/linter/rules/html.rs @@ -6,7 +6,7 @@ use std::{ }; #[derive(Debug, Default)] -pub(crate) struct HtmlWriter { +pub struct HtmlWriter { inner: RefCell, }