Skip to content

Commit 36ea6b7

Browse files
zaneduffieldjgardn3r
authored andcommitted
Remove extra trailing newline when formatting stdin to stdout
The `println!` macro was used when printing the result of formatting stdin. This added a newline character to the output stream which otherwise contained exactly the formatted file contents. When using the formatter with IDE integrations it's important for stdout to be exactly as intended.
1 parent 79d4e7e commit 36ea6b7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Incorrect parsing for generic type param lists containing semicolons.
13+
- Extra trailing newline when formatting stdin to stdout.
1314

1415
## [0.1.0] - 2023-08-28
1516

orchestrator/src/file_formatter.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ impl FileFormatter {
124124
}
125125
pub fn format_stdin_to_stdout(&self, input: &str) {
126126
let formatted_input = self.formatter.format(input);
127-
println!("{}", formatted_input);
127+
print!("{}", formatted_input);
128128
}
129129
pub fn format_files_to_stdout<S: AsRef<str>>(&self, paths: &[S]) {
130130
self.exec_format(
131131
paths,
132132
OpenOptions::new(),
133133
|_, file_path, _, formatted_output| {
134+
// Append a newline to the formatted output deliberately because makes it more
135+
// human-readable and no less machine-readable.
134136
println!("{}:\n{}", file_path.to_string_lossy(), formatted_output);
135137
Ok(())
136138
},

0 commit comments

Comments
 (0)