Repository navigation
feat: implement remove newlines in brackets before toggle block to on… - #3005
Closed
Hungle2911 wants to merge 9 commits into
Closed
Hungle2911 wants to merge 9 commits into
Hungle2911 wants to merge 9 commits into
Conversation
vinistock
reviewed
Jan 7, 2025
| end | ||
|
|
||
| sig { params(str: String).returns(String) } | ||
| def remove_newlines_in_brackets(str) |
Member
There was a problem hiding this comment.
This approach is essentially re-parsing the string that was already parsed by Prism to remove the newlines. I'm concerned that this will be quite error prone, since parsing Ruby is challenging.
For example, will the code work properly in a case like this?
[].each do |something|
# Brackets that don't represent an array mixed with arrays
a[:hello] = [
something[1],
]
endIf we could find a way to use the already parsed nodes from Prism to rebuild the block's body, I think that would be more robust. Maybe we need to go through the nodes inside the body and transform them into single line one by one, with different rules for hash and array nodes so that we can produce valid code.
vinistock
reviewed
Feb 7, 2025
Contributor
|
This pull request is being marked as stale because there was no activity in the last 2 months |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Close #2968
The current block conversion from
do..endto brackets fails when handling complex data structures like Hashes or Arrays. Simply converting line breaks to semicolons doesn't maintain code validity in these cases.Implementation
remove_newlines_in_bracketsmethod to properly handle newlines within Hash/Array literalsAutomated Tests
test_toggle_block_do_end_to_brackets: Verifies basic block conversion functionalitytest_toggle_block_do_end_with_hash_to_brackets: Ensures proper handling of Hash literals within blocks