aboutsummaryrefslogtreecommitdiff
path: root/bin/src/config.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-10-31 09:05:26 +0000
committerAkshay <[email protected]>2021-10-31 16:05:15 +0000
commite8c955da4cbb042e6f9b89307d143f5bfa6779fa (patch)
tree0ae4ec11fd3dc0f8b69bc0f32c08858ef23a9485 /bin/src/config.rs
parent246c69f8cfc74cf4c56fdaceaeb0562ed1f3dad5 (diff)
add `explain` subcommand and explanations to all lints
Diffstat (limited to 'bin/src/config.rs')
-rw-r--r--bin/src/config.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/bin/src/config.rs b/bin/src/config.rs
index ef3a29d..1649017 100644
--- a/bin/src/config.rs
+++ b/bin/src/config.rs
@@ -26,6 +26,8 @@ pub enum SubCommand {
26 Fix(Fix), 26 Fix(Fix),
27 /// Fix exactly one issue at provided position 27 /// Fix exactly one issue at provided position
28 Single(Single), 28 Single(Single),
29 /// Print detailed explanation for a lint warning
30 Explain(Explain),
29} 31}
30 32
31#[derive(Clap, Debug)] 33#[derive(Clap, Debug)]
@@ -88,6 +90,13 @@ pub struct Single {
88 pub diff_only: bool, 90 pub diff_only: bool,
89} 91}
90 92
93#[derive(Clap, Debug)]
94pub struct Explain {
95 /// Warning code to explain
96 #[clap(parse(try_from_str = parse_warning_code))]
97 pub target: u32,
98}
99
91mod dirs { 100mod dirs {
92 use std::{ 101 use std::{
93 fs, 102 fs,
@@ -160,6 +169,21 @@ fn parse_line_col(src: &str) -> Result<(usize, usize), ConfigErr> {
160 } 169 }
161} 170}
162 171
172fn parse_warning_code(src: &str) -> Result<u32, ConfigErr> {
173 let mut char_stream = src.chars();
174 let severity = char_stream
175 .next()
176 .ok_or(ConfigErr::InvalidWarningCode(src.to_owned()))?
177 .to_ascii_lowercase();
178 match severity {
179 'w' => char_stream
180 .collect::<String>()
181 .parse::<u32>()
182 .map_err(|_| ConfigErr::InvalidWarningCode(src.to_owned())),
183 _ => Ok(0),
184 }
185}
186
163fn build_ignore_set(ignores: &[String]) -> Result<GlobSet, GlobError> { 187fn build_ignore_set(ignores: &[String]) -> Result<GlobSet, GlobError> {
164 let mut set = GlobSetBuilder::new(); 188 let mut set = GlobSetBuilder::new();
165 for pattern in ignores { 189 for pattern in ignores {