@markuplint/rules 3.0.0-alpha.0 → 3.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/README.md +1 -1
- package/lib/attr-check.js +1 -1
- package/lib/attr-duplication/index.js +1 -1
- package/lib/attr-value-quotes/index.js +1 -1
- package/lib/case-sensitive-attr-name/index.js +3 -3
- package/lib/case-sensitive-tag-name/index.js +3 -3
- package/lib/class-naming/index.js +1 -1
- package/lib/create-message.d.ts +1 -1
- package/lib/create-message.js +5 -5
- package/lib/deprecated-element/index.js +2 -2
- package/lib/doctype/index.d.ts +1 -1
- package/lib/doctype/index.js +1 -1
- package/lib/end-tag/index.js +1 -1
- package/lib/helpers.d.ts +7 -2
- package/lib/helpers.js +17 -11
- package/lib/index.d.ts +2 -6
- package/lib/ineffective-attr/index.js +1 -1
- package/lib/invalid-attr/index.js +3 -3
- package/lib/landmark-roles/index.js +1 -1
- package/lib/no-boolean-attr-value/index.js +1 -1
- package/lib/no-default-value/index.js +1 -1
- package/lib/no-hard-code-id/index.js +1 -1
- package/lib/no-use-event-handler-attr/index.js +2 -2
- package/lib/permitted-contents/choice.d.ts +3 -0
- package/lib/permitted-contents/choice.js +37 -0
- package/lib/permitted-contents/complex-branch.d.ts +13 -0
- package/lib/permitted-contents/complex-branch.js +27 -0
- package/lib/permitted-contents/content-model.d.ts +2 -0
- package/lib/permitted-contents/content-model.js +49 -0
- package/lib/permitted-contents/count-pattern.d.ts +13 -0
- package/lib/permitted-contents/count-pattern.js +155 -0
- package/lib/permitted-contents/debug.d.ts +2 -0
- package/lib/permitted-contents/debug.js +5 -0
- package/lib/permitted-contents/index.d.ts +1 -7
- package/lib/permitted-contents/index.js +75 -245
- package/lib/permitted-contents/matches-selector.d.ts +3 -0
- package/lib/permitted-contents/matches-selector.js +185 -0
- package/lib/permitted-contents/order.d.ts +13 -0
- package/lib/permitted-contents/order.js +89 -0
- package/lib/permitted-contents/recursive-branch.d.ts +4 -0
- package/lib/permitted-contents/recursive-branch.js +43 -0
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +6 -0
- package/lib/permitted-contents/represent-transparent-nodes.js +79 -0
- package/lib/permitted-contents/start.d.ts +12 -0
- package/lib/permitted-contents/start.js +71 -0
- package/lib/permitted-contents/transparent.d.ts +2 -0
- package/lib/permitted-contents/transparent.js +34 -0
- package/lib/permitted-contents/types.d.ts +45 -0
- package/lib/permitted-contents/types.js +2 -0
- package/lib/permitted-contents/utils.d.ts +32 -0
- package/lib/permitted-contents/utils.js +184 -0
- package/lib/require-accessible-name/index.js +5 -1
- package/lib/required-attr/index.js +1 -1
- package/lib/use-list/index.js +2 -2
- package/lib/wai-aria/checkings/implicit-role.js +2 -2
- package/lib/wai-aria/index.js +1 -1
- package/package.json +8 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/__foo/index.d.ts +0 -2
- package/lib/__foo/index.js +0 -46
- package/lib/attr-equal-space-after/index.d.ts +0 -3
- package/lib/attr-equal-space-after/index.js +0 -90
- package/lib/attr-equal-space-before/index.d.ts +0 -3
- package/lib/attr-equal-space-before/index.js +0 -90
- package/lib/attr-spacing/index.d.ts +0 -6
- package/lib/attr-spacing/index.js +0 -100
- package/lib/helper/aria/get-aria.d.ts +0 -7
- package/lib/helper/aria/get-aria.js +0 -53
- package/lib/helper/aria/get-computed-role.d.ts +0 -10
- package/lib/helper/aria/get-computed-role.js +0 -24
- package/lib/helper/aria/get-implicit-role.d.ts +0 -7
- package/lib/helper/aria/get-implicit-role.js +0 -12
- package/lib/helper/aria/get-permitted-roles.d.ts +0 -14
- package/lib/helper/aria/get-permitted-roles.js +0 -26
- package/lib/helper/aria/resolve-version.d.ts +0 -2
- package/lib/helper/aria/resolve-version.js +0 -21
- package/lib/helper/spec/aria-spec.d.ts +0 -5
- package/lib/helper/spec/aria-spec.js +0 -12
- package/lib/helper/spec/get-role-spec.d.ts +0 -11
- package/lib/helper/spec/get-role-spec.js +0 -39
- package/lib/helper/spec/html-spec.d.ts +0 -2
- package/lib/helper/spec/html-spec.js +0 -14
- package/lib/indentation/index.d.ts +0 -7
- package/lib/indentation/index.js +0 -208
- package/lib/permitted-contents/array.combination.d.ts +0 -1
- package/lib/permitted-contents/array.combination.js +0 -33
- package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +0 -11
- package/lib/permitted-contents/permitted-content.spec-to-regexp.js +0 -230
- package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +0 -2
- package/lib/permitted-contents/unfold-content-models-to-tags.js +0 -8
- package/lib/wai-aria/checkings/checking-required-owned-elements.d.ts +0 -11
- package/lib/wai-aria/checkings/checking-required-owned-elements.js +0 -63
package/lib/indentation/index.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
5
|
-
defaultServerity: 'warning',
|
|
6
|
-
defaultValue: 2,
|
|
7
|
-
defaultOptions: {
|
|
8
|
-
alignment: true,
|
|
9
|
-
'indent-nested-nodes': true,
|
|
10
|
-
},
|
|
11
|
-
async verify(context) {
|
|
12
|
-
await context.document.walk(node => {
|
|
13
|
-
if (node.rule.disabled) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const indent = (0, ml_core_1.getIndent)(node);
|
|
17
|
-
if (indent) {
|
|
18
|
-
/**
|
|
19
|
-
* Validate indent type and length.
|
|
20
|
-
*/
|
|
21
|
-
if (indent.type !== 'none') {
|
|
22
|
-
const ms = node.rule.severity === 'error' ? 'must' : 'should';
|
|
23
|
-
let spec = null;
|
|
24
|
-
if (node.rule.value === 'tab' && indent.type !== 'tab') {
|
|
25
|
-
spec = 'tab';
|
|
26
|
-
}
|
|
27
|
-
else if (typeof node.rule.value === 'number' && indent.type !== 'space') {
|
|
28
|
-
spec = 'space';
|
|
29
|
-
}
|
|
30
|
-
else if (typeof node.rule.value === 'number' &&
|
|
31
|
-
indent.type === 'space' &&
|
|
32
|
-
indent.width % node.rule.value) {
|
|
33
|
-
spec = context.translate('{0} width spaces', `${node.rule.value}`);
|
|
34
|
-
}
|
|
35
|
-
if (spec) {
|
|
36
|
-
const message = context.translate(`{0} ${ms} be {1}`, 'Indentation', spec);
|
|
37
|
-
context.report({
|
|
38
|
-
scope: node,
|
|
39
|
-
message,
|
|
40
|
-
line: indent.line,
|
|
41
|
-
col: 1,
|
|
42
|
-
raw: indent.raw,
|
|
43
|
-
});
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Validate nested parent-children nodes.
|
|
49
|
-
*/
|
|
50
|
-
const nested = node.rule.option['indent-nested-nodes'];
|
|
51
|
-
if (!nested) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const parent = node.syntaxicalParentNode;
|
|
55
|
-
if (parent) {
|
|
56
|
-
const parentIndent = (0, ml_core_1.getIndent)(parent);
|
|
57
|
-
const parentIndentWidth = parentIndent ? parentIndent.width : 0;
|
|
58
|
-
const childIndentWidth = indent.width;
|
|
59
|
-
const expectedWidth = node.rule.value === 'tab' ? 1 : node.rule.value;
|
|
60
|
-
const diff = childIndentWidth - parentIndentWidth;
|
|
61
|
-
if (nested === 'never') {
|
|
62
|
-
if (diff !== 0) {
|
|
63
|
-
const message = context.translate(diff < 1 ? 'Should increase indentation' : 'Should decrease indentation');
|
|
64
|
-
context.report({
|
|
65
|
-
scope: node,
|
|
66
|
-
message,
|
|
67
|
-
line: indent.line,
|
|
68
|
-
col: 1,
|
|
69
|
-
raw: indent.raw,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
if (diff !== expectedWidth) {
|
|
75
|
-
const message = context.translate(diff < 1 ? 'Should increase indentation' : 'Should decrease indentation');
|
|
76
|
-
context.report({
|
|
77
|
-
scope: node,
|
|
78
|
-
message,
|
|
79
|
-
line: indent.line,
|
|
80
|
-
col: 1,
|
|
81
|
-
raw: indent.raw,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Validate alignment end-tags.
|
|
89
|
-
*/
|
|
90
|
-
if (node instanceof ml_core_1.ElementCloseTag) {
|
|
91
|
-
const closeTag = node;
|
|
92
|
-
const startTag = closeTag.startTag;
|
|
93
|
-
if (!closeTag.rule.option.alignment) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const closeTagIndent = (0, ml_core_1.getIndent)(closeTag);
|
|
97
|
-
if (!closeTagIndent) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
if (startTag.endLine === closeTag.endLine) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const startTagIndent = (0, ml_core_1.getIndent)(startTag);
|
|
104
|
-
const endTagIndentationWidth = closeTagIndent ? closeTagIndent.width : 0;
|
|
105
|
-
const startTagIndentationWidth = startTagIndent ? startTagIndent.width : 0;
|
|
106
|
-
if (startTagIndentationWidth !== endTagIndentationWidth) {
|
|
107
|
-
const message = context.translate('Start tag and end tag indentation should align');
|
|
108
|
-
context.report({
|
|
109
|
-
scope: closeTag,
|
|
110
|
-
message,
|
|
111
|
-
line: closeTagIndent ? closeTagIndent.line : closeTag.startLine,
|
|
112
|
-
col: 1,
|
|
113
|
-
raw: closeTagIndent ? closeTagIndent.raw : '',
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
async fix({ document }) {
|
|
120
|
-
/**
|
|
121
|
-
* Validate indent type and length.
|
|
122
|
-
*/
|
|
123
|
-
await document.walk(node => {
|
|
124
|
-
const indent = (0, ml_core_1.getIndent)(node);
|
|
125
|
-
if (!node.rule.disabled && indent) {
|
|
126
|
-
if (indent.type !== 'none') {
|
|
127
|
-
const spec = node.rule.value === 'tab' ? '\t' : ' ';
|
|
128
|
-
const baseWidth = node.rule.value === 'tab' ? 4 : node.rule.value;
|
|
129
|
-
let width;
|
|
130
|
-
if (node.rule.value === 'tab') {
|
|
131
|
-
width = indent.type === 'tab' ? indent.width : Math.ceil(indent.width / baseWidth);
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
width =
|
|
135
|
-
indent.type === 'tab'
|
|
136
|
-
? indent.width * baseWidth
|
|
137
|
-
: Math.ceil(indent.width / baseWidth) * baseWidth;
|
|
138
|
-
}
|
|
139
|
-
const raw = indent.raw;
|
|
140
|
-
const fixed = spec.repeat(width);
|
|
141
|
-
if (raw !== fixed) {
|
|
142
|
-
indent.fix(fixed);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
await document.walk(node => {
|
|
148
|
-
if (node.rule.disabled) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const indent = (0, ml_core_1.getIndent)(node);
|
|
152
|
-
if (indent) {
|
|
153
|
-
/**
|
|
154
|
-
* Validate nested parent-children nodes.
|
|
155
|
-
*/
|
|
156
|
-
const nested = node.rule.option['indent-nested-nodes'];
|
|
157
|
-
if (!nested) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const parent = node.syntaxicalParentNode;
|
|
161
|
-
if (!parent) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const parentIndent = (0, ml_core_1.getIndent)(parent);
|
|
165
|
-
if (!parentIndent) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const parentIndentWidth = parentIndent.width;
|
|
169
|
-
const childIndentWidth = indent.width;
|
|
170
|
-
const expectedWidth = node.rule.value === 'tab' ? 1 : node.rule.value;
|
|
171
|
-
const diff = childIndentWidth - parentIndentWidth;
|
|
172
|
-
if (nested === 'never') {
|
|
173
|
-
if (diff !== 0) {
|
|
174
|
-
const fixed = parentIndent.raw;
|
|
175
|
-
indent.fix(fixed);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
if (diff !== expectedWidth) {
|
|
180
|
-
const fixed = (node.rule.value === 'tab' ? '\t' : ' ').repeat(parentIndentWidth + expectedWidth);
|
|
181
|
-
indent.fix(fixed);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
/**
|
|
187
|
-
* Validate alignment end-tags.
|
|
188
|
-
*/
|
|
189
|
-
await document.walkOn('ElementCloseTag', endTag => {
|
|
190
|
-
if (!endTag.rule || !endTag.rule.option) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (!endTag.rule.option.alignment) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const endTagIndent = (0, ml_core_1.getIndent)(endTag);
|
|
197
|
-
const startTagIndent = (0, ml_core_1.getIndent)(endTag.startTag);
|
|
198
|
-
if (endTagIndent && startTagIndent) {
|
|
199
|
-
const endTagIndentationWidth = endTagIndent.width;
|
|
200
|
-
const startTagIndentationWidth = startTagIndent.width;
|
|
201
|
-
if (startTagIndentationWidth !== endTagIndentationWidth) {
|
|
202
|
-
const fixed = startTagIndent.raw;
|
|
203
|
-
endTagIndent.fix(fixed);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function combination<T>(array: T[]): T[][];
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function combination(array) {
|
|
4
|
-
// Unique
|
|
5
|
-
array = Array.from(new Set(array));
|
|
6
|
-
if (array.length <= 1) {
|
|
7
|
-
return [array];
|
|
8
|
-
}
|
|
9
|
-
// Sort
|
|
10
|
-
array.sort();
|
|
11
|
-
// Combination
|
|
12
|
-
const combinated = [];
|
|
13
|
-
for (const i1 of array) {
|
|
14
|
-
for (const i2 of array) {
|
|
15
|
-
for (const i3 of array) {
|
|
16
|
-
for (const i4 of array) {
|
|
17
|
-
for (const i5 of array) {
|
|
18
|
-
const item = Array.from(new Set([i1, i2, i3, i4, i5]));
|
|
19
|
-
if (item.length === array.length) {
|
|
20
|
-
const itemA = JSON.stringify(item);
|
|
21
|
-
if (!combinated.includes(itemA)) {
|
|
22
|
-
combinated.push(itemA);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const result = combinated.map(i => JSON.parse(i));
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
exports.default = combination;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { NamespaceURI } from '@markuplint/ml-ast';
|
|
2
|
-
import type { MLMLSpec, PermittedContent } from '@markuplint/ml-spec';
|
|
3
|
-
export default class ExpGenerator {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(specs: MLMLSpec, id: number);
|
|
6
|
-
specToRegExp(contentRule: PermittedContent[] | boolean, parentExp?: RegExp | null, ownNS?: NamespaceURI): RegExp;
|
|
7
|
-
private _toPattern;
|
|
8
|
-
private _interleavePattern;
|
|
9
|
-
private _targetTags;
|
|
10
|
-
private _resolveTags;
|
|
11
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _ExpGenerator_id, _ExpGenerator_specs, _ExpGenerator_idCounter, _TagList_list;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
6
|
-
const helpers_1 = require("../helpers");
|
|
7
|
-
const array_combination_1 = tslib_1.__importDefault(require("./array.combination"));
|
|
8
|
-
const ALL = '(?:<[^>]+>)?';
|
|
9
|
-
const ___TRANSPARENT___ = '___TRANSPARENT___';
|
|
10
|
-
const ___InTRANSPARENT = '___InTRANSPARENT';
|
|
11
|
-
const CUSTOM_ELEMENT = `(?:<[a-z](?:${helpers_1.rePCENChar})*\\-(?:${helpers_1.rePCENChar})*>)`;
|
|
12
|
-
class ExpGenerator {
|
|
13
|
-
constructor(specs, id) {
|
|
14
|
-
_ExpGenerator_id.set(this, void 0);
|
|
15
|
-
_ExpGenerator_specs.set(this, void 0);
|
|
16
|
-
_ExpGenerator_idCounter.set(this, 0);
|
|
17
|
-
tslib_1.__classPrivateFieldSet(this, _ExpGenerator_id, id, "f");
|
|
18
|
-
tslib_1.__classPrivateFieldSet(this, _ExpGenerator_specs, specs, "f");
|
|
19
|
-
}
|
|
20
|
-
specToRegExp(contentRule, parentExp = null, ownNS = 'http://www.w3.org/1999/xhtml') {
|
|
21
|
-
if (contentRule === true) {
|
|
22
|
-
return new RegExp(`^(?:${ALL})+$`);
|
|
23
|
-
}
|
|
24
|
-
if (contentRule === false) {
|
|
25
|
-
return new RegExp('^$');
|
|
26
|
-
}
|
|
27
|
-
const parentPattern = parentExp ? parentExp.source.replace(/^\^|\$$/g, '') : ALL;
|
|
28
|
-
const pattern = this._toPattern(contentRule, null, ownNS, 1, 1).replace(___TRANSPARENT___, () => { var _a, _b; return `(?<TRANSPARENT_${tslib_1.__classPrivateFieldGet(this, _ExpGenerator_id, "f")}${tslib_1.__classPrivateFieldSet(this, _ExpGenerator_idCounter, (_b = tslib_1.__classPrivateFieldGet(this, _ExpGenerator_idCounter, "f"), _a = _b++, _b), "f"), _a}>${parentPattern})`; });
|
|
29
|
-
return new RegExp(`^${pattern}$`, 'i');
|
|
30
|
-
}
|
|
31
|
-
_toPattern(contentRule, ignore, ownNS, min, max) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
if (isTarget(contentRule)) {
|
|
34
|
-
return this._targetTags(contentRule, ignore, ownNS, min, max);
|
|
35
|
-
}
|
|
36
|
-
let notAllowedDescendantsNamedCapture = '';
|
|
37
|
-
const exp = [];
|
|
38
|
-
for (const nodeRule of contentRule) {
|
|
39
|
-
let pattern = '';
|
|
40
|
-
if (isRequiredContents(nodeRule)) {
|
|
41
|
-
if (nodeRule.notAllowedDescendants) {
|
|
42
|
-
notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
|
|
43
|
-
.map(r => r.replace('#', '_'))
|
|
44
|
-
.join('_');
|
|
45
|
-
if (nodeRule.require === '#transparent') {
|
|
46
|
-
notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
pattern = this._targetTags(nodeRule.require, nodeRule.ignore || null, ownNS, nodeRule.min || 1, nodeRule.max || nodeRule.min || 1);
|
|
50
|
-
}
|
|
51
|
-
else if (isOptionalContents(nodeRule)) {
|
|
52
|
-
if (nodeRule.notAllowedDescendants) {
|
|
53
|
-
notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
|
|
54
|
-
.map(r => r.replace('#', '_'))
|
|
55
|
-
.join('_');
|
|
56
|
-
if (nodeRule.optional === '#transparent') {
|
|
57
|
-
notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
pattern = this._targetTags(nodeRule.optional, nodeRule.ignore || null, ownNS, 0, nodeRule.max || 1);
|
|
61
|
-
}
|
|
62
|
-
else if (isOneOrMoreContents(nodeRule)) {
|
|
63
|
-
if (nodeRule.notAllowedDescendants) {
|
|
64
|
-
notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
|
|
65
|
-
.map(r => r.replace('#', '_'))
|
|
66
|
-
.join('_');
|
|
67
|
-
if (nodeRule.oneOrMore === '#transparent') {
|
|
68
|
-
notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
pattern = this._toPattern(nodeRule.oneOrMore, nodeRule.ignore || null, ownNS, 1, nodeRule.max || Infinity);
|
|
72
|
-
}
|
|
73
|
-
else if (isZeroOrMoreContents(nodeRule)) {
|
|
74
|
-
if (nodeRule.notAllowedDescendants) {
|
|
75
|
-
notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
|
|
76
|
-
.map(r => r.replace('#', '_'))
|
|
77
|
-
.join('_');
|
|
78
|
-
if (nodeRule.zeroOrMore === '#transparent') {
|
|
79
|
-
notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
pattern = this._toPattern(nodeRule.zeroOrMore, nodeRule.ignore || null, ownNS, 0, nodeRule.max || Infinity);
|
|
83
|
-
}
|
|
84
|
-
else if (isChoiceContents(nodeRule)) {
|
|
85
|
-
pattern = `(?:${nodeRule.choice.map(choice => this._toPattern(choice, null, ownNS, 1, 1)).join('|')})`;
|
|
86
|
-
}
|
|
87
|
-
else if (isInterleaveContents(nodeRule)) {
|
|
88
|
-
pattern = this._interleavePattern(nodeRule.interleave, ownNS);
|
|
89
|
-
}
|
|
90
|
-
exp.push(pattern);
|
|
91
|
-
}
|
|
92
|
-
const range = createRange(min, max);
|
|
93
|
-
const c = notAllowedDescendantsNamedCapture
|
|
94
|
-
? `?<NAD_${tslib_1.__classPrivateFieldGet(this, _ExpGenerator_id, "f")}${tslib_1.__classPrivateFieldSet(this, _ExpGenerator_idCounter, (_b = tslib_1.__classPrivateFieldGet(this, _ExpGenerator_idCounter, "f"), _a = _b++, _b), "f"), _a}_${notAllowedDescendantsNamedCapture}>`
|
|
95
|
-
: '?:';
|
|
96
|
-
if (1 === exp.length && range === '') {
|
|
97
|
-
if (notAllowedDescendantsNamedCapture) {
|
|
98
|
-
return `(${c}${exp[0]})`;
|
|
99
|
-
}
|
|
100
|
-
return exp[0];
|
|
101
|
-
}
|
|
102
|
-
if (range === '') {
|
|
103
|
-
if (notAllowedDescendantsNamedCapture) {
|
|
104
|
-
return `(${c}${exp.join('')})`;
|
|
105
|
-
}
|
|
106
|
-
return exp.join('');
|
|
107
|
-
}
|
|
108
|
-
return `(${c}${exp.join('')})${range}`;
|
|
109
|
-
}
|
|
110
|
-
_interleavePattern(contents, ownNS) {
|
|
111
|
-
const interleave = contents.map(content => this._toPattern(content, null, ownNS, 1, 1));
|
|
112
|
-
const patterns = (0, array_combination_1.default)(interleave).map((pattern, i) => pattern.join('').replace(/(\(\?<[A-Z]+_)([0-9]+)_/g, ($0, $1, $2) => `${$1}${$2}${i}_`));
|
|
113
|
-
return join(patterns);
|
|
114
|
-
}
|
|
115
|
-
_targetTags(target, ignore, ownNS, min, max) {
|
|
116
|
-
const tagList = this._resolveTags(target, ownNS);
|
|
117
|
-
const ignoreList = ignore ? this._resolveTags(ignore, ownNS) : null;
|
|
118
|
-
if (ignoreList) {
|
|
119
|
-
ignoreList.forEach(ignore => tagList.delete(ignore));
|
|
120
|
-
}
|
|
121
|
-
return join(Array.from(tagList), createRange(min, max));
|
|
122
|
-
}
|
|
123
|
-
_resolveTags(target, ownNS) {
|
|
124
|
-
var _a, _b;
|
|
125
|
-
const list = Array.isArray(target) ? target : [target];
|
|
126
|
-
const tagList = new TagList();
|
|
127
|
-
for (const name of list) {
|
|
128
|
-
if (name !== '#text' && name[0] === '#') {
|
|
129
|
-
switch (name) {
|
|
130
|
-
case '#transparent': {
|
|
131
|
-
tagList.addPattern(___TRANSPARENT___);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case '#custom': {
|
|
135
|
-
tagList.addPattern(CUSTOM_ELEMENT);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
default: {
|
|
139
|
-
const selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(name, tslib_1.__classPrivateFieldGet(this, _ExpGenerator_specs, "f"));
|
|
140
|
-
const counter = (tslib_1.__classPrivateFieldSet(this, _ExpGenerator_idCounter, (_b = tslib_1.__classPrivateFieldGet(this, _ExpGenerator_idCounter, "f"), _a = _b++, _b), "f"), _a);
|
|
141
|
-
selectors.forEach(selector => {
|
|
142
|
-
if (selector === '#custom') {
|
|
143
|
-
tagList.addPattern(CUSTOM_ELEMENT);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (/]$/i.test(selector)) {
|
|
147
|
-
const [, tagName] = /^([^[\]]+)\[[^\]]+\]$/.exec(selector) || [];
|
|
148
|
-
// ACM = Attributes by content model
|
|
149
|
-
const exp = `(?<ACM_${tslib_1.__classPrivateFieldGet(this, _ExpGenerator_id, "f")}${counter}_${name.slice(1)}_${tagName}><${tagName}>)`;
|
|
150
|
-
tagList.addPattern(exp);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
tagList.addTag(selector, ownNS);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
tagList.addTag(name, ownNS);
|
|
160
|
-
}
|
|
161
|
-
return tagList.result();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.default = ExpGenerator;
|
|
165
|
-
_ExpGenerator_id = new WeakMap(), _ExpGenerator_specs = new WeakMap(), _ExpGenerator_idCounter = new WeakMap();
|
|
166
|
-
class TagList {
|
|
167
|
-
constructor() {
|
|
168
|
-
_TagList_list.set(this, new Set());
|
|
169
|
-
}
|
|
170
|
-
addPattern(pattern) {
|
|
171
|
-
tslib_1.__classPrivateFieldGet(this, _TagList_list, "f").add(pattern);
|
|
172
|
-
}
|
|
173
|
-
addTag(tagNameOrSelector, ownNS) {
|
|
174
|
-
tagNameOrSelector = tagNameOrSelector.replace(/\|/g, ':');
|
|
175
|
-
tagNameOrSelector = tagNameOrSelector.replace(/^html:/i, '');
|
|
176
|
-
tslib_1.__classPrivateFieldGet(this, _TagList_list, "f").add(`<${tagNameOrSelector}>`);
|
|
177
|
-
}
|
|
178
|
-
result() {
|
|
179
|
-
return tslib_1.__classPrivateFieldGet(this, _TagList_list, "f");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
_TagList_list = new WeakMap();
|
|
183
|
-
function isRequiredContents(contents) {
|
|
184
|
-
return 'require' in contents;
|
|
185
|
-
}
|
|
186
|
-
function isOptionalContents(contents) {
|
|
187
|
-
return 'optional' in contents;
|
|
188
|
-
}
|
|
189
|
-
function isOneOrMoreContents(contents) {
|
|
190
|
-
return 'oneOrMore' in contents;
|
|
191
|
-
}
|
|
192
|
-
function isZeroOrMoreContents(contents) {
|
|
193
|
-
return 'zeroOrMore' in contents;
|
|
194
|
-
}
|
|
195
|
-
function isChoiceContents(contents) {
|
|
196
|
-
return 'choice' in contents;
|
|
197
|
-
}
|
|
198
|
-
function isInterleaveContents(contents) {
|
|
199
|
-
return 'interleave' in contents;
|
|
200
|
-
}
|
|
201
|
-
function createRange(min, max) {
|
|
202
|
-
let result = `{${min},${max}}`;
|
|
203
|
-
switch (result) {
|
|
204
|
-
case '{0,1}':
|
|
205
|
-
result = '?';
|
|
206
|
-
break;
|
|
207
|
-
case '{1,1}':
|
|
208
|
-
result = '';
|
|
209
|
-
break;
|
|
210
|
-
case '{0,Infinity}':
|
|
211
|
-
result = '*';
|
|
212
|
-
break;
|
|
213
|
-
case '{1,Infinity}':
|
|
214
|
-
result = '+';
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
return result;
|
|
218
|
-
}
|
|
219
|
-
function isTarget(contentRule) {
|
|
220
|
-
if (typeof contentRule === 'string') {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
return contentRule.some((i) => typeof i === 'string');
|
|
224
|
-
}
|
|
225
|
-
function join(pattern, range = '') {
|
|
226
|
-
if (1 === pattern.length && range === '') {
|
|
227
|
-
return pattern[0];
|
|
228
|
-
}
|
|
229
|
-
return `(?:${pattern.join('|')})${range}`;
|
|
230
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const html_spec_1 = require("@markuplint/html-spec");
|
|
4
|
-
function unfoldContentModelsToTags(contentModel) {
|
|
5
|
-
const tags = html_spec_1.def['#contentModels'][contentModel];
|
|
6
|
-
return tags && Array.isArray(tags) ? tags.sort() : [];
|
|
7
|
-
}
|
|
8
|
-
exports.default = unfoldContentModelsToTags;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Options } from '../types';
|
|
2
|
-
import type { ElementChecker } from '@markuplint/ml-core';
|
|
3
|
-
import type { ARIARole } from '@markuplint/ml-spec';
|
|
4
|
-
/**
|
|
5
|
-
* Required Owned Elements
|
|
6
|
-
*
|
|
7
|
-
* @see https://w3c.github.io/aria/#mustContain
|
|
8
|
-
*/
|
|
9
|
-
export declare const checkingRequiredOwnedElements: ElementChecker<boolean, Options, {
|
|
10
|
-
role?: ARIARole | null;
|
|
11
|
-
}>;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkingRequiredOwnedElements = void 0;
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
/**
|
|
6
|
-
* Required Owned Elements
|
|
7
|
-
*
|
|
8
|
-
* @see https://w3c.github.io/aria/#mustContain
|
|
9
|
-
*/
|
|
10
|
-
const checkingRequiredOwnedElements = ({ el, role }) => t => {
|
|
11
|
-
if (!role) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (!role.requiredOwnedElements.length) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* > There may be times that required owned elements are missing,
|
|
19
|
-
* > for example, while editing or while loading a data set.
|
|
20
|
-
* > When a widget is missing required owned elements due to script execution or loading,
|
|
21
|
-
* > authors MUST mark a containing element with aria-busy equal to true.
|
|
22
|
-
* > For example, until a page is fully initialized and complete,
|
|
23
|
-
* > an author could mark the document element as busy.
|
|
24
|
-
*
|
|
25
|
-
* Stop to evaluate when it has `aria-busy=true` for it considers the contents are missing.
|
|
26
|
-
*/
|
|
27
|
-
if (el.matches('[aria-busy="true" i]')) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
// TODO: Needs to resolve `aria-own`
|
|
31
|
-
if (!el.children.length) {
|
|
32
|
-
return {
|
|
33
|
-
scope: el,
|
|
34
|
-
message: t('{0}. Or, {1}', t('Require {0} to content', t('the {0*} {1}', t(role.requiredOwnedElements), 'role')), t('require {0}', 'aria-busy="true"')),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const children = Array.from(el.childNodes).map(child => {
|
|
38
|
-
if (child.is(child.ELEMENT_NODE)) {
|
|
39
|
-
const computedChild = (0, ml_spec_1.getComputedRole)(child.ownerMLDocument.specs, child, child.rule.option.version);
|
|
40
|
-
if (role.requiredOwnedElements.some(ownedRole => (0, ml_spec_1.isRequiredOwnedElement)(computedChild, ownedRole, child.ownerMLDocument.specs, child.rule.option.version))) {
|
|
41
|
-
return 'REQUIRED';
|
|
42
|
-
}
|
|
43
|
-
return 'OTHER';
|
|
44
|
-
}
|
|
45
|
-
else if (child.MARKUPLINT_PREPROCESSOR_BLOCK) {
|
|
46
|
-
return 'PB';
|
|
47
|
-
}
|
|
48
|
-
return 'NO_ELEMENT';
|
|
49
|
-
});
|
|
50
|
-
if (children.includes('PB')) {
|
|
51
|
-
return {
|
|
52
|
-
scope: el,
|
|
53
|
-
message: t('{0} expects {1}', t('the "{0*}" {1}', role.name, 'role'), t(role.requiredContextRole.map(ownedRole => t('the "{0*}" {1}', ownedRole, 'role')))),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (!children.includes('REQUIRED')) {
|
|
57
|
-
return {
|
|
58
|
-
scope: el,
|
|
59
|
-
message: t('{0} expects {1}', t('the "{0*}" {1}', role.name, 'role'), t('the {0*} {1}', t(role.requiredOwnedElements), 'roles')),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
exports.checkingRequiredOwnedElements = checkingRequiredOwnedElements;
|