diff options
Diffstat (limited to 'lib/src/lints/bool_comparison.rs')
-rw-r--r-- | lib/src/lints/bool_comparison.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/src/lints/bool_comparison.rs b/lib/src/lints/bool_comparison.rs index 0b5733b..6636faf 100644 --- a/lib/src/lints/bool_comparison.rs +++ b/lib/src/lints/bool_comparison.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; | 1 | use crate::{make, Metadata, Report, Rule, Suggestion}; |
2 | 2 | ||
3 | use if_chain::if_chain; | 3 | use if_chain::if_chain; |
4 | use macros::lint; | 4 | use macros::lint; |
@@ -7,6 +7,28 @@ use rnix::{ | |||
7 | NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, | 7 | NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | /// What it does | ||
11 | /// ------------ | ||
12 | /// Checks for expressions of the form x == true, x != true and | ||
13 | /// suggests using the variable directly. | ||
14 | /// | ||
15 | /// Why is this bad? | ||
16 | /// ---------------- | ||
17 | /// Unnecessary code. | ||
18 | /// | ||
19 | /// Example | ||
20 | /// -------- | ||
21 | /// Instead of checking the value of x: | ||
22 | /// | ||
23 | /// if x == true | ||
24 | /// then 0 | ||
25 | /// else 1 | ||
26 | /// | ||
27 | /// Use x directly: | ||
28 | /// | ||
29 | /// if x | ||
30 | /// then 0 | ||
31 | /// else 1 | ||
10 | #[lint( | 32 | #[lint( |
11 | name = "bool_comparison", | 33 | name = "bool_comparison", |
12 | note = "Unnecessary comparison with boolean", | 34 | note = "Unnecessary comparison with boolean", |
@@ -71,7 +93,7 @@ impl Rule for BoolComparison { | |||
71 | non_bool_side, | 93 | non_bool_side, |
72 | bool_side | 94 | bool_side |
73 | ); | 95 | ); |
74 | Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) | 96 | Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) |
75 | } else { | 97 | } else { |
76 | None | 98 | None |
77 | } | 99 | } |