Skip to content

Commit d484ad3

Browse files
authored
fix: ignore checking tag names in svg in lowercase (#377)
1 parent 0e691b3 commit d484ad3

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

packages/eslint-plugin/lib/rules/lowercase.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
* @typedef { import("../types").RuleModule<[]> } RuleModule
66
*/
77

8-
const { NODE_TYPES } = require("@html-eslint/parser");
98
const { RULE_CATEGORY } = require("../constants");
109
const SVG_CAMEL_CASE_ATTRIBUTES = require("../constants/svg-camel-case-attributes");
1110
const { createVisitors } = require("./utils/visitors");
12-
const { hasTemplate } = require("./utils/node");
11+
const { hasTemplate, isScript, isStyle } = require("./utils/node");
1312
const { getRuleUrl } = require("./utils/rule");
1413

1514
const MESSAGE_IDS = {
@@ -67,8 +66,8 @@ module.exports = {
6766
* @param {Tag | StyleTag | ScriptTag} node
6867
*/
6968
function nameOf(node) {
70-
if (node.type === NODE_TYPES.ScriptTag) return "script";
71-
if (node.type === NODE_TYPES.StyleTag) return "style";
69+
if (isScript(node)) return "script";
70+
if (isStyle(node)) return "style";
7271
return node.name;
7372
}
7473

@@ -77,7 +76,11 @@ module.exports = {
7776
*/
7877
function check(node) {
7978
const raw = node.openStart.value.slice(1);
80-
if (nameOf(node) !== raw) {
79+
const name = nameOf(node);
80+
if (
81+
name !== raw &&
82+
(svgStack.length === 0 || name.toLowerCase() === "svg")
83+
) {
8184
context.report({
8285
node: node.openStart,
8386
messageId: MESSAGE_IDS.UNEXPECTED,

packages/eslint-plugin/tests/rules/lowercase.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ ruleTester.run("lowercase", rule, {
4343
repeatCount="indefinite" />
4444
</rect>
4545
</svg>`,
46+
},
47+
{
48+
code: `<svg viewBox="0 0 100 100">
49+
<clipPath id="myClip">
50+
<circle cx="40" cy="35" r="35" />
51+
</clipPath>
52+
</svg>
53+
`,
4654
},
4755
{
4856
code: "<div {{ID}}></div>",
@@ -110,6 +118,15 @@ ruleTester.run("lowercase", rule, {
110118
},
111119
],
112120
},
121+
{
122+
code: `<SVG></SVG>`,
123+
output: `<svg></svg>`,
124+
errors: [
125+
{
126+
message: "'SVG' is not in lowercase.",
127+
},
128+
],
129+
},
113130
{
114131
code: "<div ID={{ID}}></div>",
115132
output: "<div id={{ID}}></div>",

0 commit comments

Comments
 (0)