@markuplint/rules 3.0.0-canary.3 → 3.0.0-dev.176
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.d.ts +20 -8
- package/lib/attr-check.js +31 -22
- package/lib/attr-duplication/index.d.ts +3 -1
- package/lib/attr-duplication/index.js +2 -1
- package/lib/attr-value-quotes/index.d.ts +2 -2
- package/lib/case-sensitive-attr-name/index.d.ts +1 -1
- package/lib/case-sensitive-tag-name/index.d.ts +1 -1
- package/lib/character-reference/index.d.ts +1 -1
- package/lib/class-naming/index.d.ts +1 -1
- package/lib/class-naming/index.js +2 -4
- package/lib/create-message.d.ts +13 -2
- package/lib/create-message.js +4 -3
- package/lib/debug.js +1 -1
- package/lib/deprecated-attr/index.d.ts +3 -1
- package/lib/deprecated-element/index.d.ts +3 -1
- package/lib/deprecated-element/index.js +2 -2
- package/lib/disallowed-element/index.d.ts +1 -1
- package/lib/doctype/index.d.ts +2 -2
- package/lib/end-tag/index.d.ts +1 -1
- package/lib/helpers.d.ts +37 -22
- package/lib/helpers.js +27 -14
- package/lib/id-duplication/index.d.ts +3 -1
- package/lib/index.d.ts +243 -3
- package/lib/index.js +6 -1
- package/lib/ineffective-attr/index.d.ts +3 -1
- package/lib/ineffective-attr/index.js +2 -5
- package/lib/invalid-attr/index.d.ts +39 -12
- package/lib/invalid-attr/index.js +153 -27
- package/lib/label-has-control/index.d.ts +3 -1
- package/lib/landmark-roles/index.d.ts +3 -3
- package/lib/landmark-roles/index.js +9 -5
- package/lib/no-boolean-attr-value/index.d.ts +3 -1
- package/lib/no-default-value/index.d.ts +3 -1
- package/lib/no-empty-palpable-content/index.d.ts +3 -3
- package/lib/no-empty-palpable-content/index.js +11 -3
- package/lib/no-hard-code-id/index.d.ts +3 -1
- package/lib/no-refer-to-non-existent-id/index.d.ts +9 -4
- package/lib/no-refer-to-non-existent-id/index.js +65 -5
- package/lib/no-use-event-handler-attr/index.d.ts +2 -2
- package/lib/no-use-event-handler-attr/index.js +4 -4
- package/lib/permitted-contents/choice.d.ts +8 -1
- package/lib/permitted-contents/choice.js +37 -2
- package/lib/permitted-contents/complex-branch.d.ts +8 -1
- package/lib/permitted-contents/complex-branch.js +4 -2
- package/lib/permitted-contents/content-model.d.ts +1 -1
- package/lib/permitted-contents/content-model.js +7 -3
- package/lib/permitted-contents/count-pattern.d.ts +18 -2
- package/lib/permitted-contents/count-pattern.js +71 -64
- package/lib/permitted-contents/debug.browser.d.ts +30 -0
- package/lib/permitted-contents/debug.browser.js +14 -0
- package/lib/permitted-contents/debug.d.ts +2 -1
- package/lib/permitted-contents/debug.js +9 -1
- package/lib/permitted-contents/index.d.ts +1 -1
- package/lib/permitted-contents/index.js +12 -15
- package/lib/permitted-contents/matches-selector.d.ts +7 -2
- package/lib/permitted-contents/matches-selector.js +8 -6
- package/lib/permitted-contents/order.d.ts +8 -1
- package/lib/permitted-contents/order.js +25 -15
- package/lib/permitted-contents/recursive-branch.d.ts +8 -1
- package/lib/permitted-contents/recursive-branch.js +5 -3
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +7 -3
- package/lib/permitted-contents/represent-transparent-nodes.js +4 -5
- package/lib/permitted-contents/start.d.ts +7 -1
- package/lib/permitted-contents/start.js +5 -3
- package/lib/permitted-contents/transparent.d.ts +2 -2
- package/lib/permitted-contents/transparent.js +11 -14
- package/lib/permitted-contents/types.d.ts +35 -28
- package/lib/permitted-contents/utils.d.ts +96 -28
- package/lib/permitted-contents/utils.js +135 -17
- package/lib/placeholder-label-option/index.d.ts +2 -0
- package/lib/placeholder-label-option/index.js +88 -0
- package/lib/require-accessible-name/index.d.ts +2 -2
- package/lib/require-accessible-name/index.js +5 -5
- package/lib/require-datetime/index.d.ts +6 -0
- package/lib/require-datetime/index.js +34 -0
- package/lib/require-datetime/types.d.ts +10 -0
- package/lib/require-datetime/types.js +2 -0
- package/lib/require-datetime/utils.d.ts +11 -0
- package/lib/require-datetime/utils.js +137 -0
- package/lib/required-attr/index.d.ts +3 -3
- package/lib/required-attr/index.js +19 -16
- package/lib/required-element/index.d.ts +2 -2
- package/lib/required-element/index.js +3 -2
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/required-h1/index.js +4 -3
- package/lib/use-list/index.d.ts +3 -3
- package/lib/use-list/index.js +7 -5
- package/lib/wai-aria/checkings/_.d.ts +15 -0
- package/lib/wai-aria/checkings/_.js +27 -0
- package/lib/wai-aria/checkings/abstract-role.js +1 -1
- package/lib/wai-aria/checkings/default-value.d.ts +7 -3
- package/lib/wai-aria/checkings/deprecated-props.d.ts +8 -4
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +8 -4
- package/lib/wai-aria/checkings/disallowed-prop.js +27 -3
- package/lib/wai-aria/checkings/implicit-props.d.ts +8 -4
- package/lib/wai-aria/checkings/implicit-props.js +3 -2
- package/lib/wai-aria/checkings/implicit-role.js +1 -1
- package/lib/wai-aria/checkings/interaction-in-hidden.js +3 -1
- package/lib/wai-aria/checkings/no-global-prop.d.ts +7 -3
- package/lib/wai-aria/checkings/non-existent-role.js +1 -1
- package/lib/wai-aria/checkings/permitted-roles.js +1 -1
- package/lib/wai-aria/checkings/presentational-children.js +4 -2
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +7 -3
- package/lib/wai-aria/checkings/required-owned-elements.js +28 -12
- package/lib/wai-aria/checkings/required-prop copy.d.ts +15 -0
- package/lib/wai-aria/checkings/required-prop copy.js +27 -0
- package/lib/wai-aria/checkings/required-prop.d.ts +12 -6
- package/lib/wai-aria/checkings/unadopted-explicit-roles.d.ts +15 -0
- package/lib/wai-aria/checkings/unadopted-explicit-roles.js +17 -0
- package/lib/wai-aria/checkings/value.d.ts +15 -6
- package/lib/wai-aria/checkings/value.js +3 -1
- package/lib/wai-aria/index.d.ts +1 -1
- package/lib/wai-aria/index.js +13 -12
- package/lib/wai-aria/types.d.ts +10 -10
- package/lib/xxx/index.d.ts +2 -0
- package/lib/xxx/index.js +32 -0
- package/package.json +16 -11
- package/schema.json +6 -0
- package/test/attr-check.spec.js +77 -0
- package/test/attr-duplication/index.spec.js +159 -0
- package/test/attr-value-quotes/index.spec.js +133 -0
- package/test/case-sensitive-attr-name/index.spec.js +65 -0
- package/test/case-sensitive-tag-name/index.spec.js +80 -0
- package/test/character-reference/index.spec.js +57 -0
- package/test/class-naming/index.spec.js +470 -0
- package/test/create-message.spec.js +497 -0
- package/test/deprecated-attr/index.spec.js +48 -0
- package/test/deprecated-element/index.spec.js +48 -0
- package/test/disallowed-element/index.spec.js +90 -0
- package/test/doctype/index.spec.js +50 -0
- package/test/end-tag/index.spec.js +162 -0
- package/test/id-duplication/index.spec.js +47 -0
- package/test/ineffective-attr/index.spec.js +31 -0
- package/test/invalid-attr/index.spec.js +1632 -0
- package/test/label-has-control/index.spec.js +29 -0
- package/test/landmark-roles/index.spec.js +187 -0
- package/test/no-boolean-attr-value/index.spec.js +41 -0
- package/test/no-default-value/index.spec.js +74 -0
- package/test/no-empty-palpable-content/index.spec.js +115 -0
- package/test/no-hard-code-id/index.spec.js +100 -0
- package/test/no-refer-to-non-existent-id/index.spec.js +254 -0
- package/test/no-use-event-handler-attr/index.spec.js +57 -0
- package/test/permitted-contents/choice.spec.js +174 -0
- package/test/permitted-contents/count-pattern.spec.js +308 -0
- package/test/permitted-contents/index.spec.js +1371 -0
- package/test/permitted-contents/matches-selector.spec.js +59 -0
- package/test/permitted-contents/order.spec.js +351 -0
- package/test/permitted-contents/recursive-branch.spec.js +41 -0
- package/test/permitted-contents/represent-transparent-nodes.spec.js +24 -0
- package/test/permitted-contents/start.spec.js +67 -0
- package/test/placeholder-label-option/index.spec.js +113 -0
- package/test/require-accessible-name/index.spec.js +446 -0
- package/test/require-datetime/index.spec.js +54 -0
- package/test/require-datetime/utils.spec.js +52 -0
- package/test/required-attr/index.spec.js +414 -0
- package/test/required-element/index.spec.js +188 -0
- package/test/required-h1/index.spec.js +69 -0
- package/test/use-list/index.spec.js +109 -0
- package/test/wai-aria/checkings/value.spec.js +33 -0
- package/test/wai-aria/index.spec.js +1173 -0
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -11,22 +11,17 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
11
11
|
async verify({ document, report, t }) {
|
|
12
12
|
await document.walkOn('Element', el => {
|
|
13
13
|
var _a, _b, _c;
|
|
14
|
-
if (
|
|
14
|
+
if (el.rule.options.ignoreHasMutableChildren && el.hasMutableChildren()) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const results = (0, content_model_1.contentModel)(el, el.rule.value, el.rule.option);
|
|
17
|
+
const results = (0, content_model_1.contentModel)(el, el.rule.value, el.rule.options);
|
|
21
18
|
for (const { type, scope, query, hint } of results) {
|
|
22
19
|
let message = '';
|
|
23
|
-
if (hint) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
t('
|
|
27
|
-
|
|
28
|
-
t('the max number of elements required is {0}', `${hint.max}`);
|
|
29
|
-
}
|
|
20
|
+
if (hint.max != null) {
|
|
21
|
+
message =
|
|
22
|
+
t('there is more content than it needs') +
|
|
23
|
+
t('. ') +
|
|
24
|
+
t('the max number of elements required is {0}', `${hint.max}`);
|
|
30
25
|
}
|
|
31
26
|
switch (type) {
|
|
32
27
|
case 'MATCHED':
|
|
@@ -75,10 +70,10 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
75
70
|
});
|
|
76
71
|
break;
|
|
77
72
|
}
|
|
78
|
-
case '
|
|
73
|
+
case 'NOTHING': {
|
|
79
74
|
report({
|
|
80
75
|
scope: el,
|
|
81
|
-
message: t('{0}
|
|
76
|
+
message: t('{0} disallows {1}', t('the {0}', 'element'), 'contents'),
|
|
82
77
|
});
|
|
83
78
|
break;
|
|
84
79
|
}
|
|
@@ -91,7 +86,9 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
91
86
|
});
|
|
92
87
|
},
|
|
93
88
|
});
|
|
94
|
-
function name(
|
|
89
|
+
function name(
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
91
|
+
scope, t) {
|
|
95
92
|
if (scope.is(scope.ELEMENT_NODE)) {
|
|
96
93
|
return t('the "{0}" {1}', scope.localName, 'element');
|
|
97
94
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import type { ChildNode,
|
|
1
|
+
import type { ChildNode, Result, Specs } from './types';
|
|
2
2
|
export type SelectorResult = Result<'UNMATCHED_SELECTOR_BUT_MAY_EMPTY' | 'MISSING_NODE' | 'UNMATCHED_SELECTORS'>;
|
|
3
|
-
export declare function matchesSelector(
|
|
3
|
+
export declare function matchesSelector(
|
|
4
|
+
query: string,
|
|
5
|
+
node: ChildNode | undefined,
|
|
6
|
+
specs: Specs,
|
|
7
|
+
depth: number,
|
|
8
|
+
): SelectorResult;
|
|
@@ -4,7 +4,9 @@ exports.matchesSelector = void 0;
|
|
|
4
4
|
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
5
|
const debug_1 = require("./debug");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
function matchesSelector(query,
|
|
7
|
+
function matchesSelector(query,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
|
+
node, specs, depth) {
|
|
8
10
|
const nodeLog = debug_1.cmLog.extend(`node#${depth}`);
|
|
9
11
|
const { selector, hasText, hasCustom } = optCondition(query, specs);
|
|
10
12
|
if (node == null) {
|
|
@@ -12,7 +14,7 @@ function matchesSelector(query, node, specs, options, depth) {
|
|
|
12
14
|
nodeLog('<#text>.matches(%s) => ""', query);
|
|
13
15
|
return {
|
|
14
16
|
type: 'MATCHED_ZERO',
|
|
15
|
-
matched:
|
|
17
|
+
matched: [],
|
|
16
18
|
unmatched: [],
|
|
17
19
|
zeroMatch: true,
|
|
18
20
|
query,
|
|
@@ -103,9 +105,9 @@ function matchesSelector(query, node, specs, options, depth) {
|
|
|
103
105
|
unmatched: [node],
|
|
104
106
|
zeroMatch: true,
|
|
105
107
|
query,
|
|
106
|
-
hint: {
|
|
108
|
+
hint: (0, utils_1.cleanObject)({
|
|
107
109
|
not: result.not,
|
|
108
|
-
},
|
|
110
|
+
}),
|
|
109
111
|
};
|
|
110
112
|
}
|
|
111
113
|
return {
|
|
@@ -114,9 +116,9 @@ function matchesSelector(query, node, specs, options, depth) {
|
|
|
114
116
|
unmatched: [node],
|
|
115
117
|
zeroMatch: false,
|
|
116
118
|
query,
|
|
117
|
-
hint: {
|
|
119
|
+
hint: (0, utils_1.cleanObject)({
|
|
118
120
|
not: result.not,
|
|
119
|
-
},
|
|
121
|
+
}),
|
|
120
122
|
};
|
|
121
123
|
}
|
|
122
124
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
2
|
import type { PermittedContentPattern } from '@markuplint/ml-spec';
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
4
|
/**
|
|
4
5
|
* Check ordered array
|
|
5
6
|
*
|
|
@@ -10,4 +11,10 @@ import type { PermittedContentPattern } from '@markuplint/ml-spec';
|
|
|
10
11
|
* @param depth
|
|
11
12
|
* @returns
|
|
12
13
|
*/
|
|
13
|
-
export declare function order(
|
|
14
|
+
export declare function order(
|
|
15
|
+
contents: ReadonlyDeep<PermittedContentPattern[]>,
|
|
16
|
+
nodes: readonly ChildNode[],
|
|
17
|
+
specs: Specs,
|
|
18
|
+
options: Options,
|
|
19
|
+
depth: number,
|
|
20
|
+
): Result;
|
|
@@ -15,42 +15,51 @@ const utils_1 = require("./utils");
|
|
|
15
15
|
* @param depth
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
function order(contents,
|
|
19
|
-
|
|
18
|
+
function order(contents,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
20
|
+
nodes, specs, options, depth) {
|
|
21
|
+
var _a, _b, _c, _d, _e;
|
|
20
22
|
const orderLog = debug_1.cmLog.extend(`order#${depth}`);
|
|
21
23
|
const btLog = debug_1.cmLog.extend(`backtrack#${depth}`);
|
|
22
24
|
const patterns = (0, helpers_1.deepCopy)(contents);
|
|
23
25
|
const collection = new utils_1.Collection(nodes);
|
|
26
|
+
orderLog('Model:\n RegEx: %s\n Schema: %o', (0, utils_1.modelLog)(patterns, ''), patterns);
|
|
24
27
|
orderLog('Starts: %s', collection);
|
|
25
28
|
let result = undefined;
|
|
26
29
|
let backtrackMode = false;
|
|
27
30
|
let afterBacktrack = false;
|
|
28
31
|
const unmatchedResults = [];
|
|
29
|
-
while (patterns.length) {
|
|
32
|
+
while (patterns.length > 0 && patterns[0]) {
|
|
30
33
|
result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
|
|
31
34
|
collection.addMatched(result.matched);
|
|
32
|
-
orderLog('stack: %s', collection);
|
|
33
35
|
if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
|
|
34
36
|
unmatchedResults.push(result);
|
|
35
37
|
if (backtrackMode) {
|
|
36
38
|
collection.back();
|
|
37
|
-
btLog('
|
|
39
|
+
btLog('🔙◀BACK');
|
|
38
40
|
backtrackMode = false;
|
|
39
41
|
afterBacktrack = true;
|
|
40
42
|
continue;
|
|
41
43
|
}
|
|
42
|
-
orderLog('conformed (%s): %s', result.type, collection.toString(true));
|
|
43
44
|
const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
|
|
44
45
|
if (!barelyMatchedResult) {
|
|
45
46
|
throw new Error('Unreachable code');
|
|
46
47
|
}
|
|
48
|
+
orderLog('Result (%s): %s%s', result.type, collection.toString(true), ((_a = barelyMatchedResult.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements) != null
|
|
49
|
+
? `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`
|
|
50
|
+
: '');
|
|
47
51
|
return {
|
|
48
52
|
type: barelyMatchedResult.type,
|
|
49
53
|
matched: collection.matched,
|
|
50
54
|
unmatched: collection.unmatched,
|
|
51
55
|
zeroMatch: barelyMatchedResult.zeroMatch,
|
|
52
56
|
query: barelyMatchedResult.query,
|
|
53
|
-
hint: barelyMatchedResult.hint,
|
|
57
|
+
hint: (0, utils_1.mergeHints)(barelyMatchedResult.hint, {
|
|
58
|
+
missing: {
|
|
59
|
+
barelyMatchedElements: collection.matched.length,
|
|
60
|
+
need: barelyMatchedResult.query,
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
54
63
|
};
|
|
55
64
|
}
|
|
56
65
|
if (afterBacktrack) {
|
|
@@ -65,25 +74,26 @@ function order(contents, nodes, specs, options, depth) {
|
|
|
65
74
|
}
|
|
66
75
|
patterns.shift();
|
|
67
76
|
}
|
|
68
|
-
if (collection.unmatched.length) {
|
|
69
|
-
orderLog('
|
|
77
|
+
if (collection.unmatched.length > 0) {
|
|
78
|
+
orderLog('Result (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
|
|
70
79
|
return {
|
|
71
80
|
type: 'UNEXPECTED_EXTRA_NODE',
|
|
72
81
|
matched: collection.matched,
|
|
73
82
|
unmatched: collection.unmatched,
|
|
74
83
|
zeroMatch: false,
|
|
75
|
-
query: (
|
|
76
|
-
hint: (
|
|
84
|
+
query: (_b = result === null || result === void 0 ? void 0 : result.query) !== null && _b !== void 0 ? _b : 'N/A',
|
|
85
|
+
hint: (_c = result === null || result === void 0 ? void 0 : result.hint) !== null && _c !== void 0 ? _c : {},
|
|
77
86
|
};
|
|
78
87
|
}
|
|
79
|
-
|
|
88
|
+
const resultType = collection.matched.length > 0 ? 'MATCHED' : 'MATCHED_ZERO';
|
|
89
|
+
orderLog('Result (%s): %s', resultType, collection.toString(true));
|
|
80
90
|
return {
|
|
81
|
-
type:
|
|
91
|
+
type: resultType,
|
|
82
92
|
matched: collection.matched,
|
|
83
93
|
unmatched: collection.unmatched,
|
|
84
94
|
zeroMatch: false,
|
|
85
|
-
query: (
|
|
86
|
-
hint: (
|
|
95
|
+
query: (_d = result === null || result === void 0 ? void 0 : result.query) !== null && _d !== void 0 ? _d : 'N/A',
|
|
96
|
+
hint: (_e = result === null || result === void 0 ? void 0 : result.hint) !== null && _e !== void 0 ? _e : {},
|
|
87
97
|
};
|
|
88
98
|
}
|
|
89
99
|
exports.order = order;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { SelectorResult } from './matches-selector';
|
|
2
2
|
import type { ChildNode, Options, Specs } from './types';
|
|
3
3
|
import type { PermittedContentPattern, Model } from '@markuplint/ml-spec';
|
|
4
|
-
|
|
4
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
5
|
+
export declare function recursiveBranch(
|
|
6
|
+
model: ReadonlyDeep<Model | PermittedContentPattern[]>,
|
|
7
|
+
nodes: readonly ChildNode[],
|
|
8
|
+
specs: Specs,
|
|
9
|
+
options: Options,
|
|
10
|
+
depth: number,
|
|
11
|
+
): SelectorResult;
|
|
@@ -4,17 +4,19 @@ exports.recursiveBranch = void 0;
|
|
|
4
4
|
const matches_selector_1 = require("./matches-selector");
|
|
5
5
|
const order_1 = require("./order");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
function recursiveBranch(model,
|
|
7
|
+
function recursiveBranch(model,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
|
+
nodes, specs, options, depth) {
|
|
8
10
|
if (!(0, utils_1.isModel)(model)) {
|
|
9
11
|
return (0, order_1.order)(model, nodes, specs, options, depth + 1);
|
|
10
12
|
}
|
|
11
13
|
if (typeof model === 'string') {
|
|
12
|
-
return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs,
|
|
14
|
+
return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, depth);
|
|
13
15
|
}
|
|
14
16
|
const collection = new utils_1.Collection(nodes);
|
|
15
17
|
let lastUnmatched = null;
|
|
16
18
|
for (const query of model) {
|
|
17
|
-
const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs,
|
|
19
|
+
const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, depth);
|
|
18
20
|
collection.addMatched(result.matched);
|
|
19
21
|
if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
|
|
20
22
|
return {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
2
|
export declare const transparentMode: Map<ChildNode, true>;
|
|
3
|
-
export declare function representTransparentNodes(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function representTransparentNodes(
|
|
4
|
+
nodes: ChildNode[],
|
|
5
|
+
specs: Specs,
|
|
6
|
+
options: Options,
|
|
7
|
+
): {
|
|
8
|
+
nodes: ChildNode[];
|
|
9
|
+
errors: Result[];
|
|
6
10
|
};
|
|
@@ -5,7 +5,9 @@ const ml_spec_1 = require("@markuplint/ml-spec");
|
|
|
5
5
|
const order_1 = require("./order");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
exports.transparentMode = new Map();
|
|
8
|
-
function representTransparentNodes(
|
|
8
|
+
function representTransparentNodes(
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
|
+
nodes, specs, options) {
|
|
9
11
|
var _a;
|
|
10
12
|
const result = [];
|
|
11
13
|
const errors = [];
|
|
@@ -13,9 +15,6 @@ function representTransparentNodes(nodes, specs, options) {
|
|
|
13
15
|
if (parent) {
|
|
14
16
|
const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
|
|
15
17
|
errors.push(...parentErrors);
|
|
16
|
-
// if (!Array.isArray(parentRes)) {
|
|
17
|
-
// return parentRes;
|
|
18
|
-
// }
|
|
19
18
|
}
|
|
20
19
|
for (const node of nodes) {
|
|
21
20
|
if (!node.is(node.ELEMENT_NODE)) {
|
|
@@ -34,7 +33,7 @@ function representTransparentNodes(nodes, specs, options) {
|
|
|
34
33
|
}
|
|
35
34
|
const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
|
|
36
35
|
let unmatched;
|
|
37
|
-
if (noTransparentModels.length) {
|
|
36
|
+
if (noTransparentModels.length > 0) {
|
|
38
37
|
const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
|
|
39
38
|
unmatched = result.unmatched;
|
|
40
39
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ContentModelResult, Element, Options, Specs } from './types';
|
|
2
2
|
import type { ContentModel } from '@markuplint/ml-spec';
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
4
|
/**
|
|
4
5
|
* Check start
|
|
5
6
|
*
|
|
@@ -9,4 +10,9 @@ import type { ContentModel } from '@markuplint/ml-spec';
|
|
|
9
10
|
* @param options
|
|
10
11
|
* @returns
|
|
11
12
|
*/
|
|
12
|
-
export declare function start(
|
|
13
|
+
export declare function start(
|
|
14
|
+
contents: ReadonlyDeep<ContentModel['contents']>,
|
|
15
|
+
el: Element,
|
|
16
|
+
specs: Specs,
|
|
17
|
+
options: Options,
|
|
18
|
+
): ContentModelResult[];
|
|
@@ -13,13 +13,15 @@ const utils_1 = require("./utils");
|
|
|
13
13
|
* @param options
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
function start(contents,
|
|
16
|
+
function start(contents,
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
18
|
+
el, specs, options) {
|
|
17
19
|
var _a;
|
|
18
20
|
if (contents === false) {
|
|
19
|
-
if (el.childNodes.length) {
|
|
21
|
+
if (el.childNodes.length > 0) {
|
|
20
22
|
return [
|
|
21
23
|
{
|
|
22
|
-
type: '
|
|
24
|
+
type: 'NOTHING',
|
|
23
25
|
scope: el,
|
|
24
26
|
query: ':not(*)',
|
|
25
27
|
hint: {},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ChildNode,
|
|
2
|
-
export declare function transparent(nodes: ChildNode[]
|
|
1
|
+
import type { ChildNode, Result } from './types';
|
|
2
|
+
export declare function transparent(nodes: readonly ChildNode[]): Result;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transparent = void 0;
|
|
4
|
-
const count_pattern_1 = require("./count-pattern");
|
|
5
4
|
const debug_1 = require("./debug");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
5
|
const transparentLog = debug_1.cmLog.extend('transparent');
|
|
8
|
-
function transparent(
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
function transparent(
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
nodes) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
if (nodes.length === 0 || ((_b = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement)) {
|
|
11
11
|
transparentLog('Skipped');
|
|
12
12
|
return {
|
|
13
13
|
type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
|
|
@@ -19,16 +19,13 @@ function transparent(nodes, specs, options, depth) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
transparentLog('Transparent model element is component root');
|
|
22
|
-
const collection = new utils_1.Collection(nodes);
|
|
23
|
-
const result = (0, count_pattern_1.countPattern)({ zeroOrMore: ':model(flow)' }, collection.unmatched, specs, options, depth);
|
|
24
|
-
collection.addMatched(result.matched);
|
|
25
22
|
return {
|
|
26
|
-
type:
|
|
27
|
-
matched:
|
|
28
|
-
unmatched:
|
|
29
|
-
zeroMatch:
|
|
30
|
-
query:
|
|
31
|
-
hint:
|
|
23
|
+
type: 'MATCHED',
|
|
24
|
+
matched: nodes.slice(),
|
|
25
|
+
unmatched: [],
|
|
26
|
+
zeroMatch: false,
|
|
27
|
+
query: 'transparent',
|
|
28
|
+
hint: {},
|
|
32
29
|
};
|
|
33
30
|
}
|
|
34
31
|
exports.transparent = transparent;
|
|
@@ -1,45 +1,52 @@
|
|
|
1
1
|
import type { Element as _Element, ChildNode as _ChildNode } from '@markuplint/ml-core';
|
|
2
2
|
import type { ContentModel, MLMLSpec } from '@markuplint/ml-spec';
|
|
3
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
4
|
export type Element = _Element<TagRule[], Options>;
|
|
4
5
|
export type ChildNode = _ChildNode<TagRule[], Options>;
|
|
5
6
|
export type Specs = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
readonly cites: MLMLSpec['cites'];
|
|
8
|
+
readonly def: MLMLSpec['def'];
|
|
9
|
+
readonly specs: readonly {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly contentModel: {
|
|
12
|
+
readonly contents: MLMLSpec['specs'][0]['contentModel']['contents'];
|
|
13
|
+
};
|
|
14
|
+
}[];
|
|
14
15
|
};
|
|
15
16
|
export type ContentModelResult = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
type: MatchedReason | UnmatchedReason;
|
|
18
|
+
scope: ChildNode;
|
|
19
|
+
query: Result['query'];
|
|
20
|
+
hint: Result['hint'];
|
|
20
21
|
};
|
|
21
22
|
export type Result<T extends string = MatchedReason> = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
type: MatchedReason | UnmatchedReason | T;
|
|
24
|
+
matched: ChildNode[];
|
|
25
|
+
unmatched: ChildNode[];
|
|
26
|
+
zeroMatch: boolean;
|
|
27
|
+
query: string;
|
|
28
|
+
hint: Hints;
|
|
29
|
+
};
|
|
30
|
+
export type Hints = {
|
|
31
|
+
max?: number;
|
|
32
|
+
not?: ChildNode;
|
|
33
|
+
transparent?: Element;
|
|
34
|
+
missing?: {
|
|
35
|
+
barelyMatchedElements?: number;
|
|
36
|
+
need?: string;
|
|
37
|
+
};
|
|
32
38
|
};
|
|
33
39
|
export type MatchedReason = 'MATCHED' | 'MATCHED_ZERO';
|
|
34
|
-
export type UnmatchedReason = '
|
|
40
|
+
export type UnmatchedReason = 'NOTHING' | 'UNEXPECTED_EXTRA_NODE' | 'TRANSPARENT_MODEL_DISALLOWS' | MissingNodeReason;
|
|
35
41
|
export type MissingNodeReason = 'MISSING_NODE_REQUIRED' | 'MISSING_NODE_ONE_OR_MORE';
|
|
42
|
+
export type RepeatSign = '' | '?' | '+' | '*' | `{${number},${number}}`;
|
|
36
43
|
export type TransparentModel = {
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
el: Element;
|
|
45
|
+
additionalCondition: string;
|
|
39
46
|
};
|
|
40
47
|
export type TagRule = {
|
|
41
|
-
|
|
42
|
-
} & ContentModel
|
|
48
|
+
readonly tag: string;
|
|
49
|
+
} & ReadonlyDeep<ContentModel>;
|
|
43
50
|
export type Options = {
|
|
44
|
-
|
|
51
|
+
readonly ignoreHasMutableChildren: boolean;
|
|
45
52
|
};
|
|
@@ -1,32 +1,100 @@
|
|
|
1
|
-
import type { ChildNode, Element, Specs } from './types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types';
|
|
2
|
+
import type {
|
|
3
|
+
PermittedContentPattern,
|
|
4
|
+
PermittedContentChoice,
|
|
5
|
+
PermittedContentOneOrMore,
|
|
6
|
+
PermittedContentOptional,
|
|
7
|
+
PermittedContentRequire,
|
|
8
|
+
PermittedContentTransparent,
|
|
9
|
+
PermittedContentZeroOrMore,
|
|
10
|
+
Model,
|
|
11
|
+
} from '@markuplint/ml-spec';
|
|
12
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
13
|
export declare function getChildNodesWithoutWhitespaces(el: Element): ChildNode[];
|
|
4
|
-
export declare function isModel(model: Model | PermittedContentPattern[]): model is Model
|
|
5
|
-
export declare function matches(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
export declare function isModel(model: ReadonlyDeep<Model | PermittedContentPattern[]>): model is ReadonlyDeep<Model>;
|
|
15
|
+
export declare function matches(
|
|
16
|
+
selector: string,
|
|
17
|
+
node: ChildNode,
|
|
18
|
+
specs: Specs,
|
|
19
|
+
):
|
|
20
|
+
| {
|
|
21
|
+
matched: boolean;
|
|
22
|
+
not?: undefined;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
matched: boolean;
|
|
26
|
+
not: ChildNode | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare function isRequire(
|
|
29
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
30
|
+
): content is ReadonlyDeep<PermittedContentRequire>;
|
|
31
|
+
export declare function isOptional(
|
|
32
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
33
|
+
): content is ReadonlyDeep<PermittedContentOptional>;
|
|
34
|
+
export declare function isOneOrMore(
|
|
35
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
36
|
+
): content is ReadonlyDeep<PermittedContentOneOrMore>;
|
|
37
|
+
export declare function isZeroOrMore(
|
|
38
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
39
|
+
): content is ReadonlyDeep<PermittedContentZeroOrMore>;
|
|
40
|
+
export declare function isChoice(
|
|
41
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
42
|
+
): content is ReadonlyDeep<PermittedContentChoice>;
|
|
43
|
+
export declare function isTransparent(
|
|
44
|
+
content: ReadonlyDeep<PermittedContentPattern>,
|
|
45
|
+
): content is ReadonlyDeep<PermittedContentTransparent>;
|
|
46
|
+
export declare function normalizeModel(
|
|
47
|
+
pattern:
|
|
48
|
+
| ReadonlyDeep<PermittedContentRequire>
|
|
49
|
+
| ReadonlyDeep<PermittedContentOptional>
|
|
50
|
+
| ReadonlyDeep<PermittedContentOneOrMore>
|
|
51
|
+
| ReadonlyDeep<PermittedContentZeroOrMore>,
|
|
52
|
+
): {
|
|
53
|
+
model: ReadonlyDeep<PermittedContentPattern[] | Model>;
|
|
54
|
+
min: number;
|
|
55
|
+
max: number;
|
|
56
|
+
repeat: RepeatSign;
|
|
57
|
+
missingType: MissingNodeReason | undefined;
|
|
11
58
|
};
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
59
|
+
export declare function mergeHints(
|
|
60
|
+
a: Readonly<Hints>,
|
|
61
|
+
b: Readonly<Hints>,
|
|
62
|
+
): Partial<{
|
|
63
|
+
missing:
|
|
64
|
+
| Partial<{
|
|
65
|
+
barelyMatchedElements?: number | undefined;
|
|
66
|
+
need?: string | undefined;
|
|
67
|
+
}>
|
|
68
|
+
| undefined;
|
|
69
|
+
max?: number | undefined;
|
|
70
|
+
not?:
|
|
71
|
+
| import('packages/@markuplint/ml-core/lib').DocumentType<
|
|
72
|
+
import('./types').TagRule[],
|
|
73
|
+
import('./types').Options
|
|
74
|
+
>
|
|
75
|
+
| import('packages/@markuplint/ml-core/lib/ml-dom/node/character-data').MLCharacterData<
|
|
76
|
+
import('./types').TagRule[],
|
|
77
|
+
import('./types').Options,
|
|
78
|
+
import('packages/@markuplint/ml-ast/lib').MLASTAbstractNode
|
|
79
|
+
>
|
|
80
|
+
| import('packages/@markuplint/ml-core/lib').Element<import('./types').TagRule[], import('./types').Options>
|
|
81
|
+
| import('packages/@markuplint/ml-core/lib').Block<import('./types').TagRule[], import('./types').Options>
|
|
82
|
+
| undefined;
|
|
83
|
+
transparent?: Element | undefined;
|
|
84
|
+
}>;
|
|
85
|
+
export declare function cleanObject<T extends Object>(object: T): Partial<T>;
|
|
18
86
|
export declare class Collection {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
export declare class UnsupportedError extends Error {
|
|
87
|
+
#private;
|
|
88
|
+
constructor(origin: readonly ChildNode[]);
|
|
89
|
+
get matched(): ChildNode[];
|
|
90
|
+
get matchedCount(): number;
|
|
91
|
+
get nodes(): ChildNode[];
|
|
92
|
+
get unmatched(): ChildNode[];
|
|
93
|
+
addMatched(nodes: ChildNode[]): boolean;
|
|
94
|
+
back(): void;
|
|
95
|
+
lock(): void;
|
|
96
|
+
max(max: number): void;
|
|
97
|
+
toString(highlightExtraNodes?: boolean): string;
|
|
32
98
|
}
|
|
99
|
+
export declare class UnsupportedError extends Error {}
|
|
100
|
+
export declare function modelLog(model: ReadonlyDeep<Model | PermittedContentPattern[]>, repeat: RepeatSign): string;
|