Skip to content

Commit

Permalink
Merge pull request #573 from rodjek/issue-509
Browse files Browse the repository at this point in the history
Handle mismatched control comments gracefully
  • Loading branch information
rnelson0 authored Dec 3, 2016
2 parents 2d048d4 + 7c250f5 commit 676e20e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/puppet-lint/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,17 @@ def parse_control_comments
stack_add << [token.line, reason, check]
end
else
stack.pop.each do |start|
unless start.nil?
(start[0]..token.line).each do |i|
(ignore_overrides[start[2]] ||= {})[i] = start[1]
top_override = stack.pop
if top_override.nil?
# TODO: refactor to provide a way to expose problems from
# PuppetLint::Data via the normal problem reporting mechanism.
puts "WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line #{token.line}"
else
top_override.each do |start|
unless start.nil?
(start[0]..token.line).each do |i|
(ignore_overrides[start[2]] ||= {})[i] = start[1]
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/test/manifests/mismatched_control_comment.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# lint:endignore
9 changes: 9 additions & 0 deletions spec/puppet-lint/bin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,13 @@ def initialize(args)
its(:exitstatus) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(/^.*line 6$/) }
end

context 'when an lint:endignore control comment exists with no opening lint:ignore comment' do
let(:args) { [
'spec/fixtures/test/manifests/mismatched_control_comment.pp',
] }

its(:exitstatus) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(/WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line 1/) }
end
end

0 comments on commit 676e20e

Please sign in to comment.