Skip to content

Commit 5ae6a9d

Browse files
committed
u
1 parent 28673cf commit 5ae6a9d

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/format_report_formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn annotation(error: &FormattingError) -> Option<Annotation<'_>> {
106106

107107
fn error_kind_to_snippet_annotation_level(error_kind: &ErrorKind) -> Level {
108108
match error_kind {
109-
ErrorKind::LineOverflow(..)
109+
ErrorKind::LineOverflow { .. }
110110
| ErrorKind::TrailingWhitespace
111111
| ErrorKind::IoError(_)
112112
| ErrorKind::ModuleResolutionError(_)

src/formatting.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl FormattingError {
333333

334334
pub(crate) fn is_internal(&self) -> bool {
335335
match self.kind {
336-
ErrorKind::LineOverflow(..)
336+
ErrorKind::LineOverflow { .. }
337337
| ErrorKind::TrailingWhitespace
338338
| ErrorKind::IoError(_)
339339
| ErrorKind::ParseError
@@ -354,9 +354,13 @@ impl FormattingError {
354354
// (space, target)
355355
pub(crate) fn format_len(&self) -> (usize, usize) {
356356
match self.kind {
357-
ErrorKind::LineOverflow(_, _, byte_start) => {
358-
(byte_start, self.line_buffer.len() - byte_start)
359-
}
357+
ErrorKind::LineOverflow {
358+
overflow_start_byte,
359+
..
360+
} => (
361+
overflow_start_byte,
362+
self.line_buffer.len() - overflow_start_byte,
363+
),
360364
ErrorKind::TrailingWhitespace
361365
| ErrorKind::DeprecatedAttr
362366
| ErrorKind::BadAttr
@@ -566,10 +570,13 @@ impl<'a> FormatLines<'a> {
566570
}
567571

568572
// Check for any line width errors we couldn't correct.
569-
let max = self.config.max_width();
570-
let error_kind =
571-
ErrorKind::LineOverflow(self.line_len, max, self.byte_offset_at_col(max));
572-
if self.line_len > max
573+
let max_width = self.config.max_width();
574+
let error_kind = ErrorKind::LineOverflow {
575+
total_line_width: self.line_len,
576+
max_width,
577+
overflow_start_byte: self.byte_offset_at_col(max_width),
578+
};
579+
if self.line_len > max_width
573580
&& !self.is_skipped_line()
574581
&& self.should_report_error(kind, &error_kind)
575582
{
@@ -641,7 +648,7 @@ impl<'a> FormatLines<'a> {
641648
};
642649

643650
match error_kind {
644-
ErrorKind::LineOverflow(..) => {
651+
ErrorKind::LineOverflow { .. } => {
645652
self.config.error_on_line_overflow() && allow_error_report
646653
}
647654
ErrorKind::TrailingWhitespace | ErrorKind::LostComment => allow_error_report,

src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,16 @@ pub(crate) mod visitor;
106106
/// these can currently be propagated to clients.
107107
#[derive(Error, Debug)]
108108
pub enum ErrorKind {
109-
/// Line has exceeded character limit (found, maximum, byte offset within
110-
/// the line where the overflow region begins).
109+
/// A line exceeded the configured maximum width.
111110
#[error(
112111
"line formatted, but exceeded maximum width \
113-
(maximum: {1} (see `max_width` option), found: {0})"
112+
(maximum: {max_width} (see `max_width` option), found: {total_line_width})"
114113
)]
115-
LineOverflow {
116-
total_line_width: usize,
117-
max_width: usize,
118-
overflow_start_byte: usize
119-
}
114+
LineOverflow {
115+
total_line_width: usize,
116+
max_width: usize,
117+
overflow_start_byte: usize,
118+
},
120119
/// Line ends in whitespace.
121120
#[error("left behind trailing whitespace")]
122121
TrailingWhitespace,
@@ -230,7 +229,7 @@ impl FormatReport {
230229
}
231230
for err in new_errors {
232231
match err.kind {
233-
ErrorKind::LineOverflow(..) => {
232+
ErrorKind::LineOverflow { .. } => {
234233
errs.has_operational_errors = true;
235234
}
236235
ErrorKind::TrailingWhitespace => {

0 commit comments

Comments
 (0)