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

Update format.rs to display correct message for already formatted files #9153

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions crates/ruff_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl<'a> FormatResults<'a> {
if changed > 0 && unchanged > 0 {
writeln!(
f,
"{} file{} {}, {} file{} left unchanged",
"{} file{} {}, {} file{} already formatted",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to apply this change only in the event that we have FormatMode::Check | FormatMode::Diff -- do you mind tweaking, similar to "would be reformatted" below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't understand: Check and Diff here are like the lower branch of the 'if'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VictorGob - I pushed an update to illustrate what I meant. What do you think of this approach?

Copy link
Contributor Author

@VictorGob VictorGob Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chef kiss 👌

changed,
if changed == 1 { "" } else { "s" },
match self.mode {
Expand All @@ -539,7 +539,7 @@ impl<'a> FormatResults<'a> {
} else if unchanged > 0 {
writeln!(
f,
"{} file{} left unchanged",
"{} file{} already formatted",
unchanged,
if unchanged == 1 { "" } else { "s" },
)
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_cli/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn mixed_line_endings() -> Result<()> {
----- stdout -----

----- stderr -----
2 files left unchanged
2 files already formatted
"###);
Ok(())
}
Expand Down Expand Up @@ -876,7 +876,7 @@ fn test_diff() {


----- stderr -----
2 files would be reformatted, 1 file left unchanged
2 files would be reformatted, 1 file already formatted
"###);
});
}
Expand Down
Loading