@markuplint/rules 1.10.4 → 2.0.0-alpha.0.23
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/README.md +21 -20
- package/lib/attr-check.d.ts +16 -0
- package/lib/attr-check.js +498 -0
- package/lib/attr-duplication/index.d.ts +1 -1
- package/lib/attr-duplication/index.js +5 -8
- package/lib/attr-equal-space-after/index.d.ts +1 -1
- package/lib/attr-equal-space-after/index.js +8 -11
- package/lib/attr-equal-space-before/index.d.ts +1 -1
- package/lib/attr-equal-space-before/index.js +8 -11
- package/lib/attr-spacing/index.d.ts +3 -3
- package/lib/attr-spacing/index.js +19 -21
- package/lib/attr-value-quotes/index.d.ts +1 -1
- package/lib/attr-value-quotes/index.js +9 -12
- package/lib/case-sensitive-attr-name/index.d.ts +1 -1
- package/lib/case-sensitive-attr-name/index.js +11 -14
- package/lib/case-sensitive-tag-name/index.d.ts +1 -1
- package/lib/case-sensitive-tag-name/index.js +8 -11
- package/lib/character-reference/index.d.ts +1 -1
- package/lib/character-reference/index.js +15 -11
- package/lib/class-naming/index.d.ts +1 -1
- package/lib/class-naming/index.js +7 -10
- package/lib/deprecated-attr/index.d.ts +1 -1
- package/lib/deprecated-attr/index.js +6 -9
- package/lib/deprecated-element/index.d.ts +1 -1
- package/lib/deprecated-element/index.js +10 -15
- package/lib/doctype/index.d.ts +1 -1
- package/lib/doctype/index.js +16 -25
- package/lib/helpers.d.ts +12 -11
- package/lib/helpers.js +38 -25
- package/lib/id-duplication/index.d.ts +1 -1
- package/lib/id-duplication/index.js +5 -8
- package/lib/indentation/index.d.ts +3 -3
- package/lib/indentation/index.js +81 -116
- package/lib/index.d.ts +45 -24
- package/lib/index.js +42 -42
- package/lib/invalid-attr/index.d.ts +2 -2
- package/lib/invalid-attr/index.js +23 -25
- package/lib/landmark-roles/index.d.ts +3 -3
- package/lib/landmark-roles/index.js +12 -20
- package/lib/permitted-contents/index.d.ts +2 -2
- package/lib/permitted-contents/index.js +63 -45
- package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +2 -2
- package/lib/permitted-contents/permitted-content.spec-to-regexp.js +49 -30
- package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +1 -1
- package/lib/permitted-contents/unfold-content-models-to-tags.js +2 -3
- package/lib/{type-check.d.ts → primitive-check.d.ts} +24 -7
- package/lib/primitive-check.js +109 -0
- package/lib/required-attr/index.d.ts +1 -1
- package/lib/required-attr/index.js +12 -16
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/required-h1/index.js +8 -13
- package/lib/wai-aria/index.d.ts +1 -1
- package/lib/wai-aria/index.js +57 -64
- package/package.json +6 -6
- package/tsconfig.test.json +1 -24
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/type-check.js +0 -321
package/lib/type-check.js
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nonZeroUintCheck = exports.floatCheck = exports.uintCheck = exports.intCheck = exports.typeCheck = void 0;
|
|
4
|
-
function typeCheck(name, value, isCustomRule, spec) {
|
|
5
|
-
if (!isCustomRule) {
|
|
6
|
-
if (/^data-.+$/.test(name)) {
|
|
7
|
-
// Ignore checking because "data-*" attribute is any type
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
if (/^aria-.+$|^role$/.test(name)) {
|
|
11
|
-
// Ignore checking because ARIA attributes are check on another rule
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
// Existance
|
|
16
|
-
if (!spec) {
|
|
17
|
-
return {
|
|
18
|
-
invalidType: 'non-existent',
|
|
19
|
-
message: `The "${name}" attribute is not allowed`,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (spec.type === 'String' || spec.type === 'NonEmptyString') {
|
|
23
|
-
if (spec.type === 'NonEmptyString' && value === '') {
|
|
24
|
-
return {
|
|
25
|
-
invalidType: 'invalid-value',
|
|
26
|
-
message: `The "${name}" attribute value must not be the empty string`,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
// Valid because any string value is acceptable
|
|
30
|
-
if (!spec.enum) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
// has "enum"
|
|
34
|
-
const valid = spec.enum.includes(value.toLowerCase().trim());
|
|
35
|
-
if (valid) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
invalidType: 'invalid-value',
|
|
40
|
-
message: `The "${name}" attribute expect either "${spec.enum.join('", "')}"`,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (spec.type === 'Boolean') {
|
|
44
|
-
// Valid because an attribute is exist
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if (spec.type === 'Function') {
|
|
48
|
-
// TODO: To eval function-body string
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
if (spec.type === 'Date') {
|
|
52
|
-
// TODO: https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
if (spec.type === 'Int') {
|
|
56
|
-
if (intCheck(value)) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
invalidType: 'invalid-value',
|
|
61
|
-
message: `The "${name}" attribute expect integer`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (spec.type === 'Uint') {
|
|
65
|
-
if (uintCheck(value)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
invalidType: 'invalid-value',
|
|
70
|
-
message: `The "${name}" attribute expect non-negative integer`,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (spec.type === 'Float') {
|
|
74
|
-
if (floatCheck(value)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
invalidType: 'invalid-value',
|
|
79
|
-
message: `The "${name}" attribute expect floating-point number`,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (spec.type === 'NonZeroUint') {
|
|
83
|
-
if (nonZeroUintCheck(value)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
invalidType: 'invalid-value',
|
|
88
|
-
message: `The "${name}" attribute expect floating-point number`,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
if (spec.type === 'AcceptList') {
|
|
92
|
-
// TODO: https://html.spec.whatwg.org/multipage/input.html#attr-input-accept
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
if (spec.type === 'AutoComplete') {
|
|
96
|
-
// TODO: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
if (spec.type === 'BCP47') {
|
|
100
|
-
// TODO: https://tools.ietf.org/html/bcp47
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
if (spec.type === 'Color') {
|
|
104
|
-
// TODO: https://drafts.csswg.org/css-color/#typedef-color
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
if (spec.type === 'ColSpan') {
|
|
108
|
-
/**
|
|
109
|
-
* > value must be a valid non-negative integer greater than zero and less than or equal to 1000.
|
|
110
|
-
*
|
|
111
|
-
* @see https://html.spec.whatwg.org/multipage/tables.html#attr-tdth-colspan
|
|
112
|
-
*/
|
|
113
|
-
const i = parseInt(value);
|
|
114
|
-
if (intCheck(value) && 0 < i && i <= 1000) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
invalidType: 'invalid-value',
|
|
119
|
-
message: `The "${name}" attribute expect non-negative integer greater than zero and less than or equal to 1000`,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
if (spec.type === 'Coords') {
|
|
123
|
-
// TODO: https://html.spec.whatwg.org/multipage/image-maps.html#attr-area-coords
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
if (spec.type === 'DateTime') {
|
|
127
|
-
// TODO: https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
if (spec.type === 'Destination') {
|
|
131
|
-
// TODO: https://html.spec.whatwg.org/multipage/semantics.html#attr-link-as
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
if (spec.type === 'DOMID') {
|
|
135
|
-
// TODO: Searching ID in Document
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
if (spec.type === 'DOMIDList') {
|
|
139
|
-
// TODO: Searching ID in Document
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (spec.type === 'ItemType') {
|
|
143
|
-
// TODO: https://html.spec.whatwg.org/multipage/microdata.html#attr-itemtype
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
if (spec.type === 'LinkSizes') {
|
|
147
|
-
// TODO: https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
if (spec.type === 'LinkType') {
|
|
151
|
-
// TODO: https://html.spec.whatwg.org/multipage/links.html#linkTypes
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
if (spec.type === 'LinkTypeList') {
|
|
155
|
-
// TODO: https://html.spec.whatwg.org/multipage/links.html#linkTypes
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
if (spec.type === 'MediaQuery') {
|
|
159
|
-
// TODO: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-media-query-list
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
if (spec.type === 'MediaQueryList') {
|
|
163
|
-
// TODO: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-media-query-list
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
if (spec.type === 'MIMEType') {
|
|
167
|
-
// TODO: https://mimesniff.spec.whatwg.org/#valid-mime-type
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
if (spec.type === 'ReferrerPolicy') {
|
|
171
|
-
/**
|
|
172
|
-
* @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#referrer-policy-attributes
|
|
173
|
-
*/
|
|
174
|
-
const enumValues = [
|
|
175
|
-
'',
|
|
176
|
-
'no-referrer',
|
|
177
|
-
'no-referrer-when-downgrade',
|
|
178
|
-
'same-origin',
|
|
179
|
-
'origin',
|
|
180
|
-
'strict-origin',
|
|
181
|
-
'origin-when-cross-origin',
|
|
182
|
-
'strict-origin-when-cross-origin',
|
|
183
|
-
'unsafe-url',
|
|
184
|
-
];
|
|
185
|
-
const valid = enumValues.includes(value.toLowerCase());
|
|
186
|
-
if (valid) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
invalidType: 'invalid-value',
|
|
191
|
-
message: `The "${name}" attribute expect either "${enumValues.join('", "')}"`,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
if (spec.type === 'RowSpan') {
|
|
195
|
-
/**
|
|
196
|
-
* > value must be a valid non-negative integer less than or equal to 65534.
|
|
197
|
-
*
|
|
198
|
-
* @see https://html.spec.whatwg.org/multipage/tables.html#attr-tdth-rowspan
|
|
199
|
-
*/
|
|
200
|
-
const i = parseInt(value);
|
|
201
|
-
if (intCheck(value) && 0 <= i && i <= 65534) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
invalidType: 'invalid-value',
|
|
206
|
-
message: `The "${name}" attribute expect non-negative integer less than or equal to 65534`,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
if (spec.type === 'SourceSizeList') {
|
|
210
|
-
// TODO: https://html.spec.whatwg.org/multipage/images.html#sizes-attributes
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
if (spec.type === 'SrcSet') {
|
|
214
|
-
// TODO: https://html.spec.whatwg.org/multipage/images.html#srcset-attribute
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
if (spec.type === 'TabIndex') {
|
|
218
|
-
/**
|
|
219
|
-
* > ## omitted (or non-integer values)
|
|
220
|
-
* >
|
|
221
|
-
* > The user agent will decide whether the element is focusable, and if it is, whether it is sequentially focusable or click focusable (or both).
|
|
222
|
-
* >
|
|
223
|
-
* > ## −1 (or other negative integer values)
|
|
224
|
-
* >
|
|
225
|
-
* > Causes the element to be focusable, and indicates that the author would prefer the element to be click focusable but not sequentially focusable. The user agent might ignore this preference for click and sequential focusability, e.g., for specific element types according to platform conventions, or for keyboard-only users.
|
|
226
|
-
* >
|
|
227
|
-
* > ## 0
|
|
228
|
-
* >
|
|
229
|
-
* > Causes the element to be focusable, and indicates that the author would prefer the element to be both click focusable and sequentially focusable. The user agent might ignore this preference for click and sequential focusabiity.
|
|
230
|
-
* >
|
|
231
|
-
* > ## positive integer values
|
|
232
|
-
* >
|
|
233
|
-
* > Behaves the same as 0, but in addition creates a relative ordering within a tabindex-ordered focus navigation scope, so that elements with higher tabindex attribute value come later.
|
|
234
|
-
*
|
|
235
|
-
* @see https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex
|
|
236
|
-
*/
|
|
237
|
-
if (intCheck(value)) {
|
|
238
|
-
const i = parseInt(value);
|
|
239
|
-
if (-1 <= i) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
if (-1 > i) {
|
|
243
|
-
return {
|
|
244
|
-
invalidType: 'invalid-value',
|
|
245
|
-
message: 'Value is less than -1 behave the same as -1',
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
invalidType: 'invalid-value',
|
|
251
|
-
message: `The "${name}" attribute expect either -1, 0, positive integer`,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
if (spec.type === 'Target') {
|
|
255
|
-
// TODO: https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-target
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
if (spec.type === 'URL') {
|
|
259
|
-
/**
|
|
260
|
-
* @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces
|
|
261
|
-
*/
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
if (spec.type === 'URLHash') {
|
|
265
|
-
/**
|
|
266
|
-
* https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference
|
|
267
|
-
*/
|
|
268
|
-
const valid = value[0] === '#';
|
|
269
|
-
if (valid) {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
invalidType: 'invalid-value',
|
|
274
|
-
message: `The "${name}" attribute expect valid hash name reference`,
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (spec.type === 'URLList') {
|
|
278
|
-
/**
|
|
279
|
-
* @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces
|
|
280
|
-
*/
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
exports.typeCheck = typeCheck;
|
|
286
|
-
/**
|
|
287
|
-
* @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#signed-integers
|
|
288
|
-
*
|
|
289
|
-
* @param value
|
|
290
|
-
*/
|
|
291
|
-
function intCheck(value) {
|
|
292
|
-
return /^-?[0-9]+$/.test(value);
|
|
293
|
-
}
|
|
294
|
-
exports.intCheck = intCheck;
|
|
295
|
-
/**
|
|
296
|
-
* @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#non-negative-integers
|
|
297
|
-
*
|
|
298
|
-
* @param value
|
|
299
|
-
*/
|
|
300
|
-
function uintCheck(value) {
|
|
301
|
-
return /^[0-9]+$/.test(value);
|
|
302
|
-
}
|
|
303
|
-
exports.uintCheck = uintCheck;
|
|
304
|
-
/**
|
|
305
|
-
* @see https://html.spec.whatwg.org/dev/common-microsyntaxes.html#floating-point-numbers
|
|
306
|
-
*
|
|
307
|
-
* @param value
|
|
308
|
-
*/
|
|
309
|
-
function floatCheck(value) {
|
|
310
|
-
return value === value.trim() && Number.isFinite(parseFloat(value));
|
|
311
|
-
}
|
|
312
|
-
exports.floatCheck = floatCheck;
|
|
313
|
-
/**
|
|
314
|
-
* Non-negative integer greater than zero
|
|
315
|
-
*
|
|
316
|
-
* @param value
|
|
317
|
-
*/
|
|
318
|
-
function nonZeroUintCheck(value) {
|
|
319
|
-
return /^[0-9]+$/.test(value) && !/^0+$/.test(value);
|
|
320
|
-
}
|
|
321
|
-
exports.nonZeroUintCheck = nonZeroUintCheck;
|