diff --git a/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs b/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs index e1b846f46..e0f9591e8 100644 --- a/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs +++ b/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs @@ -79,10 +79,7 @@ fn diagnostic_assign_expr<'a>(expr: &'a AssignmentExpression<'a>, ctx: &LintCont SimpleAssignmentTarget::MemberAssignmentTarget(member_expr), ) = &expr.left { - let (span, property_name) = match get_jasmine_property_name(member_expr) { - Some(value) => value, - None => return, - }; + let Some((span, property_name)) = get_jasmine_property_name(member_expr) else { return }; if property_name == "DEFAULT_TIMEOUT_INTERVAL" { // `jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000` we can fix it to `jest.setTimeout(5000)` @@ -104,10 +101,7 @@ fn diagnostic_assign_expr<'a>(expr: &'a AssignmentExpression<'a>, ctx: &LintCont fn diagnostic_call_expr<'a>(expr: &'a CallExpression<'a>, ctx: &LintContext) { if let Expression::MemberExpression(member_expr) = &expr.callee { - let (span, property_name) = match get_jasmine_property_name(member_expr) { - Some(value) => value, - None => return, - }; + let Some((span, property_name)) = get_jasmine_property_name(member_expr) else { return }; JasmineProperty::from_str(property_name).map_or_else( || { diff --git a/crates/oxc_linter/src/rules/jsx_a11y/autocomplete_valid.rs b/crates/oxc_linter/src/rules/jsx_a11y/autocomplete_valid.rs index 70121a98c..f0f9f8610 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/autocomplete_valid.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/autocomplete_valid.rs @@ -187,17 +187,15 @@ impl Rule for AutocompleteValid { return; } - let autocomplete_prop = match has_jsx_prop_lowercase(jsx_el, "autocomplete") { - Some(autocomplete_prop) => autocomplete_prop, - None => return, + let Some(autocomplete_prop) = has_jsx_prop_lowercase(jsx_el, "autocomplete") else { + return; }; let attr = match autocomplete_prop { JSXAttributeItem::Attribute(attr) => attr, JSXAttributeItem::SpreadAttribute(_) => return, }; - let autocomplete_values = match &attr.value { - Some(JSXAttributeValue::StringLiteral(autocomplete_values)) => autocomplete_values, - _ => return, + let Some(JSXAttributeValue::StringLiteral(autocomplete_values)) = &attr.value else { + return; }; let value = autocomplete_values.value.to_string(); if !is_valid_autocomplete_value(&value) { diff --git a/crates/oxc_linter/src/rules/jsx_a11y/iframe_has_title.rs b/crates/oxc_linter/src/rules/jsx_a11y/iframe_has_title.rs index a4ba4ed93..c860cb8c7 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/iframe_has_title.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/iframe_has_title.rs @@ -77,9 +77,7 @@ impl Rule for IframeHasTitle { return; } - let alt_prop = if let Some(prop) = has_jsx_prop_lowercase(jsx_el, "title") { - prop - } else { + let Some(alt_prop) = has_jsx_prop_lowercase(jsx_el, "title") else { ctx.diagnostic(IframeHasTitleDiagnostic(iden.span)); return; }; diff --git a/crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs b/crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs index 65a34cf29..6acc3558d 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs @@ -121,18 +121,12 @@ impl Rule for ImgRedundantAlt { return; } - let alt_prop = match has_jsx_prop_lowercase(jsx_el, "alt") { - Some(v) => v, - None => { - return; - } + let Some(alt_prop) = has_jsx_prop_lowercase(jsx_el, "alt") else { + return; }; - let alt_attribute = match get_prop_value(alt_prop) { - Some(v) => v, - None => { - return; - } + let Some(alt_attribute) = get_prop_value(alt_prop) else { + return; }; let alt_attribute_name = match alt_prop { diff --git a/crates/oxc_linter/src/rules/nextjs/no_css_tags.rs b/crates/oxc_linter/src/rules/nextjs/no_css_tags.rs index df70c4a7d..0f0053856 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_css_tags.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_css_tags.rs @@ -66,10 +66,7 @@ impl Rule for NoCssTags { } } - let (rel_attr, href_attr) = match (rel_attr, href_attr) { - (Some(rel_attr), Some(href_attr)) => (rel_attr, href_attr), - _ => return, - }; + let (Some(rel_attr), Some(href_attr)) = (rel_attr, href_attr) else { return }; let Some(rel_prop_value) = get_string_literal_prop_value(rel_attr) else { return }; let Some(href_prop_value) = get_string_literal_prop_value(href_attr) else { return }; @@ -88,7 +85,7 @@ fn test() { let pass = vec![ r"import {Head} from 'next/document'; - + export class Blah extends Head { render() { return ( @@ -136,7 +133,7 @@ fn test() { let fail = vec![ r#" import {Head} from 'next/document'; - + export class Blah extends Head { render() { return ( diff --git a/crates/oxc_linter/src/rules/unicorn/error_message.rs b/crates/oxc_linter/src/rules/unicorn/error_message.rs index 0da4b5e3e..e9366a513 100644 --- a/crates/oxc_linter/src/rules/unicorn/error_message.rs +++ b/crates/oxc_linter/src/rules/unicorn/error_message.rs @@ -84,14 +84,11 @@ impl Rule for ErrorMessage { let message_argument = args.get(message_argument_idx); - let arg = match message_argument { - Some(v) => v, - None => { - return ctx.diagnostic(ErrorMessageDiagnostic::MissingMessage( - constructor_name.to_compact_string(), - span, - )) - } + let Some(arg) = message_argument else { + return ctx.diagnostic(ErrorMessageDiagnostic::MissingMessage( + constructor_name.to_compact_string(), + span, + )); }; let arg = match arg { diff --git a/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs b/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs index 959096d7b..56a7ed3dd 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs @@ -51,10 +51,7 @@ declare_oxc_lint!( impl Rule for NoConsoleSpaces { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - let call_expr = match node.kind() { - AstKind::CallExpression(call_expr) => call_expr, - _ => return, - }; + let AstKind::CallExpression(call_expr) = node.kind() else { return }; if !is_method_call( call_expr, diff --git a/crates/oxc_parser/src/lexer/mod.rs b/crates/oxc_parser/src/lexer/mod.rs index 8e8121920..4502aa313 100644 --- a/crates/oxc_parser/src/lexer/mod.rs +++ b/crates/oxc_parser/src/lexer/mod.rs @@ -295,9 +295,7 @@ impl<'a> Lexer<'a> { let offset = self.offset(); self.token.start = offset; - let byte = if let Some(byte) = self.source.peek_byte() { - byte - } else { + let Some(byte) = self.source.peek_byte() else { return Kind::Eof; }; diff --git a/crates/oxc_parser/src/lexer/regex.rs b/crates/oxc_parser/src/lexer/regex.rs index 93cea826f..e161ff163 100644 --- a/crates/oxc_parser/src/lexer/regex.rs +++ b/crates/oxc_parser/src/lexer/regex.rs @@ -60,9 +60,7 @@ impl<'a> Lexer<'a> { while let Some(ch @ ('$' | '_' | 'a'..='z' | 'A'..='Z' | '0'..='9')) = self.peek() { self.consume_char(); - let flag = if let Ok(flag) = RegExpFlags::try_from(ch) { - flag - } else { + let Ok(flag) = RegExpFlags::try_from(ch) else { self.error(diagnostics::RegExpFlag(ch, self.current_offset())); continue; }; diff --git a/crates/oxc_parser/src/lexer/template.rs b/crates/oxc_parser/src/lexer/template.rs index f488031db..7ebb41943 100644 --- a/crates/oxc_parser/src/lexer/template.rs +++ b/crates/oxc_parser/src/lexer/template.rs @@ -63,7 +63,7 @@ impl<'a> Lexer<'a> { if !has_escape { return; } - self.escaped_templates.insert(self.token.start, is_valid_escape_sequence.then(|| s)); + self.escaped_templates.insert(self.token.start, is_valid_escape_sequence.then_some(s)); self.token.escaped = true; } diff --git a/crates/oxc_span/Cargo.toml b/crates/oxc_span/Cargo.toml index 3d2d1943a..6b9176f25 100644 --- a/crates/oxc_span/Cargo.toml +++ b/crates/oxc_span/Cargo.toml @@ -19,8 +19,8 @@ workspace = true doctest = false [dependencies] -miette = { workspace = true } -compact_str = { version = "0.7.1" } +miette = { workspace = true } +compact_str = { version = "0.7.1" } tsify = { workspace = true, optional = true } wasm-bindgen = { workspace = true, optional = true } diff --git a/crates/oxc_transformer/src/es2015/duplicate_keys.rs b/crates/oxc_transformer/src/es2015/duplicate_keys.rs index 718a35743..f331089b6 100644 --- a/crates/oxc_transformer/src/es2015/duplicate_keys.rs +++ b/crates/oxc_transformer/src/es2015/duplicate_keys.rs @@ -18,7 +18,7 @@ pub struct DuplicateKeys<'a> { impl<'a> DuplicateKeys<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { - (options.target < TransformTarget::ES2015 || options.duplicate_keys).then(|| Self { ast }) + (options.target < TransformTarget::ES2015 || options.duplicate_keys).then_some(Self { ast }) } pub fn transform_object_expression<'b>(&mut self, obj_expr: &'b mut ObjectExpression<'a>) { diff --git a/crates/oxc_transformer/src/es2015/function_name.rs b/crates/oxc_transformer/src/es2015/function_name.rs index aa8c4d54c..9e66440fb 100644 --- a/crates/oxc_transformer/src/es2015/function_name.rs +++ b/crates/oxc_transformer/src/es2015/function_name.rs @@ -30,7 +30,7 @@ impl<'a> FunctionName<'a> { ctx: TransformerCtx<'a>, options: &TransformOptions, ) -> Option { - (options.target < TransformTarget::ES2015 || options.function_name).then(|| Self { + (options.target < TransformTarget::ES2015 || options.function_name).then_some(Self { _ast: ast, ctx, // TODO hook up the plugin diff --git a/crates/oxc_transformer/src/es2015/instanceof.rs b/crates/oxc_transformer/src/es2015/instanceof.rs index 025d4d206..f4b055204 100644 --- a/crates/oxc_transformer/src/es2015/instanceof.rs +++ b/crates/oxc_transformer/src/es2015/instanceof.rs @@ -25,7 +25,8 @@ impl<'a> Instanceof<'a> { ctx: TransformerCtx<'a>, options: &TransformOptions, ) -> Option { - (options.target < TransformTarget::ES2015 || options.instanceof).then(|| Self { ast, ctx }) + (options.target < TransformTarget::ES2015 || options.instanceof) + .then_some(Self { ast, ctx }) } pub fn transform_expression(&mut self, expr: &mut Expression<'a>) { diff --git a/crates/oxc_transformer/src/es2015/new_target.rs b/crates/oxc_transformer/src/es2015/new_target.rs index c039c9e37..1d6027cae 100644 --- a/crates/oxc_transformer/src/es2015/new_target.rs +++ b/crates/oxc_transformer/src/es2015/new_target.rs @@ -45,7 +45,7 @@ impl<'a> NewTarget<'a> { options: &TransformOptions, ) -> Option { let kinds = ast.new_vec(); - (options.target < TransformTarget::ES2015 || options.new_target).then(|| Self { + (options.target < TransformTarget::ES2015 || options.new_target).then_some(Self { ast, ctx, kinds, diff --git a/crates/oxc_transformer/src/es2015/shorthand_properties.rs b/crates/oxc_transformer/src/es2015/shorthand_properties.rs index 285b50f2b..2d198841e 100644 --- a/crates/oxc_transformer/src/es2015/shorthand_properties.rs +++ b/crates/oxc_transformer/src/es2015/shorthand_properties.rs @@ -17,7 +17,7 @@ pub struct ShorthandProperties<'a> { impl<'a> ShorthandProperties<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { (options.target < TransformTarget::ES2015 || options.shorthand_properties) - .then(|| Self { ast }) + .then_some(Self { ast }) } pub fn transform_object_property<'b>(&mut self, obj_prop: &'b mut ObjectProperty<'a>) { diff --git a/crates/oxc_transformer/src/es2015/template_literals.rs b/crates/oxc_transformer/src/es2015/template_literals.rs index 5204173ea..31fbbfe12 100644 --- a/crates/oxc_transformer/src/es2015/template_literals.rs +++ b/crates/oxc_transformer/src/es2015/template_literals.rs @@ -17,7 +17,7 @@ pub struct TemplateLiterals<'a> { impl<'a> TemplateLiterals<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { (options.target < TransformTarget::ES2015 || options.template_literals) - .then(|| Self { ast }) + .then_some(Self { ast }) } pub fn transform_expression<'b>(&mut self, expr: &'b mut Expression<'a>) { diff --git a/crates/oxc_transformer/src/es2019/json_strings.rs b/crates/oxc_transformer/src/es2019/json_strings.rs index ffb9c95de..02083ae74 100644 --- a/crates/oxc_transformer/src/es2019/json_strings.rs +++ b/crates/oxc_transformer/src/es2019/json_strings.rs @@ -17,7 +17,7 @@ pub struct JsonStrings<'a> { impl<'a> JsonStrings<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { - (options.target < TransformTarget::ES2019 || options.json_strings).then(|| Self { ast }) + (options.target < TransformTarget::ES2019 || options.json_strings).then_some(Self { ast }) } // Allow `U+2028` and `U+2029` in string literals diff --git a/crates/oxc_transformer/src/es2019/optional_catch_binding.rs b/crates/oxc_transformer/src/es2019/optional_catch_binding.rs index 34dfc0f71..004784f66 100644 --- a/crates/oxc_transformer/src/es2019/optional_catch_binding.rs +++ b/crates/oxc_transformer/src/es2019/optional_catch_binding.rs @@ -17,7 +17,7 @@ pub struct OptionalCatchBinding<'a> { impl<'a> OptionalCatchBinding<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { (options.target < TransformTarget::ES2019 || options.optional_catch_binding) - .then(|| Self { ast }) + .then_some(Self { ast }) } pub fn transform_catch_clause<'b>(&mut self, clause: &'b mut CatchClause<'a>) { diff --git a/crates/oxc_transformer/src/es2022/class_static_block.rs b/crates/oxc_transformer/src/es2022/class_static_block.rs index b647fd000..c7d089c19 100644 --- a/crates/oxc_transformer/src/es2022/class_static_block.rs +++ b/crates/oxc_transformer/src/es2022/class_static_block.rs @@ -17,7 +17,7 @@ pub struct ClassStaticBlock<'a> { impl<'a> ClassStaticBlock<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { (options.target < TransformTarget::ES2022 || options.class_static_block) - .then(|| Self { ast }) + .then_some(Self { ast }) } pub fn transform_class_body<'b>(&mut self, class_body: &'b mut ClassBody<'a>) { diff --git a/crates/oxc_transformer/src/es3/property_literals.rs b/crates/oxc_transformer/src/es3/property_literals.rs index c390d6df6..e5c0fb05b 100644 --- a/crates/oxc_transformer/src/es3/property_literals.rs +++ b/crates/oxc_transformer/src/es3/property_literals.rs @@ -15,7 +15,8 @@ pub struct PropertyLiteral<'a> { impl<'a> PropertyLiteral<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { - (options.target <= TransformTarget::ES3 || options.property_literals).then(|| Self { ast }) + (options.target <= TransformTarget::ES3 || options.property_literals) + .then_some(Self { ast }) } pub fn transform_object_property<'b>(&mut self, expr: &'b mut ObjectProperty<'a>) { diff --git a/crates/oxc_transformer/src/regexp/regexp_flags.rs b/crates/oxc_transformer/src/regexp/regexp_flags.rs index e8c584722..43ce69b04 100644 --- a/crates/oxc_transformer/src/regexp/regexp_flags.rs +++ b/crates/oxc_transformer/src/regexp/regexp_flags.rs @@ -22,7 +22,7 @@ pub struct RegexpFlags<'a> { impl<'a> RegexpFlags<'a> { pub fn new(ast: Rc>, options: &TransformOptions) -> Option { let transform_flags = Self::from_transform_target(options); - (!transform_flags.is_empty()).then(|| Self { ast, transform_flags }) + (!transform_flags.is_empty()).then_some(Self { ast, transform_flags }) } fn from_transform_target(options: &TransformOptions) -> RegExpFlags {