Skip to content

Commit 5a4aece

Browse files
committed
poc: add use-standard-html
1 parent 09bafbb commit 5a4aece

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
@@ -49,5 +49,8 @@
4949
"packageManager": "yarn@4.0.2",
5050
"workspaces": [
5151
"packages/**"
52-
]
52+
],
53+
"dependencies": {
54+
"html-standard": "^0.0.2"
55+
}
5356
}

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
@@ -40,7 +40,8 @@
4040
"dependencies": {
4141
"@eslint/plugin-kit": "0.2.8",
4242
"@html-eslint/template-parser": "^0.40.0",
43-
"@html-eslint/template-syntax-parser": "^0.40.0"
43+
"@html-eslint/template-syntax-parser": "^0.40.0",
44+
"html-standard": "^0.0.3"
4445
},
4546
"devDependencies": {
4647
"@eslint/core": "0.13.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
@@ -1305,6 +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"
13081309
typescript: "npm:^5.7.2"
13091310
languageName: unknown
13101311
linkType: soft
@@ -1320,6 +1321,7 @@ __metadata:
13201321
eslint: "npm:^9.19.0"
13211322
eslint-plugin-jest: "npm:^28.11.0"
13221323
eslint-plugin-n: "npm:^17.15.1"
1324+
html-standard: "npm:^0.0.2"
13231325
husky: "npm:^9.1.4"
13241326
jest: "npm:^29.7.0"
13251327
lerna: "npm:^8.1.9"
@@ -8818,6 +8820,20 @@ __metadata:
88188820
languageName: node
88198821
linkType: hard
88208822

8823+
"html-standard@npm:^0.0.2":
8824+
version: 0.0.2
8825+
resolution: "html-standard@npm:0.0.2"
8826+
checksum: 73823c8f664ac499e6415fa15b7f8771f92465ca2d5e98ae006ff79619f9ba4b7a69685ca212d82635c83cd9322811641f986073b7ca0b27ff0ab92484bb4247
8827+
languageName: node
8828+
linkType: hard
8829+
8830+
"html-standard@npm:^0.0.3":
8831+
version: 0.0.3
8832+
resolution: "html-standard@npm:0.0.3"
8833+
checksum: 782dcd5161cb044c18c9239f332cbcae73072c96bcf2336b0dad4f3162f45d47076aaccd679f69276108e3172171bf45a0f5374c876976793ac165e85d62923f
8834+
languageName: node
8835+
linkType: hard
8836+
88218837
"htmlnano@npm:^2.0.0":
88228838
version: 2.1.1
88238839
resolution: "htmlnano@npm:2.1.1"

0 commit comments

Comments
 (0)