Skip to content

Commit

Permalink
Merge pull request #325 from rodjek/issue-314
Browse files Browse the repository at this point in the history
Support multiple commands in a single control comment
  • Loading branch information
timtim123456 committed Sep 22, 2014
2 parents fe3a7ae + bcddef9 commit 3aa4d6d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
42 changes: 26 additions & 16 deletions lib/puppet-lint/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def ignore_overrides
# Returns nothing.
def parse_control_comments
@ignore_overrides.each_key { |check| @ignore_overrides[check].clear }
control_re = /\A(lint:\S+)(\s+lint:\S+)*(.*)/

comment_token_types = Set[:COMMENT, :MLCOMMENT, :SLASH_COMMENT]

Expand All @@ -304,28 +305,37 @@ def parse_control_comments

stack = []
control_comment_tokens.each do |token|
control, reason = token.value.strip.split(' ', 2)
split_control = control.split(':')
command = split_control[1]
comment_data = control_re.match(token.value.strip).to_a[1..-1].compact.map(&:strip)
if comment_data.last =~ /\Alint:(ignore|endignore)/
comment_data << ''
end
reason = comment_data.pop
stack_add = []
comment_data.each do |control|
split_control = control.split(':')
command = split_control[1]

if command == 'ignore'
check = split_control[2].to_sym
if command == 'ignore'
check = split_control[2].to_sym

if token.prev_token && !Set[:NEWLINE, :INDENT].include?(token.prev_token.type)
# control comment at the end of the line, override applies to
# a single line only
(ignore_overrides[check] ||= {})[token.line] = reason
if token.prev_token && !Set[:NEWLINE, :INDENT].include?(token.prev_token.type)
# control comment at the end of the line, override applies to
# a single line only
(ignore_overrides[check] ||= {})[token.line] = reason
else
stack_add << [token.line, reason, check]
end
else
stack << [token.line, reason, check]
end
else
start = stack.pop
unless start.nil?
(start[0]..token.line).each do |i|
(ignore_overrides[start[2]] ||= {})[i] = start[1]
stack.pop.each do |start|
unless start.nil?
(start[0]..token.line).each do |i|
(ignore_overrides[start[2]] ||= {})[i] = start[1]
end
end
end
end
end
stack << stack_add unless stack_add.empty?
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/ignore_multiple_block.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# lint:ignore:double_quoted_strings lint:ignore:quoted_booleans
"true"
"false"
# lint:endignore

"true"
2 changes: 2 additions & 0 deletions spec/fixtures/test/manifests/ignore_multiple_line.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"true" # lint:ignore:double_quoted_strings lint:ignore:quoted_booleans
"false" # lint:ignore:quoted_booleans lint:ignore:double_quoted_strings reason
17 changes: 17 additions & 0 deletions spec/puppet-lint/bin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,21 @@ def initialize(args)
" for a good reason",
].join("\n")) }
end

context 'ignoring multiple checks on a line' do
let(:args) { [
'spec/fixtures/test/manifests/ignore_multiple_line.pp',
] }

its(:exitstatus) { is_expected.to eq(0) }
end

context 'ignoring multiple checks in a block' do
let(:args) { [
'spec/fixtures/test/manifests/ignore_multiple_block.pp',
] }

its(:exitstatus) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(/^.*line 6$/) }
end
end
12 changes: 12 additions & 0 deletions spec/puppet-lint/ignore_overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,16 @@
expect(problems).to contain_ignored(msg).on_line(5).in_column(7).with_reason('another reason')
end
end

context 'disable multiple checks on a line with a reason' do
let(:code) { '"true" # lint:ignore:quoted_booleans lint:ignore:double_quoted_string a reason' }

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

it 'should have one ignored problems' do
expect(problems).to contain_ignored(msg).on_line(1).in_column(1).with_reason('a reason')
end
end
end

0 comments on commit 3aa4d6d

Please sign in to comment.