aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lints/bool_comparison.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-31 09:05:26 +0000
committerAkshay <[email protected]>2021-10-31 16:05:15 +0000
commite8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch)
tree0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /lib/src/lints/bool_comparison.rs
parent246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff)
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lints/bool_comparison.rs')
-rw-r--r--lib/src/lints/bool_comparison.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/src/lints/bool_comparison.rs b/lib/src/lints/bool_comparison.rs
index 0b5733b..5c9bee8 100644
--- a/lib/src/lints/bool_comparison.rs
+++ b/lib/src/lints/bool_comparison.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,25 @@ use rnix::{
7 NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, 7 NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode,
8}; 8};
9 9
10/// ## What it does
11/// Checks for expressions of the form `x == true`, `x != true` and
12/// suggests using the variable directly.
13///
14/// ## Why is this bad?
15/// Unnecessary code.
16///
17/// ## Example
18/// Instead of checking the value of `x`:
19///
20/// ```
21/// if x == true then 0 else 1
22/// ```
23///
24/// Use `x` directly:
25///
26/// ```
27/// if x then 0 else 1
28/// ```
10#[lint( 29#[lint(
11 name = "bool_comparison", 30 name = "bool_comparison",
12 note = "Unnecessary comparison with boolean", 31 note = "Unnecessary comparison with boolean",
@@ -71,7 +90,7 @@ impl Rule for BoolComparison {
71 non_bool_side, 90 non_bool_side,
72 bool_side 91 bool_side
73 ); 92 );
74 Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) 93 Some(self.report().suggest(at, message, Suggestion::new(at, replacement)))
75 } else { 94 } else {
76 None 95 None
77 } 96 }