yamlfix
yamlfix copied to clipboard
Feature/preserve comment only files
Fixes #183
Adds a temporary key to the document at the start and removes it again after ruyaml ran through, preventing it from removing the comments in a comment-only yaml file.
Checklist
- [x] Add test cases to all the changes you introduce
- [x] Update the documentation for the changes
Pull Request Test Coverage Report for Build 3818306019
Warning: This coverage report may be inaccurate.
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
- For more information on this, see Tracking coverage changes with pull request builds.
- To avoid this issue with future PRs, see these Recommended CI Configurations.
- For a quick fix, rebase this PR at GitHub. Your next report should be accurate.
Details
- 23 of 23 (100.0%) changed or added relevant lines in 2 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.01%) to 99.772%
Totals | |
---|---|
Change from base Build 3787161522: | 0.01% |
Covered Lines: | 438 |
Relevant Lines: | 439 |
💛 - Coveralls
@lyz-code @rsnodgrass this adds a mapping key to the document before it goes through ruyaml - meaning:
- if the document already has mapping keys on the top level, this line is treated as if it were a mapping with a "none" value
- if the document already has a sequences as the top level, this line is treated as if it were the name of the sequence
When it has other mappings yamlfix_document_fix_id
has none value:
---
yamlfix_document_fix_id: # uuid
key: value
---
# equivalent to:
yamlfix_document_fix_id: none # uuid
key: value
When it has a top level list, yamlfix_document_fix_id
is the name of said list:
---
yamlfix_document_fix_id: #uuid
- item
- item
---
# equivalent to:
yamlfix_document_fix_id: [item, item] # uuid
When the document was previously only comments, ruyaml attaches them to the "last found node" (e.g. this line):
---
yamlfix_document_fix_id: #uuid
# other comments
# comments comments
All previous tests are passing, and this should in theory work with any yaml file - but it is, admittedly, "clever" (not to say hacky 😅) - not exactly sure what happens with shorter files, that are converted to flow-style or something like that.
@lyz-code please wait on merging this until #199 is merged and this is rebased. I want to modify it a bit.
Thanks @marcules for the fix!!
@marcules #199 is merged! Tell me when it's ready for review
@marcules pull the changes from main
and run make install
. I've updated the dependencies versions
@lyz-code you can review this and pull it in now if it looks good I have rebased it onto main and also fixed the issue in regards to flakeheaven looking into folders other than src/ tests/