aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/unquoted_splice.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/lints/unquoted_splice.rs')
-rw-r--r--lib/src/lints/unquoted_splice.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/src/lints/unquoted_splice.rs b/lib/src/lints/unquoted_splice.rs
index 4d1ed69..c2fd6e4 100644
--- a/lib/src/lints/unquoted_splice.rs
+++ b/lib/src/lints/unquoted_splice.rs
@@ -1,4 +1,4 @@
1use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; 1use crate::{make, Metadata, Report, Rule, Suggestion};
2 2
3use if_chain::if_chain; 3use if_chain::if_chain;
4use macros::lint; 4use macros::lint;
@@ -7,6 +7,30 @@ use rnix::{
7 NodeOrToken, SyntaxElement, SyntaxKind, 7 NodeOrToken, SyntaxElement, SyntaxKind,
8}; 8};
9 9
10/// ## What it does
11/// Checks for antiquote/splice expressions that are not quoted.
12///
13/// ## Why is this bad?
14/// An *anti*quoted expression should always occur within a *quoted*
15/// expression.
16///
17/// ## Example
18///
19/// ```
20/// let
21/// pkgs = nixpkgs.legacyPackages.${system};
22/// in
23/// pkgs
24/// ```
25///
26/// Quote the splice expression:
27///
28/// ```
29/// let
30/// pkgs = nixpkgs.legacyPackages."${system}";
31/// in
32/// pkgs
33/// ```
10#[lint( 34#[lint(
11 name = "unquoted splice", 35 name = "unquoted splice",
12 note = "Found unquoted splice expression", 36 note = "Found unquoted splice expression",
@@ -24,7 +48,7 @@ impl Rule for UnquotedSplice {
24 let at = node.text_range(); 48 let at = node.text_range();
25 let replacement = make::quote(&node).node().clone(); 49 let replacement = make::quote(&node).node().clone();
26 let message = "Consider quoting this splice expression"; 50 let message = "Consider quoting this splice expression";
27 Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) 51 Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
28 } else { 52 } else {
29 None 53 None
30 } 54 }