@@ -26,8 +26,7 @@ pub fn format_node<'src>(ps: &mut ParserState<'src>, node: prism::Node<'src>) {
2626 && !( matches ! ( node, Node :: StatementsNode { .. } )
2727 || node
2828 . as_begin_node ( )
29- . map ( |b| b. begin_keyword_loc ( ) . is_none ( ) )
30- . unwrap_or ( false ) ) ;
29+ . is_some_and ( |b| b. begin_keyword_loc ( ) . is_none ( ) ) ) ;
3130
3231 if needs_handling {
3332 ps. emit_indent ( ) ;
@@ -661,7 +660,7 @@ fn format_string_node<'src>(ps: &mut ParserState<'src>, string_node: prism::Stri
661660 // (e.g. the inner contents of a heredoc)
662661 let opener = string_node. opening_loc ( ) . map ( |s| s. as_slice ( ) . trim_ascii ( ) ) ;
663662 let closer = string_node. closing_loc ( ) . map ( |s| s. as_slice ( ) . trim_ascii ( ) ) ;
664- let is_heredoc = opener. map ( |s| s. starts_with ( b"<" ) ) . unwrap_or ( false ) ;
663+ let is_heredoc = opener. is_some_and ( |s| s. starts_with ( b"<" ) ) ;
665664
666665 if is_heredoc {
667666 format_heredoc (
@@ -680,7 +679,7 @@ fn format_string_node<'src>(ps: &mut ParserState<'src>, string_node: prism::Stri
680679
681680 // If opener is nil, we must be in some kind of interpolated string context, which
682681 // means the contents must already be appropriately escaped -- hence we default to `true` here
683- let in_escaped_context = is_heredoc || opener. map ( |s| s. starts_with ( b"\" " ) ) . unwrap_or ( true ) ;
682+ let in_escaped_context = is_heredoc || opener. is_none_or ( |s| s. starts_with ( b"\" " ) ) ;
684683 let string_content = if in_escaped_context {
685684 Cow :: Borrowed ( string_node. content_loc ( ) . as_slice ( ) )
686685 } else {
@@ -721,10 +720,8 @@ fn format_interpolated_string_node<'src>(
721720 let closer = interpolated_string_node
722721 . closing_loc ( )
723722 . map ( |s| s. as_slice ( ) . trim_ascii ( ) ) ;
724- let is_heredoc = opener. map ( |s| s. starts_with ( b"<" ) ) . unwrap_or ( false ) ;
725- let needs_escape = opener
726- . map ( |s| !s. starts_with ( b"\" " ) && !is_heredoc)
727- . unwrap_or ( false ) ;
723+ let is_heredoc = opener. is_some_and ( |s| s. starts_with ( b"<" ) ) ;
724+ let needs_escape = opener. is_some_and ( |s| !s. starts_with ( b"\" " ) && !is_heredoc) ;
728725
729726 // Prism actually handles string concatenation when using "\", so it treats
730727 // ```ruby
@@ -742,12 +739,10 @@ fn format_interpolated_string_node<'src>(
742739 && interpolated_string_node. parts ( ) . len ( ) > 1
743740 && interpolated_string_node. parts ( ) . iter ( ) . any ( |node| {
744741 node. as_string_node ( )
745- . map ( |node| node. opening_loc ( ) . is_some ( ) )
746- . unwrap_or ( false )
742+ . is_some_and ( |node| node. opening_loc ( ) . is_some ( ) )
747743 || node
748744 . as_interpolated_string_node ( )
749- . map ( |node| node. opening_loc ( ) . is_some ( ) )
750- . unwrap_or ( false )
745+ . is_some_and ( |node| node. opening_loc ( ) . is_some ( ) )
751746 } ) ;
752747
753748 ps. at_offset ( interpolated_string_node. location ( ) . start_offset ( ) ) ;
@@ -879,13 +874,10 @@ fn maybe_render_heredocs_in_string<'src: 'a, 'a>(
879874 ps : & mut ParserState < ' src > ,
880875 peekable : & mut std:: iter:: Peekable < impl Iterator < Item = & ' a prism:: Node < ' src > > > ,
881876) {
882- let should_render = peekable
883- . peek ( )
884- . and_then ( |node| {
885- node. as_string_node ( )
886- . map ( |sn| sn. content_loc ( ) . as_slice ( ) . starts_with ( b"\n " ) )
887- } )
888- . unwrap_or ( false ) ;
877+ let should_render = peekable. peek ( ) . is_some_and ( |node| {
878+ node. as_string_node ( )
879+ . is_some_and ( |sn| sn. content_loc ( ) . as_slice ( ) . starts_with ( b"\n " ) )
880+ } ) ;
889881 if should_render {
890882 ps. render_heredocs ( true )
891883 }
@@ -1671,14 +1663,11 @@ fn use_parens_for_call_node<'src>(
16711663 // Foo # class reference
16721664 // Foo() # method call
16731665 // ```
1674- let has_arguments = call_node
1675- . arguments ( )
1676- . map ( |args| {
1677- !( args. arguments ( ) . is_empty ( )
1678- || ( args. arguments ( ) . len ( ) == 1
1679- && is_empty_parentheses_node ( & args. arguments ( ) . first ( ) . unwrap ( ) ) ) )
1680- } )
1681- . unwrap_or ( false ) ;
1666+ let has_arguments = call_node. arguments ( ) . is_some_and ( |args| {
1667+ !( args. arguments ( ) . is_empty ( )
1668+ || ( args. arguments ( ) . len ( ) == 1
1669+ && is_empty_parentheses_node ( & args. arguments ( ) . first ( ) . unwrap ( ) ) ) )
1670+ } ) ;
16821671
16831672 if is_terminal_call && method_name. first ( ) . is_some_and ( |c| c. is_ascii_uppercase ( ) ) {
16841673 if !has_arguments && call_node. block ( ) . is_some ( ) {
@@ -1731,8 +1720,7 @@ fn use_parens_for_call_node<'src>(
17311720 let has_brace_block = call_node
17321721 . block ( )
17331722 . and_then ( |b| b. as_block_node ( ) )
1734- . map ( |block| block. opening_loc ( ) . as_slice ( ) != b"do" )
1735- . unwrap_or ( false ) ;
1723+ . is_some_and ( |block| block. opening_loc ( ) . as_slice ( ) != b"do" ) ;
17361724
17371725 if has_arguments && has_brace_block {
17381726 // Brace blocks require parens, eliding is a syntax error
@@ -1948,8 +1936,7 @@ fn format_call_node<'src>(
19481936 && ( !skip_receiver
19491937 || call_node
19501938 . receiver ( )
1951- . map ( |r| r. as_self_node ( ) . is_some ( ) )
1952- . unwrap_or ( false ) )
1939+ . is_some_and ( |r| r. as_self_node ( ) . is_some ( ) ) )
19531940 {
19541941 // Check if we need parens in two cases: we're the
19551942 // first/only item in a call chain (thus `!skip_receiver`)
@@ -2048,8 +2035,7 @@ fn format_unary_operator<'src>(
20482035 let is_not_with_parens = method_name == b"!"
20492036 && call_node
20502037 . message_loc ( )
2051- . map ( |loc| loc. as_slice ( ) == b"not" )
2052- . unwrap_or ( false )
2038+ . is_some_and ( |loc| loc. as_slice ( ) == b"not" )
20532039 && call_node. opening_loc ( ) . is_some ( ) ;
20542040
20552041 let operator_symbol: & [ u8 ] = match method_name {
@@ -2265,8 +2251,7 @@ fn extract_trailing_arefs(mut elements: Vec<prism::Node>) -> (Vec<prism::Node>,
22652251 let mut trailing_arefs = Vec :: new ( ) ;
22662252 let has_dot_calls = elements. iter ( ) . any ( |elem| {
22672253 elem. as_call_node ( )
2268- . map ( |c| c. call_operator_loc ( ) . is_some ( ) )
2269- . unwrap_or ( false )
2254+ . is_some_and ( |c| c. call_operator_loc ( ) . is_some ( ) )
22702255 } ) ;
22712256
22722257 if has_dot_calls {
@@ -2444,12 +2429,10 @@ fn call_chain_elements_are_user_multilined(
24442429 // to first skip it if it's not a CallNode and there's an aref following it.
24452430 let first_is_not_call = call_chain_elements
24462431 . first ( )
2447- . map ( |n| n. as_call_node ( ) . is_none ( ) )
2448- . unwrap_or ( false ) ;
2432+ . is_some_and ( |n| n. as_call_node ( ) . is_none ( ) ) ;
24492433 let second_is_aref = call_chain_elements. get ( 1 ) . is_some_and ( |n| {
24502434 n. as_call_node ( )
2451- . map ( |c| c. call_operator_loc ( ) . is_none ( ) )
2452- . unwrap_or ( false )
2435+ . is_some_and ( |c| c. call_operator_loc ( ) . is_none ( ) )
24532436 } ) ;
24542437
24552438 if first_is_not_call && second_is_aref {
@@ -2481,8 +2464,9 @@ fn call_chain_elements_are_user_multilined(
24812464 . as_call_node ( )
24822465 . unwrap ( )
24832466 . call_operator_loc ( )
2484- . map ( |loc| ps. get_line_number_for_offset ( loc. start_offset ( ) ) )
2485- . unwrap_or ( start_line)
2467+ . map_or ( start_line, |loc| {
2468+ ps. get_line_number_for_offset ( loc. start_offset ( ) )
2469+ } )
24862470 } )
24872471}
24882472
@@ -2589,7 +2573,7 @@ fn format_symbol_node<'src>(ps: &mut ParserState<'src>, symbol_node: prism::Symb
25892573
25902574 // Check if this is a quoted symbol that needs normalization to double quotes
25912575 // Symbols like :'"foo"' (single-quoted) should become :"\"foo\""
2592- let is_single_quoted = opener. map ( |s| s == b":'" ) . unwrap_or ( false ) ;
2576+ let is_single_quoted = opener. is_some_and ( |s| s == b":'" ) ;
25932577
25942578 if is_single_quoted {
25952579 ps. emit_ident ( b":" ) ;
@@ -2716,8 +2700,7 @@ fn format_block_node<'src>(ps: &mut ParserState<'src>, block_node: prism::BlockN
27162700 if let Some ( body) = block_node. body ( ) {
27172701 let has_multiple_statements = body
27182702 . as_statements_node ( )
2719- . map ( |statements_node| statements_node. body ( ) . len ( ) > 1 )
2720- . unwrap_or ( false ) ;
2703+ . is_some_and ( |statements_node| statements_node. body ( ) . len ( ) > 1 ) ;
27212704 if has_multiple_statements {
27222705 ps. emit_newline ( ) ;
27232706 ps. emit_indent ( ) ;
@@ -2816,7 +2799,7 @@ fn format_array_node<'src>(ps: &mut ParserState<'src>, array_node: prism::ArrayN
28162799 let opening = array_node
28172800 . opening_loc ( )
28182801 . map ( |loc| loc. as_slice ( ) . trim_ascii ( ) ) ;
2819- let is_word_array = opening. map ( |s| s. starts_with ( b"%" ) ) . unwrap_or ( false ) ;
2802+ let is_word_array = opening. is_some_and ( |s| s. starts_with ( b"%" ) ) ;
28202803
28212804 let orig_delim = opening. and_then ( |s| s. get ( 2 ) . copied ( ) ) . unwrap_or ( b'[' ) ;
28222805
@@ -3620,8 +3603,8 @@ fn format_hash_pattern_node<'src>(
36203603 }
36213604
36223605 let opener = hash_pattern_node. opening_loc ( ) . map ( |loc| loc. as_slice ( ) ) ;
3623- let use_parens = hash_pattern_node . constant ( ) . is_some ( )
3624- || opener. map ( |s| s. starts_with ( b"(" ) ) . unwrap_or ( false ) ;
3606+ let use_parens =
3607+ hash_pattern_node . constant ( ) . is_some ( ) || opener. is_some_and ( |s| s. starts_with ( b"(" ) ) ;
36253608
36263609 let elements = hash_pattern_node. elements ( ) ;
36273610
@@ -3721,8 +3704,7 @@ impl<'pr> Conditional<'pr> {
37213704 match self {
37223705 Conditional :: If ( node) => node
37233706 . if_keyword_loc ( )
3724- . map ( |loc| loc. start_offset ( ) )
3725- . unwrap_or ( node. location ( ) . start_offset ( ) ) ,
3707+ . map_or ( node. location ( ) . start_offset ( ) , |loc| loc. start_offset ( ) ) ,
37263708 Conditional :: Unless ( node) => node. keyword_loc ( ) . start_offset ( ) ,
37273709 Conditional :: While ( node) => node. keyword_loc ( ) . start_offset ( ) ,
37283710 Conditional :: Until ( node) => node. keyword_loc ( ) . start_offset ( ) ,
@@ -4864,18 +4846,17 @@ fn format_yield_node<'src>(ps: &mut ParserState<'src>, yield_node: prism::YieldN
48644846 let use_parens = ps. current_formatting_context_requires_parens ( )
48654847 || yield_node. lparen_loc ( ) . is_some ( )
48664848 // For single assoc values (`yield a: b`) we keep parens
4867- || ( yield_node
4849+ || yield_node
48684850 . arguments ( )
4869- . map ( |args| {
4851+ . is_some_and ( |args| {
48704852 args. arguments ( ) . len ( ) == 1
48714853 && args
48724854 . arguments ( )
48734855 . last ( )
48744856 . unwrap ( )
48754857 . as_keyword_hash_node ( )
48764858 . is_some ( )
4877- } )
4878- . unwrap_or ( false ) ) ;
4859+ } ) ;
48794860
48804861 let delims = if use_parens {
48814862 BreakableDelims :: for_method_call ( )
0 commit comments