From 8eccf15964e09c2e024710512e671c6b1b88e885 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 27 Oct 2021 19:50:52 +0530 Subject: add 3 new lints, bump to v0.2.3 - empty_pattern - redundant_pattern_bind - unquoted_splice --- lib/src/lints/unquoted_splice.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/src/lints/unquoted_splice.rs (limited to 'lib/src/lints/unquoted_splice.rs') diff --git a/lib/src/lints/unquoted_splice.rs b/lib/src/lints/unquoted_splice.rs new file mode 100644 index 0000000..4d1ed69 --- /dev/null +++ b/lib/src/lints/unquoted_splice.rs @@ -0,0 +1,33 @@ +use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; + +use if_chain::if_chain; +use macros::lint; +use rnix::{ + types::{Dynamic, TypedNode}, + NodeOrToken, SyntaxElement, SyntaxKind, +}; + +#[lint( + name = "unquoted splice", + note = "Found unquoted splice expression", + code = 9, + match_with = SyntaxKind::NODE_DYNAMIC +)] +struct UnquotedSplice; + +impl Rule for UnquotedSplice { + fn validate(&self, node: &SyntaxElement) -> Option { + if_chain! { + if let NodeOrToken::Node(node) = node; + if Dynamic::cast(node.clone()).is_some(); + then { + let at = node.text_range(); + let replacement = make::quote(&node).node().clone(); + let message = "Consider quoting this splice expression"; + Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) + } else { + None + } + } + } +} -- cgit v1.2.3