fix: print unchanged formatted file when using stdin (#11047)

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc 2021-06-03 14:02:42 +02:00 committed by GitHub
parent 4be9dfd183
commit 36a7b28b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -156,6 +156,7 @@ func Test_fmt_pipe(t *testing.T) {
expected string
}{
{unformattedHCL, []string{"fmt", "-"}, nil, formattedHCL},
{formattedHCL, []string{"fmt", "-"}, nil, formattedHCL},
}
for _, tc := range tc {

View File

@ -139,6 +139,10 @@ func (f *HCL2Formatter) processFile(filename string) ([]byte, error) {
outSrc := hclwrite.Format(inSrc)
if bytes.Equal(inSrc, outSrc) {
if filename == "-" {
_, _ = f.Output.Write(outSrc)
}
return nil, nil
}