Skip to content

Formatter moves linter disable comments so that the linter fails #1987

Description

@maxnotarangelo

I started with this code:

<blockquote id="note">
  <%= @note1 %>
</blockquote>

<blockquote id="note">
  <%= @note2 %>
</blockquote>

There's a linter error (no duplicate ids), so I tried to ignore it:

<blockquote id="note">
  <%= @note1 %>
</blockquote>

<blockquote id="note"> <%# herb:disable html-no-duplicate-ids %>
  <%= @note2 %>
</blockquote>

Then, running the formatter moves the disable line to the first id="note" line, which produces two lint errors (unnecessary disable on the first line, and duplicate ids one the second line).

Output:

<blockquote id="note"> <%# herb:disable html-no-duplicate-ids %>
  <%= @note1 %>
</blockquote>

<blockquote id="note"><%= @note2 %></blockquote>

It takes a couple more formatting runs to converge to the final output (with the same lint errors):

<blockquote id="note"><%= @note1 %></blockquote> <%# herb:disable html-no-duplicate-ids %>
<blockquote id="note"><%= @note2 %></blockquote>

Expected: Either no formatting change, or no lint errors after moving the disable to the first line.

Playground:

Unformatted code: https://herb-tools.dev/playground/?tab=format#DwIwNg9gxg1gjgVwgFwKYAICWATAvAIgDsVV8A+AKHXWAFJd0ABYtARnVsuAHpxp4kaShVCRYiEljxES5GrQDE6ABaoATiABc2TAGcAhuAzLkAWzABaYhewIADmExR9aCzl0dK1Og2YkATJ4ivGICJGRAA

Formatted code with lint errors: https://herb-tools.dev/playground/?tab=format#DwIwNg9gxg1gjgVwgFwKYAICWATAvAIgDsVV8A+dYAUgGJ0ALVAJxAC5tMBnAQ3A3uQBbMAFpiI7AgAOYTFG5oROTuipkAUOkpVc6AALE0ARlUbgAenDR4SNBvWhIsRCSx4iJctV0GSAJlMLK2dbVDIgA

Final result of formatting with the same lint errors: https://herb-tools.dev/playground/?tab=format#DwIwNg9gxg1gjgVwgFwKYAICWATAvAIgDsVV8A+YAUl3QAFi0BGdSigenGniTTPSoDE6ABaoATiABc2TAGcAhuAzDkAWzABaYhuwIADmExR5aDTlksyAKFCRYiEljxES5KjXokATJeAc73CRkQA

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformatter@herb-tools/formatter for HTML+ERB templates

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions