Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better message for LineOverflow error #1268

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Better message for LineOverflow error
(with current length and configured limit)
  • Loading branch information
stepancheg committed Jan 8, 2017
commit 92c854bd826377f6f7c01c78ccf5eff32ca7d8c6
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl Sub<usize> for Indent {
}

pub enum ErrorKind {
// Line has exceeded character limit
LineOverflow,
// Line has exceeded character limit (found, maximum)
LineOverflow(usize, usize),
// Line ends in whitespace
TrailingWhitespace,
// TO-DO or FIX-ME item without an issue number
Expand All @@ -213,7 +213,12 @@ pub enum ErrorKind {
impl fmt::Display for ErrorKind {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
ErrorKind::LineOverflow => write!(fmt, "line exceeded maximum length"),
ErrorKind::LineOverflow(found, maximum) => {
write!(fmt,
"line exceeded maximum length (maximum: {}, found: {})",
maximum,
found)
}
ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"),
ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue),
}
Expand All @@ -229,15 +234,15 @@ pub struct FormattingError {
impl FormattingError {
fn msg_prefix(&self) -> &str {
match self.kind {
ErrorKind::LineOverflow |
ErrorKind::LineOverflow(..) |
ErrorKind::TrailingWhitespace => "Rustfmt failed at",
ErrorKind::BadIssue(_) => "WARNING:",
}
}

fn msg_suffix(&self) -> &str {
match self.kind {
ErrorKind::LineOverflow |
ErrorKind::LineOverflow(..) |
ErrorKind::TrailingWhitespace => "(sorry)",
ErrorKind::BadIssue(_) => "",
}
Expand Down Expand Up @@ -353,7 +358,7 @@ fn format_lines(text: &mut StringBuffer, name: &str, config: &Config, report: &m
if line_len > config.max_width {
errors.push(FormattingError {
line: cur_line,
kind: ErrorKind::LineOverflow,
kind: ErrorKind::LineOverflow(line_len, config.max_width),
});
}
line_len = 0;
Expand Down