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

Fix indentation of xstring literal #1038

Merged
merged 1 commit into from
Nov 26, 2024
Merged

Conversation

tompng
Copy link
Member

@tompng tompng commented Nov 26, 2024

Fixes wrong indent calculation of this input

irb(main):001* if false
irb(main):002> p `ls`
irb(main):003> end

Description

We need to distinguish Kernel.` from `xstring_literal`.

code event state xstring_literal
`ls` :on_backtick EXPR_BEG yes
class `ls`::A;end :on_backtick EXPR_CLASS yes
p `ls` :on_backtick EXPR_CMDARG yes
p x: `ls` :on_backtick EXPR_ARG|EXPR_LABELED yes
p(`ls`) :on_backtick EXPR_BEG|EXPR_LABEL yes
Kernel.` :on_backtick EXPR_ARG no

The simplest way to check is using state != EXPR_ARG.

Known issues

As shown in the table below, checking by state != EXPR_ARG is not perfect. But there is no easy way.

code event state xstring_literal
p p `ls` :on_backtick EXPR_ARG yes
Kernel.` :on_backtick EXPR_ARG no
# still fails to indent this
if false
p p `ls`
end

Fixes indent calculation of this input
```
if false
p `ls`
end
```
@st0012 st0012 added the bug Something isn't working label Nov 26, 2024
@tompng tompng merged commit 4217a46 into ruby:master Nov 26, 2024
28 checks passed
@tompng tompng deleted the fix_backtick_indent branch November 26, 2024 17:50
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 26, 2024
(ruby/irb#1038)

Fixes indent calculation of this input
```
if false
p `ls`
end
```

ruby/irb@4217a46f5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

2 participants