From fa4917514cabcea6702f6ecc8f1c0e0e85f71c0b Mon Sep 17 00:00:00 2001 From: Rob Nelson Date: Tue, 28 Jun 2016 17:57:30 +0000 Subject: [PATCH 1/2] Add better description of the problem in arrow_alignment check --- lib/puppet-lint/plugins/check_whitespace.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-lint/plugins/check_whitespace.rb b/lib/puppet-lint/plugins/check_whitespace.rb index 205990f1..ec278315 100644 --- a/lib/puppet-lint/plugins/check_whitespace.rb +++ b/lib/puppet-lint/plugins/check_whitespace.rb @@ -148,7 +148,7 @@ def check unless arrow_tok.column == indent_depth[indent_depth_idx] || level_tokens[indent_depth_idx].size == 1 arrows_on_line = level_tokens[indent_depth_idx].select { |t| t.line == arrow_tok.line } notify :warning, { - :message => 'indentation of => is not properly aligned', + :message => "indentation of => is not properly aligned (expected in column #{indent_depth[indent_depth_idx]}, but found it in column #{arrow_tok.column})", :line => arrow_tok.line, :column => arrow_tok.column, :token => arrow_tok, From 8a4e8da3270cc9d4a0bf1895baeb75d37cced966 Mon Sep 17 00:00:00 2001 From: Rob Nelson Date: Sat, 13 Aug 2016 02:40:02 +0000 Subject: [PATCH 2/2] Rspec tests match the updated warning text. --- .../check_whitespace/arrow_alignment_spec.rb | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb b/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb index 22ff04e5..d1a7f67e 100644 --- a/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +++ b/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'arrow_alignment' do - let(:msg) { 'indentation of => is not properly aligned' } + let(:msg) { 'indentation of => is not properly aligned (expected in column %d, but found it in column %d)' } context 'with fix disabled' do context 'selectors inside a resource' do @@ -119,10 +119,10 @@ class { 'lvs::base': end it 'should create four warnings' do - expect(problems).to contain_warning(msg).on_line(3).in_column(15) - expect(problems).to contain_warning(msg).on_line(4).in_column(15) - expect(problems).to contain_warning(msg).on_line(6).in_column(16) - expect(problems).to contain_warning(msg).on_line(7).in_column(15) + expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(3).in_column(15) + expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(4).in_column(15) + expect(problems).to contain_warning(sprintf(msg,17,16)).on_line(6).in_column(16) + expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(7).in_column(15) end end @@ -142,10 +142,10 @@ class { 'lvs::base': end it 'should create four warnings' do - expect(problems).to contain_warning(msg).on_line(3).in_column(15) - expect(problems).to contain_warning(msg).on_line(4).in_column(15) - expect(problems).to contain_warning(msg).on_line(6).in_column(16) - expect(problems).to contain_warning(msg).on_line(7).in_column(15) + expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(3).in_column(15) + expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(4).in_column(15) + expect(problems).to contain_warning(sprintf(msg,17,16)).on_line(6).in_column(16) + expect(problems).to contain_warning(sprintf(msg,17,15)).on_line(7).in_column(15) end end context 'complex resource with a misaligned =>' do @@ -166,9 +166,9 @@ class { 'lvs::base': end it 'should create three warnings' do - expect(problems).to contain_warning(msg).on_line(3).in_column(15) - expect(problems).to contain_warning(msg).on_line(6).in_column(17) - expect(problems).to contain_warning(msg).on_line(9).in_column(15) + expect(problems).to contain_warning(sprintf(msg,16,15)).on_line(3).in_column(15) + expect(problems).to contain_warning(sprintf(msg,19,17)).on_line(6).in_column(17) + expect(problems).to contain_warning(sprintf(msg,16,15)).on_line(9).in_column(15) end end @@ -189,7 +189,7 @@ class { 'lvs::base': end it 'should create a warning' do - expect(problems).to contain_warning(msg).on_line(8).in_column(17) + expect(problems).to contain_warning(sprintf(msg,19,17)).on_line(8).in_column(17) end end @@ -214,10 +214,10 @@ class { 'lvs::base': end it 'should create a warning' do - expect(problems).to contain_warning(msg).on_line(5).in_column(19) - expect(problems).to contain_warning(msg).on_line(6).in_column(18) - expect(problems).to contain_warning(msg).on_line(11).in_column(19) - expect(problems).to contain_warning(msg).on_line(12).in_column(18) + expect(problems).to contain_warning(sprintf(msg,20,19)).on_line(5).in_column(19) + expect(problems).to contain_warning(sprintf(msg,20,18)).on_line(6).in_column(18) + expect(problems).to contain_warning(sprintf(msg,20,19)).on_line(11).in_column(19) + expect(problems).to contain_warning(sprintf(msg,20,18)).on_line(12).in_column(18) end end @@ -282,8 +282,8 @@ class { 'lvs::base': end it 'should create 2 warnings' do - expect(problems).to contain_warning(msg).on_line(3).in_column(19) - expect(problems).to contain_warning(msg).on_line(4).in_column(19) + expect(problems).to contain_warning(sprintf(msg,18,19)).on_line(3).in_column(19) + expect(problems).to contain_warning(sprintf(msg,18,19)).on_line(4).in_column(19) end end @@ -314,8 +314,8 @@ class { 'lvs::base': end it 'should create 2 warnings' do - expect(problems).to contain_warning(msg).on_line(3).in_column(13) - expect(problems).to contain_warning(msg).on_line(3).in_column(26) + expect(problems).to contain_warning(sprintf(msg,15,13)).on_line(3).in_column(13) + expect(problems).to contain_warning(sprintf(msg,15,26)).on_line(3).in_column(26) end end @@ -368,10 +368,10 @@ class { 'lvs::base': end it 'should fix the manifest' do - expect(problems).to contain_fixed(msg).on_line(3).in_column(15) - expect(problems).to contain_fixed(msg).on_line(4).in_column(15) - expect(problems).to contain_fixed(msg).on_line(6).in_column(16) - expect(problems).to contain_fixed(msg).on_line(7).in_column(15) + expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(3).in_column(15) + expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(4).in_column(15) + expect(problems).to contain_fixed(sprintf(msg,17,16)).on_line(6).in_column(16) + expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(7).in_column(15) end it 'should align the arrows' do @@ -408,9 +408,9 @@ class { 'lvs::base': end it 'should fix the manifest' do - expect(problems).to contain_fixed(msg).on_line(3).in_column(15) - expect(problems).to contain_fixed(msg).on_line(6).in_column(17) - expect(problems).to contain_fixed(msg).on_line(9).in_column(15) + expect(problems).to contain_fixed(sprintf(msg,16,15)).on_line(3).in_column(15) + expect(problems).to contain_fixed(sprintf(msg,19,17)).on_line(6).in_column(17) + expect(problems).to contain_fixed(sprintf(msg,16,15)).on_line(9).in_column(15) end it 'should align the arrows' do @@ -445,7 +445,7 @@ class { 'lvs::base': end it 'should fix the manifest' do - expect(problems).to contain_fixed(msg).on_line(8).in_column(17) + expect(problems).to contain_fixed(sprintf(msg,19,17)).on_line(8).in_column(17) end it 'should align the arrows' do @@ -473,8 +473,8 @@ class { 'lvs::base': end it 'should create 2 warnings' do - expect(problems).to contain_fixed(msg).on_line(3).in_column(19) - expect(problems).to contain_fixed(msg).on_line(4).in_column(19) + expect(problems).to contain_fixed(sprintf(msg,18,19)).on_line(3).in_column(19) + expect(problems).to contain_fixed(sprintf(msg,18,19)).on_line(4).in_column(19) end it 'should realign the arrows with the minimum whitespace' do @@ -502,7 +502,7 @@ class { 'lvs::base': end it 'should fix the problem' do - expect(problems).to contain_fixed(msg).on_line(4).in_column(17) + expect(problems).to contain_fixed(sprintf(msg,18,17)).on_line(4).in_column(17) end it 'should add whitespace between the param and the arrow' do @@ -531,8 +531,8 @@ class { 'lvs::base': end it 'should fix 2 problems' do - expect(problems).to contain_fixed(msg).on_line(3).in_column(13) - expect(problems).to contain_fixed(msg).on_line(3).in_column(26) + expect(problems).to contain_fixed(sprintf(msg,15,13)).on_line(3).in_column(13) + expect(problems).to contain_fixed(sprintf(msg,15,26)).on_line(3).in_column(26) end it 'should move the extra param onto its own line and realign' do @@ -561,9 +561,9 @@ class { 'lvs::base': end it 'should fix 2 problems' do - expect(problems).to contain_fixed(msg).on_line(3).in_column(13) - expect(problems).to contain_fixed(msg).on_line(3).in_column(29) - expect(problems).to contain_fixed(msg).on_line(4).in_column(15) + expect(problems).to contain_fixed(sprintf(msg,17,13)).on_line(3).in_column(13) + expect(problems).to contain_fixed(sprintf(msg,17,29)).on_line(3).in_column(29) + expect(problems).to contain_fixed(sprintf(msg,17,15)).on_line(4).in_column(15) end it 'should move the extra param onto its own line and realign' do