Skip to content

should_report_error: don't report error when using stdin #2495

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 12 additions & 3 deletions rustfmt-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,15 @@ fn is_skipped_line(line_number: usize, skipped_range: &[(usize, usize)]) -> bool
}

fn should_report_error(
path: &FileName,
config: &Config,
char_kind: FullCodeCharKind,
is_string: bool,
error_kind: ErrorKind,
) -> bool {
let allow_error_report = if char_kind.is_comment() || is_string {
let allow_error_report = if path.to_string() == STDIN {
false
} else if char_kind.is_comment() || is_string {
config.error_on_unformatted()
} else {
true
Expand Down Expand Up @@ -445,7 +448,13 @@ fn format_lines(
if format_line {
// Check for (and record) trailing whitespace.
if let Some(..) = last_wspace {
if should_report_error(config, kind, is_string, ErrorKind::TrailingWhitespace) {
if should_report_error(
name,
config,
kind,
is_string,
ErrorKind::TrailingWhitespace,
) {
trims.push((cur_line, kind, line_buffer.clone()));
}
line_len -= 1;
Expand All @@ -454,7 +463,7 @@ fn format_lines(
// Check for any line width errors we couldn't correct.
let error_kind = ErrorKind::LineOverflow(line_len, config.max_width());
if line_len > config.max_width() && !is_skipped_line(cur_line, skipped_range)
&& should_report_error(config, kind, is_string, error_kind)
&& should_report_error(name, config, kind, is_string, error_kind)
{
errors.push(FormattingError {
line: cur_line,
Expand Down