Shopify / erb-lint

Lint your ERB or HTML files
MIT License
592 stars 113 forks source link

removes <%= if ruby expression is not on a same line #331

Open skatkov opened 9 months ago

skatkov commented 9 months ago

Good day,

Thanks for a great gem. I've ran into what seems to be a questionable behavior that might be not safe to autocorrect.

We have a following code snippet:

<div>
  <%=
                form.select :group_key, (Array.wrap(@gift_card_offer.group_key) + Rewards::Retailer.pluck(:group_key).uniq).sort,
                {include_blank: true, selected: @gift_card_offer.group_key},
                {"data-admin--groupkey-target": "output"}
            %>
</div>

That turned into

<div>
   form.select :group_key, (Array.wrap(@gift_card_offer.group_key) + Rewards::Retailer.pluck(:group_key).uniq).sort,
                {include_blank: true, selected: @gift_card_offer.group_key},
                {"data-admin--groupkey-target": "output"}
            %>
</div>

as you can see <%= was removed. this is not an issue, if <%= and reuby expression is on same line. But doing such "autocorrection" doesn't seem safe to me?

kanejamison commented 2 hours ago

I'm seeing this same behavior across many files in our app.

A couple of generalized examples where the leading tag gets removed:

<%
options ||= {}
html_options ||= {}
html_options[:id] ||= id_for(form, method)
html_options[:class] = "form-control select2 #{html_options[:class]}".strip
other_options ||= {}
%>
<%
          project = FactoryBot.build(:project, id: 1, team: team, name: "Project A", created_at: 1.year.ago)
          %>
          <pre><code><%= pretty_parse(render(template: "api/projects/show", formats: [:json], locals: { project: project })) %>

Seems to happen in all of our files where <% is followed by a line break, with or without linespace after <%, and with or without line space on the beginning of the next line.

For anyone else dealing with this I was able to do a bulk find/replace on <% with the line break and then replace it with a space, and then review the occurrences manually, and all worked afterwards. image