mirror of
https://github.com/nerdypepper/statix.git
synced 2024-09-11 13:45:32 +03:00
remove isNull deprecation lint
see https://github.com/NixOS/nix/pull/9645
This commit is contained in:
parent
d324490e45
commit
bc90852458
@ -1,6 +0,0 @@
|
||||
let
|
||||
e = null;
|
||||
in
|
||||
if isNull e
|
||||
then "no"
|
||||
else "yes"
|
@ -59,7 +59,6 @@ test_lint! {
|
||||
empty_pattern,
|
||||
redundant_pattern_bind,
|
||||
unquoted_uri,
|
||||
deprecated_is_null,
|
||||
empty_inherit,
|
||||
faster_groupby => session_info!("2.5"),
|
||||
faster_zipattrswith => session_info!("2.6"),
|
||||
|
@ -1,13 +0,0 @@
|
||||
---
|
||||
source: bin/tests/main.rs
|
||||
expression: "&out"
|
||||
|
||||
---
|
||||
[W13] Warning: Found usage of deprecated builtin isNull
|
||||
╭─[data/deprecated_is_null.nix:4:4]
|
||||
│
|
||||
4 │ if isNull e
|
||||
· ────┬───
|
||||
· ╰───── isNull is deprecated, check equality with null instead
|
||||
───╯
|
||||
|
@ -13,7 +13,6 @@ lints! {
|
||||
empty_pattern,
|
||||
redundant_pattern_bind,
|
||||
unquoted_uri,
|
||||
deprecated_is_null,
|
||||
empty_inherit,
|
||||
faster_groupby,
|
||||
faster_zipattrswith,
|
||||
|
@ -1,60 +0,0 @@
|
||||
use crate::{make, session::SessionInfo, Metadata, Report, Rule, Suggestion};
|
||||
|
||||
use if_chain::if_chain;
|
||||
use macros::lint;
|
||||
use rnix::{
|
||||
types::{Apply, Ident, TokenWrapper, TypedNode},
|
||||
NodeOrToken, SyntaxElement, SyntaxKind,
|
||||
};
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for usage of the `isNull` function.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// `isNull` is deprecated.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// Instead of `isNull` for `null` checks,
|
||||
///
|
||||
/// ```nix
|
||||
/// isNull e
|
||||
/// ```
|
||||
///
|
||||
/// use the equality operator:
|
||||
///
|
||||
/// ```nix
|
||||
/// e == null
|
||||
/// ```
|
||||
#[lint(
|
||||
name = "deprecated_is_null",
|
||||
note = "Found usage of deprecated builtin isNull",
|
||||
code = 13,
|
||||
match_with = SyntaxKind::NODE_APPLY
|
||||
)]
|
||||
struct DeprecatedIsNull;
|
||||
|
||||
impl Rule for DeprecatedIsNull {
|
||||
fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option<Report> {
|
||||
if_chain! {
|
||||
if let NodeOrToken::Node(node) = node;
|
||||
if let Some(apply) = Apply::cast(node.clone());
|
||||
if let Some(ident) = Ident::cast(apply.lambda()?);
|
||||
if ident.as_str() == "isNull";
|
||||
|
||||
if let Some(value) = apply.value();
|
||||
then {
|
||||
let null = make::ident("null");
|
||||
let binop = make::binary(&value, "==", null.node());
|
||||
let parenthesized = make::parenthesize(binop.node());
|
||||
|
||||
let at = node.text_range();
|
||||
let replacement = parenthesized.node().clone();
|
||||
let message = "`isNull` is deprecated, check equality with `null` instead";
|
||||
Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user