yamlfix icon indicating copy to clipboard operation
yamlfix copied to clipboard

Feature/preserve comment only files

Open marcules opened this issue 2 years ago • 7 comments

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

marcules avatar Dec 26 '22 23:12 marcules

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.

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 Coverage Status
Change from base Build 3787161522: 0.01%
Covered Lines: 438
Relevant Lines: 439

💛 - Coveralls

coveralls avatar Dec 26 '22 23:12 coveralls

@lyz-code @rsnodgrass this adds a mapping key to the document before it goes through ruyaml - meaning:

  1. 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
  2. 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.

marcules avatar Dec 27 '22 00:12 marcules

@lyz-code please wait on merging this until #199 is merged and this is rebased. I want to modify it a bit.

marcules avatar Dec 27 '22 06:12 marcules

Thanks @marcules for the fix!!

rsnodgrass avatar Dec 27 '22 06:12 rsnodgrass

@marcules #199 is merged! Tell me when it's ready for review

lyz-code avatar Dec 27 '22 10:12 lyz-code

@marcules pull the changes from main and run make install. I've updated the dependencies versions

lyz-code avatar Dec 27 '22 11:12 lyz-code

@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/

marcules avatar Jan 01 '23 19:01 marcules