From d666cfa6b1739ac17d080790068e31eb26bb9c4a Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 19 Oct 2021 16:00:03 +0530 Subject: rework few error messages --- lib/src/lib.rs | 7 +++++++ lib/src/lints/collapsible_let_in.rs | 4 ++-- lib/src/lints/manual_inherit.rs | 2 +- lib/src/lints/manual_inherit_from.rs | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4374ac7..6bb16b6 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -42,6 +42,13 @@ impl Report { .push(Diagnostic::suggest(at, message, suggestion)); self } + /// A range that encompasses all the suggestions provided in this report + pub fn total_suggestion_range(&self) -> Option { + self.diagnostics + .iter() + .flat_map(|d| Some(d.suggestion.as_ref()?.at)) + .reduce(|acc, next| acc.cover(next)) + } } /// Mapping from a bytespan to an error message. diff --git a/lib/src/lints/collapsible_let_in.rs b/lib/src/lints/collapsible_let_in.rs index c2cdf9b..878d218 100644 --- a/lib/src/lints/collapsible_let_in.rs +++ b/lib/src/lints/collapsible_let_in.rs @@ -26,10 +26,10 @@ impl Rule for CollapsibleLetIn { if LetIn::cast(body.clone()).is_some(); then { let first_annotation = node.text_range(); - let first_message = "This let-in expression contains a nested let-in expression"; + let first_message = "This `let in` expression contains a nested `let in` expression"; let second_annotation = body.text_range(); - let second_message = "This let-in expression is nested"; + let second_message = "This `let in` expression is nested"; let replacement_at = { let start = body diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index 717d190..3524dd3 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.rs @@ -32,7 +32,7 @@ impl Rule for ManualInherit { then { let at = node.text_range(); let replacement = make::inherit_stmt(&[key]).node().clone(); - let message = format!("The assignment `{}` is better written with `inherit`", node); + let message = format!("This assignment is better written with `inherit`"); Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) } else { None diff --git a/lib/src/lints/manual_inherit_from.rs b/lib/src/lints/manual_inherit_from.rs index 41eb5cf..d7a00b2 100644 --- a/lib/src/lints/manual_inherit_from.rs +++ b/lib/src/lints/manual_inherit_from.rs @@ -37,7 +37,7 @@ impl Rule for ManualInherit { let set = value.set()?; make::inherit_from_stmt(set, &[key]).node().clone() }; - let message = format!("The assignment `{}` is better written with `inherit`", node); + let message = format!("This assignment is better written with `inherit`"); Some(Self::report().suggest(at, message, Suggestion::new(at, replacement))) } else { None -- cgit v1.2.3