Make MethodsPass lint notes clearer

This commit is contained in:
Devon Hollowood 2015-12-30 01:07:40 -08:00
parent 2c42d46468
commit 093582c102
2 changed files with 24 additions and 14 deletions

View file

@ -327,7 +327,8 @@ fn lint_map_unwrap_or(cx: &LateContext, expr: &Expr, map_args: &MethodArgs,
if same_span && !multiline {
span_note_and_lint(
cx, OPTION_MAP_UNWRAP_OR, expr.span, msg, expr.span,
&format!("replace this with map_or({1}, {0})", map_snippet, unwrap_snippet)
&format!("replace `map({0}).unwrap_or({1})` with `map_or({1}, {0})`", map_snippet,
unwrap_snippet)
);
}
else if same_span && multiline {
@ -356,7 +357,8 @@ fn lint_map_unwrap_or_else(cx: &LateContext, expr: &Expr, map_args: &MethodArgs,
if same_span && !multiline {
span_note_and_lint(
cx, OPTION_MAP_UNWRAP_OR_ELSE, expr.span, msg, expr.span,
&format!("replace this with map_or_else({1}, {0})", map_snippet, unwrap_snippet)
&format!("replace `map({0}).unwrap_or_else({1})` with `with map_or_else({1}, {0})`",
map_snippet, unwrap_snippet)
);
}
else if same_span && multiline {
@ -375,7 +377,7 @@ fn lint_filter_next(cx: &LateContext, expr: &Expr, filter_args: &MethodArgs) {
let filter_snippet = snippet(cx, filter_args[1].span, "..");
if filter_snippet.lines().count() <= 1 { // add note if not multi-line
span_note_and_lint(cx, FILTER_NEXT, expr.span, msg, expr.span,
&format!("replace this with `find({})`)", filter_snippet));
&format!("replace `filter({0}).next()` with `find({0})`", filter_snippet));
}
else {
span_lint(cx, FILTER_NEXT, expr.span, msg);
@ -394,7 +396,8 @@ fn lint_search_is_some(cx: &LateContext, expr: &Expr, search_method: &str, searc
let search_snippet = snippet(cx, search_args[1].span, "..");
if search_snippet.lines().count() <= 1 { // add note if not multi-line
span_note_and_lint(cx, SEARCH_IS_SOME, expr.span, &msg, expr.span,
&format!("replace this with `any({})`)", search_snippet));
&format!("replace `{0}({1}).is_some()` with `any({1})`", search_method,
search_snippet));
}
else {
span_lint(cx, SEARCH_IS_SOME, expr.span, &msg);

View file

@ -50,7 +50,7 @@ fn option_methods() {
// Check OPTION_MAP_UNWRAP_OR
// single line case
let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or(a)`
//~| NOTE replace this
//~| NOTE replace `map(|x| x + 1).unwrap_or(0)`
.unwrap_or(0); // should lint even though this call is on a separate line
// multi line cases
let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or(a)`
@ -67,7 +67,7 @@ fn option_methods() {
// Check OPTION_MAP_UNWRAP_OR_ELSE
// single line case
let _ = opt.map(|x| x + 1) //~ ERROR called `map(f).unwrap_or_else(g)`
//~| NOTE replace this
//~| NOTE replace `map(|x| x + 1).unwrap_or_else(|| 0)`
.unwrap_or_else(|| 0); // should lint even though this call is on a separate line
// multi line cases
let _ = opt.map(|x| { //~ ERROR called `map(f).unwrap_or_else(g)`
@ -116,8 +116,9 @@ fn filter_next() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
// check single-line case
let _ = v.iter().filter(|&x| *x < 0).next(); //~ERROR called `filter(p).next()` on an Iterator.
//~| NOTE replace this
let _ = v.iter().filter(|&x| *x < 0).next();
//~^ ERROR called `filter(p).next()` on an Iterator.
//~| NOTE replace `filter(|&x| *x < 0).next()`
// check multi-line case
let _ = v.iter().filter(|&x| { //~ERROR called `filter(p).next()` on an Iterator.
@ -135,8 +136,10 @@ fn search_is_some() {
let v = vec![3, 2, 1, 0, -1, -2, -3];
// check `find().is_some()`, single-line
let _ = v.iter().find(|&x| *x < 0).is_some(); //~ERROR called `is_some()` after searching
//~| NOTE replace this
let _ = v.iter().find(|&x| *x < 0).is_some();
//~^ ERROR called `is_some()` after searching
//~| NOTE replace `find(|&x| *x < 0).is_some()`
// check `find().is_some()`, multi-line
let _ = v.iter().find(|&x| { //~ERROR called `is_some()` after searching
*x < 0
@ -144,8 +147,10 @@ fn search_is_some() {
).is_some();
// check `position().is_some()`, single-line
let _ = v.iter().position(|&x| x < 0).is_some(); //~ERROR called `is_some()` after searching
//~| NOTE replace this
let _ = v.iter().position(|&x| x < 0).is_some();
//~^ ERROR called `is_some()` after searching
//~| NOTE replace `position(|&x| x < 0).is_some()`
// check `position().is_some()`, multi-line
let _ = v.iter().position(|&x| { //~ERROR called `is_some()` after searching
x < 0
@ -153,8 +158,10 @@ fn search_is_some() {
).is_some();
// check `rposition().is_some()`, single-line
let _ = v.iter().rposition(|&x| x < 0).is_some(); //~ERROR called `is_some()` after searching
//~| NOTE replace this
let _ = v.iter().rposition(|&x| x < 0).is_some();
//~^ ERROR called `is_some()` after searching
//~| NOTE replace `rposition(|&x| x < 0).is_some()`
// check `rposition().is_some()`, multi-line
let _ = v.iter().rposition(|&x| { //~ERROR called `is_some()` after searching
x < 0