From 38d4ba91bee94be3b42a622656e832bb69fe85fa Mon Sep 17 00:00:00 2001 From: thaim Date: Tue, 26 Sep 2023 09:41:50 +0900 Subject: [PATCH 1/2] check each rune to cmpare with newline code --- rules/formatter_blank_line.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/formatter_blank_line.go b/rules/formatter_blank_line.go index 905ff13..b6ef257 100644 --- a/rules/formatter_blank_line.go +++ b/rules/formatter_blank_line.go @@ -127,7 +127,7 @@ func (r *FormatterBlankLineRule) checkFileEnd(runner tflint.Runner, name string, totalLine := countLines(runes) line := 0 - for ; line < totalLine; line++ { + for ; line < len(runes); line++ { if runes[len(runes)-line-1] != '\n' { break } From aed242936f039e1a6fc203704cfba4cb156339d2 Mon Sep 17 00:00:00 2001 From: thaim Date: Tue, 26 Sep 2023 22:28:18 +0900 Subject: [PATCH 2/2] add test to check with file only blank line --- rules/formatter_blank_line_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rules/formatter_blank_line_test.go b/rules/formatter_blank_line_test.go index 209faf4..b93b492 100644 --- a/rules/formatter_blank_line_test.go +++ b/rules/formatter_blank_line_test.go @@ -113,6 +113,22 @@ resource "null_resource" "second" { }, }, }, + { + Name: "only blank line", + Content: ` +`, + Expected: helper.Issues{ + { + Rule: NewFormatterBlankLineRule(), + Message: "too many blank lines at start of file", + Range: hcl.Range{ + Filename: "resource.tf", + Start: hcl.Pos{Line: 1, Column: 1}, + End: hcl.Pos{Line: 2, Column: 1}, + }, + }, + }, + }, } rule := NewFormatterBlankLineRule()