Skip to content

Commit 9ab1587

Browse files
committed
Don't apologise if its not our fault in warnings
1 parent e4a6f96 commit 9ab1587

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/lib.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ impl fmt::Display for ErrorKind {
125125
match *self {
126126
ErrorKind::LineOverflow => {
127127
write!(fmt, "line exceeded maximum length")
128-
},
128+
}
129129
ErrorKind::TrailingWhitespace => {
130130
write!(fmt, "left behind trailing whitespace")
131-
},
131+
}
132132
ErrorKind::BadIssue(issue) => {
133133
write!(fmt, "found {}", issue)
134-
},
134+
}
135135
}
136136
}
137137
}
@@ -142,6 +142,24 @@ struct FormattingError {
142142
kind: ErrorKind,
143143
}
144144

145+
impl FormattingError {
146+
fn msg_prefix(&self) -> &str {
147+
match self.kind {
148+
ErrorKind::LineOverflow |
149+
ErrorKind::TrailingWhitespace => "Rustfmt failed at",
150+
ErrorKind::BadIssue(_) => "WARNING:",
151+
}
152+
}
153+
154+
fn msg_suffix(&self) -> &str {
155+
match self.kind {
156+
ErrorKind::LineOverflow |
157+
ErrorKind::TrailingWhitespace => "(sorry)",
158+
ErrorKind::BadIssue(_) => "",
159+
}
160+
}
161+
}
162+
145163
struct FormatReport {
146164
// Maps stringified file paths to their associated formatting errors
147165
file_error_map: HashMap<String, Vec<FormattingError>>,
@@ -153,10 +171,12 @@ impl fmt::Display for FormatReport {
153171
for (file, errors) in self.file_error_map.iter() {
154172
for error in errors {
155173
try!(write!(fmt,
156-
"Rustfmt failed at {}:{}: {} (sorry)\n",
174+
"{} {}:{}: {} {}\n",
175+
error.msg_prefix(),
157176
file,
158177
error.line,
159-
error.kind));
178+
error.kind,
179+
error.msg_suffix()));
160180
}
161181
}
162182
Ok(())

0 commit comments

Comments
 (0)