Lints and suggestions for the Nix programming language

refactor(empty_list_concat): let-else and try-expression

+17 -16
+17 -16
lib/src/lints/empty_list_concat.rs
··· 32 32 33 33 impl Rule for EmptyListConcat { 34 34 fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { 35 - if let NodeOrToken::Node(node) = node 36 - && let Some(bin_expr) = BinOp::cast(node.clone()) 37 - && let Some(lhs) = bin_expr.lhs() 38 - && let Some(rhs) = bin_expr.rhs() 39 - && let Some(op) = bin_expr.operator() 40 - && let BinOpKind::Concat = op 41 - { 42 - let at = node.text_range(); 43 - let message = "Concatenation with the empty list, `[]`, is a no-op"; 44 - if is_empty_array(&lhs) { 45 - Some(self.report().suggest(at, message, Suggestion::new(at, rhs))) 46 - } else if is_empty_array(&rhs) { 47 - Some(self.report().suggest(at, message, Suggestion::new(at, lhs))) 48 - } else { 49 - None 50 - } 35 + let NodeOrToken::Node(node) = node else { 36 + return None; 37 + }; 38 + 39 + let bin_expr = BinOp::cast(node.clone())?; 40 + let lhs = bin_expr.lhs()?; 41 + let rhs = bin_expr.rhs()?; 42 + let Some(BinOpKind::Concat) = bin_expr.operator() else { 43 + return None; 44 + }; 45 + 46 + let at = node.text_range(); 47 + let message = "Concatenation with the empty list, `[]`, is a no-op"; 48 + if is_empty_array(&lhs) { 49 + Some(self.report().suggest(at, message, Suggestion::new(at, rhs))) 50 + } else if is_empty_array(&rhs) { 51 + Some(self.report().suggest(at, message, Suggestion::new(at, lhs))) 51 52 } else { 52 53 None 53 54 }