Skip to content

Commit

Permalink
Merge pull request #476 from wybczu/fix/arrows-with-semicolons
Browse files Browse the repository at this point in the history
Fix arrow aligment check in multiple resources declaration
  • Loading branch information
rnelson0 committed Jun 20, 2016
2 parents eec92c1 + 5d07999 commit b04a35f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet-lint/plugins/check_whitespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
50 changes: 50 additions & 0 deletions spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit b04a35f

Please sign in to comment.