Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Add flag to only apply certain lints/errors' suggestions #42

Merged
merged 3 commits into from
Nov 7, 2017
Merged

Conversation

oli-obk
Copy link
Collaborator

@oli-obk oli-obk commented Nov 7, 2017

cc #36

Copy link
Member

@killercup killercup left a 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> {
Copy link
Member

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()?

Copy link
Collaborator Author

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])] = &[
Copy link
Member

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| {
Copy link
Member

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))?

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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()

@killercup
Copy link
Member

I probably won't have time to play with this tonight, so… I trust ya!

bors r+

bors bot added a commit that referenced this pull request Nov 7, 2017
42: Add flag to only apply certain lints/errors' suggestions  r=killercup a=oli-obk

cc #36
@bors
Copy link

bors bot commented Nov 7, 2017

Build succeeded

@bors bors bot merged commit 2a3258f into master Nov 7, 2017
@oli-obk oli-obk deleted the sniper branch November 7, 2017 14:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants