Skip to content

Behavior Change: \# Not Handled Properly #918

Description

@nicholasdower

Originally reported in #915

Commit: 95210d7

Input

→ View on rubyfmt.run

$g = 1
puts('"\#$g"')

@g = 2
puts('"\#@g"')

x = 3
puts('"\#{x}"')
puts(%q{text with \#{x} test})

Output

→ View on rubyfmt.run

$g = 1
puts("\"\\#$g\"")

@g = 2
puts("\"\\#@g\"")

x = 3
puts("\"\\#{x}\"")
puts("text with \\#{x} test")

Second Output

$g = 1
puts("\"\\#{$g}\"")

@g = 2
puts("\"\\#{@g}\"")

x = 3
puts("\"\\#{x}\"")
puts("text with \\#{x} test")

Expected behavior

The behavior should not be changed. The input contains strings without interpolation. The output has strings with interpolation. The output should also be stable.

Found in: ruby source (test/ripper/test_scanner_events.rb)
Found in: slim 5.2.1 (test/logic_less/test_logic_less.rb)
Found in: rubocop-rubocop (spec/rubocop/cop/style/redundant_regexp_escape_spec.rb)
Found in: rubocop-rubocop (spec/rubocop/cop/style/redundant_string_escape_spec.rb)
Found in: Homebrew-brew main (Library/Homebrew/test/rubocops/text/strict_spec.rb)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions