@markuplint/rules 3.15.0 → 4.0.0-alpha.10
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/.eslintrc +5 -0
- package/LICENSE +1 -1
- package/lib/attr-check.d.ts +8 -19
- package/lib/attr-check.js +16 -21
- package/lib/attr-duplication/index.d.ts +1 -3
- package/lib/attr-duplication/index.js +6 -6
- package/lib/attr-value-quotes/index.d.ts +2 -2
- package/lib/attr-value-quotes/index.js +8 -10
- package/lib/case-sensitive-attr-name/index.d.ts +1 -1
- package/lib/case-sensitive-attr-name/index.js +12 -13
- package/lib/case-sensitive-tag-name/index.d.ts +1 -1
- package/lib/case-sensitive-tag-name/index.js +5 -4
- package/lib/character-reference/index.d.ts +1 -1
- package/lib/character-reference/index.js +13 -12
- package/lib/class-naming/index.d.ts +1 -1
- package/lib/class-naming/index.js +14 -13
- package/lib/create-message.d.ts +2 -12
- package/lib/create-message.js +26 -26
- package/lib/debug.js +2 -6
- package/lib/deprecated-attr/index.d.ts +1 -3
- package/lib/deprecated-attr/index.js +9 -9
- package/lib/deprecated-element/index.d.ts +1 -3
- package/lib/deprecated-element/index.js +7 -6
- package/lib/disallowed-element/index.d.ts +1 -1
- package/lib/disallowed-element/index.js +9 -8
- package/lib/doctype/index.d.ts +2 -2
- package/lib/doctype/index.js +5 -4
- package/lib/end-tag/index.d.ts +1 -1
- package/lib/end-tag/index.js +8 -8
- package/lib/helpers.d.ts +17 -35
- package/lib/helpers.js +25 -32
- package/lib/id-duplication/index.d.ts +1 -3
- package/lib/id-duplication/index.js +5 -4
- package/lib/index.d.ts +21 -17
- package/lib/index.js +63 -66
- package/lib/ineffective-attr/index.d.ts +1 -3
- package/lib/ineffective-attr/index.js +8 -7
- package/lib/invalid-attr/index.d.ts +31 -38
- package/lib/invalid-attr/index.js +33 -33
- package/lib/label-has-control/index.d.ts +1 -3
- package/lib/label-has-control/index.js +5 -4
- package/lib/landmark-roles/index.d.ts +3 -3
- package/lib/landmark-roles/index.js +16 -18
- package/lib/no-boolean-attr-value/index.d.ts +1 -3
- package/lib/no-boolean-attr-value/index.js +9 -9
- package/lib/no-default-value/index.d.ts +1 -3
- package/lib/no-default-value/index.js +12 -12
- package/lib/no-empty-palpable-content/index.d.ts +3 -3
- package/lib/no-empty-palpable-content/index.js +9 -8
- package/lib/no-hard-code-id/index.d.ts +1 -3
- package/lib/no-hard-code-id/index.js +5 -4
- package/lib/no-refer-to-non-existent-id/index.d.ts +1 -1
- package/lib/no-refer-to-non-existent-id/index.js +37 -38
- package/lib/no-use-event-handler-attr/index.d.ts +2 -2
- package/lib/no-use-event-handler-attr/index.js +7 -6
- package/lib/permitted-contents/choice.d.ts +2 -8
- package/lib/permitted-contents/choice.js +14 -19
- package/lib/permitted-contents/complex-branch.d.ts +2 -8
- 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 +10 -11
- package/lib/permitted-contents/count-pattern.d.ts +3 -18
- package/lib/permitted-contents/count-pattern.js +19 -24
- package/lib/permitted-contents/debug.browser.d.ts +16 -16
- package/lib/permitted-contents/debug.browser.js +9 -12
- package/lib/permitted-contents/debug.d.ts +10 -3
- package/lib/permitted-contents/debug.js +12 -13
- package/lib/permitted-contents/index.d.ts +2 -2
- package/lib/permitted-contents/index.js +13 -13
- package/lib/permitted-contents/matches-selector.d.ts +2 -7
- package/lib/permitted-contents/matches-selector.js +13 -18
- package/lib/permitted-contents/order.d.ts +2 -8
- package/lib/permitted-contents/order.js +19 -24
- package/lib/permitted-contents/recursive-branch.d.ts +3 -9
- package/lib/permitted-contents/recursive-branch.js +9 -13
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +4 -8
- package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
- package/lib/permitted-contents/start.d.ts +2 -7
- package/lib/permitted-contents/start.js +13 -21
- package/lib/permitted-contents/transparent.d.ts +1 -1
- package/lib/permitted-contents/transparent.js +6 -11
- package/lib/permitted-contents/types.d.ts +29 -29
- package/lib/permitted-contents/types.js +1 -2
- package/lib/permitted-contents/utils.d.ts +42 -79
- package/lib/permitted-contents/utils.js +72 -82
- package/lib/placeholder-label-option/index.d.ts +1 -1
- package/lib/placeholder-label-option/index.js +12 -13
- package/lib/require-accessible-name/index.d.ts +2 -2
- package/lib/require-accessible-name/index.js +12 -15
- package/lib/require-datetime/index.d.ts +3 -3
- package/lib/require-datetime/index.js +14 -13
- package/lib/require-datetime/types.d.ts +2 -2
- package/lib/require-datetime/types.js +1 -2
- package/lib/require-datetime/utils.d.ts +1 -1
- package/lib/require-datetime/utils.js +5 -12
- package/lib/required-attr/index.d.ts +3 -3
- package/lib/required-attr/index.js +11 -11
- package/lib/required-element/index.d.ts +2 -2
- package/lib/required-element/index.js +7 -7
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/required-h1/index.js +6 -6
- package/lib/use-list/index.d.ts +6 -2
- package/lib/use-list/index.js +27 -11
- 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 +4 -8
- package/lib/wai-aria/checkings/default-value.js +2 -6
- package/lib/wai-aria/checkings/deprecated-props.d.ts +5 -9
- package/lib/wai-aria/checkings/deprecated-props.js +3 -8
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +5 -9
- package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
- package/lib/wai-aria/checkings/implicit-props.d.ts +5 -9
- package/lib/wai-aria/checkings/implicit-props.js +12 -17
- 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 +4 -8
- 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 +5 -10
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +4 -8
- package/lib/wai-aria/checkings/required-owned-elements.js +7 -11
- package/lib/wai-aria/checkings/required-prop.d.ts +7 -13
- package/lib/wai-aria/checkings/required-prop.js +2 -7
- package/lib/wai-aria/checkings/value.d.ts +7 -16
- package/lib/wai-aria/checkings/value.js +7 -13
- package/lib/wai-aria/index.d.ts +2 -2
- package/lib/wai-aria/index.js +41 -40
- package/lib/wai-aria/types.d.ts +10 -10
- package/lib/wai-aria/types.js +1 -2
- package/package.json +17 -13
- 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 -1631
- 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,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
const shared_1 = require("@markuplint/shared");
|
|
1
|
+
import { createRule, getAttrSpecs, ariaSpecs } from '@markuplint/ml-core';
|
|
2
|
+
import { ARIA_RECOMMENDED_VERSION } from '@markuplint/ml-spec';
|
|
3
|
+
import { decodeEntities, decodeHref } from '@markuplint/shared';
|
|
6
4
|
const HYPERLINK_SELECTOR = 'a[href], area[href]';
|
|
7
|
-
|
|
5
|
+
export default createRule({
|
|
6
|
+
meta: {
|
|
7
|
+
category: 'a11y',
|
|
8
|
+
},
|
|
8
9
|
defaultOptions: {
|
|
9
|
-
ariaVersion:
|
|
10
|
+
ariaVersion: ARIA_RECOMMENDED_VERSION,
|
|
10
11
|
fragmentRefersNameAttr: false,
|
|
11
12
|
},
|
|
12
13
|
async verify({ document, report, t }) {
|
|
@@ -18,36 +19,35 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
18
19
|
if (isMutable) {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
|
-
document.querySelectorAll('[id]')
|
|
22
|
+
for (const el of document.querySelectorAll('[id]')) {
|
|
22
23
|
const attr = el.getAttributeNode('id');
|
|
23
24
|
if (!attr) {
|
|
24
|
-
|
|
25
|
+
continue;
|
|
25
26
|
}
|
|
26
27
|
if (attr.isDynamicValue) {
|
|
27
28
|
hasDynamicId = true;
|
|
28
29
|
}
|
|
29
30
|
if (attr.valueType !== 'code') {
|
|
30
|
-
idList.add(
|
|
31
|
+
idList.add(decodeEntities(attr.value));
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
}
|
|
33
34
|
if (hasDynamicId) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
document.querySelectorAll('[name]')
|
|
37
|
+
for (const el of document.querySelectorAll('[name]')) {
|
|
37
38
|
const attr = el.getAttributeNode('name');
|
|
38
39
|
if (!attr) {
|
|
39
|
-
|
|
40
|
+
continue;
|
|
40
41
|
}
|
|
41
42
|
if (attr.isDynamicValue) {
|
|
42
43
|
hasDynamicName = true;
|
|
43
44
|
}
|
|
44
45
|
if (attr.valueType !== 'code') {
|
|
45
|
-
nameList.add(
|
|
46
|
+
nameList.add(decodeEntities(attr.value));
|
|
46
47
|
}
|
|
47
|
-
}
|
|
48
|
+
}
|
|
48
49
|
await document.walkOn('Attr', attr => {
|
|
49
|
-
|
|
50
|
-
const attrSpec = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
|
|
50
|
+
const attrSpec = getAttrSpecs(attr.ownerElement, document.specs);
|
|
51
51
|
if (!attrSpec) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
@@ -68,9 +68,9 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
68
68
|
if (spec.type === 'DOMID' && !idList.has(value)) {
|
|
69
69
|
report({
|
|
70
70
|
scope: attr,
|
|
71
|
-
line:
|
|
72
|
-
col:
|
|
73
|
-
raw:
|
|
71
|
+
line: attr.valueNode?.startLine,
|
|
72
|
+
col: attr.valueNode?.startCol,
|
|
73
|
+
raw: attr.valueNode?.raw,
|
|
74
74
|
message: t('Missing {0}', t('"{0*}" ID', value)),
|
|
75
75
|
});
|
|
76
76
|
}
|
|
@@ -78,29 +78,29 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
78
78
|
const refs = value
|
|
79
79
|
.split(spec.type.separator === 'space' ? /\s/ : ',')
|
|
80
80
|
.map(id => id.trim())
|
|
81
|
-
.filter(
|
|
81
|
+
.filter(Boolean);
|
|
82
82
|
for (const ref of refs) {
|
|
83
83
|
if (!idList.has(ref)) {
|
|
84
84
|
report({
|
|
85
85
|
scope: attr,
|
|
86
|
-
line:
|
|
87
|
-
col:
|
|
88
|
-
raw:
|
|
86
|
+
line: attr.valueNode?.startLine,
|
|
87
|
+
col: attr.valueNode?.startCol,
|
|
88
|
+
raw: attr.valueNode?.raw,
|
|
89
89
|
message: t('Missing {0}', t('"{0*}" ID', ref)),
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
const { props } =
|
|
95
|
+
const { props } = ariaSpecs(document.specs, attr.rule.options.ariaVersion);
|
|
96
96
|
const aria = props.find(prop => prop.name === name);
|
|
97
97
|
if (aria) {
|
|
98
98
|
if (aria.value === 'ID reference' && !idList.has(value)) {
|
|
99
99
|
report({
|
|
100
100
|
scope: attr,
|
|
101
|
-
line:
|
|
102
|
-
col:
|
|
103
|
-
raw:
|
|
101
|
+
line: attr.valueNode?.startLine,
|
|
102
|
+
col: attr.valueNode?.startCol,
|
|
103
|
+
raw: attr.valueNode?.raw,
|
|
104
104
|
message: t('Missing {0}', t('"{0*}" ID', value)),
|
|
105
105
|
});
|
|
106
106
|
}
|
|
@@ -108,14 +108,14 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
108
108
|
const refs = value
|
|
109
109
|
.split(/\s/)
|
|
110
110
|
.map(id => id.trim())
|
|
111
|
-
.filter(
|
|
111
|
+
.filter(Boolean);
|
|
112
112
|
for (const ref of refs) {
|
|
113
113
|
if (!idList.has(ref)) {
|
|
114
114
|
report({
|
|
115
115
|
scope: attr,
|
|
116
|
-
line:
|
|
117
|
-
col:
|
|
118
|
-
raw:
|
|
116
|
+
line: attr.valueNode?.startLine,
|
|
117
|
+
col: attr.valueNode?.startCol,
|
|
118
|
+
raw: attr.valueNode?.raw,
|
|
119
119
|
message: t('Missing {0}', t('"{0*}" ID', ref)),
|
|
120
120
|
});
|
|
121
121
|
}
|
|
@@ -127,7 +127,6 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
127
127
|
* @see https://html.spec.whatwg.org/multipage/browsing-the-web.html#scrolling-to-a-fragment
|
|
128
128
|
*/
|
|
129
129
|
await document.walkOn('Element', el => {
|
|
130
|
-
var _a, _b, _c, _d;
|
|
131
130
|
if (el.rule.options.fragmentRefersNameAttr && hasDynamicName) {
|
|
132
131
|
return;
|
|
133
132
|
}
|
|
@@ -138,11 +137,11 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
138
137
|
if (!href) {
|
|
139
138
|
return;
|
|
140
139
|
}
|
|
141
|
-
const rawFragment =
|
|
140
|
+
const rawFragment = href.value.match(/^#(.+)/)?.[1];
|
|
142
141
|
if (rawFragment == null) {
|
|
143
142
|
return;
|
|
144
143
|
}
|
|
145
|
-
const decodedFragment =
|
|
144
|
+
const decodedFragment = decodeHref(rawFragment);
|
|
146
145
|
// > 2. If fragment is the empty string, then return the special value top of the document.
|
|
147
146
|
// >
|
|
148
147
|
// > 9. If decodedFragment is an ASCII case-insensitive match for the string top, then return the top of the document.
|
|
@@ -153,9 +152,9 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
153
152
|
(el.rule.options.fragmentRefersNameAttr ? !nameList.has(decodedFragment) : true)) {
|
|
154
153
|
report({
|
|
155
154
|
scope: href,
|
|
156
|
-
line:
|
|
157
|
-
col:
|
|
158
|
-
raw:
|
|
155
|
+
line: href.valueNode?.startLine,
|
|
156
|
+
col: href.valueNode?.startCol,
|
|
157
|
+
raw: href.valueNode?.raw,
|
|
159
158
|
message: t('Missing {0}', t('"{0*}" ID', decodedFragment)),
|
|
160
159
|
});
|
|
161
160
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type Options = {
|
|
2
|
-
|
|
2
|
+
ignore?: string | string[];
|
|
3
3
|
};
|
|
4
|
-
declare const _default: Readonly<import(
|
|
4
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Options>>;
|
|
5
5
|
export default _default;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
import { match } from '../helpers.js';
|
|
3
|
+
export default createRule({
|
|
4
|
+
meta: {
|
|
5
|
+
category: 'maintainability',
|
|
6
|
+
},
|
|
6
7
|
defaultSeverity: 'warning',
|
|
7
8
|
defaultOptions: {},
|
|
8
9
|
async verify({ document, report, t }) {
|
|
@@ -17,7 +18,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
17
18
|
: [];
|
|
18
19
|
const name = attr.name;
|
|
19
20
|
for (const ignore of ignoreList) {
|
|
20
|
-
if (
|
|
21
|
+
if (match(name, ignore)) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types.js';
|
|
2
2
|
import type { PermittedContentChoice } from '@markuplint/ml-spec';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
-
export declare function choice(
|
|
5
|
-
pattern: ReadonlyDeep<PermittedContentChoice>,
|
|
6
|
-
elements: readonly ChildNode[],
|
|
7
|
-
specs: Specs,
|
|
8
|
-
options: Options,
|
|
9
|
-
depth: number,
|
|
10
|
-
): Result;
|
|
4
|
+
export declare function choice(pattern: ReadonlyDeep<PermittedContentChoice>, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("./debug");
|
|
5
|
-
const order_1 = require("./order");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { bgBlue, bgGreen, cmLog } from './debug.js';
|
|
2
|
+
import { order } from './order.js';
|
|
3
|
+
import { Collection, modelLog } from './utils.js';
|
|
7
4
|
const indexes = new WeakMap();
|
|
8
|
-
function choice(pattern,
|
|
5
|
+
export function choice(pattern,
|
|
9
6
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
7
|
elements, specs, options, depth) {
|
|
11
|
-
const choiceLog =
|
|
12
|
-
const collection = new
|
|
8
|
+
const choiceLog = cmLog.extend(`choice#${depth}`);
|
|
9
|
+
const collection = new Collection(elements);
|
|
13
10
|
const unmatchedResults = [];
|
|
14
11
|
let i = 0;
|
|
15
12
|
for (const some of pattern.choice) {
|
|
16
|
-
choiceLog('Patterns[%s]: %s', i,
|
|
17
|
-
const result =
|
|
13
|
+
choiceLog('Patterns[%s]: %s', i, modelLog(some, ''));
|
|
14
|
+
const result = order(some, collection.unmatched, specs, options, depth + 1);
|
|
18
15
|
if (result.type === 'MATCHED' ||
|
|
19
16
|
result.type === 'MATCHED_ZERO' ||
|
|
20
|
-
(result.type === 'UNEXPECTED_EXTRA_NODE' && result.matched.length
|
|
17
|
+
(result.type === 'UNEXPECTED_EXTRA_NODE' && result.matched.length > 0)) {
|
|
21
18
|
choiceLog('Results[%s]: %s', i, choiceLogString(pattern.choice, i));
|
|
22
19
|
return {
|
|
23
20
|
type: result.type,
|
|
@@ -34,7 +31,6 @@ elements, specs, options, depth) {
|
|
|
34
31
|
i++;
|
|
35
32
|
}
|
|
36
33
|
const barelyMatchedResult = unmatchedResults.sort((a, b) => {
|
|
37
|
-
var _c, _d, _e, _f;
|
|
38
34
|
if (a.type !== b.type) {
|
|
39
35
|
if (a.type === 'UNEXPECTED_EXTRA_NODE') {
|
|
40
36
|
return -1;
|
|
@@ -47,8 +43,8 @@ elements, specs, options, depth) {
|
|
|
47
43
|
if (computed1 !== 0) {
|
|
48
44
|
return computed1;
|
|
49
45
|
}
|
|
50
|
-
const _a =
|
|
51
|
-
const _b =
|
|
46
|
+
const _a = a.hint.missing?.barelyMatchedElements ?? 0;
|
|
47
|
+
const _b = b.hint.missing?.barelyMatchedElements ?? 0;
|
|
52
48
|
const computed2 = _b - _a;
|
|
53
49
|
return computed2;
|
|
54
50
|
})[0];
|
|
@@ -68,15 +64,14 @@ elements, specs, options, depth) {
|
|
|
68
64
|
hint: barelyMatchedResult.hint,
|
|
69
65
|
};
|
|
70
66
|
}
|
|
71
|
-
exports.choice = choice;
|
|
72
67
|
function choiceLogString(choice, index, barely = false) {
|
|
73
|
-
const colorFn = barely ?
|
|
68
|
+
const colorFn = barely ? bgBlue : bgGreen;
|
|
74
69
|
return choice
|
|
75
70
|
.map((pattern, i) => {
|
|
76
71
|
if (i === index) {
|
|
77
|
-
return colorFn(
|
|
72
|
+
return colorFn(modelLog(pattern, ''));
|
|
78
73
|
}
|
|
79
|
-
return
|
|
74
|
+
return modelLog(pattern, '');
|
|
80
75
|
})
|
|
81
76
|
.join(', ');
|
|
82
77
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types.js';
|
|
2
2
|
import type { PermittedContentPattern } from '@markuplint/ml-spec';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
4
|
/**
|
|
@@ -11,10 +11,4 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
11
11
|
* @param depth
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
export declare function complexBranch(
|
|
15
|
-
pattern: ReadonlyDeep<PermittedContentPattern>,
|
|
16
|
-
elements: readonly ChildNode[],
|
|
17
|
-
specs: Specs,
|
|
18
|
-
options: Options,
|
|
19
|
-
depth: number,
|
|
20
|
-
): Result;
|
|
14
|
+
export declare function complexBranch(pattern: ReadonlyDeep<PermittedContentPattern>, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const count_pattern_1 = require("./count-pattern");
|
|
6
|
-
const transparent_1 = require("./transparent");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { choice } from './choice.js';
|
|
2
|
+
import { countPattern } from './count-pattern.js';
|
|
3
|
+
import { transparent } from './transparent.js';
|
|
4
|
+
import { isChoice, isTransparent } from './utils.js';
|
|
8
5
|
/**
|
|
9
6
|
* Check content condition
|
|
10
7
|
*
|
|
@@ -15,15 +12,14 @@ const utils_1 = require("./utils");
|
|
|
15
12
|
* @param depth
|
|
16
13
|
* @returns
|
|
17
14
|
*/
|
|
18
|
-
function complexBranch(pattern,
|
|
15
|
+
export function complexBranch(pattern,
|
|
19
16
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
20
17
|
elements, specs, options, depth) {
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
18
|
+
if (isChoice(pattern)) {
|
|
19
|
+
return choice(pattern, elements, specs, options, depth);
|
|
23
20
|
}
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
21
|
+
if (isTransparent(pattern)) {
|
|
22
|
+
return transparent(elements);
|
|
26
23
|
}
|
|
27
|
-
return
|
|
24
|
+
return countPattern(pattern, elements, specs, options, depth);
|
|
28
25
|
}
|
|
29
|
-
exports.complexBranch = complexBranch;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ContentModelResult, Element, Options, TagRule } from './types';
|
|
1
|
+
import type { ContentModelResult, Element, Options, TagRule } from './types.js';
|
|
2
2
|
export declare function contentModel(el: Element, rules: readonly TagRule[], options: Options): ContentModelResult[];
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
const start_1 = require("./start");
|
|
6
|
-
function contentModel(
|
|
1
|
+
import { getContentModel } from '@markuplint/ml-spec';
|
|
2
|
+
import { start } from './start.js';
|
|
3
|
+
export function contentModel(
|
|
7
4
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
5
|
el, rules, options) {
|
|
9
|
-
const model = createModel(el, rules);
|
|
6
|
+
const { model, specs } = createModel(el, rules);
|
|
10
7
|
if (model == null) {
|
|
11
8
|
return [
|
|
12
9
|
{
|
|
@@ -17,16 +14,18 @@ el, rules, options) {
|
|
|
17
14
|
},
|
|
18
15
|
];
|
|
19
16
|
}
|
|
20
|
-
const result =
|
|
17
|
+
const result = start(model, el, specs, options);
|
|
21
18
|
return result;
|
|
22
19
|
}
|
|
23
|
-
exports.contentModel = contentModel;
|
|
24
20
|
function createModel(
|
|
25
21
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
26
22
|
el, rules) {
|
|
27
23
|
const specs = cachedSpecs(el.ownerMLDocument.specs, rules);
|
|
28
|
-
const model =
|
|
29
|
-
return
|
|
24
|
+
const model = getContentModel(el, specs.specs);
|
|
25
|
+
return {
|
|
26
|
+
model,
|
|
27
|
+
specs,
|
|
28
|
+
};
|
|
30
29
|
}
|
|
31
30
|
const caches = new Map();
|
|
32
31
|
function cachedSpecs(specs, rules) {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
import type {
|
|
3
|
-
PermittedContentOneOrMore,
|
|
4
|
-
PermittedContentOptional,
|
|
5
|
-
PermittedContentRequire,
|
|
6
|
-
PermittedContentZeroOrMore,
|
|
7
|
-
} from '@markuplint/ml-spec';
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types.js';
|
|
2
|
+
import type { PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentZeroOrMore } from '@markuplint/ml-spec';
|
|
8
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
9
4
|
/**
|
|
10
5
|
* Check count
|
|
@@ -16,14 +11,4 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
16
11
|
* @param depth
|
|
17
12
|
* @returns
|
|
18
13
|
*/
|
|
19
|
-
export declare function countPattern(
|
|
20
|
-
pattern:
|
|
21
|
-
| ReadonlyDeep<PermittedContentOneOrMore>
|
|
22
|
-
| ReadonlyDeep<PermittedContentOptional>
|
|
23
|
-
| ReadonlyDeep<PermittedContentRequire>
|
|
24
|
-
| ReadonlyDeep<PermittedContentZeroOrMore>,
|
|
25
|
-
elements: readonly ChildNode[],
|
|
26
|
-
specs: Specs,
|
|
27
|
-
options: Options,
|
|
28
|
-
depth: number,
|
|
29
|
-
): Result;
|
|
14
|
+
export declare function countPattern(pattern: ReadonlyDeep<PermittedContentOneOrMore> | ReadonlyDeep<PermittedContentOptional> | ReadonlyDeep<PermittedContentRequire> | ReadonlyDeep<PermittedContentZeroOrMore>, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const recursive_branch_1 = require("./recursive-branch");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const cLog = debug_1.cmLog.extend('countCompereResult');
|
|
1
|
+
import { cmLog } from './debug.js';
|
|
2
|
+
import { recursiveBranch } from './recursive-branch.js';
|
|
3
|
+
import { Collection, mergeHints, modelLog, normalizeModel } from './utils.js';
|
|
4
|
+
const cLog = cmLog.extend('countCompereResult');
|
|
8
5
|
/**
|
|
9
6
|
* Check count
|
|
10
7
|
*
|
|
@@ -15,13 +12,13 @@ const cLog = debug_1.cmLog.extend('countCompereResult');
|
|
|
15
12
|
* @param depth
|
|
16
13
|
* @returns
|
|
17
14
|
*/
|
|
18
|
-
function countPattern(pattern,
|
|
15
|
+
export function countPattern(pattern,
|
|
19
16
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
20
17
|
elements, specs, options, depth) {
|
|
21
|
-
const ptLog =
|
|
22
|
-
const collection = new
|
|
23
|
-
const { model, min, max, repeat, missingType } =
|
|
24
|
-
ptLog('Model:\n RegEx: %s\n Schema: %o',
|
|
18
|
+
const ptLog = cmLog.extend(`countPattern#${depth}`);
|
|
19
|
+
const collection = new Collection(elements);
|
|
20
|
+
const { model, min, max, repeat, missingType } = normalizeModel(pattern);
|
|
21
|
+
ptLog('Model:\n RegEx: %s\n Schema: %o', modelLog(model, repeat), pattern);
|
|
25
22
|
let prevResult = null;
|
|
26
23
|
let barelyResult = null;
|
|
27
24
|
let loopCount = 0;
|
|
@@ -29,11 +26,11 @@ elements, specs, options, depth) {
|
|
|
29
26
|
while (true) {
|
|
30
27
|
loopCount++;
|
|
31
28
|
ptLog('Check#%s: %s', loopCount, collection);
|
|
32
|
-
const result =
|
|
29
|
+
const result = recursiveBranch(model, collection.unmatched, specs, options, depth);
|
|
33
30
|
const added = collection.addMatched(result.matched);
|
|
34
31
|
const { matchedCount } = collection;
|
|
35
32
|
if (result.type === 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY') {
|
|
36
|
-
ptLog('MATCHED_ZERO:\n model: %s\n max: %s\n collection: %s\n matched element: %s',
|
|
33
|
+
ptLog('MATCHED_ZERO:\n model: %s\n max: %s\n collection: %s\n matched element: %s', modelLog(model, repeat), max, collection, matchedCount);
|
|
37
34
|
return compereResult({
|
|
38
35
|
type: 'MATCHED_ZERO',
|
|
39
36
|
matched: collection.matched,
|
|
@@ -45,14 +42,14 @@ elements, specs, options, depth) {
|
|
|
45
42
|
}
|
|
46
43
|
if (max < collection.matchedCount) {
|
|
47
44
|
collection.max(max);
|
|
48
|
-
ptLog('UNEXPECTED_EXTRA_NODE:\n model: %s\n max: %s\n collection: %s\n matched element: %s',
|
|
45
|
+
ptLog('UNEXPECTED_EXTRA_NODE:\n model: %s\n max: %s\n collection: %s\n matched element: %s', modelLog(model, repeat), max, collection, matchedCount);
|
|
49
46
|
return compereResult({
|
|
50
47
|
type: 'UNEXPECTED_EXTRA_NODE',
|
|
51
48
|
matched: collection.matched,
|
|
52
49
|
unmatched: collection.unmatched,
|
|
53
50
|
zeroMatch: result.zeroMatch,
|
|
54
51
|
query: result.query,
|
|
55
|
-
hint:
|
|
52
|
+
hint: mergeHints(result.hint, { max }),
|
|
56
53
|
}, barelyResult);
|
|
57
54
|
}
|
|
58
55
|
if (prevResult) {
|
|
@@ -91,7 +88,7 @@ elements, specs, options, depth) {
|
|
|
91
88
|
result.type === 'MISSING_NODE_ONE_OR_MORE' ||
|
|
92
89
|
result.type === 'TRANSPARENT_MODEL_DISALLOWS'
|
|
93
90
|
? result.type
|
|
94
|
-
: missingType
|
|
91
|
+
: missingType ?? 'MISSING_NODE_REQUIRED';
|
|
95
92
|
ptLog('%s(in %s); Needs %s', resultType, missingType, result.query);
|
|
96
93
|
return compereResult({
|
|
97
94
|
type: resultType,
|
|
@@ -99,7 +96,7 @@ elements, specs, options, depth) {
|
|
|
99
96
|
unmatched: collection.unmatched,
|
|
100
97
|
zeroMatch: result.zeroMatch,
|
|
101
98
|
query: result.query,
|
|
102
|
-
hint:
|
|
99
|
+
hint: mergeHints(result.hint, {
|
|
103
100
|
missing: {
|
|
104
101
|
barelyMatchedElements: collection.matched.length,
|
|
105
102
|
need: result.query,
|
|
@@ -115,7 +112,7 @@ elements, specs, options, depth) {
|
|
|
115
112
|
unmatched: collection.unmatched,
|
|
116
113
|
zeroMatch,
|
|
117
114
|
query: result.query,
|
|
118
|
-
hint:
|
|
115
|
+
hint: mergeHints(result.hint, {
|
|
119
116
|
missing: {
|
|
120
117
|
barelyMatchedElements: collection.matched.length,
|
|
121
118
|
need: result.query,
|
|
@@ -127,7 +124,7 @@ elements, specs, options, depth) {
|
|
|
127
124
|
ptLog('continue⤴️ (add prev)');
|
|
128
125
|
continue;
|
|
129
126
|
}
|
|
130
|
-
ptLog('%s:\n model: %s\n max: %s\n collection: %s\n matched element: %s', resultType,
|
|
127
|
+
ptLog('%s:\n model: %s\n max: %s\n collection: %s\n matched element: %s', resultType, modelLog(model, repeat), max, collection, matchedCount);
|
|
131
128
|
if (result.type === 'MISSING_NODE_REQUIRED' ||
|
|
132
129
|
result.type === 'MISSING_NODE_ONE_OR_MORE' ||
|
|
133
130
|
result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
|
|
@@ -143,20 +140,18 @@ elements, specs, options, depth) {
|
|
|
143
140
|
return compereResult(matchedResult, barelyResult);
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
|
-
exports.countPattern = countPattern;
|
|
147
143
|
function compereResult(
|
|
148
144
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
149
145
|
a,
|
|
150
146
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
151
147
|
b) {
|
|
152
|
-
|
|
153
|
-
cLog('current: %s %O\nbarely: %s %O', a.type, a.hint, b === null || b === void 0 ? void 0 : b.type, b === null || b === void 0 ? void 0 : b.hint);
|
|
148
|
+
cLog('current: %s %O\nbarely: %s %O', a.type, a.hint, b?.type, b?.hint);
|
|
154
149
|
if (b == null) {
|
|
155
150
|
return a;
|
|
156
151
|
}
|
|
157
152
|
if (a.type === 'MATCHED' || a.type === 'MATCHED_ZERO' || a.type === 'UNEXPECTED_EXTRA_NODE') {
|
|
158
153
|
return a;
|
|
159
154
|
}
|
|
160
|
-
const result =
|
|
155
|
+
const result = [a, b].sort((a, b) => (b.hint.missing?.barelyMatchedElements ?? 0) - (a.hint.missing?.barelyMatchedElements ?? 0))[0] ?? a;
|
|
161
156
|
return result;
|
|
162
157
|
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const cmLog:
|
|
1
|
+
import type { Log } from '../debug.js';
|
|
2
|
+
export declare const cmLog: Log;
|
|
3
3
|
export declare const bgGreen: {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
(): void;
|
|
5
|
+
bold(): void;
|
|
6
6
|
};
|
|
7
7
|
export declare const green: {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
(): void;
|
|
9
|
+
bold(): void;
|
|
10
10
|
};
|
|
11
11
|
export declare const bgRed: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
(): void;
|
|
13
|
+
bold(): void;
|
|
14
14
|
};
|
|
15
15
|
export declare const bgBlue: {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
(): void;
|
|
17
|
+
bold(): void;
|
|
18
18
|
};
|
|
19
19
|
export declare const blue: {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
(): void;
|
|
21
|
+
bold(): void;
|
|
22
22
|
};
|
|
23
23
|
export declare const bgMagenta: {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
(): void;
|
|
25
|
+
bold(): void;
|
|
26
26
|
};
|
|
27
27
|
export declare const cyan: {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
(): void;
|
|
29
|
+
bold(): void;
|
|
30
30
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.cyan = exports.bgMagenta = exports.blue = exports.bgBlue = exports.bgRed = exports.green = exports.bgGreen = exports.cmLog = void 0;
|
|
4
|
-
const debug_1 = require("../debug");
|
|
5
|
-
exports.cmLog = debug_1.log.extend('content-model');
|
|
1
|
+
import { log } from '../debug.js';
|
|
2
|
+
export const cmLog = log.extend('content-model');
|
|
6
3
|
const fn = () => { };
|
|
7
4
|
fn.bold = () => { };
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
export const bgGreen = fn;
|
|
6
|
+
export const green = fn;
|
|
7
|
+
export const bgRed = fn;
|
|
8
|
+
export const bgBlue = fn;
|
|
9
|
+
export const blue = fn;
|
|
10
|
+
export const bgMagenta = fn;
|
|
11
|
+
export const cyan = fn;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import type { Log } from '../debug.js';
|
|
2
|
+
import color from 'ansi-colors';
|
|
3
|
+
export declare const cmLog: Log;
|
|
4
|
+
export declare const bgGreen: color.StyleFunction;
|
|
5
|
+
export declare const green: color.StyleFunction;
|
|
6
|
+
export declare const bgRed: color.StyleFunction;
|
|
7
|
+
export declare const bgBlue: color.StyleFunction;
|
|
8
|
+
export declare const blue: color.StyleFunction;
|
|
9
|
+
export declare const bgMagenta: color.StyleFunction;
|
|
10
|
+
export declare const cyan: color.StyleFunction;
|