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/manual_inherit.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'lib/src/lints/manual_inherit.rs') diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index 0a6933c..2d119c3 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.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,30 @@ use rnix::{ NodeOrToken, SyntaxElement, SyntaxKind, }; +/// ## What it does +/// Checks for bindings of the form `a = a`. +/// +/// ## Why is this bad? +/// If the aim is to bring attributes from a larger scope into +/// the current scope, prefer an inherit statement. +/// +/// ## Example +/// +/// ``` +/// let +/// a = 2; +/// in +/// { a = a; b = 3; } +/// ``` +/// +/// Try `inherit` instead: +/// +/// ``` +/// let +/// a = 2; +/// in +/// { inherit a; b = 3; } +/// ``` #[lint( name = "manual inherit", note = "Assignment instead of inherit", @@ -35,7 +59,7 @@ impl Rule for ManualInherit { let at = node.text_range(); let replacement = make::inherit_stmt(&[key]).node().clone(); let message = "This assignment is better written with `inherit`"; - 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