Use failure for FormattingError
This commit is contained in:
parent
efb8069cfc
commit
5581be2616
27
src/lib.rs
27
src/lib.rs
@ -19,6 +19,7 @@
|
||||
#[macro_use]
|
||||
extern crate derive_new;
|
||||
extern crate diff;
|
||||
extern crate failure;
|
||||
extern crate getopts;
|
||||
extern crate itertools;
|
||||
#[cfg(test)]
|
||||
@ -53,6 +54,7 @@ use syntax::errors::{DiagnosticBuilder, Handler};
|
||||
use syntax::parse::{self, ParseSess};
|
||||
|
||||
use comment::{CharClasses, FullCodeCharKind, LineClasses};
|
||||
use failure::Fail;
|
||||
use issues::{BadIssueSeeker, Issue};
|
||||
use shape::Indent;
|
||||
use utils::use_colored_tty;
|
||||
@ -109,33 +111,26 @@ pub(crate) type FileMap = Vec<FileRecord>;
|
||||
|
||||
pub(crate) type FileRecord = (FileName, String);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Fail, Debug, Clone, Copy)]
|
||||
pub enum ErrorKind {
|
||||
// Line has exceeded character limit (found, maximum)
|
||||
#[fail(
|
||||
display = "line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})",
|
||||
_0,
|
||||
_1
|
||||
)]
|
||||
LineOverflow(usize, usize),
|
||||
// Line ends in whitespace
|
||||
#[fail(display = "left behind trailing whitespace")]
|
||||
TrailingWhitespace,
|
||||
// TODO or FIXME item without an issue number
|
||||
#[fail(display = "found {}", _0)]
|
||||
BadIssue(Issue),
|
||||
// License check has failed
|
||||
#[fail(display = "license check failed")]
|
||||
LicenseCheck,
|
||||
}
|
||||
|
||||
impl fmt::Display for ErrorKind {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
ErrorKind::LineOverflow(found, maximum) => write!(
|
||||
fmt,
|
||||
"line formatted, but exceeded maximum width (maximum: {} (see `max_width` option), found: {})",
|
||||
maximum, found,
|
||||
),
|
||||
ErrorKind::TrailingWhitespace => write!(fmt, "left behind trailing whitespace"),
|
||||
ErrorKind::BadIssue(issue) => write!(fmt, "found {}", issue),
|
||||
ErrorKind::LicenseCheck => write!(fmt, "license check failed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Formatting errors that are identified *after* rustfmt has run.
|
||||
struct FormattingError {
|
||||
line: usize,
|
||||
|
Loading…
x
Reference in New Issue
Block a user