From 4fffb2cf48c5302173a6f00120318dfcd2c1d168 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:57:25 +0000 Subject: [PATCH 1/2] chore(rust): rust-version = "1.82.0" (#9270) --- Cargo.toml | 2 +- crates/oxc_isolated_declarations/src/class.rs | 2 +- crates/oxc_linter/src/ast_util.rs | 6 +++--- .../src/rules/eslint/no_constant_binary_expression.rs | 2 +- crates/oxc_linter/src/rules/eslint/no_dupe_else_if.rs | 5 +---- .../oxc_linter/src/rules/nextjs/google_font_preconnect.rs | 2 +- crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs | 2 +- .../oxc_linter/src/rules/promise/no_callback_in_promise.rs | 2 +- crates/oxc_linter/src/rules/react/no_is_mounted.rs | 2 +- crates/oxc_linter/src/rules/react/no_set_state.rs | 2 +- crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs | 2 +- crates/oxc_linter/src/utils/react.rs | 2 +- crates/oxc_linter/src/utils/unicorn.rs | 2 +- crates/oxc_prettier/src/format/js.rs | 2 +- .../src/parser/reader/string_literal_parser/parser_impl.rs | 2 +- crates/oxc_semantic/src/checker/typescript.rs | 2 +- crates/oxc_transformer/src/jsx/refresh.rs | 2 +- crates/oxc_transformer/src/typescript/namespace.rs | 2 +- 18 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ed0244e85673..cb2ac6328b5a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ homepage = "https://oxc.rs" keywords = ["JavaScript", "TypeScript", "linter", "minifier", "parser"] license = "MIT" repository = "https://github.com/oxc-project/oxc" -rust-version = "1.81.0" # Support last 4 minor versions. +rust-version = "1.82.0" # Support last 4 minor versions. (NOTE: bump to `edition = "2021"` when 1.85.0. description = "A collection of JavaScript tools written in Rust." # diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index 9f35010e6d3a9..17d4792d1e098 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -82,7 +82,7 @@ impl<'a> IsolatedDeclarations<'a> { let mut type_annotations = None; let mut value = None; - if property.accessibility.map_or(true, |a| !a.is_private()) { + if property.accessibility.is_none_or(|a| !a.is_private()) { if property.type_annotation.is_some() { type_annotations = property.type_annotation.clone_in(self.ast.allocator); } else if let Some(expr) = property.value.as_ref() { diff --git a/crates/oxc_linter/src/ast_util.rs b/crates/oxc_linter/src/ast_util.rs index 06a80753fbf6f..e391567169f41 100644 --- a/crates/oxc_linter/src/ast_util.rs +++ b/crates/oxc_linter/src/ast_util.rs @@ -151,7 +151,7 @@ impl<'a> IsConstant<'a, '_> for CallExpression<'a> { .arguments .iter() .next() - .map_or(true, |first| first.is_constant(true, semantic)) + .is_none_or(|first| first.is_constant(true, semantic)) { return semantic.is_reference_to_global_variable(ident); } @@ -545,7 +545,7 @@ pub fn could_be_error(ctx: &LintContext, expr: &Expression) -> bool { expr.operator, AssignmentOperator::LogicalOr | AssignmentOperator::LogicalNullish ) { - return expr.left.get_expression().map_or(true, |expr| could_be_error(ctx, expr)) + return expr.left.get_expression().is_none_or(|expr| could_be_error(ctx, expr)) || could_be_error(ctx, &expr.right); } @@ -673,7 +673,7 @@ pub fn is_default_this_binding<'a>( AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) ) }); - if upper_func.map_or(true, |node| !is_callee(node, semantic)) { + if upper_func.is_none_or(|node| !is_callee(node, semantic)) { return true; } current_node = parent; diff --git a/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs b/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs index 1ebefc8249c2b..21c7ee0ba901f 100644 --- a/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs +++ b/crates/oxc_linter/src/rules/eslint/no_constant_binary_expression.rs @@ -308,7 +308,7 @@ impl NoConstantBinaryExpression { .arguments .iter() .next() - .map_or(true, |first| first.is_constant(true, ctx)); + .is_none_or(|first| first.is_constant(true, ctx)); } } false 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 adeeb7bc68c94..753b8a084cdc3 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 @@ -140,10 +140,7 @@ impl Rule for NoDupeElseIf { break; }; - if !stmt - .alternate - .as_ref() - .is_some_and(|stmt| stmt.span() == current_node.kind().span()) + if stmt.alternate.as_ref().is_none_or(|stmt| stmt.span() != current_node.kind().span()) { break; } diff --git a/crates/oxc_linter/src/rules/nextjs/google_font_preconnect.rs b/crates/oxc_linter/src/rules/nextjs/google_font_preconnect.rs index 4560727ef20b9..716824bdcb4d8 100644 --- a/crates/oxc_linter/src/rules/nextjs/google_font_preconnect.rs +++ b/crates/oxc_linter/src/rules/nextjs/google_font_preconnect.rs @@ -56,7 +56,7 @@ impl Rule for GoogleFontPreconnect { }; let preconnect_missing = - has_jsx_prop_ignore_case(jsx_opening_element, "rel").map_or(true, |rel_prop| { + has_jsx_prop_ignore_case(jsx_opening_element, "rel").is_none_or(|rel_prop| { let rel_prop_value = get_string_literal_prop_value(rel_prop); rel_prop_value != Some("preconnect") }); diff --git a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs index 38822a00f3cd4..b24ce6607a9a1 100644 --- a/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs +++ b/crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs @@ -171,7 +171,7 @@ fn check_reduce_usage<'a>( // Skip non-parameter or non-first-parameter declarations. let first_param_symbol_id = params.items.first().and_then(|item| get_identifier_symbol_id(&item.pattern.kind)); - if !first_param_symbol_id.is_some_and(|id| id == referenced_symbol_id) { + if first_param_symbol_id.is_none_or(|id| id != referenced_symbol_id) { return; } diff --git a/crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs b/crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs index b5e4eee4f7e42..c58dffe5725d9 100644 --- a/crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs +++ b/crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs @@ -100,7 +100,7 @@ impl Rule for NoCallbackInPromise { let is_not_callback = call_expr .callee .get_identifier_reference() - .map_or(true, |id| self.callbacks.binary_search(&id.name.as_str().into()).is_err()); + .is_none_or(|id| self.callbacks.binary_search(&id.name.as_str().into()).is_err()); if is_not_callback { if Self::has_promise_callback(call_expr) { diff --git a/crates/oxc_linter/src/rules/react/no_is_mounted.rs b/crates/oxc_linter/src/rules/react/no_is_mounted.rs index a5a5241b6a9d4..2323c30ec702c 100644 --- a/crates/oxc_linter/src/rules/react/no_is_mounted.rs +++ b/crates/oxc_linter/src/rules/react/no_is_mounted.rs @@ -56,7 +56,7 @@ impl Rule for NoIsMounted { }; if !matches!(member_expr.object(), Expression::ThisExpression(_)) - || !member_expr.static_property_name().is_some_and(|str| str == "isMounted") + || member_expr.static_property_name().is_none_or(|str| str != "isMounted") { return; } diff --git a/crates/oxc_linter/src/rules/react/no_set_state.rs b/crates/oxc_linter/src/rules/react/no_set_state.rs index 27ab0901af819..77e0dca796bbc 100644 --- a/crates/oxc_linter/src/rules/react/no_set_state.rs +++ b/crates/oxc_linter/src/rules/react/no_set_state.rs @@ -63,7 +63,7 @@ impl Rule for NoSetState { }; if !matches!(member_expr.object(), Expression::ThisExpression(_)) - || !member_expr.static_property_name().is_some_and(|str| str == "setState") + || member_expr.static_property_name().is_none_or(|str| str != "setState") || get_parent_component(node, ctx).is_none() { return; diff --git a/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs b/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs index 8be10789d06f6..c3642044243a2 100644 --- a/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs +++ b/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs @@ -59,7 +59,7 @@ declare_oxc_lint!( impl Rule for SwitchCaseBraces { fn from_configuration(value: serde_json::Value) -> Self { - let always = value.get(0).map_or(true, |v| v.as_str() != Some("avoid")); + let always = value.get(0).is_none_or(|v| v.as_str() != Some("avoid")); Self { always_braces: always } } diff --git a/crates/oxc_linter/src/utils/react.rs b/crates/oxc_linter/src/utils/react.rs index 08028f69fec31..440f9e37604dc 100644 --- a/crates/oxc_linter/src/utils/react.rs +++ b/crates/oxc_linter/src/utils/react.rs @@ -274,7 +274,7 @@ pub fn parse_jsx_value(value: &JSXAttributeValue) -> Result { /// Hook names must start with use followed by a capital letter, /// like useState (built-in) or useOnlineStatus (custom). pub fn is_react_hook_name(name: &str) -> bool { - name.starts_with("use") && name.chars().nth(3).map_or(true, char::is_uppercase) + name.starts_with("use") && name.chars().nth(3).is_none_or(char::is_uppercase) // uncomment this check if react decided to drop the idea of `use` hook. // It is currently in `Canary` builds. // name.starts_with("use") && name.chars().nth(3).is_some_and(char::is_uppercase) diff --git a/crates/oxc_linter/src/utils/unicorn.rs b/crates/oxc_linter/src/utils/unicorn.rs index 3c521b694f20b..dc65d254b3d3c 100644 --- a/crates/oxc_linter/src/utils/unicorn.rs +++ b/crates/oxc_linter/src/utils/unicorn.rs @@ -46,7 +46,7 @@ pub fn is_prototype_property( property: &str, object: Option<&str>, ) -> bool { - if !member_expr.static_property_name().is_some_and(|name| name == property) + if member_expr.static_property_name().is_none_or(|name| name != property) || member_expr.optional() { return false; diff --git a/crates/oxc_prettier/src/format/js.rs b/crates/oxc_prettier/src/format/js.rs index 224731f8063c4..96c7d53f3c302 100644 --- a/crates/oxc_prettier/src/format/js.rs +++ b/crates/oxc_prettier/src/format/js.rs @@ -577,7 +577,7 @@ impl<'a> Format<'a> for VariableDeclaration<'a> { } } - if !parent_for_loop_span.is_some_and(|span| span != self.span) { + if parent_for_loop_span.is_none_or(|span| span == self.span) { if let Some(semi) = p.semi() { parts.push(semi); } diff --git a/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs b/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs index 2eb3750f2c5eb..0bfb2dd3e391a 100644 --- a/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs +++ b/crates/oxc_regular_expression/src/parser/reader/string_literal_parser/parser_impl.rs @@ -201,7 +201,7 @@ impl Parser { if let Some(cp) = self.parse_character_escape_sequence() { return Ok(Some(cp)); } - if self.peek() == Some('0') && self.peek2().map_or(true, |ch| !ch.is_ascii_digit()) { + if self.peek() == Some('0') && self.peek2().is_none_or(|ch| !ch.is_ascii_digit()) { self.advance(); return Ok(Some(0x00)); } diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index f7a8fe9331315..84b4e9eccb4c7 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -358,7 +358,7 @@ pub fn check_class<'a>(class: &Class<'a>, ctx: &SemanticBuilder<'a>) { if !a.r#type.is_abstract() && !a.optional && a.value.r#type == FunctionType::TSEmptyBodyFunctionExpression - && b.map_or(true, |b| match b { + && b.is_none_or(|b| match b { ClassElement::StaticBlock(_) | ClassElement::PropertyDefinition(_) | ClassElement::AccessorProperty(_) diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index 8dd1de36b5bb9..64d784b042505 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -878,7 +878,7 @@ fn is_componentish_name(name: &str) -> bool { } fn is_use_hook_name(name: &str) -> bool { - name.starts_with("use") && name.as_bytes().get(3).map_or(true, u8::is_ascii_uppercase) + name.starts_with("use") && name.as_bytes().get(3).is_none_or(u8::is_ascii_uppercase) } #[rustfmt::skip] diff --git a/crates/oxc_transformer/src/typescript/namespace.rs b/crates/oxc_transformer/src/typescript/namespace.rs index 857d416150957..2b8a088147a4c 100644 --- a/crates/oxc_transformer/src/typescript/namespace.rs +++ b/crates/oxc_transformer/src/typescript/namespace.rs @@ -60,7 +60,7 @@ impl<'a> Traverse<'a> for TypeScriptNamespace<'a, '_> { continue; } Statement::ExportNamedDeclaration(export_decl) => { - if export_decl.declaration.as_ref().map_or(true, |decl| { + if export_decl.declaration.as_ref().is_none_or(|decl| { decl.declare() || !matches!(decl, Declaration::TSModuleDeclaration(_)) }) { new_stmts.push(Statement::ExportNamedDeclaration(export_decl)); From 32e738d4813a999103d5d3d64427b885741e3971 Mon Sep 17 00:00:00 2001 From: Boshen Date: Fri, 21 Feb 2025 22:09:12 +0800 Subject: [PATCH 2/2] Update Cargo.toml Co-authored-by: Cameron --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cb2ac6328b5a6..b6f4ba7ff3ff9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ homepage = "https://oxc.rs" keywords = ["JavaScript", "TypeScript", "linter", "minifier", "parser"] license = "MIT" repository = "https://github.com/oxc-project/oxc" -rust-version = "1.82.0" # Support last 4 minor versions. (NOTE: bump to `edition = "2021"` when 1.85.0. +rust-version = "1.82.0" # Support last 4 minor versions. (NOTE: bump to `edition = "2024"` when 1.85.0. description = "A collection of JavaScript tools written in Rust." #