Skip to content

Commit a097e9e

Browse files
authored
Linter: Make html-no-self-closing Action View Helper aware (#1432)
Now that we have support for detecting Action View Tag helpers we can update the `html-no-self-closing` linter rule to make it Action View Tag helpers aware. Since the parser already transforms the nodes we don't need to change anything else about the existing rule. With this pull request, the following doesn't get flagged anymore: ```erb <%= tag.svg(height:, width:) do %> <path d="M29.396,2.303 L27.867,2.924 L25.13,18.045 L25.735,18.571 L27.167,18.045 L29.953,2.781 z" fill="currentColor" /> <% end %> ``` Previously, this was flagged as: ``` Use `<path></path>` instead of self-closing `<path />` for HTML compatibility. [html-no-self-closing] ``` Resolves #567
1 parent ae806a8 commit a097e9e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

javascript/packages/linter/src/rules/html-no-self-closing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isVoidElement, findParent, BaseRuleVisitor } from "./rule-utils.js"
33
import { getTagName, getTagLocalName, isWhitespaceNode, Location, HTMLCloseTagNode } from "@herb-tools/core"
44

55
import type { UnboundLintOffense, LintContext, LintOffense, FullRuleConfig } from "../types.js"
6-
import type { Node, HTMLOpenTagNode, HTMLElementNode, SerializedToken, ParseResult } from "@herb-tools/core"
6+
import type { Node, HTMLOpenTagNode, HTMLElementNode, SerializedToken, ParseResult, ParserOptions } from "@herb-tools/core"
77

88
interface NoSelfClosingAutofixContext extends BaseAutofixContext {
99
node: Mutable<HTMLOpenTagNode>
@@ -50,6 +50,10 @@ export class HTMLNoSelfClosingRule extends ParserRule<NoSelfClosingAutofixContex
5050
}
5151
}
5252

53+
get parserOptions(): Partial<ParserOptions> {
54+
return { action_view_helpers: true }
55+
}
56+
5357
check(result: ParseResult, context?: Partial<LintContext>): UnboundLintOffense<NoSelfClosingAutofixContext>[] {
5458
const visitor = new NoSelfClosingVisitor(this.ruleName, context)
5559

javascript/packages/linter/test/rules/html-no-self-closing.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ describe("html-no-self-closing", () => {
130130
`)
131131
})
132132

133+
test("passes for self-closing elements inside tag.svg helper", () => {
134+
expectNoOffenses(`
135+
<%= tag.svg(height:, width:) do %>
136+
<path d="M29.396,2.303 L27.867,2.924 L25.13,18.045 L25.735,18.571 L27.167,18.045 L29.953,2.781 z" fill="currentColor" />
137+
<% end %>
138+
`)
139+
})
140+
133141
describe("ActionMailer exclusion", () => {
134142
test("excludes ActionMailer view files without any config", () => {
135143
const linter = Linter.from(Herb)

0 commit comments

Comments
 (0)