Skip to content

Commit 5f329d8

Browse files
committed
feat: implement
1 parent abd5d0c commit 5f329d8

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

docs/rules/use-standard-html.md

Whitespace-only changes.

packages/eslint-plugin/lib/rules/use-standard-html.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
const { RULE_CATEGORY } = require("../constants");
1212
const { getElementSpec } = require("html-standard");
13+
const { isTag } = require("./utils/node");
1314

1415
const MESSAGE_IDS = {
15-
UNSORTED: "unsorted",
16+
DISALLOW_CHILD: "disallowChild",
1617
};
1718

1819
/**
@@ -43,14 +44,42 @@ module.exports = {
4344
},
4445
],
4546
messages: {
46-
[MESSAGE_IDS.UNSORTED]: "TBD",
47+
[MESSAGE_IDS.DISALLOW_CHILD]: "TBD",
4748
},
4849
},
4950
create(context) {
5051
return {
5152
Tag(node) {
5253
const spec = getElementSpec(node.name);
53-
console.log(spec);
54+
if (!spec || !spec.contents) {
55+
return;
56+
}
57+
58+
node.children.forEach((child) => {
59+
if (!spec.contents) {
60+
return;
61+
}
62+
if (!isTag(child)) {
63+
return;
64+
}
65+
const isAllowed = spec.contents.some((model) => {
66+
if (
67+
model.type === "required" ||
68+
model.type === "oneOrMore" ||
69+
model.type === "zeroOrMore" ||
70+
model.type === "optional"
71+
) {
72+
return model.contents.has(child.name.toLowerCase());
73+
}
74+
return false;
75+
});
76+
if (!isAllowed) {
77+
context.report({
78+
node: child,
79+
messageId: MESSAGE_IDS.DISALLOW_CHILD,
80+
});
81+
}
82+
});
5483
},
5584
};
5685
},

packages/eslint-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"@html-eslint/template-parser": "^0.38.0",
4141
"@html-eslint/template-syntax-parser": "^0.38.0",
42-
"html-standard": "^0.0.3"
42+
"html-standard": "^0.0.4"
4343
},
4444
"devDependencies": {
4545
"@html-eslint/parser": "^0.38.0",

packages/eslint-plugin/tests/rules/use-standard-html.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,16 @@ ruleTester.run("use-standard-html", rule, {
99
code: `<slot></slot>`,
1010
},
1111
],
12-
invalid: [],
12+
invalid: [
13+
{
14+
code: `<html>
15+
<div></div>
16+
</html`,
17+
errors: [
18+
{
19+
messageId: "disallowChild",
20+
},
21+
],
22+
},
23+
],
1324
});

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ __metadata:
12841284
es-html-parser: "npm:0.1.1"
12851285
eslint: "npm:^9.21.0"
12861286
espree: "npm:^10.3.0"
1287-
html-standard: "npm:^0.0.3"
1287+
html-standard: "npm:^0.0.4"
12881288
typescript: "npm:^5.7.2"
12891289
languageName: unknown
12901290
linkType: soft
@@ -8806,10 +8806,10 @@ __metadata:
88068806
languageName: node
88078807
linkType: hard
88088808

8809-
"html-standard@npm:^0.0.3":
8810-
version: 0.0.3
8811-
resolution: "html-standard@npm:0.0.3"
8812-
checksum: 782dcd5161cb044c18c9239f332cbcae73072c96bcf2336b0dad4f3162f45d47076aaccd679f69276108e3172171bf45a0f5374c876976793ac165e85d62923f
8809+
"html-standard@npm:^0.0.4":
8810+
version: 0.0.4
8811+
resolution: "html-standard@npm:0.0.4"
8812+
checksum: 268df7985c491c757ed035d741e9f9d6ac1b545e18ff4b06ec55a8e291e7912168be0306fe8ed85648193cd756351a29b679b8f457394d6cba5e9a172225cf28
88138813
languageName: node
88148814
linkType: hard
88158815

0 commit comments

Comments
 (0)