From d22a4b72f32259b1e09aa099165b3a0d56a08351 Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Thu, 7 Feb 2019 14:32:11 +0000 Subject: [PATCH] Fix issue with blank line at the beginning of a file. --- lib/puppet-lint/plugins/check_strict_indent.rb | 4 ++-- .../puppet-lint/plugins/check_strict_indent_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/puppet-lint/plugins/check_strict_indent.rb b/lib/puppet-lint/plugins/check_strict_indent.rb index 81a3828..4510660 100644 --- a/lib/puppet-lint/plugins/check_strict_indent.rb +++ b/lib/puppet-lint/plugins/check_strict_indent.rb @@ -131,9 +131,9 @@ def check actual = 0 if token.next_token.type == :INDENT actual = token.next_token.value.length - elsif token.prev_token.type == :HEREDOC + elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC actual = token.prev_token.value.split("\n").last.length - elsif token.prev_token.type == :HEREDOC_OPEN + elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC_OPEN actual = next_token.prev_token.value.split("\n").last.length else actual = 0 diff --git a/spec/puppet-lint/plugins/check_strict_indent_spec.rb b/spec/puppet-lint/plugins/check_strict_indent_spec.rb index d3de4d5..ce14b15 100644 --- a/spec/puppet-lint/plugins/check_strict_indent_spec.rb +++ b/spec/puppet-lint/plugins/check_strict_indent_spec.rb @@ -77,4 +77,17 @@ class ( expect(problems).to have(1).problems end end + + context 'blank line at beginning of file' do + let(:code) { + <<-EOF.gsub(/^ {8}/, '') + + class () {} + EOF + } + + it 'should detect 0 problems' do + expect(problems).to have(0).problems + end + end end