@html-eslint/eslint-plugin 0.33.0 → 0.34.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/rules/element-newline.js +2 -2
- package/lib/rules/lowercase.js +4 -0
- package/lib/rules/sort-attrs.js +46 -18
- package/lib/rules/utils/node.js +10 -0
- package/package.json +6 -4
- package/types/rules/lowercase.d.ts.map +1 -1
- package/types/rules/sort-attrs.d.ts.map +1 -1
- package/types/rules/utils/node.d.ts +6 -0
- package/types/rules/utils/node.d.ts.map +1 -1
- /package/lib/types/{settings.ts → settings.d.ts} +0 -0
|
@@ -246,14 +246,14 @@ module.exports = {
|
|
|
246
246
|
* @param {NewlineNode} node
|
|
247
247
|
*/
|
|
248
248
|
function isNotNewlineEnd(node) {
|
|
249
|
-
return node.type !== `Text` ||
|
|
249
|
+
return node.type !== `Text` || /(\n|\r\n)\s*$/.test(node.value) === false;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
253
|
* @param {NewlineNode} node
|
|
254
254
|
*/
|
|
255
255
|
function isNotNewlineStart(node) {
|
|
256
|
-
return node.type !== `Text` ||
|
|
256
|
+
return node.type !== `Text` || /^(\n|\r\n)/.test(node.value) === false;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
/**
|
package/lib/rules/lowercase.js
CHANGED
|
@@ -9,6 +9,7 @@ const { NODE_TYPES } = require("@html-eslint/parser");
|
|
|
9
9
|
const { RULE_CATEGORY } = require("../constants");
|
|
10
10
|
const SVG_CAMEL_CASE_ATTRIBUTES = require("../constants/svg-camel-case-attributes");
|
|
11
11
|
const { createVisitors } = require("./utils/visitors");
|
|
12
|
+
const { hasTemplate } = require("./utils/node");
|
|
12
13
|
|
|
13
14
|
const MESSAGE_IDS = {
|
|
14
15
|
UNEXPECTED: "unexpected",
|
|
@@ -102,6 +103,9 @@ module.exports = {
|
|
|
102
103
|
if (isAllowedAttributeKey(attribute.key.value)) {
|
|
103
104
|
return;
|
|
104
105
|
}
|
|
106
|
+
if (hasTemplate(attribute.key)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
105
109
|
if (attribute.key.value !== attribute.key.value.toLowerCase()) {
|
|
106
110
|
context.report({
|
|
107
111
|
node: attribute.key,
|
package/lib/rules/sort-attrs.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @typedef { import("../types").Text } Text
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
const { hasTemplate } = require("./utils/node");
|
|
8
9
|
const { RULE_CATEGORY } = require("../constants");
|
|
9
10
|
const { getSourceCode } = require("./utils/source-code");
|
|
10
11
|
const { createVisitors } = require("./utils/visitors");
|
|
@@ -62,6 +63,7 @@ module.exports = {
|
|
|
62
63
|
function compare(attrA, attrB) {
|
|
63
64
|
const keyA = attrA.key.value;
|
|
64
65
|
const keyB = attrB.key.value;
|
|
66
|
+
|
|
65
67
|
const keyAReservedValue = priority.indexOf(keyA);
|
|
66
68
|
const keyBReservedValue = priority.indexOf(keyB);
|
|
67
69
|
if (keyAReservedValue >= 0 && keyBReservedValue >= 0) {
|
|
@@ -122,6 +124,30 @@ module.exports = {
|
|
|
122
124
|
return false;
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
/**
|
|
128
|
+
* @param {Attribute[]} attributes
|
|
129
|
+
* @return {Attribute[][]}
|
|
130
|
+
*/
|
|
131
|
+
function groupAttributes(attributes) {
|
|
132
|
+
/**
|
|
133
|
+
* @type {Attribute[][]}
|
|
134
|
+
*/
|
|
135
|
+
const attributesList = [];
|
|
136
|
+
let index = 0;
|
|
137
|
+
|
|
138
|
+
for (const attribute of attributes) {
|
|
139
|
+
if (hasTemplate(attribute.key)) {
|
|
140
|
+
index = attributesList.length;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!attributesList[index]) {
|
|
144
|
+
attributesList[index] = [];
|
|
145
|
+
}
|
|
146
|
+
attributesList[index].push(attribute);
|
|
147
|
+
}
|
|
148
|
+
return attributesList;
|
|
149
|
+
}
|
|
150
|
+
|
|
125
151
|
/**
|
|
126
152
|
* @param {Attribute[]} unsorted
|
|
127
153
|
*/
|
|
@@ -129,26 +155,28 @@ module.exports = {
|
|
|
129
155
|
if (unsorted.length <= 1) {
|
|
130
156
|
return;
|
|
131
157
|
}
|
|
158
|
+
const grouped = groupAttributes(unsorted);
|
|
159
|
+
grouped.forEach((unsorted) => {
|
|
160
|
+
const sorted = [...unsorted].sort(compare);
|
|
132
161
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
end: last.loc.end,
|
|
162
|
+
if (!isChanged(unsorted, sorted)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const first = unsorted[0];
|
|
166
|
+
const last = unsorted[unsorted.length - 1];
|
|
167
|
+
context.report({
|
|
168
|
+
node: {
|
|
169
|
+
range: [first.range[0], last.range[1]],
|
|
170
|
+
loc: {
|
|
171
|
+
start: first.loc.start,
|
|
172
|
+
end: last.loc.end,
|
|
173
|
+
},
|
|
146
174
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
175
|
+
messageId: MESSAGE_IDS.UNSORTED,
|
|
176
|
+
fix(fixer) {
|
|
177
|
+
return fix(fixer, unsorted, sorted);
|
|
178
|
+
},
|
|
179
|
+
});
|
|
152
180
|
});
|
|
153
181
|
}
|
|
154
182
|
|
package/lib/rules/utils/node.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @typedef { import("../../types").Comment } Comment
|
|
10
10
|
* @typedef { import("../../types").AnyNode } AnyNode
|
|
11
11
|
* @typedef { import("../../types").AttributeValue } AttributeValue
|
|
12
|
+
* @typedef { import("../../types").AttributeKey } AttributeKey
|
|
12
13
|
* @typedef { import("eslint").AST.Range } Range
|
|
13
14
|
* @typedef { import("eslint").AST.SourceLocation } SourceLocation
|
|
14
15
|
* @typedef { import("es-html-parser").AnyToken } AnyToken
|
|
@@ -67,6 +68,14 @@ function isOverlapWithTemplates(templates, range) {
|
|
|
67
68
|
.some((template) => isRangesOverlap(template.range, range));
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/**
|
|
72
|
+
* @param {AttributeKey} node
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
function hasTemplate(node) {
|
|
76
|
+
return node.templates.some((template) => template.isTemplate);
|
|
77
|
+
}
|
|
78
|
+
|
|
70
79
|
/**
|
|
71
80
|
*
|
|
72
81
|
* @param {Text | CommentContent} node
|
|
@@ -258,4 +267,5 @@ module.exports = {
|
|
|
258
267
|
codeToLines,
|
|
259
268
|
isRangesOverlap,
|
|
260
269
|
getTemplateTokens,
|
|
270
|
+
hasTemplate,
|
|
261
271
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-eslint/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0-alpha.0",
|
|
4
4
|
"description": "ESLint plugin for html",
|
|
5
5
|
"author": "yeonjuan",
|
|
6
6
|
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
|
|
@@ -45,15 +45,17 @@
|
|
|
45
45
|
"accessibility"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@html-eslint/template-parser": "^0.33.0"
|
|
48
|
+
"@html-eslint/template-parser": "^0.33.0",
|
|
49
|
+
"@html-eslint/template-syntax-parser": "^0.34.0-alpha.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@html-eslint/parser": "^0.
|
|
52
|
+
"@html-eslint/parser": "^0.34.0-alpha.0",
|
|
52
53
|
"@types/eslint": "^9.6.1",
|
|
53
54
|
"@types/estree": "^0.0.47",
|
|
54
55
|
"es-html-parser": "^1.0.0-alpha.4",
|
|
56
|
+
"eslint": "^8",
|
|
55
57
|
"espree": "^10.3.0",
|
|
56
58
|
"typescript": "^5.7.2"
|
|
57
59
|
},
|
|
58
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "4c4b4673a068ddc2f37bb2581048bdbfd09b34b2"
|
|
59
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lowercase.d.ts","sourceRoot":"","sources":["../../lib/rules/lowercase.js"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"lowercase.d.ts","sourceRoot":"","sources":["../../lib/rules/lowercase.js"],"names":[],"mappings":";;;wBAkBU,UAAU;;kBAjBN,OAAO,UAAU,EAAE,UAAU;WAC7B,OAAO,UAAU,EAAE,GAAG;gBACtB,OAAO,UAAU,EAAE,QAAQ;iBAC3B,OAAO,UAAU,EAAE,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-attrs.d.ts","sourceRoot":"","sources":["../../lib/rules/sort-attrs.js"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"sort-attrs.d.ts","sourceRoot":"","sources":["../../lib/rules/sort-attrs.js"],"names":[],"mappings":";;;wBAiBU,UAAU;;iBAhBN,OAAO,QAAQ,EAAE,IAAI,CAAC,SAAS;kBAC/B,OAAO,UAAU,EAAE,UAAU;iBAC7B,OAAO,UAAU,EAAE,SAAS;YAC5B,OAAO,UAAU,EAAE,IAAI"}
|
|
@@ -8,6 +8,7 @@ export type CommentContent = import("../../types").CommentContent;
|
|
|
8
8
|
export type Comment = import("../../types").Comment;
|
|
9
9
|
export type AnyNode = import("../../types").AnyNode;
|
|
10
10
|
export type AttributeValue = import("../../types").AttributeValue;
|
|
11
|
+
export type AttributeKey = import("../../types").AttributeKey;
|
|
11
12
|
export type Range = import("eslint").AST.Range;
|
|
12
13
|
export type SourceLocation = import("eslint").AST.SourceLocation;
|
|
13
14
|
export type AnyToken = import("es-html-parser").AnyToken;
|
|
@@ -106,4 +107,9 @@ export function isRangesOverlap(rangeA: Range, rangeB: Range): boolean;
|
|
|
106
107
|
* @returns {((CommentContent | Text)['templates'][number])[]}
|
|
107
108
|
*/
|
|
108
109
|
export function getTemplateTokens(tokens: AnyToken[]): ((CommentContent | Text)["templates"][number])[];
|
|
110
|
+
/**
|
|
111
|
+
* @param {AttributeKey} node
|
|
112
|
+
* @returns {boolean}
|
|
113
|
+
*/
|
|
114
|
+
export function hasTemplate(node: AttributeKey): boolean;
|
|
109
115
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../lib/rules/utils/node.js"],"names":[],"mappings":"wBACc,OAAO,aAAa,EAAE,SAAS;kBAC/B,OAAO,aAAa,EAAE,GAAG;wBACzB,OAAO,aAAa,EAAE,SAAS;uBAC/B,OAAO,aAAa,EAAE,QAAQ;mBAC9B,OAAO,aAAa,EAAE,IAAI;mBAC1B,OAAO,aAAa,EAAE,IAAI;6BAC1B,OAAO,aAAa,EAAE,cAAc;sBACpC,OAAO,aAAa,EAAE,OAAO;sBAC7B,OAAO,aAAa,EAAE,OAAO;6BAC7B,OAAO,aAAa,EAAE,cAAc;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../lib/rules/utils/node.js"],"names":[],"mappings":"wBACc,OAAO,aAAa,EAAE,SAAS;kBAC/B,OAAO,aAAa,EAAE,GAAG;wBACzB,OAAO,aAAa,EAAE,SAAS;uBAC/B,OAAO,aAAa,EAAE,QAAQ;mBAC9B,OAAO,aAAa,EAAE,IAAI;mBAC1B,OAAO,aAAa,EAAE,IAAI;6BAC1B,OAAO,aAAa,EAAE,cAAc;sBACpC,OAAO,aAAa,EAAE,OAAO;sBAC7B,OAAO,aAAa,EAAE,OAAO;6BAC7B,OAAO,aAAa,EAAE,cAAc;2BACpC,OAAO,aAA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