Skip to content

Commit f044290

Browse files
committed
poc: add use-standard-html
1 parent 2028683 commit f044290

File tree

6 files changed

+94
-2
lines changed

6 files changed

+94
-2
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@
4848
"packageManager": "yarn@4.0.2",
4949
"workspaces": [
5050
"packages/**"
51-
]
51+
],
52+
"dependencies": {
53+
"html-standard": "^0.0.2"
54+
}
5255
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const maxElementDepth = require("./max-element-depth");
4747
const requireExplicitSize = require("./require-explicit-size");
4848
const useBaseLine = require("./use-baseline");
4949
const noDuplicateClass = require("./no-duplicate-class");
50+
const useStandardHtml = require("./use-standard-html");
5051
// import new rule here ↑
5152
// DO NOT REMOVE THIS COMMENT
5253

@@ -100,6 +101,7 @@ module.exports = {
100101
"require-explicit-size": requireExplicitSize,
101102
"use-baseline": useBaseLine,
102103
"no-duplicate-class": noDuplicateClass,
104+
"use-standard-html": useStandardHtml,
103105
// export new rule here ↑
104106
// DO NOT REMOVE THIS COMMENT
105107
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @typedef { import("../types").RuleFixer } RuleFixer
3+
* @typedef { import("@html-eslint/types").Attribute } Attribute
4+
* @typedef { import("@html-eslint/types").Text } Text
5+
*
6+
* @typedef {Object} Option
7+
* @property {string[]} [Option.priority]
8+
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
9+
*/
10+
11+
const { RULE_CATEGORY } = require("../constants");
12+
const { getElementSpec } = require("html-standard");
13+
14+
const MESSAGE_IDS = {
15+
UNSORTED: "unsorted",
16+
};
17+
18+
/**
19+
* @type {RuleModule}
20+
*/
21+
module.exports = {
22+
meta: {
23+
type: "code",
24+
25+
docs: {
26+
description: "TBD",
27+
category: RULE_CATEGORY.BEST_PRACTICE,
28+
recommended: false,
29+
},
30+
fixable: "code",
31+
schema: [
32+
{
33+
type: "object",
34+
properties: {
35+
priority: {
36+
type: "array",
37+
items: {
38+
type: "string",
39+
uniqueItems: true,
40+
},
41+
},
42+
},
43+
},
44+
],
45+
messages: {
46+
[MESSAGE_IDS.UNSORTED]: "TBD",
47+
},
48+
},
49+
create(context) {
50+
return {
51+
Tag(node) {
52+
const spec = getElementSpec(node.name);
53+
console.log(spec);
54+
},
55+
};
56+
},
57+
};

packages/eslint-plugin/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
],
3939
"dependencies": {
4040
"@html-eslint/template-parser": "^0.39.0",
41-
"@html-eslint/template-syntax-parser": "^0.39.0"
41+
"@html-eslint/template-syntax-parser": "^0.39.0",
42+
"html-standard": "^0.0.3"
4243
},
4344
"devDependencies": {
4445
"@html-eslint/parser": "^0.39.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const createRuleTester = require("../rule-tester");
2+
const rule = require("../../lib/rules/use-standard-html");
3+
4+
const ruleTester = createRuleTester();
5+
6+
ruleTester.run("use-standard-html", rule, {
7+
valid: [
8+
{
9+
code: `<slot></slot>`,
10+
},
11+
],
12+
invalid: [],
13+
});

yarn.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +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"
12871288
typescript: "npm:^5.7.2"
12881289
languageName: unknown
12891290
linkType: soft
@@ -1299,6 +1300,7 @@ __metadata:
12991300
eslint: "npm:^9.19.0"
13001301
eslint-plugin-jest: "npm:^28.11.0"
13011302
eslint-plugin-n: "npm:^17.15.1"
1303+
html-standard: "npm:^0.0.2"
13021304
husky: "npm:^9.1.4"
13031305
jest: "npm:^29.7.0"
13041306
lerna: "npm:^8.1.9"
@@ -8797,6 +8799,20 @@ __metadata:
87978799
languageName: node
87988800
linkType: hard
87998801

8802+
"html-standard@npm:^0.0.2":
8803+
version: 0.0.2
8804+
resolution: "html-standard@npm:0.0.2"
8805+
checksum: 73823c8f664ac499e6415fa15b7f8771f92465ca2d5e98ae006ff79619f9ba4b7a69685ca212d82635c83cd9322811641f986073b7ca0b27ff0ab92484bb4247
8806+
languageName: node
8807+
linkType: hard
8808+
8809+
"html-standard@npm:^0.0.3":
8810+
version: 0.0.3
8811+
resolution: "html-standard@npm:0.0.3"
8812+
checksum: 782dcd5161cb044c18c9239f332cbcae73072c96bcf2336b0dad4f3162f45d47076aaccd679f69276108e3172171bf45a0f5374c876976793ac165e85d62923f
8813+
languageName: node
8814+
linkType: hard
8815+
88008816
"htmlnano@npm:^2.0.0":
88018817
version: 2.1.1
88028818
resolution: "htmlnano@npm:2.1.1"

0 commit comments

Comments
 (0)