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 } 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()