Skip to content

Supporting string interpolation in attribute names #5

@nerfologist

Description

@nerfologist

Hello, I have an ERB fragment such as the following, which is a common pattern to pass values to sidecar Javascript in Stimulus:

<div data-<%= controller_name %>-someattribute-value="<%= attribute_value %>"></div>

And I run it through erb-linter, I get the following error:

#<Thread:0x00007f82d9299d58 /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/checker.rb:26 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        6: from /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/checker.rb:30:in `block (3 levels) in check_files'
        5: from /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/converter.rb:37:in `erb2html'
        4: from /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/converter.rb:37:in `each'
        3: from /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/converter.rb:37:in `gsub!'
        2: from /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/converter.rb:48:in `block in erb2html'
        1: from /Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/converter.rb:48:in `map!'
/Users/marco/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/erb-linter-0.2.0/lib/erb/linter/converter.rb:66:in `block (2 levels) in erb2html': Don't know how to process attribute: "data-<%= controller_name %>-someattribute-value=\\"<%= attribute_value %>\\"" (RuntimeError)
rails aborted!
Don't know how to process attribute: "data-<%= controller_name %>-someattribute-value=\"<%= attribute_value %>\""

Is it possible to support string interpolation in attribute names? Rails seems to manage it properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions