diff options
author | Akshay <[email protected]> | 2021-10-27 15:20:52 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-27 20:03:48 +0100 |
commit | 8eccf15964e09c2e024710512e671c6b1b88e885 (patch) | |
tree | da902a799840c3031f2ca68e3be39e3f101b05eb /lib/src/lints/unquoted_splice.rs | |
parent | f909b20c540ea99dddfd04b8439ee35b8dd703b8 (diff) |
add 3 new lints, bump to v0.2.3v0.2.3
- empty_pattern
- redundant_pattern_bind
- unquoted_splice
Diffstat (limited to 'lib/src/lints/unquoted_splice.rs')
-rw-r--r-- | lib/src/lints/unquoted_splice.rs | 33 |
1 files changed, 33 insertions, 0 deletions
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 @@ | |||
1 | use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; | ||
2 | |||
3 | use if_chain::if_chain; | ||
4 | use macros::lint; | ||
5 | use rnix::{ | ||
6 | types::{Dynamic, TypedNode}, | ||
7 | NodeOrToken, SyntaxElement, SyntaxKind, | ||
8 | }; | ||
9 | |||
10 | #[lint( | ||
11 | name = "unquoted splice", | ||
12 | note = "Found unquoted splice expression", | ||
13 | code = 9, | ||
14 | match_with = SyntaxKind::NODE_DYNAMIC | ||
15 | )] | ||
16 | struct UnquotedSplice; | ||
17 | |||
18 | impl Rule for UnquotedSplice { | ||
19 | fn validate(&self, node: &SyntaxElement) -> Option<Report> { | ||
20 | if_chain! { | ||
21 | if let NodeOrToken::Node(node) = node; | ||
22 | if Dynamic::cast(node.clone()).is_some(); | ||
23 | then { | ||
24 | let at = node.text_range(); | ||
25 | let replacement = make::quote(&node).node().clone(); | ||
26 | let message = "Consider quoting this splice expression"; | ||
27 | Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) | ||
28 | } else { | ||
29 | None | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | } | ||