diff options
author | Akshay <[email protected]> | 2021-10-31 09:05:26 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-10-31 16:05:15 +0000 |
commit | e8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch) | |
tree | 0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /lib/src/lib.rs | |
parent | 246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff) |
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'lib/src/lib.rs')
-rw-r--r-- | lib/src/lib.rs | 30 |
1 files changed, 17 insertions, 13 deletions
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 { | |||
226 | /// Contains information about the lint itself. Do not implement manually, | 226 | /// Contains information about the lint itself. Do not implement manually, |
227 | /// look at the `lint` attribute macro instead for implementing rules | 227 | /// look at the `lint` attribute macro instead for implementing rules |
228 | pub trait Metadata { | 228 | pub trait Metadata { |
229 | fn name() -> &'static str | 229 | fn name(&self) -> &'static str; |
230 | where | 230 | fn note(&self) -> &'static str; |
231 | Self: Sized; | 231 | fn code(&self) -> u32; |
232 | fn note() -> &'static str | 232 | fn report(&self) -> Report; |
233 | where | ||
234 | Self: Sized; | ||
235 | fn code() -> u32 | ||
236 | where | ||
237 | Self: Sized; | ||
238 | fn report() -> Report | ||
239 | where | ||
240 | Self: Sized; | ||
241 | fn match_with(&self, with: &SyntaxKind) -> bool; | 233 | fn match_with(&self, with: &SyntaxKind) -> bool; |
242 | fn match_kind(&self) -> Vec<SyntaxKind>; | 234 | fn match_kind(&self) -> Vec<SyntaxKind>; |
243 | } | 235 | } |
244 | 236 | ||
237 | /// Contains offline explanation for each lint | ||
238 | /// The `lint` macro scans nearby doc comments for | ||
239 | /// explanations and derives this trait. | ||
240 | /// | ||
241 | /// FIXME: the lint macro does way too much, maybe | ||
242 | /// split it into smaller macros. | ||
243 | pub trait Explain { | ||
244 | fn explanation(&self) -> &'static str { | ||
245 | "no explanation found" | ||
246 | } | ||
247 | } | ||
248 | |||
245 | /// Combines Rule and Metadata, do not implement manually, this is derived by | 249 | /// Combines Rule and Metadata, do not implement manually, this is derived by |
246 | /// the `lint` macro. | 250 | /// the `lint` macro. |
247 | pub trait Lint: Metadata + Rule + Send + Sync {} | 251 | pub trait Lint: Metadata + Explain + Rule + Send + Sync {} |
248 | 252 | ||
249 | /// Helper utility to take lints from modules and insert them into a map for efficient | 253 | /// Helper utility to take lints from modules and insert them into a map for efficient |
250 | /// access. Mapping is from a SyntaxKind to a list of lints that apply on that Kind. | 254 | /// access. Mapping is from a SyntaxKind to a list of lints that apply on that Kind. |