From 36a7b28b5f3bee03b4281a6b7f7bdea75346b099 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Thu, 3 Jun 2021 14:02:42 +0200 Subject: [PATCH] fix: print unchanged formatted file when using stdin (#11047) Signed-off-by: Yoan Blanc --- command/fmt_test.go | 1 + hcl2template/formatter.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/command/fmt_test.go b/command/fmt_test.go index b63ca5fb9..0a9c0a6e7 100644 --- a/command/fmt_test.go +++ b/command/fmt_test.go @@ -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 { diff --git a/hcl2template/formatter.go b/hcl2template/formatter.go index 34d63e8de..700e0c40b 100644 --- a/hcl2template/formatter.go +++ b/hcl2template/formatter.go @@ -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 }