aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/deprecated_is_null.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/lints/deprecated_is_null.rs')
-rw-r--r--lib/src/lints/deprecated_is_null.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/src/lints/deprecated_is_null.rs b/lib/src/lints/deprecated_is_null.rs
new file mode 100644
index 0000000..99fb3fb
--- /dev/null
+++ b/lib/src/lints/deprecated_is_null.rs
@@ -0,0 +1,41 @@
1use crate::{make, Metadata, Report, Rule, Suggestion};
2
3use if_chain::if_chain;
4use macros::lint;
5use rnix::{
6 types::{Apply, Ident, TokenWrapper, TypedNode},
7 NodeOrToken, SyntaxElement, SyntaxKind,
8};
9
10#[lint(
11 name = "deprecated isNull",
12 note = "Found usage of deprecated builtin isNull",
13 code = 13,
14 match_with = SyntaxKind::NODE_APPLY
15)]
16struct DeprecatedIsNull;
17
18impl Rule for DeprecatedIsNull {
19 fn validate(&self, node: &SyntaxElement) -> Option<Report> {
20 if_chain! {
21 if let NodeOrToken::Node(node) = node;
22 if let Some(apply) = Apply::cast(node.clone());
23 if let Some(ident) = Ident::cast(apply.lambda()?);
24 if ident.as_str() == "isNull";
25
26 if let Some(value) = apply.value();
27 then {
28 let null = make::ident("null");
29 let binop = make::binary(&value, "==", null.node());
30 let parenthesized = make::parenthesize(binop.node());
31
32 let at = node.text_range();
33 let replacement = parenthesized.node().clone();
34 let message = "`isNull` is deprecated, check equality with `null` instead";
35 Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
36 } else {
37 None
38 }
39 }
40 }
41}