Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(bool_comparison): unwrap match from extraneous block

Co-authored-by: x10an14 <x10an14@users.noreply.github.com>

+21 -25
+21 -25
lib/src/lints/bool_comparison.rs
··· 55 55 }; 56 56 57 57 let at = node.text_range(); 58 - let replacement = { 59 - match (boolean_ident(&bool_side).unwrap(), op == BinOpKind::Equal) { 60 - (NixBoolean::True, true) | (NixBoolean::False, false) => { 61 - // `a == true`, `a != false` replace with just `a` 62 - non_bool_side.clone() 63 - } 64 - (NixBoolean::True, false) | (NixBoolean::False, true) => { 65 - // `a != true`, `a == false` replace with `!a` 66 - match non_bool_side.kind() { 67 - SyntaxKind::NODE_APPLY 68 - | SyntaxKind::NODE_PAREN 69 - | SyntaxKind::NODE_IDENT => { 70 - // do not parenthsize the replacement 58 + let replacement = match (boolean_ident(&bool_side).unwrap(), op == BinOpKind::Equal) { 59 + (NixBoolean::True, true) | (NixBoolean::False, false) => { 60 + // `a == true`, `a != false` replace with just `a` 61 + non_bool_side.clone() 62 + } 63 + (NixBoolean::True, false) | (NixBoolean::False, true) => { 64 + // `a != true`, `a == false` replace with `!a` 65 + match non_bool_side.kind() { 66 + SyntaxKind::NODE_APPLY | SyntaxKind::NODE_PAREN | SyntaxKind::NODE_IDENT => { 67 + // do not parenthsize the replacement 68 + make::unary_not(&non_bool_side).node().clone() 69 + } 70 + SyntaxKind::NODE_BIN_OP => { 71 + let inner = BinOp::cast(non_bool_side.clone()).unwrap(); 72 + // `!a ? b`, no paren required 73 + if inner.operator()? == BinOpKind::IsSet { 71 74 make::unary_not(&non_bool_side).node().clone() 72 - } 73 - SyntaxKind::NODE_BIN_OP => { 74 - let inner = BinOp::cast(non_bool_side.clone()).unwrap(); 75 - // `!a ? b`, no paren required 76 - if inner.operator()? == BinOpKind::IsSet { 77 - make::unary_not(&non_bool_side).node().clone() 78 - } else { 79 - let parens = make::parenthesize(&non_bool_side); 80 - make::unary_not(parens.node()).node().clone() 81 - } 82 - } 83 - _ => { 75 + } else { 84 76 let parens = make::parenthesize(&non_bool_side); 85 77 make::unary_not(parens.node()).node().clone() 86 78 } 79 + } 80 + _ => { 81 + let parens = make::parenthesize(&non_bool_side); 82 + make::unary_not(parens.node()).node().clone() 87 83 } 88 84 } 89 85 }