aboutsummaryrefslogtreecommitdiff
path: root/lib/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/lib.rs')
-rw-r--r--lib/src/lib.rs43
1 files changed, 32 insertions, 11 deletions
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;
4pub use lints::LINTS; 4pub use lints::LINTS;
5 5
6use rnix::{SyntaxElement, SyntaxKind, TextRange}; 6use rnix::{SyntaxElement, SyntaxKind, TextRange};
7use std::{default::Default, convert::Into}; 7use std::{convert::Into, default::Default};
8 8
9/// Report generated by a lint 9/// Report generated by a lint
10#[derive(Debug, Default)] 10#[derive(Debug, Default)]
@@ -32,11 +32,16 @@ impl Report {
32 self 32 self
33 } 33 }
34 /// Add a diagnostic with a fix to this report 34 /// Add a diagnostic with a fix to this report
35 pub fn suggest<S: AsRef<str>>(mut self, at: TextRange, message: S, suggestion: Suggestion) -> Self { 35 pub fn suggest<S: AsRef<str>>(
36 self.diagnostics.push(Diagnostic::suggest(at, message, suggestion)); 36 mut self,
37 at: TextRange,
38 message: S,
39 suggestion: Suggestion,
40 ) -> Self {
41 self.diagnostics
42 .push(Diagnostic::suggest(at, message, suggestion));
37 self 43 self
38 } 44 }
39
40} 45}
41 46
42/// Mapping from a bytespan to an error message. 47/// Mapping from a bytespan to an error message.
@@ -51,11 +56,19 @@ pub struct Diagnostic {
51impl Diagnostic { 56impl Diagnostic {
52 /// Construct a diagnostic. 57 /// Construct a diagnostic.
53 pub fn new(at: TextRange, message: String) -> Self { 58 pub fn new(at: TextRange, message: String) -> Self {
54 Self { at, message, suggestion: None } 59 Self {
60 at,
61 message,
62 suggestion: None,
63 }
55 } 64 }
56 /// Construct a diagnostic with a fix. 65 /// Construct a diagnostic with a fix.
57 pub fn suggest<S: AsRef<str>>(at: TextRange, message: S, suggestion: Suggestion) -> Self { 66 pub fn suggest<S: AsRef<str>>(at: TextRange, message: S, suggestion: Suggestion) -> Self {
58 Self { at, message: message.as_ref().into(), suggestion: Some(suggestion) } 67 Self {
68 at,
69 message: message.as_ref().into(),
70 suggestion: Some(suggestion),
71 }
59 } 72 }
60} 73}
61 74
@@ -72,7 +85,7 @@ impl Suggestion {
72 pub fn new<E: Into<SyntaxElement>>(at: TextRange, fix: E) -> Self { 85 pub fn new<E: Into<SyntaxElement>>(at: TextRange, fix: E) -> Self {
73 Self { 86 Self {
74 at, 87 at,
75 fix: fix.into() 88 fix: fix.into(),
76 } 89 }
77 } 90 }
78} 91}
@@ -86,10 +99,18 @@ pub trait Rule {
86/// Contains information about the lint itself. Do not implement manually, 99/// Contains information about the lint itself. Do not implement manually,
87/// look at the `lint` attribute macro instead for implementing rules 100/// look at the `lint` attribute macro instead for implementing rules
88pub trait Metadata { 101pub trait Metadata {
89 fn name() -> &'static str where Self: Sized; 102 fn name() -> &'static str
90 fn note() -> &'static str where Self: Sized; 103 where
91 fn code() -> u32 where Self: Sized; 104 Self: Sized;
92 fn report() -> Report where Self: Sized; 105 fn note() -> &'static str
106 where
107 Self: Sized;
108 fn code() -> u32
109 where
110 Self: Sized;
111 fn report() -> Report
112 where
113 Self: Sized;
93 fn match_with(&self, with: &SyntaxKind) -> bool; 114 fn match_with(&self, with: &SyntaxKind) -> bool;
94 fn match_kind(&self) -> SyntaxKind; 115 fn match_kind(&self) -> SyntaxKind;
95} 116}