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

Improve HEREDOCS #291

Merged
merged 1 commit into from
Sep 22, 2021
Merged

Improve HEREDOCS #291

merged 1 commit into from
Sep 22, 2021

Conversation

kaiquekandykoga
Copy link
Contributor

@kaiquekandykoga kaiquekandykoga commented Sep 19, 2021

Hi guys,

This is an attempt to fix the issue #265.

During auto indentation the methods check_newline_depth_difference and check_corresponding_token_depth are not considering on_heredoc_beg and on_heredoc_end.

The solution is checking if the line is inside heredocs, if so the extra spaces in the beginning of the line is returned.

Without brackets

After

3.0.2 :001"> <<a
3.0.2 :002">   0
3.0.2 :003 > a
 => "  0\n"
3.0.2 :004"> <<-a
3.0.2 :005">   0
3.0.2 :006 > a
 => "  0\n"
3.0.2 :007"> <<~a
3.0.2 :008">   0
3.0.2 :009 > a
 => "0\n"

Before

3.0.2 :001"> <<a
3.0.2 :002"> 0
3.0.2 :003 > a
 => "0\n"
3.0.2 :004"> <<-a
3.0.2 :005"> 0
3.0.2 :006 > a
 => "0\n"
3.0.2 :007"> <<~a
3.0.2 :008"> 0
3.0.2 :009 > a
 => "0\n"

Using brackets

After

3.0.2 :001"> [<<a]
3.0.2 :002">   0
3.0.2 :003 > a
 => ["  0\n"]
3.0.2 :004"> [<<-a]
3.0.2 :005">   0
3.0.2 :006 > a
 => ["  0\n"]
3.0.2 :007"> [<<~a]
3.0.2 :008">   0
3.0.2 :009 > a
 => ["0\n"]

Before

3.0.2 :001"> [<<a]
3.0.2 :002"> 0
3.0.2 :003 > a
 => ["0\n"]
3.0.2 :004"> [<<-a]
3.0.2 :005"> 0
3.0.2 :006 > a
 => ["0\n"]
3.0.2 :007"> [<<~a]
3.0.2 :008"> 0
3.0.2 :009 > a
 => ["0\n"]

Thank you very much.

Use first method instead of square brackets to support 2.5 and 2.6 versions

Use tokens

Clear check_newline_depth_difference
@kaiquekandykoga kaiquekandykoga marked this pull request as ready for review September 20, 2021 12:48
@aycabta aycabta merged commit 360c9c3 into ruby:master Sep 22, 2021
@aycabta
Copy link
Member

aycabta commented Sep 22, 2021

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants