Skip to content

Avoid using the manifest lexer on YAML #239

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

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

tokenrove
Copy link

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

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified.

@tokenrove tokenrove requested review from bastelfreak and a team as code owners March 6, 2025 18:00
@CLAassistant
Copy link

CLAassistant commented Mar 6, 2025

CLA assistant check
All committers have signed the CLA.

@bastelfreak bastelfreak added the bug Something isn't working label Mar 6, 2025
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.
@tokenrove tokenrove force-pushed the fix-yaml-syntax-errors branch from 92530b7 to 1b8f597 Compare March 7, 2025 12:06
@tokenrove
Copy link
Author

(Sorry, obvious typo in my initial push; I did the initial change and testing on a work machine, but couldn't send that directly to my personal machine to make this contribution. I thought I retested here before pushing but clearly I didn't.)

Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but would like some followup approves from others

@david22swan david22swan merged commit b44f264 into puppetlabs:main Mar 10, 2025
8 checks passed
@tokenrove
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants