@html-eslint/eslint-plugin 0.20.0 → 0.22.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/constants/index.js +0 -2
- package/lib/rules/element-newline.js +30 -11
- package/lib/rules/id-naming-convention.js +30 -12
- package/lib/rules/indent.js +7 -10
- package/lib/rules/index.js +8 -0
- package/lib/rules/lowercase.js +93 -0
- package/lib/rules/no-abstract-roles.js +15 -13
- package/lib/rules/no-accesskey-attrs.js +5 -6
- package/lib/rules/no-aria-hidden-body.js +2 -6
- package/lib/rules/no-duplicate-attrs.js +3 -4
- package/lib/rules/no-duplicate-id.js +7 -7
- package/lib/rules/no-extra-spacing-attrs.js +29 -9
- package/lib/rules/no-inline-styles.js +5 -2
- package/lib/rules/no-multiple-empty-lines.js +3 -4
- package/lib/rules/no-multiple-h1.js +3 -4
- package/lib/rules/no-non-scalable-viewport.js +3 -7
- package/lib/rules/no-obsolete-tags.js +4 -2
- package/lib/rules/no-positive-tabindex.js +5 -6
- package/lib/rules/no-restricted-attr-values.js +9 -3
- package/lib/rules/no-restricted-attrs.js +13 -2
- package/lib/rules/no-script-style-type.js +69 -0
- package/lib/rules/no-skip-heading-levels.js +4 -5
- package/lib/rules/no-target-blank.js +5 -9
- package/lib/rules/no-trailing-spaces.js +0 -4
- package/lib/rules/quotes.js +24 -1
- package/lib/rules/require-attrs.js +18 -7
- package/lib/rules/require-button-type.js +2 -6
- package/lib/rules/require-closing-tags.js +8 -5
- package/lib/rules/require-doctype.js +4 -5
- package/lib/rules/require-frame-title.js +5 -2
- package/lib/rules/require-img-alt.js +10 -0
- package/lib/rules/require-lang.js +5 -6
- package/lib/rules/require-li-container.js +9 -2
- package/lib/rules/require-meta-charset.js +19 -13
- package/lib/rules/require-meta-description.js +9 -12
- package/lib/rules/require-meta-viewport.js +19 -20
- package/lib/rules/require-open-graph-protocol.js +135 -0
- package/lib/rules/require-title.js +19 -25
- package/lib/rules/sort-attrs.js +158 -0
- package/lib/rules/utils/array.js +26 -0
- package/lib/rules/utils/node.js +70 -0
- package/lib/types.d.ts +262 -246
- package/package.json +4 -4
- package/lib/constants/node-types.js +0 -13
- package/lib/rules/utils/index.js +0 -7
- package/lib/rules/utils/node-utils.js +0 -112
- /package/lib/rules/utils/{naming-utils.js → naming.js} +0 -0
package/lib/types.d.ts
CHANGED
|
@@ -2,253 +2,269 @@ import ESTree from "estree";
|
|
|
2
2
|
import ESLint from "eslint";
|
|
3
3
|
import * as ESHtml from "es-html-parser";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
declare global {
|
|
6
|
+
type Fix = ESLint.Rule.Fix;
|
|
7
|
+
type Token = ESLint.AST.Token;
|
|
8
|
+
|
|
9
|
+
type AnyNode = ESHtml.AnyNode | LineNode;
|
|
10
|
+
|
|
11
|
+
type Range = ESLint.AST.Range;
|
|
12
|
+
|
|
13
|
+
type Location = ESLint.AST.SourceLocation;
|
|
14
|
+
|
|
15
|
+
interface BaseNode {
|
|
16
|
+
range: [number, number];
|
|
17
|
+
loc: {
|
|
18
|
+
start: ESTree.Position;
|
|
19
|
+
end: ESTree.Position;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ProgramNode extends Omit<ESHtml.DocumentNode, "type" | "children"> {
|
|
24
|
+
type: "Program";
|
|
25
|
+
body: ESHtml.DocumentNode["children"];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface AttributeKeyNode extends ESHtml.AttributeKeyNode {
|
|
29
|
+
parent: AttributeNode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TextNode extends ESHtml.TextNode {
|
|
33
|
+
parent: TagNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface TagNode extends ESHtml.TagNode {
|
|
37
|
+
attributes: AttributeNode[];
|
|
38
|
+
parent: TagNode | ProgramNode;
|
|
39
|
+
openStart: OpenTagStartNode;
|
|
40
|
+
openEnd: OpenTagEndNode;
|
|
41
|
+
close: CloseTagNode;
|
|
42
|
+
children: Array<
|
|
43
|
+
TextNode | TagNode | ScriptTagNode | StyleTagNode | CommentNode
|
|
44
|
+
>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface OpenTagStartNode extends ESHtml.OpenTagStartNode {
|
|
48
|
+
parent: TagNode;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface OpenTagEndNode extends ESHtml.OpenTagEndNode {
|
|
52
|
+
parent: TagNode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface CloseTagNode extends ESHtml.CloseTagNode {
|
|
56
|
+
parent: TagNode;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface AttributeNode extends ESHtml.AttributeNode {
|
|
60
|
+
key: AttributeKeyNode;
|
|
61
|
+
value?: AttributeValueNode;
|
|
62
|
+
parent: TagNode | StyleTagNode | ScriptTagNode;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface AttributeValueNode extends ESHtml.AttributeValueNode {
|
|
66
|
+
parent: AttributeNode;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface AttributeValueWrapperEndNode
|
|
70
|
+
extends ESHtml.AttributeValueWrapperEndNode {
|
|
71
|
+
parent: AttributeNode;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface AttributeValueWrapperStartNode
|
|
75
|
+
extends ESHtml.AttributeValueWrapperStartNode {
|
|
76
|
+
parent: AttributeNode;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface ScriptTagNode extends ESHtml.ScriptTagNode {
|
|
80
|
+
attributes: AttributeNode[];
|
|
81
|
+
parent: ProgramNode | TagNode;
|
|
82
|
+
openStart: OpenScriptTagStartNode;
|
|
83
|
+
openEnd: OpenScriptTagEndNode;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface OpenScriptTagStartNode extends ESHtml.OpenScriptTagStartNode {
|
|
87
|
+
parent: ScriptTagNode;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface CloseScriptTagNode extends ESHtml.CloseScriptTagNode {
|
|
91
|
+
parent: ScriptTagNode;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface OpenScriptTagEndNode extends ESHtml.OpenScriptTagEndNode {
|
|
95
|
+
parent: ScriptTagNode;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface ScriptTagContentNode extends ESHtml.ScriptTagContentNode {
|
|
99
|
+
parent: ScriptTagNode;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface StyleTagNode extends ESHtml.StyleTagNode {
|
|
103
|
+
attributes: AttributeNode[];
|
|
104
|
+
parent: TagNode | ProgramNode;
|
|
105
|
+
openStart: OpenStyleTagStartNode;
|
|
106
|
+
openEnd: OpenStyleTagEndNode;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface OpenStyleTagStartNode extends ESHtml.OpenStyleTagStartNode {
|
|
110
|
+
parent: StyleTagNode;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface OpenStyleTagEndNode extends ESHtml.OpenStyleTagEndNode {
|
|
114
|
+
parent: StyleTagNode;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface StyleTagContentNode extends ESHtml.StyleTagContentNode {
|
|
118
|
+
parent: StyleTagNode;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface CloseStyleTagNode extends ESHtml.CloseStyleTagNode {
|
|
122
|
+
parent: StyleTagNode;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface CommentNode extends ESHtml.CommentNode {
|
|
126
|
+
parent: ProgramNode | TagNode;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface CommentOpenNode extends ESHtml.CommentOpenNode {
|
|
130
|
+
parent: CommentNode;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface CommentCloseNode extends ESHtml.CommentCloseNode {
|
|
134
|
+
parent: CommentNode;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface CommentContentNode extends ESHtml.CommentContentNode {
|
|
138
|
+
parent: CommentNode;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface DoctypeNode extends ESHtml.DoctypeNode {
|
|
142
|
+
parent: ProgramNode;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface DoctypeOpenNode extends ESHtml.DoctypeOpenNode {
|
|
146
|
+
parent: DoctypeNode;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface DoctypeCloseNode extends ESHtml.DoctypeCloseNode {
|
|
150
|
+
parent: DoctypeNode;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface DoctypeAttributeNode extends ESHtml.DoctypeAttributeNode {
|
|
154
|
+
parent: DoctypeNode;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface DoctypeAttributeValueNode extends ESHtml.DoctypeAttributeValueNode {
|
|
158
|
+
parent: DoctypeNode;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface DoctypeAttributeWrapperStart
|
|
162
|
+
extends ESHtml.DoctypeAttributeWrapperStartNode {
|
|
163
|
+
parent: DoctypeNode;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface DoctypeAttributeWrapperEnd
|
|
167
|
+
extends ESHtml.DoctypeAttributeWrapperEndNode {
|
|
168
|
+
parent: DoctypeNode;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
interface LineNode extends BaseNode {
|
|
172
|
+
type: "Line";
|
|
173
|
+
value: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface RuleListener {
|
|
177
|
+
Program?: (node: ProgramNode) => void;
|
|
178
|
+
AttributeKey?: (node: AttributeKeyNode) => void;
|
|
179
|
+
Text?: (node: TextNode) => void;
|
|
180
|
+
Tag?: (node: TagNode) => void;
|
|
181
|
+
OpenTagStart?: (node: OpenTagStartNode) => void;
|
|
182
|
+
OpenTagEnd?: (node: OpenTagEndNode) => void;
|
|
183
|
+
CloseTag?: (node: CloseTagNode) => void;
|
|
184
|
+
Attribute?: (node: AttributeNode) => void;
|
|
185
|
+
AttributeValue?: (node: AttributeValueNode) => void;
|
|
186
|
+
AttributeValueWrapperEnd?: (node: AttributeValueWrapperEndNode) => void;
|
|
187
|
+
AttributeValueWrapperStart?: (node: AttributeValueWrapperStartNode) => void;
|
|
188
|
+
ScriptTag?: (node: ScriptTagNode) => void;
|
|
189
|
+
OpenScriptTagStart?: (node: OpenScriptTagStartNode) => void;
|
|
190
|
+
CloseScriptTag?: (node: CloseScriptTagNode) => void;
|
|
191
|
+
OpenScriptTagEnd?: (node: OpenScriptTagEndNode) => void;
|
|
192
|
+
ScriptTagContent?: (node: ScriptTagContentNode) => void;
|
|
193
|
+
StyleTag?: (node: StyleTagNode) => void;
|
|
194
|
+
OpenStyleTagStart?: (node: OpenStyleTagStartNode) => void;
|
|
195
|
+
OpenStyleTagEnd?: (node: OpenStyleTagEndNode) => void;
|
|
196
|
+
StyleTagContent?: (node: StyleTagContentNode) => void;
|
|
197
|
+
CloseStyleTag?: (node: CloseStyleTagNode) => void;
|
|
198
|
+
Comment?: (node: CommentNode) => void;
|
|
199
|
+
CommentOpen?: (node: CommentOpenNode) => void;
|
|
200
|
+
CommentClose?: (node: CommentCloseNode) => void;
|
|
201
|
+
CommentContent?: (node: CommentContentNode) => void;
|
|
202
|
+
Doctype?: (node: DoctypeNode) => void;
|
|
203
|
+
DoctypeOpen: (node: DoctypeOpenNode) => void;
|
|
204
|
+
DoctypeClose?: (node: DoctypeCloseNode) => void;
|
|
205
|
+
DoctypeAttribute?: (node: DoctypeAttributeNode) => void;
|
|
206
|
+
DoctypeAttributeValue?: (node: DoctypeAttributeValueNode) => void;
|
|
207
|
+
DoctypeAttributeWrapperStart?: (node: DoctypeAttributeWrapperStart) => void;
|
|
208
|
+
DoctypeAttributeWrapperEnd?: (node: DoctypeAttributeWrapperEnd) => void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
interface Rule {
|
|
212
|
+
create(context: Context): RuleListener;
|
|
213
|
+
meta?: ESLint.Rule.RuleMetaData;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
interface RuleFixer {
|
|
217
|
+
insertTextAfter(nodeOrToken: BaseNode | Token, text: string): Fix;
|
|
218
|
+
|
|
219
|
+
insertTextAfterRange(range: Range, text: string): Fix;
|
|
220
|
+
|
|
221
|
+
insertTextBefore(nodeOrToken: BaseNode | Token, text: string): Fix;
|
|
222
|
+
|
|
223
|
+
insertTextBeforeRange(range: Range, text: string): Fix;
|
|
224
|
+
|
|
225
|
+
remove(nodeOrToken: BaseNode | Token): Fix;
|
|
226
|
+
|
|
227
|
+
removeRange(range: Range): Fix;
|
|
228
|
+
|
|
229
|
+
replaceText(nodeOrToken: BaseNode | Token, text: string): Fix;
|
|
230
|
+
|
|
231
|
+
replaceTextRange(range: Range, text: string): Fix;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
interface ReportDescriptorOptionsBase {
|
|
235
|
+
data?: { [key: string]: string };
|
|
236
|
+
|
|
237
|
+
fix?:
|
|
238
|
+
| null
|
|
239
|
+
| ((fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[]);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
|
|
243
|
+
type SuggestionReportDescriptor = SuggestionDescriptorMessage &
|
|
244
|
+
ReportDescriptorOptionsBase;
|
|
245
|
+
|
|
246
|
+
interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
|
|
247
|
+
suggest?: SuggestionReportDescriptor[] | null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
type ReportDescriptor = ReportDescriptorMessage &
|
|
251
|
+
ReportDescriptorLocation &
|
|
252
|
+
ReportDescriptorOptions;
|
|
253
|
+
type ReportDescriptorMessage = { message: string } | { messageId: string };
|
|
254
|
+
type ReportDescriptorLocation = {
|
|
255
|
+
node?: BaseNode;
|
|
256
|
+
loc?: ESLint.AST.SourceLocation;
|
|
257
|
+
line?: number;
|
|
258
|
+
column?: number;
|
|
19
259
|
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ProgramNode
|
|
23
|
-
extends Omit<ESHtml.DocumentNode, "type" | "children"> {
|
|
24
|
-
type: "Program";
|
|
25
|
-
body: ESHtml.DocumentNode["children"];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface AttributeKeyNode extends ESHtml.AttributeKeyNode {
|
|
29
|
-
parent: AttributeNode;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface TextNode extends ESHtml.TextNode {
|
|
33
|
-
parent: TagNode;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface TagNode extends ESHtml.TagNode {
|
|
37
|
-
parent: TagNode | ProgramNode;
|
|
38
|
-
openStart: OpenTagStartNode;
|
|
39
|
-
close: CloseTagNode;
|
|
40
|
-
children: Array<
|
|
41
|
-
TextNode | TagNode | ScriptTagNode | StyleTagNode | CommentNode
|
|
42
|
-
>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface OpenTagStartNode extends ESHtml.OpenTagStartNode {
|
|
46
|
-
parent: TagNode;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface OpenTagEndNode extends ESHtml.OpenTagEndNode {
|
|
50
|
-
parent: TagNode;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface CloseTagNode extends ESHtml.CloseTagNode {
|
|
54
|
-
parent: TagNode;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface AttributeNode extends ESHtml.AttributeNode {
|
|
58
|
-
parent: TagNode;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface AttributeValueNode extends ESHtml.AttributeValueNode {
|
|
62
|
-
parent: AttributeNode;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface AttributeValueWrapperEndNode
|
|
66
|
-
extends ESHtml.AttributeValueWrapperEndNode {
|
|
67
|
-
parent: AttributeNode;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface AttributeValueWrapperStartNode
|
|
71
|
-
extends ESHtml.AttributeValueWrapperStartNode {
|
|
72
|
-
parent: AttributeNode;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface ScriptTagNode extends ESHtml.ScriptTagNode {
|
|
76
|
-
parent: ProgramNode | TagNode;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface OpenScriptTagStartNode extends ESHtml.OpenScriptTagStartNode {
|
|
80
|
-
parent: ScriptTagNode;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface CloseScriptTagNode extends ESHtml.CloseScriptTagNode {
|
|
84
|
-
parent: ScriptTagNode;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface OpenScriptTagEndNode extends ESHtml.OpenScriptTagEndNode {
|
|
88
|
-
parent: ScriptTagNode;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface ScriptTagContentNode extends ESHtml.ScriptTagContentNode {
|
|
92
|
-
parent: ScriptTagNode;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface StyleTagNode extends ESHtml.StyleTagNode {
|
|
96
|
-
parent: TagNode | ProgramNode;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface OpenStyleTagStartNode extends ESHtml.OpenStyleTagStartNode {
|
|
100
|
-
parent: StyleTagNode;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface OpenStyleTagEndNode extends ESHtml.OpenStyleTagEndNode {
|
|
104
|
-
parent: StyleTagNode;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface StyleTagContentNode extends ESHtml.StyleTagContentNode {
|
|
108
|
-
parent: StyleTagNode;
|
|
109
|
-
}
|
|
110
260
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface CommentNode extends ESHtml.CommentNode {
|
|
116
|
-
parent: ProgramNode | TagNode;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface CommentOpenNode extends ESHtml.CommentOpenNode {
|
|
120
|
-
parent: CommentNode;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface CommentCloseNode extends ESHtml.CommentCloseNode {
|
|
124
|
-
parent: CommentNode;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface CommentContentNode extends ESHtml.CommentContentNode {
|
|
128
|
-
parent: CommentNode;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface DoctypeNode extends ESHtml.DoctypeNode {
|
|
132
|
-
parent: ProgramNode;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface DoctypeOpenNode extends ESHtml.DoctypeOpenNode {
|
|
136
|
-
parent: DoctypeNode;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface DoctypeCloseNode extends ESHtml.DoctypeCloseNode {
|
|
140
|
-
parent: DoctypeNode;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface DoctypeAttributeNode extends ESHtml.DoctypeAttributeNode {
|
|
144
|
-
parent: DoctypeNode;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface DoctypeAttributeValueNode
|
|
148
|
-
extends ESHtml.DoctypeAttributeValueNode {
|
|
149
|
-
parent: DoctypeNode;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface DoctypeAttributeWrapperStart
|
|
153
|
-
extends ESHtml.DoctypeAttributeWrapperStartNode {
|
|
154
|
-
parent: DoctypeNode;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export interface DoctypeAttributeWrapperEnd
|
|
158
|
-
extends ESHtml.DoctypeAttributeWrapperEndNode {
|
|
159
|
-
parent: DoctypeNode;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export interface LineNode extends BaseNode {
|
|
163
|
-
type: "Line";
|
|
164
|
-
value: string;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
interface RuleListener {
|
|
168
|
-
Program?: (node: ProgramNode) => void;
|
|
169
|
-
AttributeKey?: (node: AttributeKeyNode) => void;
|
|
170
|
-
Text?: (node: TextNode) => void;
|
|
171
|
-
Tag?: (node: TagNode) => void;
|
|
172
|
-
OpenTagStart?: (node: OpenTagStartNode) => void;
|
|
173
|
-
OpenTagEnd?: (node: OpenTagEndNode) => void;
|
|
174
|
-
CloseTag?: (node: CloseTagNode) => void;
|
|
175
|
-
Attribute?: (node: AttributeNode) => void;
|
|
176
|
-
AttributeValue?: (node: AttributeValueNode) => void;
|
|
177
|
-
AttributeValueWrapperEnd?: (node: AttributeValueWrapperEndNode) => void;
|
|
178
|
-
AttributeValueWrapperStart?: (node: AttributeValueWrapperStartNode) => void;
|
|
179
|
-
ScriptTag?: (node: ScriptTagNode) => void;
|
|
180
|
-
OpenScriptTagStart?: (node: OpenScriptTagStartNode) => void;
|
|
181
|
-
CloseScriptTag?: (node: CloseScriptTagNode) => void;
|
|
182
|
-
OpenScriptTagEnd?: (node: OpenScriptTagEndNode) => void;
|
|
183
|
-
ScriptTagContent?: (node: ScriptTagContentNode) => void;
|
|
184
|
-
StyleTag?: (node: StyleTagNode) => void;
|
|
185
|
-
OpenStyleTagStart?: (node: OpenStyleTagStartNode) => void;
|
|
186
|
-
OpenStyleTagEnd?: (node: OpenStyleTagEndNode) => void;
|
|
187
|
-
StyleTagContent?: (node: StyleTagContentNode) => void;
|
|
188
|
-
CloseStyleTag?: (node: CloseStyleTagNode) => void;
|
|
189
|
-
Comment?: (node: CommentNode) => void;
|
|
190
|
-
CommentOpen?: (node: CommentOpenNode) => void;
|
|
191
|
-
CommentClose?: (node: CommentCloseNode) => void;
|
|
192
|
-
CommentContent?: (node: CommentContentNode) => void;
|
|
193
|
-
Doctype?: (node: DoctypeNode) => void;
|
|
194
|
-
DoctypeOpen: (node: DoctypeOpenNode) => void;
|
|
195
|
-
DoctypeClose?: (node: DoctypeCloseNode) => void;
|
|
196
|
-
DoctypeAttribute?: (node: DoctypeAttributeNode) => void;
|
|
197
|
-
DoctypeAttributeValue?: (node: DoctypeAttributeValueNode) => void;
|
|
198
|
-
DoctypeAttributeWrapperStart?: (node: DoctypeAttributeWrapperStart) => void;
|
|
199
|
-
DoctypeAttributeWrapperEnd?: (node: DoctypeAttributeWrapperEnd) => void;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export interface Rule {
|
|
203
|
-
create(context: Context): RuleListener;
|
|
204
|
-
meta?: ESLint.Rule.RuleMetaData;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
interface RuleFixer {
|
|
208
|
-
insertTextAfter(nodeOrToken: BaseNode | Token, text: string): Fix;
|
|
209
|
-
|
|
210
|
-
insertTextAfterRange(range: Range, text: string): Fix;
|
|
211
|
-
|
|
212
|
-
insertTextBefore(nodeOrToken: BaseNode | Token, text: string): Fix;
|
|
213
|
-
|
|
214
|
-
insertTextBeforeRange(range: Range, text: string): Fix;
|
|
215
|
-
|
|
216
|
-
remove(nodeOrToken: BaseNode | Token): Fix;
|
|
217
|
-
|
|
218
|
-
removeRange(range: Range): Fix;
|
|
219
|
-
|
|
220
|
-
replaceText(nodeOrToken: BaseNode | Token, text: string): Fix;
|
|
221
|
-
|
|
222
|
-
replaceTextRange(range: Range, text: string): Fix;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
interface ReportDescriptorOptionsBase {
|
|
226
|
-
data?: { [key: string]: string };
|
|
227
|
-
|
|
228
|
-
fix?:
|
|
229
|
-
| null
|
|
230
|
-
| ((fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[]);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
|
|
234
|
-
type SuggestionReportDescriptor = SuggestionDescriptorMessage &
|
|
235
|
-
ReportDescriptorOptionsBase;
|
|
236
|
-
|
|
237
|
-
interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
|
|
238
|
-
suggest?: SuggestionReportDescriptor[] | null;
|
|
239
|
-
}
|
|
261
|
+
interface Context extends Omit<ESLint.Rule.RuleContext, "report"> {
|
|
262
|
+
report(descriptor: ReportDescriptor): void;
|
|
263
|
+
}
|
|
240
264
|
|
|
241
|
-
type
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
node?: BaseNode;
|
|
247
|
-
loc?: ESLint.AST.SourceLocation;
|
|
248
|
-
line?: number;
|
|
249
|
-
column?: number;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
export interface Context extends Omit<ESLint.Rule.RuleContext, "report"> {
|
|
253
|
-
report(descriptor: ReportDescriptor): void;
|
|
265
|
+
type ChildType<T extends BaseNode> = T extends ProgramNode
|
|
266
|
+
? T["body"][number]
|
|
267
|
+
: T extends TagNode
|
|
268
|
+
? T["children"][number]
|
|
269
|
+
: never;
|
|
254
270
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-eslint/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "ESLint plugin for html",
|
|
5
5
|
"author": "yeonjuan",
|
|
6
6
|
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "jest --coverage",
|
|
25
|
-
"
|
|
25
|
+
"ts": "tsc",
|
|
26
26
|
"lint": "eslint . --ext .js"
|
|
27
27
|
},
|
|
28
28
|
"bugs": {
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"accessibility"
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@html-eslint/parser": "^0.
|
|
44
|
+
"@html-eslint/parser": "^0.22.0",
|
|
45
45
|
"@types/eslint": "^7.2.10",
|
|
46
46
|
"@types/estree": "^0.0.47",
|
|
47
47
|
"es-html-parser": "^0.0.8",
|
|
48
48
|
"typescript": "^4.4.4"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "56a3c7726aa4d89f81035a3e3ea37bdd02be94ac"
|
|
51
51
|
}
|
package/lib/rules/utils/index.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import("es-html-parser").TagNode} TagNode
|
|
3
|
-
* @typedef {import("es-html-parser").AnyNode} AnyNode
|
|
4
|
-
* @typedef {import("es-html-parser").TextNode} TextNode
|
|
5
|
-
* @typedef {import("es-html-parser").AttributeNode} AttributeNode
|
|
6
|
-
* @typedef {import("../../types").LineNode} LineNode
|
|
7
|
-
* @typedef {import("../../types").CommentContentNode} CommentContentNode
|
|
8
|
-
* @typedef {import("../../types").BaseNode} BaseNode
|
|
9
|
-
* @typedef {import("../../types").Location} Location
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
/*
|
|
14
|
-
* @param {TagNode} node
|
|
15
|
-
* @param {string} name
|
|
16
|
-
* @returns {AttributeNode | undefined}
|
|
17
|
-
*/
|
|
18
|
-
findAttr(node, name) {
|
|
19
|
-
return node.attributes.find(
|
|
20
|
-
(attr) => attr.key && attr.key.value.toLowerCase() === name.toLowerCase()
|
|
21
|
-
);
|
|
22
|
-
},
|
|
23
|
-
/**
|
|
24
|
-
* Checks a node has attribute with the given name or not.
|
|
25
|
-
* @param {TagNode} node node
|
|
26
|
-
* @param {string} name attribute name
|
|
27
|
-
* @return {boolean} `true` if the node has a attribute, otherwise `false`.
|
|
28
|
-
*/
|
|
29
|
-
hasAttr(node, name) {
|
|
30
|
-
return (
|
|
31
|
-
!!node &&
|
|
32
|
-
(node.attributes || []).some(
|
|
33
|
-
(attr) => attr.key && attr.key.value === name
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
},
|
|
37
|
-
/**
|
|
38
|
-
* Checks whether a node's all tokens are on the same line or not.
|
|
39
|
-
* @param {AnyNode} node A node to check
|
|
40
|
-
* @returns {boolean} `true` if a node's tokens are on the same line, otherwise `false`.
|
|
41
|
-
*/
|
|
42
|
-
isNodeTokensOnSameLine(node) {
|
|
43
|
-
return node.loc.start.line === node.loc.end.line;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Checks whether a node is a TextNode or not.
|
|
48
|
-
* @param {Object} node A node to check
|
|
49
|
-
* @returns {node is TextNode} `true` if a node is `TextNode`, otherwise `false`.
|
|
50
|
-
*/
|
|
51
|
-
isTextNode(node) {
|
|
52
|
-
return !!(node && node.type === "text" && typeof node.value === "string");
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Checks whether a node is a CommentNode or not.
|
|
57
|
-
* @param {Object} node A node to check
|
|
58
|
-
* @returns {node is CommentNode} `true` if a node is `CommentNode`, otherwise `false`.
|
|
59
|
-
*/
|
|
60
|
-
isCommentNode(node) {
|
|
61
|
-
return !!(node && node.type === "comment");
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @param {TextNode | CommentContentNode} node
|
|
67
|
-
* @returns {LineNode[]}
|
|
68
|
-
*/
|
|
69
|
-
splitToLineNodes(node) {
|
|
70
|
-
let start = node.range[0];
|
|
71
|
-
let line = node.loc.start.line;
|
|
72
|
-
const startCol = node.loc.start.column;
|
|
73
|
-
|
|
74
|
-
return node.value.split("\n").map((value, index) => {
|
|
75
|
-
const columnStart = index === 0 ? startCol : 0;
|
|
76
|
-
/**
|
|
77
|
-
* @type {LineNode}
|
|
78
|
-
*/
|
|
79
|
-
const lineNode = {
|
|
80
|
-
type: "Line",
|
|
81
|
-
value,
|
|
82
|
-
range: [start, start + value.length],
|
|
83
|
-
loc: {
|
|
84
|
-
start: {
|
|
85
|
-
line,
|
|
86
|
-
column: columnStart,
|
|
87
|
-
},
|
|
88
|
-
end: {
|
|
89
|
-
line,
|
|
90
|
-
column: columnStart + value.length,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
start += value.length + 1;
|
|
96
|
-
line += 1;
|
|
97
|
-
return lineNode;
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
/**
|
|
101
|
-
* Get location between two nodes.
|
|
102
|
-
* @param {BaseNode} before A node placed in before
|
|
103
|
-
* @param {BaseNode} after A node placed in after
|
|
104
|
-
* @returns {Location} location between two nodes.
|
|
105
|
-
*/
|
|
106
|
-
getLocBetween(before, after) {
|
|
107
|
-
return {
|
|
108
|
-
start: before.loc.end,
|
|
109
|
-
end: after.loc.start,
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
};
|
|
File without changes
|