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/collapsible_let_in.rs | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'lib/src/lints/collapsible_let_in.rs') diff --git a/lib/src/lints/collapsible_let_in.rs b/lib/src/lints/collapsible_let_in.rs index 878d218..21199a8 100644 --- a/lib/src/lints/collapsible_let_in.rs +++ b/lib/src/lints/collapsible_let_in.rs @@ -1,13 +1,41 @@ -use crate::{make, Lint, Metadata, Report, Rule, Suggestion}; +use crate::{make, Metadata, Report, Rule, Suggestion}; use if_chain::if_chain; use macros::lint; -use rowan::Direction; use rnix::{ types::{LetIn, TypedNode}, - NodeOrToken, SyntaxElement, SyntaxKind, TextRange + NodeOrToken, SyntaxElement, SyntaxKind, TextRange, }; +use rowan::Direction; +/// ## What it does +/// Checks for `let-in` expressions whose body is another `let-in` +/// expression. +/// +/// ## Why is this bad? +/// Unnecessary code, the `let-in` expressions can be merged. +/// +/// ## Example +/// +/// ``` +/// let +/// a = 2; +/// in +/// let +/// b = 3; +/// in +/// a + b +/// ``` +/// +/// Merge both `let-in` expressions: +/// +/// ``` +/// let +/// a = 2; +/// b = 3; +/// in +/// a + b +/// ``` #[lint( name = "collapsible let in", note = "These let-in expressions are collapsible", @@ -47,7 +75,7 @@ impl Rule for CollapsibleLetIn { let replacement = make::empty().node().clone(); Some( - Self::report() + self.report() .diagnostic(first_annotation, first_message) .suggest(second_annotation, second_message, Suggestion::new(replacement_at, replacement)) ) @@ -57,4 +85,3 @@ impl Rule for CollapsibleLetIn { } } } - -- cgit v1.2.3