Skip to content

Commit

Permalink
Merge pull request #25 from chelnak/GH-16-ignore_enum_arrays
Browse files Browse the repository at this point in the history
(GH-16) Ignore data type arrays
  • Loading branch information
ekohl authored Sep 30, 2022
2 parents 078b7cf + e425048 commit 19ee9a9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 19 deletions.
5 changes: 5 additions & 0 deletions lib/puppet-lint/plugins/check_trailing_comma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def array_indexes
# Ignore resource references
next if token.prev_code_token && \
token.prev_code_token.type == :CLASSREF

# Ignore data types
next if token.prev_code_token && \
token.prev_code_token.type == :TYPE

arrays << {
:start => token_idx,
:end => real_idx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
class { '::apache':
timeout => '100',
docroot => '/var/www',
Enum[
'a',
'b',
'c'
] $test = 'c',
}
class{ '::nginx': }
Expand Down Expand Up @@ -70,6 +75,12 @@ class { '::apache':
if $var !~ Mymodule::MyType {
fail("encountered error ${err}")
}
$test = [
'a',
'b',
'c',
],
EOS
}

Expand All @@ -83,7 +94,12 @@ class { '::apache':
<<-EOS
class { '::apache':
timeout => '100',
docroot => '/var/www'
docroot => '/var/www',
Enum[
'a',
'b',
'c'
] $test = 'c'
}
class{ '::nginx': }
Expand Down Expand Up @@ -129,20 +145,27 @@ class { '::apache':
'/etc/baz.conf', '/etc/baz.conf.d'
],
}
$test = [
'a',
'b',
'c'
]
EOS
}

it 'should detect 6 problems' do
expect(problems).to have(6).problems
it 'should detect 7 problems' do
expect(problems).to have(7).problems
end

it 'should create warnings' do
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(33).in_column(23)
expect(problems).to contain_warning(msg).on_line(39).in_column(26)
expect(problems).to contain_warning(msg).on_line(41).in_column(25)
expect(problems).to contain_warning(msg).on_line(8).in_column(24)
expect(problems).to contain_warning(msg).on_line(15).in_column(27)
expect(problems).to contain_warning(msg).on_line(29).in_column(18)
expect(problems).to contain_warning(msg).on_line(38).in_column(23)
expect(problems).to contain_warning(msg).on_line(44).in_column(26)
expect(problems).to contain_warning(msg).on_line(46).in_column(25)
expect(problems).to contain_warning(msg).on_line(58).in_column(14)
end
end

Expand Down Expand Up @@ -223,6 +246,11 @@ class { '::apache':
class { '::apache':
timeout => '100',
docroot => '/var/www',
Enum[
'a',
'b',
'c'
] $test = 'c',
}
class{ '::nginx': }
Expand Down Expand Up @@ -268,6 +296,12 @@ class { '::apache':
'/etc/baz.conf', '/etc/baz.conf.d'
],
}
$test = [
'a',
'b',
'c',
],
EOS
}

Expand All @@ -285,7 +319,12 @@ class { '::apache':
<<-EOS
class { '::apache':
timeout => '100',
docroot => '/var/www'
docroot => '/var/www',
Enum[
'a',
'b',
'c'
] $test = 'c'
}
class{ '::nginx': }
Expand Down Expand Up @@ -331,20 +370,27 @@ class { '::apache':
'/etc/baz.conf', '/etc/baz.conf.d'
],
}
$test = [
'a',
'b',
'c'
]
EOS
}

it 'should detect 6 problems' do
expect(problems).to have(6).problems
it 'should detect 7 problems' do
expect(problems).to have(7).problems
end

it 'should create a warning' do
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(33).in_column(23)
expect(problems).to contain_fixed(msg).on_line(39).in_column(26)
expect(problems).to contain_fixed(msg).on_line(41).in_column(25)
expect(problems).to contain_fixed(msg).on_line(8).in_column(24)
expect(problems).to contain_fixed(msg).on_line(15).in_column(27)
expect(problems).to contain_fixed(msg).on_line(29).in_column(18)
expect(problems).to contain_fixed(msg).on_line(38).in_column(23)
expect(problems).to contain_fixed(msg).on_line(44).in_column(26)
expect(problems).to contain_fixed(msg).on_line(46).in_column(25)
expect(problems).to contain_fixed(msg).on_line(58).in_column(14)
end

it 'should add trailing commas' do
Expand All @@ -353,6 +399,11 @@ class { '::apache':
class { '::apache':
timeout => '100',
docroot => '/var/www',
Enum[
'a',
'b',
'c'
] $test = 'c',
}
class{ '::nginx': }
Expand Down Expand Up @@ -398,7 +449,13 @@ class { '::apache':
'/etc/baz.conf', '/etc/baz.conf.d'
],
}
EOS
$test = [
'a',
'b',
'c',
]
EOS
)
end
end
Expand Down

0 comments on commit 19ee9a9

Please sign in to comment.