From e8c955da4cbb042e6f9b89307d143f5bfa6779fa Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 31 Oct 2021 14:35:26 +0530 Subject: add `explain` subcommand and explanations to all lints --- lib/src/lints/bool_comparison.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lib/src/lints/bool_comparison.rs') 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 @@ -use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; +use crate::{make, Metadata, Report, Rule, Suggestion}; use if_chain::if_chain; use macros::lint; @@ -7,6 +7,25 @@ use rnix::{ NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, }; +/// ## What it does +/// Checks for expressions of the form `x == true`, `x != true` and +/// suggests using the variable directly. +/// +/// ## Why is this bad? +/// Unnecessary code. +/// +/// ## Example +/// Instead of checking the value of `x`: +/// +/// ``` +/// if x == true then 0 else 1 +/// ``` +/// +/// Use `x` directly: +/// +/// ``` +/// if x then 0 else 1 +/// ``` #[lint( name = "bool_comparison", note = "Unnecessary comparison with boolean", @@ -71,7 +90,7 @@ impl Rule for BoolComparison { non_bool_side, bool_side ); - Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) + Some(self.report().suggest(at, message, Suggestion::new(at, replacement))) } else { None } -- cgit v1.2.3