Skip to content
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

Refactor list and map mutations #94

Closed

Conversation

kekavc24
Copy link
Contributor

@kekavc24 kekavc24 commented Jul 5, 2024

This PR improves #90 by:

  1. Refactoring skipAndExtractComments:
    • Fixes an issue where the function never exits if more than one comment is encountered. My bad!
    • Prevents the function from eagerly skipping line-breaks within the loop. This was causing in faulty edits.
  2. Introduces a reclaimIndentAndLineBreak function for taking back indent greedily consumed by skipAndExtractComments when removing an element or entry within a YamlList or YamlMap respectively.
  3. Refactors functions that mutate block lists and maps to take advantage of skipAndExtractComments and reclaimIndentAndLineBreak which include:
    • _appendToBlockList and _removeFromBlockList in lists.
    • _removeFromBlockMap in maps.

Completely aligns the changes from #90 and #93 with existing YamlEditor behaviour.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@kekavc24
Copy link
Contributor Author

kekavc24 commented Jul 5, 2024

@jonasfj it could be argued that the code that finally does the adjustment of the startOffset
and endOffset is quite similar for both _removeFromBlockList and _removeFromBlockMap once I deal with the nuances yaml has for each:

For list mutations:
https://github.com/kekavc24/yaml_edit/blob/7378e9212575ddcea4627fef0cb28ab7d6b53fec/lib/src/list_mutations.dart#L343-L426

For map mutations:
https://github.com/kekavc24/yaml_edit/blob/7378e9212575ddcea4627fef0cb28ab7d6b53fec/lib/src/map_mutations.dart#L214-L285

Is it "DRY"-worthy? I thought of extracting it to a function.

This was referenced Jul 5, 2024
@kekavc24 kekavc24 closed this Jul 17, 2024
@kekavc24 kekavc24 deleted the refactor-list-and-map-mutations branch July 17, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant