Skip to content

Commit

Permalink
Manage exceptions per elem type
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Feb 10, 2015
1 parent 17da368 commit 1c22eab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/puppet-lint/plugins/check_trailing_comma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def defaults_indexes
results
end

def check_elem(elem)
def check_elem(elem, except_type)
lbo_token = elem[:tokens][-1].prev_code_token
if lbo_token && lbo_token.type != :COLON && \
if lbo_token && lbo_token.type != except_type && \
elem[:tokens][-1].type != :SEMIC && \
lbo_token.type != :COMMA && \
lbo_token.next_token.type == :NEWLINE
Expand All @@ -59,17 +59,17 @@ def check_elem(elem)
def check
# Resource and class declarations
resource_indexes.each do |resource|
check_elem(resource)
check_elem(resource, :COLON)
end

# Arrays
array_indexes.each do |array|
check_elem(array)
check_elem(array, :LBRACK)
end

# Defaults
defaults_indexes.each do |defaults|
check_elem(defaults)
check_elem(defaults, :LBRACE)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class { '::apache':
'bar',
],
groupss => ['baz', 'qux'],
groupz => [
],
}
File {
Expand Down Expand Up @@ -76,6 +78,8 @@ class { '::apache':
'bar'
],
groupss => ['baz', 'qux'],
groupz => [
],
}
File {
Expand All @@ -93,7 +97,7 @@ class { '::apache':
expect(problems).to contain_warning(msg).on_line(3).in_column(32)
expect(problems).to contain_warning(msg).on_line(10).in_column(27)
expect(problems).to contain_warning(msg).on_line(24).in_column(18)
expect(problems).to contain_warning(msg).on_line(31).in_column(23)
expect(problems).to contain_warning(msg).on_line(33).in_column(23)
end
end
end
Expand Down Expand Up @@ -136,6 +140,8 @@ class { '::apache':
'bar',
],
groupss => ['baz', 'qux'],
groupz => [
],
}
File {
Expand Down Expand Up @@ -183,6 +189,8 @@ class { '::apache':
'bar'
],
groupss => ['baz', 'qux'],
groupz => [
],
}
File {
Expand All @@ -200,7 +208,7 @@ class { '::apache':
expect(problems).to contain_fixed(msg).on_line(3).in_column(32)
expect(problems).to contain_fixed(msg).on_line(10).in_column(27)
expect(problems).to contain_fixed(msg).on_line(24).in_column(18)
expect(problems).to contain_fixed(msg).on_line(31).in_column(23)
expect(problems).to contain_fixed(msg).on_line(33).in_column(23)
end

it 'should add trailing commas' do
Expand Down Expand Up @@ -232,6 +240,8 @@ class { '::apache':
'bar',
],
groupss => ['baz', 'qux'],
groupz => [
],
}
File {
Expand Down

0 comments on commit 1c22eab

Please sign in to comment.