diff --git a/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb b/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb index 4af40b73..7d34feb2 100644 --- a/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +++ b/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb @@ -30,7 +30,7 @@ def fix(problem) prev_token = problem[:token].prev_token next_token = problem[:token].next_token - prev_token.next_token = next_token + prev_token.next_token = next_token unless prev_token.nil? next_token.prev_token = prev_token unless next_token.nil? tokens.delete(problem[:token]) end diff --git a/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb b/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb index 55db6c06..12eb8d67 100644 --- a/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +++ b/spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb @@ -105,5 +105,17 @@ expect(manifest).to eq(fixed) end end + + context 'empty lines with nothing but whitespace' do + let(:code) { " \n " } + + it 'detects problems with both empty lines' do + expect(problems).to have(2).problem + end + + it 'fixes the manifest' do + expect(manifest).to eq("\n") + end + end end end