(CAT-2484) Prevent YAML corruption by making PuppetLint instances file-type aware #256
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.
Context
GitHub Issue #254 revealed that puppet-lint's
--fixflag was incorrectly overwriting YAML files with Puppet manifest content.The root cause was in the file processing logic in
bin.rb, which was applying fix logic to all discovered files (*.pp,*.yaml,*.yml) regardless of file type. This resulted in YAML configuration files being corrupted with Puppet manifest content, creating potential data loss scenarios in production environments.Changes
Since each file has an associated
PuppetLintinstance, then I refactored the file-write logic frombin.rbinto thePuppetLint. This refactor makes eachPuppetLintfile instance aware of its file type and fix eligibility. Each PuppetLint instance is now responsible for its own behavior based on its file type (and other constraints)Now
bin.rbsimply callsfix()on eachPuppetLintinstance if the user passes the--fixflag. Only if the instance is elegible for a fix will this occur.Testing
bundle exec puppet-lint --fix spec/fixtures/test/manifests/issue_254_overwriting_yaml/