File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -127,12 +127,19 @@ impl FmtArgs {
127
127
let path = source_unit. file . name . as_real ( ) ;
128
128
let original = source_unit. file . src . as_str ( ) ;
129
129
let formatted = forge_fmt:: format_ast ( gcx, source_unit, fmt_config. clone ( ) ) ?;
130
+ let from_stdin = path. is_none ( ) ;
131
+
132
+ // Return formatted code when read from stdin without check or raw switch.
133
+ // <https://github.com/foundry-rs/foundry/issues/11871>
134
+ if from_stdin && !self . check && !self . raw {
135
+ return Some ( Ok ( formatted) ) ;
136
+ }
130
137
131
138
if original == formatted {
132
139
return None ;
133
140
}
134
141
135
- if self . check || path . is_none ( ) {
142
+ if self . check || from_stdin {
136
143
let summary = if self . raw {
137
144
formatted
138
145
} else {
Original file line number Diff line number Diff line change @@ -89,3 +89,12 @@ Diff in stdin:
89
89
90
90
"# ] ] ) ;
91
91
} ) ;
92
+
93
+ // Test that original is returned if read from stdin and no diff.
94
+ // <https://github.com/foundry-rs/foundry/issues/11871>
95
+ forgetest ! ( fmt_stdin_original, |_prj, cmd| {
96
+ cmd. args( [ "fmt" , "-" ] ) ;
97
+
98
+ cmd. stdin( FORMATTED . as_bytes( ) ) ;
99
+ cmd. assert_success( ) . stdout_eq( FORMATTED . as_bytes( ) ) ;
100
+ } ) ;
You can’t perform that action at this time.
0 commit comments