Lints and suggestions for the Nix programming language
1
fork

Configure Feed

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

remove isNull deprecation lint (#86)

see https://github.com/NixOS/nix/pull/9645

authored by

seth and committed by
GitHub
7393fb27 d324490e

-82
-6
bin/tests/data/deprecated_is_null.nix
··· 1 - let 2 - e = null; 3 - in 4 - if isNull e 5 - then "no" 6 - else "yes"
-1
bin/tests/main.rs
··· 59 59 empty_pattern, 60 60 redundant_pattern_bind, 61 61 unquoted_uri, 62 - deprecated_is_null, 63 62 empty_inherit, 64 63 faster_groupby => session_info!("2.5"), 65 64 faster_zipattrswith => session_info!("2.6"),
-13
bin/tests/snapshots/main__deprecated_is_null.snap
··· 1 - --- 2 - source: bin/tests/main.rs 3 - expression: "&out" 4 - 5 - --- 6 - [W13] Warning: Found usage of deprecated builtin isNull 7 - ╭─[data/deprecated_is_null.nix:4:4] 8 - 9 - 4 │ if isNull e 10 - · ────┬─── 11 - · ╰───── isNull is deprecated, check equality with null instead 12 - ───╯ 13 -
-1
lib/src/lints.rs
··· 13 13 empty_pattern, 14 14 redundant_pattern_bind, 15 15 unquoted_uri, 16 - deprecated_is_null, 17 16 empty_inherit, 18 17 faster_groupby, 19 18 faster_zipattrswith,
-60
lib/src/lints/deprecated_is_null.rs
··· 1 - use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion}; 2 - 3 - use if_chain::if_chain; 4 - use macros::lint; 5 - use rnix::{ 6 - types::{Apply, Ident, TokenWrapper, TypedNode}, 7 - NodeOrToken, SyntaxElement, SyntaxKind, 8 - }; 9 - 10 - /// ## What it does 11 - /// Checks for usage of the `isNull` function. 12 - /// 13 - /// ## Why is this bad? 14 - /// `isNull` is deprecated. 15 - /// 16 - /// ## Example 17 - /// 18 - /// Instead of `isNull` for `null` checks, 19 - /// 20 - /// ```nix 21 - /// isNull e 22 - /// ``` 23 - /// 24 - /// use the equality operator: 25 - /// 26 - /// ```nix 27 - /// e == null 28 - /// ``` 29 - #[lint( 30 - name = "deprecated_is_null", 31 - note = "Found usage of deprecated builtin isNull", 32 - code = 13, 33 - match_with = SyntaxKind::NODE_APPLY 34 - )] 35 - struct DeprecatedIsNull; 36 - 37 - impl Rule for DeprecatedIsNull { 38 - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> { 39 - if_chain! { 40 - if let NodeOrToken::Node(node) = node; 41 - if let Some(apply) = Apply::cast(node.clone()); 42 - if let Some(ident) = Ident::cast(apply.lambda()?); 43 - if ident.as_str() == "isNull"; 44 - 45 - if let Some(value) = apply.value(); 46 - then { 47 - let null = make::ident("null"); 48 - let binop = make::binary(&value, "==", null.node()); 49 - let parenthesized = make::parenthesize(binop.node()); 50 - 51 - let at = node.text_range(); 52 - let replacement = parenthesized.node().clone(); 53 - let message = "`isNull` is deprecated, check equality with `null` instead"; 54 - Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) 55 - } else { 56 - None 57 - } 58 - } 59 - } 60 - }
-1
readme.md
··· 136 136 empty_pattern 137 137 redundant_pattern_bind 138 138 unquoted_uri 139 - deprecated_is_null 140 139 empty_inherit 141 140 faster_groupby 142 141 faster_zipattrswith