diff --git a/lib/puppet-lint/plugins/check_whitespace.rb b/lib/puppet-lint/plugins/check_whitespace.rb index 8d350aef..f8ab79b4 100644 --- a/lib/puppet-lint/plugins/check_whitespace.rb +++ b/lib/puppet-lint/plugins/check_whitespace.rb @@ -123,7 +123,7 @@ def check indent_depth_idx += 1 indent_depth << 0 level_tokens[indent_depth_idx] ||= [] - elsif token.type == :RBRACE + elsif token.type == :RBRACE || token.type == :SEMIC level_tokens[indent_depth_idx].each do |arrow_tok| 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 } 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 84769932..22ff04e5 100644 --- a/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +++ b/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb @@ -126,6 +126,28 @@ class { 'lvs::base': end end + context 'single resource with a misaligned => and semicolon at the end' do + let(:code) { " + file { '/tmp/bar': + foo => 1, + bar => 2, + gronk => 3, + baz => 4, + meh => 5; + }" + } + + it 'should detect four problems' do + expect(problems).to have(4).problems + 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) + end + end context 'complex resource with a misaligned =>' do let(:code) { " file { '/tmp/foo': @@ -171,6 +193,34 @@ class { 'lvs::base': end end + context 'multi-resource with a misaligned => and semicolons' do + let(:code) { " + file { + '/tmp/foo': + ensure => 'directory', + owner => 'root', + mode => '0755'; + '/tmp/bar': + ensure => 'directory'; + '/tmp/baz': + ensure => 'directory', + owner => 'root', + mode => '0755'; + }" + } + + it 'should only detect a single problem' do + expect(problems).to have(4).problem + 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) + end + end + context 'multiple single line resources' do let(:code) { " file { 'foo': ensure => file }