Avoid using the manifest lexer on YAML #239
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The new feature of checking YAML files chokes on valid YAML files; this change attempts to mitigate that problem.
Additional Context
PR #235 added scanning of YAML files to puppet-lint; to my surprise, my CI started failing with a number of syntax errors that hadn't been there before. Digging into it, it seems to be because the YAML files get fed through
PuppetLint::Lexer
, which doesn't handle some YAML literals correctly (and, being designed for Puppet manifests, I wouldn't expect it to).Note that a YAML file as included in the change 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. I have larger examples but this was the smallest reduction I could make that still failed.
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. (I only, afterwards, noticed the test for this in
checks_spec
-- I leave it up to you, maintainers, to let me know if you'd rather I put the heredoc case there.)Checklist