@html-eslint/core 0.56.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 YeonJuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @html-eslint/core
2
+
3
+ Core HTML validation logic for html-eslint.
4
+
5
+ ## Overview
6
+
7
+ This package provides framework-agnostic HTML validation utilities that can be used across different ESLint plugins (Angular, Svelte, etc.).
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @html-eslint/core
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```javascript
18
+ import { noInvalidAttrValue } from "@html-eslint/core";
19
+
20
+ // Create a rule instance with options
21
+ const rule = noInvalidAttrValue({
22
+ allow: [{ tag: "img", attr: "src", valuePattern: "^https://.*" }],
23
+ });
24
+
25
+ // Validate attributes using an adapter
26
+ const result = rule.checkAttributes(elementAdapter);
27
+ ```
28
+
29
+ ## License
30
+
31
+ MIT
@@ -0,0 +1,237 @@
1
+ interface ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode> {
2
+ getTagName(): string;
3
+ getAttributes(): AttributeAdapter<AttributeKeyNode, AttributeValueNode>[];
4
+ node: () => ElementNode;
5
+ }
6
+ interface AttributeAdapter<AttributeKeyNode, AttributeValueNode> {
7
+ key: {
8
+ node: () => AttributeKeyNode;
9
+ isExpression: () => boolean;
10
+ value: () => null | string;
11
+ raw: () => null | string;
12
+ };
13
+ value: {
14
+ node: () => AttributeValueNode | null;
15
+ isExpression: () => boolean;
16
+ value: () => string | null;
17
+ };
18
+ }
19
+ interface NoInvalidAttrValueOptions {
20
+ allow?: Array<{
21
+ tag: string;
22
+ attr: string;
23
+ valuePattern?: string;
24
+ }>;
25
+ }
26
+ type NoInvalidAttrValueResult<AttributeKeyNode, AttributeValueNode> = Array<{
27
+ messageId: "invalid";
28
+ node: AttributeKeyNode | AttributeValueNode;
29
+ data: {
30
+ value: string;
31
+ attr: string;
32
+ element: string;
33
+ suggestion: string;
34
+ };
35
+ }>;
36
+ interface UseBaselineOptions {
37
+ available: "widely" | "newly" | number;
38
+ }
39
+ type UseBaselineResult<ElementNode, AttributeKeyNode, AttributeValueNode> = Array<{
40
+ messageId: "noBaselineElement";
41
+ node: ElementNode | AttributeValueNode;
42
+ data: {
43
+ element: string;
44
+ availability: string;
45
+ };
46
+ } | {
47
+ messageId: "notBaselineElementAttribute";
48
+ node: ElementNode | AttributeValueNode | AttributeKeyNode;
49
+ data: {
50
+ element: string;
51
+ attr: string;
52
+ availability: string;
53
+ };
54
+ } | {
55
+ messageId: "notBaselineGlobalAttribute";
56
+ node: AttributeValueNode | AttributeKeyNode;
57
+ data: {
58
+ attr: string;
59
+ availability: string;
60
+ };
61
+ }>;
62
+ type NoIneffectiveAttrsResult<AttributeKeyNode> = Array<{
63
+ messageId: "ineffective";
64
+ node: AttributeKeyNode;
65
+ data: {
66
+ message: string;
67
+ };
68
+ }>;
69
+ type NoObsoleteTagsResult<ElementNode> = Array<{
70
+ messageId: "unexpected";
71
+ node: ElementNode;
72
+ data: {
73
+ tag: string;
74
+ };
75
+ }>;
76
+ type NoObsoleteAttrsResult<AttributeKeyNode> = Array<{
77
+ messageId: "obsolete";
78
+ node: AttributeKeyNode;
79
+ data: {
80
+ attr: string;
81
+ element: string;
82
+ suggestion: string;
83
+ };
84
+ }>;
85
+
86
+ /**
87
+ * @template ElementNode
88
+ * @template AttributeKeyNode
89
+ * @template AttributeValueNode
90
+ * @param {NoInvalidAttrValueOptions} options
91
+ */
92
+ declare function noInvalidAttrValue<ElementNode, AttributeKeyNode, AttributeValueNode>(options: NoInvalidAttrValueOptions): {
93
+ /**
94
+ * @param {ElementNodeAdapter<
95
+ * ElementNode,
96
+ * AttributeKeyNode,
97
+ * AttributeValueNode
98
+ * >} adapter
99
+ * @returns {NoInvalidAttrValueResult<
100
+ * AttributeKeyNode,
101
+ * AttributeValueNode
102
+ * >}
103
+ */
104
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoInvalidAttrValueResult<AttributeKeyNode, AttributeValueNode>;
105
+ };
106
+ /**
107
+ * @type {{
108
+ * invalid: "invalid";
109
+ * }}
110
+ */
111
+ declare const NO_INVALID_ATTR_VALUE_MESSAGE_IDS: {
112
+ invalid: "invalid";
113
+ };
114
+
115
+ /**
116
+ * @template ElementNode
117
+ * @template AttributeKeyNode
118
+ * @template AttributeValueNode
119
+ * @param {UseBaselineOptions} options
120
+ */
121
+ declare function useBaseline<ElementNode, AttributeKeyNode, AttributeValueNode>(options: UseBaselineOptions): {
122
+ /**
123
+ * @param {ElementNodeAdapter<
124
+ * ElementNode,
125
+ * AttributeKeyNode,
126
+ * AttributeValueNode
127
+ * >} adapter
128
+ * @returns {UseBaselineResult<
129
+ * ElementNode,
130
+ * AttributeKeyNode,
131
+ * AttributeValueNode
132
+ * >}
133
+ */
134
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): UseBaselineResult<ElementNode, AttributeKeyNode, AttributeValueNode>;
135
+ };
136
+ /**
137
+ * @type {{
138
+ * noBaselineElement: "noBaselineElement";
139
+ * notBaselineElementAttribute: "notBaselineElementAttribute";
140
+ * notBaselineGlobalAttribute: "notBaselineGlobalAttribute";
141
+ * }}
142
+ */
143
+ declare const USE_BASELINE_MESSAGE_IDS: {
144
+ noBaselineElement: "noBaselineElement";
145
+ notBaselineElementAttribute: "notBaselineElementAttribute";
146
+ notBaselineGlobalAttribute: "notBaselineGlobalAttribute";
147
+ };
148
+
149
+ /**
150
+ * @template ElementNode
151
+ * @template AttributeKeyNode
152
+ * @template AttributeValueNode
153
+ */
154
+ declare function noIneffectiveAttrs<ElementNode, AttributeKeyNode, AttributeValueNode>(): {
155
+ /**
156
+ * @param {ElementNodeAdapter<
157
+ * ElementNode,
158
+ * AttributeKeyNode,
159
+ * AttributeValueNode
160
+ * >} adapter
161
+ * @returns {NoIneffectiveAttrsResult<AttributeKeyNode>}
162
+ */
163
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoIneffectiveAttrsResult<AttributeKeyNode>;
164
+ };
165
+ /**
166
+ * @import {
167
+ * ElementNodeAdapter,
168
+ * NoIneffectiveAttrsResult
169
+ * } from "../types"
170
+ */
171
+ /**
172
+ * @typedef {{
173
+ * attr: string;
174
+ * when: (adapter: ElementNodeAdapter<any, any, any>) => boolean;
175
+ * message: string;
176
+ * }} AttributeChecker
177
+ */
178
+ /**
179
+ * @type {{
180
+ * ineffective: "ineffective";
181
+ * }}
182
+ */
183
+ declare const NO_INEFFECTIVE_ATTRS_MESSAGE_IDS: {
184
+ ineffective: "ineffective";
185
+ };
186
+
187
+ /**
188
+ * @template ElementNode
189
+ * @template AttributeKeyNode
190
+ * @template AttributeValueNode
191
+ */
192
+ declare function noObsoleteTags<ElementNode, AttributeKeyNode, AttributeValueNode>(): {
193
+ /**
194
+ * @param {ElementNodeAdapter<
195
+ * ElementNode,
196
+ * AttributeKeyNode,
197
+ * AttributeValueNode
198
+ * >} adapter
199
+ * @returns {NoObsoleteTagsResult<ElementNode>}
200
+ */
201
+ checkElement(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoObsoleteTagsResult<ElementNode>;
202
+ };
203
+ /**
204
+ * @type {{
205
+ * unexpected: "unexpected";
206
+ * }}
207
+ */
208
+ declare const NO_OBSOLETE_TAGS_MESSAGE_IDS: {
209
+ unexpected: "unexpected";
210
+ };
211
+
212
+ /**
213
+ * @template ElementNode
214
+ * @template AttributeKeyNode
215
+ * @template AttributeValueNode
216
+ */
217
+ declare function noObsoleteAttrs<ElementNode, AttributeKeyNode, AttributeValueNode>(): {
218
+ /**
219
+ * @param {ElementNodeAdapter<
220
+ * ElementNode,
221
+ * AttributeKeyNode,
222
+ * AttributeValueNode
223
+ * >} adapter
224
+ * @returns {NoObsoleteAttrsResult<AttributeKeyNode>}
225
+ */
226
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoObsoleteAttrsResult<AttributeKeyNode>;
227
+ };
228
+ /**
229
+ * @type {{
230
+ * obsolete: "obsolete";
231
+ * }}
232
+ */
233
+ declare const NO_OBSOLETE_ATTRS_MESSAGE_IDS: {
234
+ obsolete: "obsolete";
235
+ };
236
+
237
+ export { type AttributeAdapter, type ElementNodeAdapter, NO_INEFFECTIVE_ATTRS_MESSAGE_IDS, NO_INVALID_ATTR_VALUE_MESSAGE_IDS, NO_OBSOLETE_ATTRS_MESSAGE_IDS, NO_OBSOLETE_TAGS_MESSAGE_IDS, type NoIneffectiveAttrsResult, type NoInvalidAttrValueOptions, type NoInvalidAttrValueResult, type NoObsoleteAttrsResult, type NoObsoleteTagsResult, USE_BASELINE_MESSAGE_IDS, type UseBaselineOptions, type UseBaselineResult, noIneffectiveAttrs, noInvalidAttrValue, noObsoleteAttrs, noObsoleteTags, useBaseline };
@@ -0,0 +1,237 @@
1
+ interface ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode> {
2
+ getTagName(): string;
3
+ getAttributes(): AttributeAdapter<AttributeKeyNode, AttributeValueNode>[];
4
+ node: () => ElementNode;
5
+ }
6
+ interface AttributeAdapter<AttributeKeyNode, AttributeValueNode> {
7
+ key: {
8
+ node: () => AttributeKeyNode;
9
+ isExpression: () => boolean;
10
+ value: () => null | string;
11
+ raw: () => null | string;
12
+ };
13
+ value: {
14
+ node: () => AttributeValueNode | null;
15
+ isExpression: () => boolean;
16
+ value: () => string | null;
17
+ };
18
+ }
19
+ interface NoInvalidAttrValueOptions {
20
+ allow?: Array<{
21
+ tag: string;
22
+ attr: string;
23
+ valuePattern?: string;
24
+ }>;
25
+ }
26
+ type NoInvalidAttrValueResult<AttributeKeyNode, AttributeValueNode> = Array<{
27
+ messageId: "invalid";
28
+ node: AttributeKeyNode | AttributeValueNode;
29
+ data: {
30
+ value: string;
31
+ attr: string;
32
+ element: string;
33
+ suggestion: string;
34
+ };
35
+ }>;
36
+ interface UseBaselineOptions {
37
+ available: "widely" | "newly" | number;
38
+ }
39
+ type UseBaselineResult<ElementNode, AttributeKeyNode, AttributeValueNode> = Array<{
40
+ messageId: "noBaselineElement";
41
+ node: ElementNode | AttributeValueNode;
42
+ data: {
43
+ element: string;
44
+ availability: string;
45
+ };
46
+ } | {
47
+ messageId: "notBaselineElementAttribute";
48
+ node: ElementNode | AttributeValueNode | AttributeKeyNode;
49
+ data: {
50
+ element: string;
51
+ attr: string;
52
+ availability: string;
53
+ };
54
+ } | {
55
+ messageId: "notBaselineGlobalAttribute";
56
+ node: AttributeValueNode | AttributeKeyNode;
57
+ data: {
58
+ attr: string;
59
+ availability: string;
60
+ };
61
+ }>;
62
+ type NoIneffectiveAttrsResult<AttributeKeyNode> = Array<{
63
+ messageId: "ineffective";
64
+ node: AttributeKeyNode;
65
+ data: {
66
+ message: string;
67
+ };
68
+ }>;
69
+ type NoObsoleteTagsResult<ElementNode> = Array<{
70
+ messageId: "unexpected";
71
+ node: ElementNode;
72
+ data: {
73
+ tag: string;
74
+ };
75
+ }>;
76
+ type NoObsoleteAttrsResult<AttributeKeyNode> = Array<{
77
+ messageId: "obsolete";
78
+ node: AttributeKeyNode;
79
+ data: {
80
+ attr: string;
81
+ element: string;
82
+ suggestion: string;
83
+ };
84
+ }>;
85
+
86
+ /**
87
+ * @template ElementNode
88
+ * @template AttributeKeyNode
89
+ * @template AttributeValueNode
90
+ * @param {NoInvalidAttrValueOptions} options
91
+ */
92
+ declare function noInvalidAttrValue<ElementNode, AttributeKeyNode, AttributeValueNode>(options: NoInvalidAttrValueOptions): {
93
+ /**
94
+ * @param {ElementNodeAdapter<
95
+ * ElementNode,
96
+ * AttributeKeyNode,
97
+ * AttributeValueNode
98
+ * >} adapter
99
+ * @returns {NoInvalidAttrValueResult<
100
+ * AttributeKeyNode,
101
+ * AttributeValueNode
102
+ * >}
103
+ */
104
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoInvalidAttrValueResult<AttributeKeyNode, AttributeValueNode>;
105
+ };
106
+ /**
107
+ * @type {{
108
+ * invalid: "invalid";
109
+ * }}
110
+ */
111
+ declare const NO_INVALID_ATTR_VALUE_MESSAGE_IDS: {
112
+ invalid: "invalid";
113
+ };
114
+
115
+ /**
116
+ * @template ElementNode
117
+ * @template AttributeKeyNode
118
+ * @template AttributeValueNode
119
+ * @param {UseBaselineOptions} options
120
+ */
121
+ declare function useBaseline<ElementNode, AttributeKeyNode, AttributeValueNode>(options: UseBaselineOptions): {
122
+ /**
123
+ * @param {ElementNodeAdapter<
124
+ * ElementNode,
125
+ * AttributeKeyNode,
126
+ * AttributeValueNode
127
+ * >} adapter
128
+ * @returns {UseBaselineResult<
129
+ * ElementNode,
130
+ * AttributeKeyNode,
131
+ * AttributeValueNode
132
+ * >}
133
+ */
134
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): UseBaselineResult<ElementNode, AttributeKeyNode, AttributeValueNode>;
135
+ };
136
+ /**
137
+ * @type {{
138
+ * noBaselineElement: "noBaselineElement";
139
+ * notBaselineElementAttribute: "notBaselineElementAttribute";
140
+ * notBaselineGlobalAttribute: "notBaselineGlobalAttribute";
141
+ * }}
142
+ */
143
+ declare const USE_BASELINE_MESSAGE_IDS: {
144
+ noBaselineElement: "noBaselineElement";
145
+ notBaselineElementAttribute: "notBaselineElementAttribute";
146
+ notBaselineGlobalAttribute: "notBaselineGlobalAttribute";
147
+ };
148
+
149
+ /**
150
+ * @template ElementNode
151
+ * @template AttributeKeyNode
152
+ * @template AttributeValueNode
153
+ */
154
+ declare function noIneffectiveAttrs<ElementNode, AttributeKeyNode, AttributeValueNode>(): {
155
+ /**
156
+ * @param {ElementNodeAdapter<
157
+ * ElementNode,
158
+ * AttributeKeyNode,
159
+ * AttributeValueNode
160
+ * >} adapter
161
+ * @returns {NoIneffectiveAttrsResult<AttributeKeyNode>}
162
+ */
163
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoIneffectiveAttrsResult<AttributeKeyNode>;
164
+ };
165
+ /**
166
+ * @import {
167
+ * ElementNodeAdapter,
168
+ * NoIneffectiveAttrsResult
169
+ * } from "../types"
170
+ */
171
+ /**
172
+ * @typedef {{
173
+ * attr: string;
174
+ * when: (adapter: ElementNodeAdapter<any, any, any>) => boolean;
175
+ * message: string;
176
+ * }} AttributeChecker
177
+ */
178
+ /**
179
+ * @type {{
180
+ * ineffective: "ineffective";
181
+ * }}
182
+ */
183
+ declare const NO_INEFFECTIVE_ATTRS_MESSAGE_IDS: {
184
+ ineffective: "ineffective";
185
+ };
186
+
187
+ /**
188
+ * @template ElementNode
189
+ * @template AttributeKeyNode
190
+ * @template AttributeValueNode
191
+ */
192
+ declare function noObsoleteTags<ElementNode, AttributeKeyNode, AttributeValueNode>(): {
193
+ /**
194
+ * @param {ElementNodeAdapter<
195
+ * ElementNode,
196
+ * AttributeKeyNode,
197
+ * AttributeValueNode
198
+ * >} adapter
199
+ * @returns {NoObsoleteTagsResult<ElementNode>}
200
+ */
201
+ checkElement(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoObsoleteTagsResult<ElementNode>;
202
+ };
203
+ /**
204
+ * @type {{
205
+ * unexpected: "unexpected";
206
+ * }}
207
+ */
208
+ declare const NO_OBSOLETE_TAGS_MESSAGE_IDS: {
209
+ unexpected: "unexpected";
210
+ };
211
+
212
+ /**
213
+ * @template ElementNode
214
+ * @template AttributeKeyNode
215
+ * @template AttributeValueNode
216
+ */
217
+ declare function noObsoleteAttrs<ElementNode, AttributeKeyNode, AttributeValueNode>(): {
218
+ /**
219
+ * @param {ElementNodeAdapter<
220
+ * ElementNode,
221
+ * AttributeKeyNode,
222
+ * AttributeValueNode
223
+ * >} adapter
224
+ * @returns {NoObsoleteAttrsResult<AttributeKeyNode>}
225
+ */
226
+ checkAttributes(adapter: ElementNodeAdapter<ElementNode, AttributeKeyNode, AttributeValueNode>): NoObsoleteAttrsResult<AttributeKeyNode>;
227
+ };
228
+ /**
229
+ * @type {{
230
+ * obsolete: "obsolete";
231
+ * }}
232
+ */
233
+ declare const NO_OBSOLETE_ATTRS_MESSAGE_IDS: {
234
+ obsolete: "obsolete";
235
+ };
236
+
237
+ export { type AttributeAdapter, type ElementNodeAdapter, NO_INEFFECTIVE_ATTRS_MESSAGE_IDS, NO_INVALID_ATTR_VALUE_MESSAGE_IDS, NO_OBSOLETE_ATTRS_MESSAGE_IDS, NO_OBSOLETE_TAGS_MESSAGE_IDS, type NoIneffectiveAttrsResult, type NoInvalidAttrValueOptions, type NoInvalidAttrValueResult, type NoObsoleteAttrsResult, type NoObsoleteTagsResult, USE_BASELINE_MESSAGE_IDS, type UseBaselineOptions, type UseBaselineResult, noIneffectiveAttrs, noInvalidAttrValue, noObsoleteAttrs, noObsoleteTags, useBaseline };