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/eta_reduction.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'lib/src/lints/eta_reduction.rs') diff --git a/lib/src/lints/eta_reduction.rs b/lib/src/lints/eta_reduction.rs index 79a5101..3a483d0 100644 --- a/lib/src/lints/eta_reduction.rs +++ b/lib/src/lints/eta_reduction.rs @@ -1,4 +1,4 @@ -use crate::{Lint, Metadata, Report, Rule, Suggestion}; +use crate::{Metadata, Report, Rule, Suggestion}; use if_chain::if_chain; use macros::lint; @@ -7,6 +7,32 @@ use rnix::{ NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, }; +/// ## What it does +/// Checks for eta-reducible functions, i.e.: converts lambda +/// expressions into free standing functions where applicable. +/// +/// ## Why is this bad? +/// Oftentimes, eta-reduction results in code that is more natural +/// to read. +/// +/// ## Example +/// +/// ``` +/// let +/// double = i: 2 * i; +/// in +/// map (x: double x) [ 1 2 3 ] +/// ``` +/// +/// The lambda passed to the `map` function is eta-reducible, and the +/// result reads more naturally: +/// +/// ``` +/// let +/// double = i: 2 * i; +/// in +/// map double [ 1 2 3 ] +/// ``` #[lint( name = "eta reduction", note = "This function expression is eta reducible", @@ -43,7 +69,7 @@ impl Rule for EtaReduction { "Found eta-reduction: `{}`", replacement.text().to_string() ); - 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