Skip to content

Commit 25ae024

Browse files
authored
Linter: Allow style inside svg for html-head-only-elements (#1082)
Resolves #912
1 parent 6f8370a commit 25ae024

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

javascript/packages/linter/src/rules/html-head-only-elements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class HeadOnlyElementsVisitor extends BaseRuleVisitor {
2323
if (!this.insideBody) return
2424
if (!isHeadOnlyTag(tagName)) return
2525
if (tagName === "title" && this.insideSVG) return
26+
if (tagName === "style" && this.insideSVG) return
2627
if (tagName === "meta" && this.hasItempropAttribute(node)) return
2728

2829
this.addOffense(

javascript/packages/linter/test/rules/html-head-only-elements.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,26 @@ describe("html-head-only-elements", () => {
332332
`)
333333
})
334334

335+
test("allows style element inside SVG", () => {
336+
expectNoOffenses(dedent`
337+
<!DOCTYPE html>
338+
<html lang="en">
339+
<head>
340+
<title>Hi</title>
341+
</head>
342+
<body>
343+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 29 29">
344+
<defs>
345+
<style>
346+
.cls-1 {fill:none;stroke:#fff}
347+
</style>
348+
</defs>
349+
</svg>
350+
</body>
351+
</html>
352+
`)
353+
})
354+
335355
test("still fails for other head-only elements inside SVG", () => {
336356
expectError("Element `<meta>` must be placed inside the `<head>` tag.")
337357
expectError("Element `<link>` must be placed inside the `<head>` tag.")

0 commit comments

Comments
 (0)