Skip to content

Commit 1b8f597

Browse files
committed
Avoid using the manifest lexer on YAML
A YAML file like in the fixture added is parsed fine by Psych and yamllint, but puppet-lint chokes on it because it gets fed through the manifest lexer first, which can't cope with some things that are valid YAML. Since the one check that operates on YAML files doesn't support fixing and doesn't use tokens, it seems reasonable to bypass the lexer; more sophisticated YAML checks would need to use a separate YAML lexer anyway. Note that this can't be a unit test because those bypass the lexer processing.
1 parent 0e8feb3 commit 1b8f597

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

lib/puppet-lint/checks.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ def load_data(path, content)
5454
#
5555
# Returns an Array of problem Hashes.
5656
def run(fileinfo, data)
57-
load_data(fileinfo, data)
58-
5957
checks_run = []
6058
if File.extname(fileinfo).downcase.match?(%r{\.ya?ml$})
59+
PuppetLint::Data.path = fileinfo
60+
PuppetLint::Data.manifest_lines = data.split("\n", -1)
61+
6162
enabled_checks.select { |check| YAML_COMPATIBLE_CHECKS.include?(check) }.each do |check|
6263
klass = PuppetLint.configuration.check_object[check].new
6364
# FIXME: shadowing #problems
6465
problems = klass.run
6566
checks_run << [klass, problems]
6667
end
6768
else
69+
load_data(fileinfo, data)
70+
6871
enabled_checks.each do |check|
6972
klass = PuppetLint.configuration.check_object[check].new
7073
# FIXME: shadowing #problems

spec/acceptance/puppet_lint_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@
4343
expect(result[:stdout]).to have_warnings(2)
4444
end
4545
end
46+
47+
context 'with a YAML file provided' do
48+
it 'returns zero errors' do
49+
result = puppet_lint([File.join(manifest_root, 'parseable.yaml')])
50+
expect(result[:stdout]).to have_errors(0)
51+
end
52+
end
4653
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
heredoc: |
3+
contains $

spec/unit/puppet-lint/checks_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@
223223
allow(File).to receive(:extname).with(fileinfo).and_return('.yaml')
224224
end
225225

226-
it 'loads the yaml data' do
227-
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original # rubocop: disable RSpec/SubjectStub
228-
instance.run(fileinfo, data)
229-
end
230-
231226
context 'when there are checks enabled' do
232227
let(:enabled_checks) { [:legacy_facts] }
233228
let(:enabled_check_classes) { enabled_checks.map { |r| PuppetLint.configuration.check_object[r] } }

0 commit comments

Comments
 (0)