From 8dd7db632d317bcfc23ecb2fe19695f2d3d17096 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 10 Feb 2023 16:43:50 +0100 Subject: [PATCH 1/3] Deal with the first token being "trailing whitespace" If the token is considered "trailing whitespace" and needs to be deleted, it tries to remove the item from the linked list. However, that doesn't work on the first and last entries. There already is a clause for the last item, just not the first item. --- lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From d4ec64b4d7617724957de2edcc96a67d85acc495 Mon Sep 17 00:00:00 2001 From: nwoythal Date: Wed, 15 Feb 2023 16:04:40 +0100 Subject: [PATCH 2/3] Add test for whitespace-only lines --- .../check_whitespace/trailing_whitespace_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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..6cf17cd4 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 line with nothing but whitespace' do + let(:code) { " \n " } + + it 'only detects a single problem' do + expect(problems).to have(2).problem + end + + it 'fixes the manifest' do + expect(manifest).to eq("\n") + end + end end end From a9e7c21bf1b0b751cc9a4d941f4468c1734895cf Mon Sep 17 00:00:00 2001 From: nwoythal Date: Fri, 24 Feb 2023 11:01:00 +0100 Subject: [PATCH 3/3] Fix copy-pasted test name to reflect behavior --- .../plugins/check_whitespace/trailing_whitespace_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6cf17cd4..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 @@ -106,10 +106,10 @@ end end - context 'empty line with nothing but whitespace' do + context 'empty lines with nothing but whitespace' do let(:code) { " \n " } - it 'only detects a single problem' do + it 'detects problems with both empty lines' do expect(problems).to have(2).problem end