Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore data types where trailing commas are illegal #25

Merged
merged 2 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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