@markuplint/rules 3.12.0 → 4.0.0-alpha.1
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/attr-check.js +14 -19
- package/lib/attr-duplication/index.js +3 -6
- package/lib/attr-value-quotes/index.js +5 -9
- package/lib/case-sensitive-attr-name/index.js +9 -13
- package/lib/case-sensitive-tag-name/index.js +2 -4
- package/lib/character-reference/index.js +6 -8
- package/lib/class-naming/index.js +9 -11
- package/lib/create-message.js +9 -16
- package/lib/debug.js +2 -6
- package/lib/deprecated-attr/index.js +6 -9
- package/lib/deprecated-element/index.js +3 -5
- package/lib/disallowed-element/index.js +2 -4
- package/lib/doctype/index.js +2 -4
- package/lib/end-tag/index.js +5 -8
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +17 -28
- package/lib/id-duplication/index.js +2 -4
- package/lib/index.d.ts +15 -15
- package/lib/index.js +63 -66
- package/lib/ineffective-attr/index.js +5 -7
- package/lib/invalid-attr/index.js +30 -33
- package/lib/label-has-control/index.js +2 -4
- package/lib/landmark-roles/index.js +3 -6
- package/lib/no-boolean-attr-value/index.js +6 -9
- package/lib/no-default-value/index.js +9 -12
- package/lib/no-empty-palpable-content/index.js +5 -7
- package/lib/no-hard-code-id/index.js +2 -4
- package/lib/no-refer-to-non-existent-id/index.js +26 -30
- package/lib/no-use-event-handler-attr/index.js +4 -6
- package/lib/permitted-contents/choice.d.ts +1 -1
- package/lib/permitted-contents/choice.js +13 -18
- package/lib/permitted-contents/complex-branch.d.ts +1 -1
- package/lib/permitted-contents/complex-branch.js +10 -14
- package/lib/permitted-contents/content-model.d.ts +1 -1
- package/lib/permitted-contents/content-model.js +5 -9
- package/lib/permitted-contents/count-pattern.d.ts +1 -1
- package/lib/permitted-contents/count-pattern.js +19 -24
- package/lib/permitted-contents/debug.browser.js +9 -12
- package/lib/permitted-contents/debug.d.ts +8 -1
- package/lib/permitted-contents/debug.js +12 -13
- package/lib/permitted-contents/index.d.ts +1 -1
- package/lib/permitted-contents/index.js +10 -13
- package/lib/permitted-contents/matches-selector.d.ts +1 -1
- package/lib/permitted-contents/matches-selector.js +12 -17
- package/lib/permitted-contents/order.d.ts +1 -1
- package/lib/permitted-contents/order.js +17 -22
- package/lib/permitted-contents/recursive-branch.d.ts +2 -2
- package/lib/permitted-contents/recursive-branch.js +9 -13
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +1 -1
- package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
- package/lib/permitted-contents/start.d.ts +1 -1
- package/lib/permitted-contents/start.js +13 -21
- package/lib/permitted-contents/transparent.d.ts +1 -1
- package/lib/permitted-contents/transparent.js +4 -9
- package/lib/permitted-contents/types.js +1 -2
- package/lib/permitted-contents/utils.d.ts +1 -1
- package/lib/permitted-contents/utils.js +55 -74
- package/lib/placeholder-label-option/index.js +5 -9
- package/lib/require-accessible-name/index.js +10 -13
- package/lib/require-datetime/index.d.ts +1 -1
- package/lib/require-datetime/index.js +6 -8
- package/lib/require-datetime/types.js +1 -2
- package/lib/require-datetime/utils.d.ts +1 -1
- package/lib/require-datetime/utils.js +4 -11
- package/lib/required-attr/index.js +8 -11
- package/lib/required-element/index.js +3 -6
- package/lib/required-h1/index.js +3 -6
- package/lib/use-list/index.js +6 -10
- package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
- package/lib/wai-aria/checkings/abstract-role.js +5 -10
- package/lib/wai-aria/checkings/default-value.d.ts +1 -1
- package/lib/wai-aria/checkings/default-value.js +2 -6
- package/lib/wai-aria/checkings/deprecated-props.d.ts +1 -1
- package/lib/wai-aria/checkings/deprecated-props.js +3 -8
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +1 -1
- package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
- package/lib/wai-aria/checkings/implicit-props.d.ts +1 -1
- package/lib/wai-aria/checkings/implicit-props.js +6 -11
- package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
- package/lib/wai-aria/checkings/implicit-role.js +4 -9
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
- package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
- package/lib/wai-aria/checkings/no-global-prop.d.ts +1 -1
- package/lib/wai-aria/checkings/no-global-prop.js +2 -7
- package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
- package/lib/wai-aria/checkings/non-existent-role.js +4 -9
- package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
- package/lib/wai-aria/checkings/permitted-roles.js +4 -9
- package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
- package/lib/wai-aria/checkings/presentational-children.js +4 -9
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +1 -1
- package/lib/wai-aria/checkings/required-owned-elements.js +4 -8
- package/lib/wai-aria/checkings/required-prop.d.ts +1 -1
- package/lib/wai-aria/checkings/required-prop.js +2 -7
- package/lib/wai-aria/checkings/value.d.ts +1 -1
- package/lib/wai-aria/checkings/value.js +4 -10
- package/lib/wai-aria/index.d.ts +1 -1
- package/lib/wai-aria/index.js +38 -40
- package/lib/wai-aria/types.js +1 -2
- package/package.json +17 -12
- package/test/attr-check.spec.js +0 -77
- package/test/attr-duplication/index.spec.js +0 -159
- package/test/attr-value-quotes/index.spec.js +0 -133
- package/test/case-sensitive-attr-name/index.spec.js +0 -65
- package/test/case-sensitive-tag-name/index.spec.js +0 -80
- package/test/character-reference/index.spec.js +0 -72
- package/test/class-naming/index.spec.js +0 -470
- package/test/create-message.spec.js +0 -497
- package/test/deprecated-attr/index.spec.js +0 -48
- package/test/deprecated-element/index.spec.js +0 -35
- package/test/disallowed-element/index.spec.js +0 -90
- package/test/doctype/index.spec.js +0 -50
- package/test/end-tag/index.spec.js +0 -162
- package/test/id-duplication/index.spec.js +0 -47
- package/test/ineffective-attr/index.spec.js +0 -31
- package/test/invalid-attr/index.spec.js +0 -1641
- package/test/label-has-control/index.spec.js +0 -29
- package/test/landmark-roles/index.spec.js +0 -187
- package/test/no-boolean-attr-value/index.spec.js +0 -41
- package/test/no-default-value/index.spec.js +0 -74
- package/test/no-empty-palpable-content/index.spec.js +0 -115
- package/test/no-hard-code-id/index.spec.js +0 -100
- package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
- package/test/no-use-event-handler-attr/index.spec.js +0 -57
- package/test/permitted-contents/choice.spec.js +0 -174
- package/test/permitted-contents/count-pattern.spec.js +0 -308
- package/test/permitted-contents/index.spec.js +0 -1395
- package/test/permitted-contents/matches-selector.spec.js +0 -59
- package/test/permitted-contents/order.spec.js +0 -351
- package/test/permitted-contents/recursive-branch.spec.js +0 -41
- package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
- package/test/permitted-contents/start.spec.js +0 -67
- package/test/placeholder-label-option/index.spec.js +0 -113
- package/test/require-accessible-name/index.spec.js +0 -444
- package/test/require-datetime/index.spec.js +0 -54
- package/test/require-datetime/utils.spec.js +0 -52
- package/test/required-attr/index.spec.js +0 -414
- package/test/required-element/index.spec.js +0 -188
- package/test/required-h1/index.spec.js +0 -69
- package/test/use-list/index.spec.js +0 -109
- package/test/wai-aria/checkings/value.spec.js +0 -33
- package/test/wai-aria/index.spec.js +0 -1203
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _Collection_locked, _Collection_matched, _Collection_nodes, _Collection_origin;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const debug_1 = require("./debug");
|
|
8
|
-
const represent_transparent_nodes_1 = require("./represent-transparent-nodes");
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { createSelector } from '@markuplint/selector';
|
|
4
|
+
import { bgGreen, green, bgRed, bgBlue, blue, bgMagenta, cyan } from './debug.js';
|
|
5
|
+
import { transparentMode } from './represent-transparent-nodes.js';
|
|
9
6
|
const getChildNodesWithoutWhitespacesCaches = new Map();
|
|
10
|
-
function getChildNodesWithoutWhitespaces(
|
|
7
|
+
export function getChildNodesWithoutWhitespaces(
|
|
11
8
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
12
9
|
el) {
|
|
13
10
|
let nodes = getChildNodesWithoutWhitespacesCaches.get(el);
|
|
@@ -20,8 +17,7 @@ el) {
|
|
|
20
17
|
getChildNodesWithoutWhitespacesCaches.set(el, nodes);
|
|
21
18
|
return nodes;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
function isModel(model) {
|
|
20
|
+
export function isModel(model) {
|
|
25
21
|
if (typeof model === 'string') {
|
|
26
22
|
return true;
|
|
27
23
|
}
|
|
@@ -37,11 +33,10 @@ function isModel(model) {
|
|
|
37
33
|
}
|
|
38
34
|
return modelMode;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
function matches(selector,
|
|
36
|
+
export function matches(selector,
|
|
42
37
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
38
|
node, specs) {
|
|
44
|
-
const selectorResult =
|
|
39
|
+
const selectorResult = createSelector(selector, specs).search(node);
|
|
45
40
|
const matched = selectorResult.filter((r) => r.matched);
|
|
46
41
|
if (matched.length > 0) {
|
|
47
42
|
return {
|
|
@@ -49,7 +44,7 @@ node, specs) {
|
|
|
49
44
|
};
|
|
50
45
|
}
|
|
51
46
|
const not = selectorResult
|
|
52
|
-
.map(r =>
|
|
47
|
+
.map(r => (r.matched ? [] : r.not ?? []))
|
|
53
48
|
.flat()
|
|
54
49
|
.map(descendants)
|
|
55
50
|
.flat()
|
|
@@ -59,7 +54,6 @@ node, specs) {
|
|
|
59
54
|
not,
|
|
60
55
|
};
|
|
61
56
|
}
|
|
62
|
-
exports.matches = matches;
|
|
63
57
|
function descendants(
|
|
64
58
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
65
59
|
selectorResult) {
|
|
@@ -77,32 +71,25 @@ selectorResult) {
|
|
|
77
71
|
}
|
|
78
72
|
return nodes;
|
|
79
73
|
}
|
|
80
|
-
function isRequire(content) {
|
|
74
|
+
export function isRequire(content) {
|
|
81
75
|
return 'require' in content;
|
|
82
76
|
}
|
|
83
|
-
|
|
84
|
-
function isOptional(content) {
|
|
77
|
+
export function isOptional(content) {
|
|
85
78
|
return 'optional' in content;
|
|
86
79
|
}
|
|
87
|
-
|
|
88
|
-
function isOneOrMore(content) {
|
|
80
|
+
export function isOneOrMore(content) {
|
|
89
81
|
return 'oneOrMore' in content;
|
|
90
82
|
}
|
|
91
|
-
|
|
92
|
-
function isZeroOrMore(content) {
|
|
83
|
+
export function isZeroOrMore(content) {
|
|
93
84
|
return 'zeroOrMore' in content;
|
|
94
85
|
}
|
|
95
|
-
|
|
96
|
-
function isChoice(content) {
|
|
86
|
+
export function isChoice(content) {
|
|
97
87
|
return 'choice' in content;
|
|
98
88
|
}
|
|
99
|
-
|
|
100
|
-
function isTransparent(content) {
|
|
89
|
+
export function isTransparent(content) {
|
|
101
90
|
return 'transparent' in content;
|
|
102
91
|
}
|
|
103
|
-
|
|
104
|
-
function normalizeModel(pattern) {
|
|
105
|
-
var _a, _b, _c, _d, _e;
|
|
92
|
+
export function normalizeModel(pattern) {
|
|
106
93
|
let model;
|
|
107
94
|
let min;
|
|
108
95
|
let max;
|
|
@@ -110,25 +97,25 @@ function normalizeModel(pattern) {
|
|
|
110
97
|
let missingType;
|
|
111
98
|
if (isRequire(pattern)) {
|
|
112
99
|
model = pattern.require;
|
|
113
|
-
min =
|
|
114
|
-
max = Math.max(
|
|
100
|
+
min = pattern.min ?? 1;
|
|
101
|
+
max = Math.max(pattern.max ?? 1, min);
|
|
115
102
|
missingType = 'MISSING_NODE_REQUIRED';
|
|
116
103
|
}
|
|
117
104
|
else if (isOptional(pattern)) {
|
|
118
105
|
model = pattern.optional;
|
|
119
106
|
min = 0;
|
|
120
|
-
max = Math.max(
|
|
107
|
+
max = Math.max(pattern.max ?? 1, 1);
|
|
121
108
|
}
|
|
122
109
|
else if (isOneOrMore(pattern)) {
|
|
123
110
|
model = pattern.oneOrMore;
|
|
124
111
|
min = 1;
|
|
125
|
-
max = Math.max(
|
|
112
|
+
max = Math.max(pattern.max ?? Infinity, 1);
|
|
126
113
|
missingType = 'MISSING_NODE_ONE_OR_MORE';
|
|
127
114
|
}
|
|
128
115
|
else if (isZeroOrMore(pattern)) {
|
|
129
116
|
model = pattern.zeroOrMore;
|
|
130
117
|
min = 0;
|
|
131
|
-
max = Math.max(
|
|
118
|
+
max = Math.max(pattern.max ?? Infinity, 1);
|
|
132
119
|
}
|
|
133
120
|
else {
|
|
134
121
|
throw new Error('Unreachable code');
|
|
@@ -156,21 +143,19 @@ function normalizeModel(pattern) {
|
|
|
156
143
|
missingType,
|
|
157
144
|
};
|
|
158
145
|
}
|
|
159
|
-
|
|
160
|
-
function mergeHints(
|
|
146
|
+
export function mergeHints(
|
|
161
147
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
162
148
|
a,
|
|
163
149
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
164
150
|
b) {
|
|
165
|
-
const missing = [a.missing, b.missing].sort((a, b) =>
|
|
151
|
+
const missing = [a.missing, b.missing].sort((a, b) => (b?.barelyMatchedElements ?? 0) - (a?.barelyMatchedElements ?? 0))[0];
|
|
166
152
|
return cleanObject({
|
|
167
153
|
...a,
|
|
168
154
|
...b,
|
|
169
155
|
missing: missing && cleanObject(missing),
|
|
170
156
|
});
|
|
171
157
|
}
|
|
172
|
-
|
|
173
|
-
function cleanObject(object) {
|
|
158
|
+
export function cleanObject(object) {
|
|
174
159
|
const newObject = {};
|
|
175
160
|
Object.entries(object).forEach(([key, value]) => {
|
|
176
161
|
if (value !== undefined) {
|
|
@@ -179,8 +164,7 @@ function cleanObject(object) {
|
|
|
179
164
|
});
|
|
180
165
|
return newObject;
|
|
181
166
|
}
|
|
182
|
-
|
|
183
|
-
class Collection {
|
|
167
|
+
export class Collection {
|
|
184
168
|
constructor(
|
|
185
169
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
186
170
|
origin) {
|
|
@@ -188,76 +172,76 @@ class Collection {
|
|
|
188
172
|
_Collection_matched.set(this, new Set());
|
|
189
173
|
_Collection_nodes.set(this, void 0);
|
|
190
174
|
_Collection_origin.set(this, void 0);
|
|
191
|
-
|
|
192
|
-
|
|
175
|
+
__classPrivateFieldSet(this, _Collection_origin, origin.slice(), "f");
|
|
176
|
+
__classPrivateFieldSet(this, _Collection_nodes, new Set(__classPrivateFieldGet(this, _Collection_origin, "f")), "f");
|
|
193
177
|
}
|
|
194
178
|
get matched() {
|
|
195
|
-
return Array.from(
|
|
179
|
+
return Array.from(__classPrivateFieldGet(this, _Collection_matched, "f"));
|
|
196
180
|
}
|
|
197
181
|
get matchedCount() {
|
|
198
|
-
return
|
|
182
|
+
return __classPrivateFieldGet(this, _Collection_matched, "f").size;
|
|
199
183
|
}
|
|
200
184
|
get nodes() {
|
|
201
|
-
return
|
|
185
|
+
return __classPrivateFieldGet(this, _Collection_origin, "f").slice();
|
|
202
186
|
}
|
|
203
187
|
get unmatched() {
|
|
204
|
-
return Array.from(
|
|
188
|
+
return Array.from(__classPrivateFieldGet(this, _Collection_nodes, "f")).filter(n => !__classPrivateFieldGet(this, _Collection_matched, "f").has(n));
|
|
205
189
|
}
|
|
206
190
|
addMatched(
|
|
207
191
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
208
192
|
nodes) {
|
|
209
|
-
const i =
|
|
193
|
+
const i = __classPrivateFieldGet(this, _Collection_matched, "f").size;
|
|
210
194
|
for (const node of nodes) {
|
|
211
|
-
if (!
|
|
195
|
+
if (!__classPrivateFieldGet(this, _Collection_nodes, "f").has(node)) {
|
|
212
196
|
throw new ReferenceError(`External Node: ${node.nodeName}`);
|
|
213
197
|
}
|
|
214
|
-
|
|
198
|
+
__classPrivateFieldGet(this, _Collection_matched, "f").add(node);
|
|
215
199
|
}
|
|
216
|
-
return i <
|
|
200
|
+
return i < __classPrivateFieldGet(this, _Collection_matched, "f").size;
|
|
217
201
|
}
|
|
218
202
|
back() {
|
|
219
|
-
|
|
203
|
+
__classPrivateFieldSet(this, _Collection_matched, new Set(__classPrivateFieldGet(this, _Collection_locked, "f")), "f");
|
|
220
204
|
}
|
|
221
205
|
lock() {
|
|
222
|
-
|
|
206
|
+
__classPrivateFieldSet(this, _Collection_locked, new Set(__classPrivateFieldGet(this, _Collection_matched, "f")), "f");
|
|
223
207
|
}
|
|
224
208
|
max(max) {
|
|
225
|
-
const sliced = Array.from(
|
|
226
|
-
sliced.forEach(n =>
|
|
209
|
+
const sliced = Array.from(__classPrivateFieldGet(this, _Collection_matched, "f")).slice(max);
|
|
210
|
+
sliced.forEach(n => __classPrivateFieldGet(this, _Collection_matched, "f").delete(n));
|
|
227
211
|
}
|
|
228
212
|
toString(highlightExtraNodes = false) {
|
|
229
213
|
const out = [];
|
|
230
|
-
for (const n of
|
|
214
|
+
for (const n of __classPrivateFieldGet(this, _Collection_origin, "f")) {
|
|
231
215
|
const raw = n.is(n.TEXT_NODE) ? `:text(${n.raw.replace(/\n/g, '\\n')})` : n.raw;
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
234
|
-
out.push(
|
|
216
|
+
if (__classPrivateFieldGet(this, _Collection_locked, "f").has(n)) {
|
|
217
|
+
if (transparentMode.has(n)) {
|
|
218
|
+
out.push(bgBlue.bold(raw));
|
|
235
219
|
}
|
|
236
220
|
else {
|
|
237
|
-
out.push(
|
|
221
|
+
out.push(bgGreen.bold(raw));
|
|
238
222
|
}
|
|
239
223
|
continue;
|
|
240
224
|
}
|
|
241
|
-
if (
|
|
242
|
-
if (
|
|
243
|
-
out.push(
|
|
225
|
+
if (__classPrivateFieldGet(this, _Collection_matched, "f").has(n)) {
|
|
226
|
+
if (transparentMode.has(n)) {
|
|
227
|
+
out.push(blue.bold(raw));
|
|
244
228
|
}
|
|
245
229
|
else {
|
|
246
|
-
out.push(
|
|
230
|
+
out.push(green.bold(raw));
|
|
247
231
|
}
|
|
248
232
|
continue;
|
|
249
233
|
}
|
|
250
234
|
if (highlightExtraNodes) {
|
|
251
|
-
if (
|
|
252
|
-
out.push(
|
|
235
|
+
if (transparentMode.has(n)) {
|
|
236
|
+
out.push(bgMagenta.bold(raw));
|
|
253
237
|
}
|
|
254
238
|
else {
|
|
255
|
-
out.push(
|
|
239
|
+
out.push(bgRed.bold(raw));
|
|
256
240
|
}
|
|
257
241
|
continue;
|
|
258
242
|
}
|
|
259
|
-
if (
|
|
260
|
-
out.push(
|
|
243
|
+
if (transparentMode.has(n)) {
|
|
244
|
+
out.push(cyan(raw));
|
|
261
245
|
}
|
|
262
246
|
else {
|
|
263
247
|
out.push(raw);
|
|
@@ -266,12 +250,10 @@ class Collection {
|
|
|
266
250
|
return `[ ${out.join(', ')} ]`;
|
|
267
251
|
}
|
|
268
252
|
}
|
|
269
|
-
exports.Collection = Collection;
|
|
270
253
|
_Collection_locked = new WeakMap(), _Collection_matched = new WeakMap(), _Collection_nodes = new WeakMap(), _Collection_origin = new WeakMap();
|
|
271
|
-
class UnsupportedError extends Error {
|
|
254
|
+
export class UnsupportedError extends Error {
|
|
272
255
|
}
|
|
273
|
-
|
|
274
|
-
function modelLog(model, repeat) {
|
|
256
|
+
export function modelLog(model, repeat) {
|
|
275
257
|
if (!isModel(model)) {
|
|
276
258
|
return orderLog(model, repeat);
|
|
277
259
|
}
|
|
@@ -280,7 +262,6 @@ function modelLog(model, repeat) {
|
|
|
280
262
|
}
|
|
281
263
|
return `(<${model.join('>|<')}>)${repeat}`;
|
|
282
264
|
}
|
|
283
|
-
exports.modelLog = modelLog;
|
|
284
265
|
function orderLog(order, repeat) {
|
|
285
266
|
return order.length === 1 && order[0]
|
|
286
267
|
? markRepeat(patternLog(order[0]), repeat)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
export default createRule({
|
|
5
3
|
verify({ document, report, t }) {
|
|
6
4
|
document.querySelectorAll('select').forEach(select => {
|
|
7
5
|
if (hasPlaceholderLabelOption(select)) {
|
|
@@ -29,7 +27,6 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
29
27
|
function needPlaceholderLabelOption(
|
|
30
28
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
31
29
|
select) {
|
|
32
|
-
var _a;
|
|
33
30
|
const hasRequired = select.hasAttribute('required');
|
|
34
31
|
if (!hasRequired) {
|
|
35
32
|
return false;
|
|
@@ -38,7 +35,7 @@ select) {
|
|
|
38
35
|
if (hasMultiple) {
|
|
39
36
|
return false;
|
|
40
37
|
}
|
|
41
|
-
const size =
|
|
38
|
+
const size = select.getAttribute('size') ?? '1';
|
|
42
39
|
if (size !== '1') {
|
|
43
40
|
return false;
|
|
44
41
|
}
|
|
@@ -59,7 +56,6 @@ select) {
|
|
|
59
56
|
function hasPlaceholderLabelOption(
|
|
60
57
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
61
58
|
select) {
|
|
62
|
-
var _a, _b;
|
|
63
59
|
// > has a required attribute specified
|
|
64
60
|
if (!select.hasAttribute('required')) {
|
|
65
61
|
return false;
|
|
@@ -69,7 +65,7 @@ select) {
|
|
|
69
65
|
return false;
|
|
70
66
|
}
|
|
71
67
|
// > has a display size of 1
|
|
72
|
-
const size =
|
|
68
|
+
const size = select.getAttribute('size') ?? '1';
|
|
73
69
|
if (size !== '1') {
|
|
74
70
|
return false;
|
|
75
71
|
}
|
|
@@ -80,7 +76,7 @@ select) {
|
|
|
80
76
|
return true;
|
|
81
77
|
}
|
|
82
78
|
// > that option element's parent node is the select element (and not an optgroup element)
|
|
83
|
-
if (
|
|
79
|
+
if (firstOption.parentElement?.localName === 'optgroup') {
|
|
84
80
|
return false;
|
|
85
81
|
}
|
|
86
82
|
const value = firstOption.getAttribute('value');
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const helpers_1 = require("../helpers");
|
|
6
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule, getRoleSpec, getComputedRole } from '@markuplint/ml-core';
|
|
2
|
+
import { ARIA_RECOMMENDED_VERSION, isExposed } from '@markuplint/ml-spec';
|
|
3
|
+
import { accnameMayBeMutable } from '../helpers.js';
|
|
4
|
+
export default createRule({
|
|
7
5
|
defaultOptions: {
|
|
8
|
-
ariaVersion:
|
|
6
|
+
ariaVersion: ARIA_RECOMMENDED_VERSION,
|
|
9
7
|
},
|
|
10
8
|
async verify({ document, report, t }) {
|
|
11
9
|
await document.walkOn('Element', el => {
|
|
12
|
-
|
|
13
|
-
if (((_a = el.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender') {
|
|
10
|
+
if (el.pretenderContext?.type === 'pretender') {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
|
-
if (
|
|
13
|
+
if (accnameMayBeMutable(el, document)) {
|
|
17
14
|
return;
|
|
18
15
|
}
|
|
19
|
-
if (!
|
|
16
|
+
if (!isExposed(el, document.specs, el.rule.options.ariaVersion)) {
|
|
20
17
|
return;
|
|
21
18
|
}
|
|
22
|
-
const computed =
|
|
19
|
+
const computed = getComputedRole(document.specs, el, el.rule.options.ariaVersion);
|
|
23
20
|
if (!computed.role) {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
26
|
-
const roleSpec =
|
|
23
|
+
const roleSpec = getRoleSpec(document.specs, computed.role.name, el.namespaceURI, el.rule.options.ariaVersion);
|
|
27
24
|
if (!roleSpec || !roleSpec.accessibleNameRequired) {
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
import { check } from '@markuplint/types';
|
|
3
|
+
import { getCandidateDatetimeString } from './utils.js';
|
|
4
|
+
export default createRule({
|
|
7
5
|
defaultOptions: {
|
|
8
6
|
langs: undefined,
|
|
9
7
|
},
|
|
@@ -13,11 +11,11 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
13
11
|
return;
|
|
14
12
|
}
|
|
15
13
|
const content = time.textContent.trim();
|
|
16
|
-
const result =
|
|
14
|
+
const result = check(content, 'DateTime');
|
|
17
15
|
if (result.matched) {
|
|
18
16
|
return;
|
|
19
17
|
}
|
|
20
|
-
const candidate =
|
|
18
|
+
const candidate = getCandidateDatetimeString(content, time.rule.options.langs);
|
|
21
19
|
if (candidate) {
|
|
22
20
|
report({
|
|
23
21
|
scope: time,
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCandidateDatetimeString = exports.parseADatetime = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const chrono = tslib_1.__importStar(require("chrono-node"));
|
|
1
|
+
import * as chrono from 'chrono-node';
|
|
6
2
|
const defaultLangs = ['en', 'ja', 'fr', 'nl', 'ru', 'de', 'pt', 'zh'];
|
|
7
3
|
/**
|
|
8
4
|
* Datetime-ish text to a datetime data
|
|
@@ -12,8 +8,7 @@ const defaultLangs = ['en', 'ja', 'fr', 'nl', 'ru', 'de', 'pt', 'zh'];
|
|
|
12
8
|
* @param base Reference date for a test
|
|
13
9
|
* @returns
|
|
14
10
|
*/
|
|
15
|
-
function parseADatetime(content, langs, base) {
|
|
16
|
-
var _a;
|
|
11
|
+
export function parseADatetime(content, langs, base) {
|
|
17
12
|
const date = parseTryMultipleLangs(content, langs, base);
|
|
18
13
|
if (!date) {
|
|
19
14
|
return null;
|
|
@@ -32,7 +27,7 @@ function parseADatetime(content, langs, base) {
|
|
|
32
27
|
data.hour = date.get('hour');
|
|
33
28
|
}
|
|
34
29
|
if (date.isCertain('hour')) {
|
|
35
|
-
data.minute =
|
|
30
|
+
data.minute = date.get('minute') ?? 0;
|
|
36
31
|
}
|
|
37
32
|
if (date.isCertain('second')) {
|
|
38
33
|
data.second = date.get('second');
|
|
@@ -48,8 +43,7 @@ function parseADatetime(content, langs, base) {
|
|
|
48
43
|
}
|
|
49
44
|
return datetime;
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
function getCandidateDatetimeString(content, langs = defaultLangs) {
|
|
46
|
+
export function getCandidateDatetimeString(content, langs = defaultLangs) {
|
|
53
47
|
const date = parseADatetime(content, langs);
|
|
54
48
|
if (!date) {
|
|
55
49
|
return null;
|
|
@@ -66,7 +60,6 @@ function getCandidateDatetimeString(content, langs = defaultLangs) {
|
|
|
66
60
|
}
|
|
67
61
|
return datetimeStr;
|
|
68
62
|
}
|
|
69
|
-
exports.getCandidateDatetimeString = getCandidateDatetimeString;
|
|
70
63
|
function toDatetimeString(date) {
|
|
71
64
|
if (only(date, ['year', 'month'])) {
|
|
72
65
|
return `${f(date.year, 4)}-${f(date.month, 2)}`;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const helpers_1 = require("../helpers");
|
|
5
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule, getAttrSpecs } from '@markuplint/ml-core';
|
|
2
|
+
import { attrMatches, match } from '../helpers.js';
|
|
3
|
+
export default createRule({
|
|
6
4
|
defaultValue: [],
|
|
7
5
|
async verify({ document, report, t }) {
|
|
8
6
|
await document.walkOn('Element', el => {
|
|
9
|
-
var _a;
|
|
10
7
|
if (el.hasSpreadAttr) {
|
|
11
8
|
return;
|
|
12
9
|
}
|
|
13
10
|
const customRequiredAttrs = typeof el.rule.value === 'string' ? [el.rule.value] : el.rule.value;
|
|
14
|
-
const attrSpec =
|
|
11
|
+
const attrSpec = getAttrSpecs(el, document.specs);
|
|
15
12
|
const attributeSpecs = {};
|
|
16
13
|
if (attrSpec && el.elementType === 'html') {
|
|
17
14
|
for (const spec of attrSpec) {
|
|
@@ -52,7 +49,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
52
49
|
invalid = !candidate.some(attrName => el.hasAttribute(attrName));
|
|
53
50
|
}
|
|
54
51
|
else if (spec.required === true) {
|
|
55
|
-
invalid =
|
|
52
|
+
invalid = attrMatches(el, spec.condition) && didntHave;
|
|
56
53
|
}
|
|
57
54
|
else if (spec.required != null && spec.required !== false) {
|
|
58
55
|
const selector = typeof spec.required === 'string' ? spec.required : spec.required.join(',');
|
|
@@ -67,13 +64,13 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
67
64
|
}
|
|
68
65
|
const value = el.getAttribute(spec.name);
|
|
69
66
|
if (spec.values.length > 0 && value) {
|
|
70
|
-
const matched = spec.values.some(pattern =>
|
|
67
|
+
const matched = spec.values.some(pattern => match(value, pattern));
|
|
71
68
|
if (!matched) {
|
|
72
69
|
const expects = spec.values.length === 1 ? t(spec.values) : t('either {0}', t(spec.values));
|
|
73
70
|
const message = t('{0} expects {1}', t('the "{0*}" {1}', spec.name, 'attribute'), expects);
|
|
74
71
|
const attrToken = el.getAttributeToken(spec.name);
|
|
75
|
-
const valueToken =
|
|
76
|
-
const token = valueToken
|
|
72
|
+
const valueToken = attrToken[0]?.valueNode;
|
|
73
|
+
const token = valueToken ?? attrToken[0];
|
|
77
74
|
if (token) {
|
|
78
75
|
report({
|
|
79
76
|
scope: {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
export default createRule({
|
|
5
3
|
defaultValue: [],
|
|
6
4
|
defaultOptions: {
|
|
7
5
|
ignoreHasMutableContents: true,
|
|
8
6
|
},
|
|
9
7
|
async verify({ document, report, t }) {
|
|
10
|
-
var _a, _b;
|
|
11
8
|
const hasMutableContent = document.nodeList.some(n => n.is(n.ELEMENT_NODE) && n.hasMutableChildren());
|
|
12
9
|
if (!hasMutableContent) {
|
|
13
10
|
for (const query of document.rule.value) {
|
|
@@ -18,7 +15,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
18
15
|
message,
|
|
19
16
|
line: 1,
|
|
20
17
|
col: 1,
|
|
21
|
-
raw:
|
|
18
|
+
raw: document.nodeList[0]?.raw.slice(0, 1) ?? '',
|
|
22
19
|
});
|
|
23
20
|
}
|
|
24
21
|
}
|
package/lib/required-h1/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
export default createRule({
|
|
5
3
|
defaultOptions: {
|
|
6
4
|
'expected-once': true,
|
|
7
5
|
'in-document-fragment': false,
|
|
8
6
|
},
|
|
9
7
|
async verify({ document, report, t }) {
|
|
10
|
-
var _a, _b;
|
|
11
8
|
const h1Stack = [];
|
|
12
9
|
if (document.nodeList.length === 0) {
|
|
13
10
|
return;
|
|
@@ -26,7 +23,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
26
23
|
message,
|
|
27
24
|
line: 1,
|
|
28
25
|
col: 1,
|
|
29
|
-
raw:
|
|
26
|
+
raw: document.nodeList[0]?.raw.slice(0, 1) ?? '',
|
|
30
27
|
});
|
|
31
28
|
}
|
|
32
29
|
else if (document.rule.options['expected-once'] && h1Stack.length > 1 && h1Stack[1]) {
|
package/lib/use-list/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const shared_1 = require("@markuplint/shared");
|
|
5
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
import { decodeEntities } from '@markuplint/shared';
|
|
3
|
+
export default createRule({
|
|
6
4
|
defaultValue: [
|
|
7
5
|
/**
|
|
8
6
|
* @see https://en.wikipedia.org/wiki/Bullet_(typography)#In_Unicode
|
|
@@ -57,8 +55,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
57
55
|
defaultSeverity: 'warning',
|
|
58
56
|
async verify({ document, report, t }) {
|
|
59
57
|
await document.walkOn('Text', textNode => {
|
|
60
|
-
|
|
61
|
-
const text = (0, shared_1.decodeEntities)(textNode.raw.trim());
|
|
58
|
+
const text = decodeEntities(textNode.raw.trim());
|
|
62
59
|
if (!text) {
|
|
63
60
|
// empty
|
|
64
61
|
return;
|
|
@@ -68,7 +65,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
68
65
|
return;
|
|
69
66
|
}
|
|
70
67
|
const bullets = textNode.rule.value;
|
|
71
|
-
const spaceNeededBullets =
|
|
68
|
+
const spaceNeededBullets = textNode.rule.options.spaceNeededBullets ?? [];
|
|
72
69
|
if (isMayListItem(text, bullets, spaceNeededBullets)) {
|
|
73
70
|
report({
|
|
74
71
|
scope: textNode,
|
|
@@ -79,9 +76,8 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
79
76
|
},
|
|
80
77
|
});
|
|
81
78
|
function isMayListItem(text, bullets, spaceNeededBullets) {
|
|
82
|
-
var _a;
|
|
83
79
|
const textArray = Array.from(text);
|
|
84
|
-
const firstLetter =
|
|
80
|
+
const firstLetter = textArray[0] ?? '';
|
|
85
81
|
const isBullet = bullets.includes(firstLetter);
|
|
86
82
|
const needSpace = spaceNeededBullets.includes(firstLetter);
|
|
87
83
|
const continuous = firstLetter === textArray[1];
|