Skip to content

Fix indentation of xstring literal#1038

Merged
tompng merged 1 commit into
ruby:masterfrom
tompng:fix_backtick_indent
Nov 26, 2024
Merged

Fix indentation of xstring literal#1038
tompng merged 1 commit into
ruby:masterfrom
tompng:fix_backtick_indent

Conversation

@tompng

@tompng tompng commented Nov 26, 2024

Copy link
Copy Markdown
Member

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
@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

2 participants