Skip to content

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants