Skip to content

Formatting of multi-line methods calls #1835

Description

@G-Rath

I've been checking out the formatter and it's really interesting - so far I've come across only two things that I'm on the fence about.

The first is with really long classes which I think is actually probably fine, I just wasn't expecting it, but the second is with code like this:

# views/kaminari/_last_page.html 
<%# locals: (url:, current_page:, total_pages:, per_page:, remote:) %>

<li class="<%= class_names("page-item user-select-none", disabled: current_page.first?) %>">
  <%=
    link_to(
      sanitize(t("views.pagination.first")),
      url,
      remote:,
      class: "page-link",
      tabindex: current_page.first? ? -1 : nil
    )
  %>
</li>

This is how I have laid the template out, which RubyMine and erb_lint both are happy with - but Herb wants to squash it:

<%# locals: (url:, current_page:, total_pages:, per_page:, remote:) %>

<li class="<%= class_names("page-item user-select-none", disabled: current_page.first?) %>">
  <%= link_to(
      sanitize(t("views.pagination.first")),
      url,
      remote:,
      class: "page-link",
      tabindex: current_page.first? ? -1 : nil
    ) %>
</li>

erb_lint does not care about this, but RubyMine then wants to indent everything:

<%# locals: (url:, current_page:, total_pages:, per_page:, remote:) %>

<li class="<%= class_names("page-item user-select-none", disabled: current_page.first?) %>">
  <%= link_to(
        sanitize(t("views.pagination.first")),
        url,
        remote:,
        class: "page-link",
        tabindex: current_page.first? ? -1 : nil
      ) %>
</li>

after which Herb, RubyMine, and erb_lint all agree again.

I'm not super worried about all three tools disagreeing because that's the point of picking a formatter, but personally for this kind of code I think I prefer having more lines and balanced on both sides to make it clear where the "block of Ruby" begins and ends

Ultimately I'm wondering if this is something you'd be open to support either configuring or doing something like what Prettier does w/ objects whereby if Herb saw the newline after the opening <%, it'd keep it.

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