From c5c4b55c2b3a3fb824c3fd64e33bb30f1b011b71 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 2 Oct 2021 20:53:19 +0530 Subject: new lint: legacy_let_syntax --- lib/src/lib.rs | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'lib/src/lib.rs') diff --git a/lib/src/lib.rs b/lib/src/lib.rs index ab4a14a..f0f26dd 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -4,7 +4,7 @@ mod make; pub use lints::LINTS; use rnix::{SyntaxElement, SyntaxKind, TextRange}; -use std::{default::Default, convert::Into}; +use std::{convert::Into, default::Default}; /// Report generated by a lint #[derive(Debug, Default)] @@ -32,11 +32,16 @@ impl Report { self } /// Add a diagnostic with a fix to this report - pub fn suggest>(mut self, at: TextRange, message: S, suggestion: Suggestion) -> Self { - self.diagnostics.push(Diagnostic::suggest(at, message, suggestion)); + pub fn suggest>( + mut self, + at: TextRange, + message: S, + suggestion: Suggestion, + ) -> Self { + self.diagnostics + .push(Diagnostic::suggest(at, message, suggestion)); self } - } /// Mapping from a bytespan to an error message. @@ -51,11 +56,19 @@ pub struct Diagnostic { impl Diagnostic { /// Construct a diagnostic. pub fn new(at: TextRange, message: String) -> Self { - Self { at, message, suggestion: None } + Self { + at, + message, + suggestion: None, + } } /// Construct a diagnostic with a fix. pub fn suggest>(at: TextRange, message: S, suggestion: Suggestion) -> Self { - Self { at, message: message.as_ref().into(), suggestion: Some(suggestion) } + Self { + at, + message: message.as_ref().into(), + suggestion: Some(suggestion), + } } } @@ -72,7 +85,7 @@ impl Suggestion { pub fn new>(at: TextRange, fix: E) -> Self { Self { at, - fix: fix.into() + fix: fix.into(), } } } @@ -86,10 +99,18 @@ pub trait Rule { /// Contains information about the lint itself. Do not implement manually, /// look at the `lint` attribute macro instead for implementing rules pub trait Metadata { - fn name() -> &'static str where Self: Sized; - fn note() -> &'static str where Self: Sized; - fn code() -> u32 where Self: Sized; - fn report() -> Report where Self: Sized; + fn name() -> &'static str + where + Self: Sized; + fn note() -> &'static str + where + Self: Sized; + fn code() -> u32 + where + Self: Sized; + fn report() -> Report + where + Self: Sized; fn match_with(&self, with: &SyntaxKind) -> bool; fn match_kind(&self) -> SyntaxKind; } -- cgit v1.2.3