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/lib.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'lib/src/lib.rs') diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 196cbf8..5347666 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -226,25 +226,29 @@ 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(&self) -> &'static str; + fn note(&self) -> &'static str; + fn code(&self) -> u32; + fn report(&self) -> Report; fn match_with(&self, with: &SyntaxKind) -> bool; fn match_kind(&self) -> Vec; } +/// Contains offline explanation for each lint +/// The `lint` macro scans nearby doc comments for +/// explanations and derives this trait. +/// +/// FIXME: the lint macro does way too much, maybe +/// split it into smaller macros. +pub trait Explain { + fn explanation(&self) -> &'static str { + "no explanation found" + } +} + /// Combines Rule and Metadata, do not implement manually, this is derived by /// the `lint` macro. -pub trait Lint: Metadata + Rule + Send + Sync {} +pub trait Lint: Metadata + Explain + Rule + Send + Sync {} /// Helper utility to take lints from modules and insert them into a map for efficient /// access. Mapping is from a SyntaxKind to a list of lints that apply on that Kind. -- cgit v1.2.3