Skip to content

[BUG] no-duplicate-attrs false positive with Go templates #409

@AdamVig

Description

@AdamVig

Describe the bug
I'm using a Go template conditional to swap class names and the second class attribute (in the "else" clause) is incorrectly flagged by this plugin:

The attribute 'class' is duplicated. eslint(@html-eslint/no-duplicate-attrs)

I can't find a way to disable it, either, since HTML doesn't allow comments within tags and the violation occurs a few lines below the opening tag. This eslint-disable pragma has no effect:

<!-- eslint-disable-next-line --> <-- ineffectual pragma
<button
  {{if eq .Data.UiState.CurrentFilter "A"}}
    class="filter-button active"
  {{else}}
    class="filter-button" <-- line with violation
  {{end}}
></button>

To Reproduce
Use this code:

<button
  {{if eq .Data.UiState.CurrentFilter "A"}}
    class="filter-button active"
  {{else}}
    class="filter-button"
  {{end}}
></button>

Expected behavior
I'm not sure. Obviously this plugin can't be expected to parse template expressions, so the next best option would be to somehow make eslint-disable-next-line work for this scenario, i.e. by considering the "next line" to include the entire opening tag, even if it's split across multiple lines:

<!-- eslint-disable-next-line --> <-- start of scope
<button
  {{if eq .Data.UiState.CurrentFilter "A"}}
    class="filter-button active"
  {{else}}
    class="filter-button"
  {{end}}
>
<---- end of eslint-disable-next-line's scope ---->
</button>

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions