From f8edfadcc5a15c4d512e2f8fee46a45b2e830cdc Mon Sep 17 00:00:00 2001 From: Ofer Chen Date: Fri, 29 Aug 2025 21:10:22 +0200 Subject: [PATCH] Make locals align no-op --- internal/align/locals.go | 12 ++---------- tests/cases/locals/aligned.tf | 2 +- tests/cases/locals/out.tf | 2 +- tests/cases/locals/out_strict.tf | 4 ++++ tests/cases/non_variable/out.tf | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 tests/cases/locals/out_strict.tf diff --git a/internal/align/locals.go b/internal/align/locals.go index df97c97..ad6d296 100644 --- a/internal/align/locals.go +++ b/internal/align/locals.go @@ -2,8 +2,6 @@ package align import ( - "sort" - "github.com/hashicorp/hcl/v2/hclwrite" ) @@ -11,14 +9,8 @@ type localsStrategy struct{} func (localsStrategy) Name() string { return "locals" } -func (localsStrategy) Align(block *hclwrite.Block, _ *Options) error { - attrs := block.Body().Attributes() - names := make([]string, 0, len(attrs)) - for name := range attrs { - names = append(names, name) - } - sort.Strings(names) - return reorderBlock(block, names) +func (localsStrategy) Align(_ *hclwrite.Block, _ *Options) error { + return nil } func init() { Register(localsStrategy{}) } diff --git a/tests/cases/locals/aligned.tf b/tests/cases/locals/aligned.tf index 391507b..59e9cc1 100644 --- a/tests/cases/locals/aligned.tf +++ b/tests/cases/locals/aligned.tf @@ -1,4 +1,4 @@ locals { - a = 1 b = 2 + a = 1 } diff --git a/tests/cases/locals/out.tf b/tests/cases/locals/out.tf index 391507b..59e9cc1 100644 --- a/tests/cases/locals/out.tf +++ b/tests/cases/locals/out.tf @@ -1,4 +1,4 @@ locals { - a = 1 b = 2 + a = 1 } diff --git a/tests/cases/locals/out_strict.tf b/tests/cases/locals/out_strict.tf new file mode 100644 index 0000000..59e9cc1 --- /dev/null +++ b/tests/cases/locals/out_strict.tf @@ -0,0 +1,4 @@ +locals { + b = 2 + a = 1 +} diff --git a/tests/cases/non_variable/out.tf b/tests/cases/non_variable/out.tf index 23400b6..95613cb 100644 --- a/tests/cases/non_variable/out.tf +++ b/tests/cases/non_variable/out.tf @@ -24,8 +24,8 @@ output "o" { } locals { - a = 2 b = 1 + a = 2 } terraform {