Skip to content

Commit 1f0bbdf

Browse files
committed
feat: implement
1 parent 5a4aece commit 1f0bbdf

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
@@ -41,7 +41,7 @@
4141
"@eslint/plugin-kit": "0.2.8",
4242
"@html-eslint/template-parser": "^0.40.0",
4343
"@html-eslint/template-syntax-parser": "^0.40.0",
44-
"html-standard": "^0.0.3"
44+
"html-standard": "^0.0.4"
4545
},
4646
"devDependencies": {
4747
"@eslint/core": "0.13.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
@@ -1305,7 +1305,7 @@ __metadata:
13051305
es-html-parser: "npm:0.2.0"
13061306
eslint: "npm:^9.21.0"
13071307
espree: "npm:^10.3.0"
1308-
html-standard: "npm:^0.0.3"
1308+
html-standard: "npm:^0.0.4"
13091309
typescript: "npm:^5.7.2"
13101310
languageName: unknown
13111311
linkType: soft
@@ -8827,10 +8827,10 @@ __metadata:
88278827
languageName: node
88288828
linkType: hard
88298829

8830-
"html-standard@npm:^0.0.3":
8831-
version: 0.0.3
8832-
resolution: "html-standard@npm:0.0.3"
8833-
checksum: 782dcd5161cb044c18c9239f332cbcae73072c96bcf2336b0dad4f3162f45d47076aaccd679f69276108e3172171bf45a0f5374c876976793ac165e85d62923f
8830+
"html-standard@npm:^0.0.4":
8831+
version: 0.0.4
8832+
resolution: "html-standard@npm:0.0.4"
8833+
checksum: 268df7985c491c757ed035d741e9f9d6ac1b545e18ff4b06ec55a8e291e7912168be0306fe8ed85648193cd756351a29b679b8f457394d6cba5e9a172225cf28
88348834
languageName: node
88358835
linkType: hard
88368836

0 commit comments

Comments
 (0)