-
Notifications
You must be signed in to change notification settings - Fork 62
Add flag to only apply certain lints/errors' suggestions #42
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I'll test this later but here are some preliminary comments
src/lib.rs
Outdated
@@ -106,7 +108,18 @@ fn collect_span(span: &DiagnosticSpan) -> Option<Replacement> { | |||
}) | |||
} | |||
|
|||
pub fn collect_suggestions(diagnostic: &Diagnostic) -> Option<Suggestion> { | |||
pub fn collect_suggestions(diagnostic: &Diagnostic, only: &Option<HashSet<String>>) -> Option<Suggestion> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what's better: Using an Option if let
or an empty HashSet with is_empty()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, the latter might be easier
src/main.rs
Outdated
@@ -48,6 +49,11 @@ macro_rules! flush { | |||
() => (try!(std::io::stdout().flush());) | |||
} | |||
|
|||
/// A list of `--only` aliases | |||
const ALIAS: &[(&str, &[&str])] = &[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALIASES
?
src/main.rs
Outdated
let mut only: Option<HashSet<String>> = matches.values_of("only").map(|values| values.map(|s| s.to_string()).collect()); | ||
let mut only: HashSet<String> = matches | ||
.values_of("only") | ||
.map_or(HashSet::new(), |values| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, do you consider map_or(fallback, mapper)
clearer than map(mapper).or(fallback)
(or actually, .or_else(|| fallback)
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or map_or_else(|| fallback, mapper)
;)
I have no opinion. clippy does. I just do what clippy says. If I have opinions I change clippy or complain in the issues and then change it or my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great opinion-finding algorithm.
I like the .map.or
better because you can put it on multiple lines and each line does a specific thing, but at the same time don't care enough because this map_or
is pretty straightforward. I also don't care about using the _else
variant here as an empty HashSet doesn't allocate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this specific case, clippy should probably be suggesting .map(m).unwrap_or_default()
I probably won't have time to play with this tonight, so… I trust ya! bors r+ |
Build succeeded |
cc #36