@markuplint/rules 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/attr-check.d.ts +19 -8
- package/lib/attr-check.js +19 -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 +12 -2
- package/lib/create-message.js +5 -4
- 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 +0 -1
- package/lib/helpers.js +8 -9
- package/lib/id-duplication/index.d.ts +3 -1
- package/lib/index.d.ts +172 -67
- package/lib/ineffective-attr/index.d.ts +3 -1
- package/lib/ineffective-attr/index.js +2 -5
- package/lib/invalid-attr/index.d.ts +17 -13
- package/lib/invalid-attr/index.js +8 -8
- 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 +1 -1
- 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-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 +4 -14
- package/lib/no-use-event-handler-attr/index.d.ts +2 -2
- package/lib/permitted-contents/choice.d.ts +7 -1
- package/lib/permitted-contents/complex-branch.d.ts +7 -1
- package/lib/permitted-contents/content-model.js +1 -1
- package/lib/permitted-contents/count-pattern.d.ts +17 -2
- package/lib/permitted-contents/count-pattern.js +1 -1
- package/lib/permitted-contents/debug.browser.d.ts +15 -15
- package/lib/permitted-contents/debug.d.ts +1 -1
- package/lib/permitted-contents/index.d.ts +1 -1
- package/lib/permitted-contents/index.js +5 -10
- package/lib/permitted-contents/matches-selector.d.ts +6 -1
- package/lib/permitted-contents/matches-selector.js +1 -1
- package/lib/permitted-contents/order.d.ts +7 -1
- package/lib/permitted-contents/order.js +4 -4
- package/lib/permitted-contents/recursive-branch.d.ts +7 -1
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +7 -3
- package/lib/permitted-contents/represent-transparent-nodes.js +1 -1
- package/lib/permitted-contents/start.d.ts +6 -1
- package/lib/permitted-contents/start.js +1 -1
- package/lib/permitted-contents/types.d.ts +29 -29
- package/lib/permitted-contents/utils.js +3 -3
- package/lib/placeholder-label-option/index.d.ts +1 -1
- package/lib/placeholder-label-option/index.js +5 -4
- package/lib/require-accessible-name/index.d.ts +2 -2
- package/lib/require-datetime/index.d.ts +2 -2
- package/lib/require-datetime/types.d.ts +2 -2
- package/lib/require-datetime/utils.js +3 -2
- package/lib/required-attr/index.d.ts +3 -3
- package/lib/required-attr/index.js +4 -4
- package/lib/required-element/index.d.ts +2 -2
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/use-list/index.d.ts +2 -2
- package/lib/use-list/index.js +4 -3
- 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.js +1 -1
- 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/no-global-prop.d.ts +7 -3
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +7 -3
- package/lib/wai-aria/checkings/required-owned-elements.js +1 -1
- package/lib/wai-aria/checkings/required-prop.d.ts +12 -6
- 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/types.d.ts +10 -10
- package/package.json +8 -8
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import type { AttributeType } from '@markuplint/ml-spec';
|
|
2
2
|
type Option = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
attrs?: Record<string, Rule>;
|
|
4
|
+
ignoreAttrNamePrefix?: string | string[];
|
|
5
|
+
allowToAddPropertiesForPretender?: boolean;
|
|
6
6
|
};
|
|
7
|
-
type Rule =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
type Rule =
|
|
8
|
+
| {
|
|
9
|
+
enum: [string, ...string[]];
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
pattern: string;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
type: AttributeType;
|
|
16
|
+
}
|
|
17
|
+
| {
|
|
18
|
+
disallowed: true;
|
|
19
|
+
};
|
|
20
|
+
declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Option>>;
|
|
17
21
|
export default _default;
|
|
@@ -9,7 +9,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
9
9
|
defaultOptions: {},
|
|
10
10
|
async verify({ document, report, t }) {
|
|
11
11
|
await document.walkOn('Attr', attr => {
|
|
12
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
13
13
|
// Default
|
|
14
14
|
const allowToAddPropertiesForPretender = (_a = attr.rule.options.allowToAddPropertiesForPretender) !== null && _a !== void 0 ? _a : true;
|
|
15
15
|
if (attr.isDirective) {
|
|
@@ -33,7 +33,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
33
33
|
}
|
|
34
34
|
const valueNode = attr.valueNode;
|
|
35
35
|
const value = attr.value;
|
|
36
|
-
if (attr.rule.options.ignoreAttrNamePrefix) {
|
|
36
|
+
if (attr.rule.options.ignoreAttrNamePrefix != null) {
|
|
37
37
|
const ignoreAttrNamePrefixes = Array.isArray(attr.rule.options.ignoreAttrNamePrefix)
|
|
38
38
|
? attr.rule.options.ignoreAttrNamePrefix
|
|
39
39
|
: [attr.rule.options.ignoreAttrNamePrefix];
|
|
@@ -75,7 +75,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
75
75
|
log('Checking %s[%s="%s"]', attr.nodeName, name, value);
|
|
76
76
|
invalid = (0, helpers_1.isValidAttr)(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
|
|
77
77
|
}
|
|
78
|
-
if (invalid) {
|
|
78
|
+
if (invalid !== false) {
|
|
79
79
|
switch (invalid.invalidType) {
|
|
80
80
|
case 'disallowed-attr': {
|
|
81
81
|
report({
|
|
@@ -92,15 +92,15 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
92
92
|
scope: attr,
|
|
93
93
|
message: invalid.message,
|
|
94
94
|
line: ((_b = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startLine) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = invalid.loc) === null || _c === void 0 ? void 0 : _c.line) !== null && _d !== void 0 ? _d : 0),
|
|
95
|
-
col:
|
|
96
|
-
? ((
|
|
97
|
-
: ((
|
|
98
|
-
raw: (
|
|
95
|
+
col: invalid.loc && invalid.loc.line > 0
|
|
96
|
+
? ((_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.col) + 1
|
|
97
|
+
: ((_f = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _f !== void 0 ? _f : 0) + ((_h = (_g = invalid.loc) === null || _g === void 0 ? void 0 : _g.col) !== null && _h !== void 0 ? _h : 0),
|
|
98
|
+
raw: (_k = (_j = invalid.loc) === null || _j === void 0 ? void 0 : _j.raw) !== null && _k !== void 0 ? _k : value,
|
|
99
99
|
});
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
102
102
|
case 'non-existent': {
|
|
103
|
-
if (allowToAddPropertiesForPretender && ((
|
|
103
|
+
if (allowToAddPropertiesForPretender && ((_l = attr.ownerElement.pretenderContext) === null || _l === void 0 ? void 0 : _l.type) === 'origin') {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs.specs);
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
declare const _default: Readonly<
|
|
1
|
+
declare const _default: Readonly<
|
|
2
|
+
import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
|
|
3
|
+
>;
|
|
2
4
|
export default _default;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
type Options = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
ignoreRoles: Roles[];
|
|
3
|
+
labelEachArea: boolean;
|
|
4
4
|
};
|
|
5
5
|
type TopLevelRoles = 'banner' | 'main' | 'complementary' | 'contentinfo';
|
|
6
6
|
type Roles = TopLevelRoles | 'form' | 'navigation' | 'region';
|
|
7
|
-
declare const _default: Readonly<import(
|
|
7
|
+
declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Options>>;
|
|
8
8
|
export default _default;
|
|
@@ -116,7 +116,7 @@ roleset) {
|
|
|
116
116
|
function hasLabel(
|
|
117
117
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
118
118
|
el) {
|
|
119
|
-
const hasHeading =
|
|
119
|
+
const hasHeading = el.querySelectorAll('h1, h2, h3, h4, h5, h6').length > 0;
|
|
120
120
|
if (hasHeading && el.matches('[aria-labelledby]')) {
|
|
121
121
|
return true;
|
|
122
122
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
declare const _default: Readonly<
|
|
1
|
+
declare const _default: Readonly<
|
|
2
|
+
import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
|
|
3
|
+
>;
|
|
2
4
|
export default _default;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
declare const _default: Readonly<
|
|
1
|
+
declare const _default: Readonly<
|
|
2
|
+
import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
|
|
3
|
+
>;
|
|
2
4
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type Options = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
extendsExposableElements?: boolean;
|
|
3
|
+
ignoreIfAriaBusy?: boolean;
|
|
4
4
|
};
|
|
5
|
-
declare const _default: Readonly<import(
|
|
5
|
+
declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Options>>;
|
|
6
6
|
export default _default;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
declare const _default: Readonly<
|
|
1
|
+
declare const _default: Readonly<
|
|
2
|
+
import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
|
|
3
|
+
>;
|
|
2
4
|
export default _default;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { ARIAVersion } from '@markuplint/ml-spec';
|
|
2
|
-
declare const _default: Readonly<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
declare const _default: Readonly<
|
|
3
|
+
import('@markuplint/ml-core').RuleSeed<
|
|
4
|
+
import('@markuplint/ml-core').RuleConfigValue,
|
|
5
|
+
{
|
|
6
|
+
ariaVersion: ARIAVersion;
|
|
7
|
+
fragmentRefersNameAttr: boolean;
|
|
8
|
+
}
|
|
9
|
+
>
|
|
10
|
+
>;
|
|
6
11
|
export default _default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
+
const shared_1 = require("@markuplint/shared");
|
|
4
5
|
const HYPERLINK_SELECTOR = 'a[href], area[href]';
|
|
5
6
|
exports.default = (0, ml_core_1.createRule)({
|
|
6
7
|
defaultOptions: {
|
|
@@ -25,7 +26,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
25
26
|
hasDynamicId = true;
|
|
26
27
|
}
|
|
27
28
|
if (attr.valueType !== 'code') {
|
|
28
|
-
idList.add(attr.value);
|
|
29
|
+
idList.add((0, shared_1.decodeEntities)(attr.value));
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
32
|
if (hasDynamicId) {
|
|
@@ -40,7 +41,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
40
41
|
hasDynamicName = true;
|
|
41
42
|
}
|
|
42
43
|
if (attr.valueType !== 'code') {
|
|
43
|
-
nameList.add(attr.value);
|
|
44
|
+
nameList.add((0, shared_1.decodeEntities)(attr.value));
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
await document.walkOn('Attr', attr => {
|
|
@@ -140,7 +141,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
140
141
|
if (rawFragment == null) {
|
|
141
142
|
return;
|
|
142
143
|
}
|
|
143
|
-
const decodedFragment =
|
|
144
|
+
const decodedFragment = (0, shared_1.decodeHref)(rawFragment);
|
|
144
145
|
// > 2. If fragment is the empty string, then return the special value top of the document.
|
|
145
146
|
// >
|
|
146
147
|
// > 9. If decodedFragment is an ASCII case-insensitive match for the string top, then return the top of the document.
|
|
@@ -160,14 +161,3 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
160
161
|
});
|
|
161
162
|
},
|
|
162
163
|
});
|
|
163
|
-
function decode(fragment) {
|
|
164
|
-
try {
|
|
165
|
-
return decodeURI(fragment);
|
|
166
|
-
}
|
|
167
|
-
catch (e) {
|
|
168
|
-
if (e instanceof URIError) {
|
|
169
|
-
return fragment;
|
|
170
|
-
}
|
|
171
|
-
throw e;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -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,4 +1,10 @@
|
|
|
1
1
|
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
2
|
import type { PermittedContentChoice } from '@markuplint/ml-spec';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
-
export declare function choice(
|
|
4
|
+
export declare function choice(
|
|
5
|
+
pattern: ReadonlyDeep<PermittedContentChoice>,
|
|
6
|
+
elements: readonly ChildNode[],
|
|
7
|
+
specs: Specs,
|
|
8
|
+
options: Options,
|
|
9
|
+
depth: number,
|
|
10
|
+
): Result;
|
|
@@ -11,4 +11,10 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
11
11
|
* @param depth
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
export declare function complexBranch(
|
|
14
|
+
export declare function complexBranch(
|
|
15
|
+
pattern: ReadonlyDeep<PermittedContentPattern>,
|
|
16
|
+
elements: readonly ChildNode[],
|
|
17
|
+
specs: Specs,
|
|
18
|
+
options: Options,
|
|
19
|
+
depth: number,
|
|
20
|
+
): Result;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
PermittedContentOneOrMore,
|
|
4
|
+
PermittedContentOptional,
|
|
5
|
+
PermittedContentRequire,
|
|
6
|
+
PermittedContentZeroOrMore,
|
|
7
|
+
} from '@markuplint/ml-spec';
|
|
3
8
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
9
|
/**
|
|
5
10
|
* Check count
|
|
@@ -11,4 +16,14 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
11
16
|
* @param depth
|
|
12
17
|
* @returns
|
|
13
18
|
*/
|
|
14
|
-
export declare function countPattern(
|
|
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;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/// <reference types="debug" />
|
|
2
|
-
export declare const cmLog: import(
|
|
2
|
+
export declare const cmLog: import('debug').Debugger;
|
|
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
|
};
|
|
@@ -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 (!el.rule.value) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
14
|
if (el.rule.options.ignoreHasMutableChildren && el.hasMutableChildren()) {
|
|
18
15
|
return;
|
|
19
16
|
}
|
|
20
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':
|
|
@@ -1,3 +1,8 @@
|
|
|
1
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;
|
|
@@ -11,4 +11,10 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
11
11
|
* @param depth
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
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;
|
|
@@ -29,7 +29,7 @@ nodes, specs, options, depth) {
|
|
|
29
29
|
let backtrackMode = false;
|
|
30
30
|
let afterBacktrack = false;
|
|
31
31
|
const unmatchedResults = [];
|
|
32
|
-
while (patterns.length && patterns[0]) {
|
|
32
|
+
while (patterns.length > 0 && patterns[0]) {
|
|
33
33
|
result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
|
|
34
34
|
collection.addMatched(result.matched);
|
|
35
35
|
if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
|
|
@@ -45,7 +45,7 @@ nodes, specs, options, depth) {
|
|
|
45
45
|
if (!barelyMatchedResult) {
|
|
46
46
|
throw new Error('Unreachable code');
|
|
47
47
|
}
|
|
48
|
-
orderLog('Result (%s): %s%s', result.type, collection.toString(true), ((_a = barelyMatchedResult.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements)
|
|
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
49
|
? `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`
|
|
50
50
|
: '');
|
|
51
51
|
return {
|
|
@@ -74,7 +74,7 @@ nodes, specs, options, depth) {
|
|
|
74
74
|
}
|
|
75
75
|
patterns.shift();
|
|
76
76
|
}
|
|
77
|
-
if (collection.unmatched.length) {
|
|
77
|
+
if (collection.unmatched.length > 0) {
|
|
78
78
|
orderLog('Result (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
|
|
79
79
|
return {
|
|
80
80
|
type: 'UNEXPECTED_EXTRA_NODE',
|
|
@@ -85,7 +85,7 @@ nodes, specs, options, depth) {
|
|
|
85
85
|
hint: (_c = result === null || result === void 0 ? void 0 : result.hint) !== null && _c !== void 0 ? _c : {},
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
const resultType = collection.matched.length ? 'MATCHED' : 'MATCHED_ZERO';
|
|
88
|
+
const resultType = collection.matched.length > 0 ? 'MATCHED' : 'MATCHED_ZERO';
|
|
89
89
|
orderLog('Result (%s): %s', resultType, collection.toString(true));
|
|
90
90
|
return {
|
|
91
91
|
type: resultType,
|
|
@@ -2,4 +2,10 @@ 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(
|
|
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;
|
|
@@ -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
|
};
|
|
@@ -33,7 +33,7 @@ nodes, specs, options) {
|
|
|
33
33
|
}
|
|
34
34
|
const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
|
|
35
35
|
let unmatched;
|
|
36
|
-
if (noTransparentModels.length) {
|
|
36
|
+
if (noTransparentModels.length > 0) {
|
|
37
37
|
const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
|
|
38
38
|
unmatched = result.unmatched;
|
|
39
39
|
}
|
|
@@ -10,4 +10,9 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
10
10
|
* @param options
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
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[];
|
|
@@ -4,49 +4,49 @@ import type { ReadonlyDeep } from 'type-fest';
|
|
|
4
4
|
export type Element = _Element<TagRule[], Options>;
|
|
5
5
|
export type ChildNode = _ChildNode<TagRule[], Options>;
|
|
6
6
|
export type Specs = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}[];
|
|
15
15
|
};
|
|
16
16
|
export type ContentModelResult = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
type: MatchedReason | UnmatchedReason;
|
|
18
|
+
scope: ChildNode;
|
|
19
|
+
query: Result['query'];
|
|
20
|
+
hint: Result['hint'];
|
|
21
21
|
};
|
|
22
22
|
export type Result<T extends string = MatchedReason> = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
type: MatchedReason | UnmatchedReason | T;
|
|
24
|
+
matched: ChildNode[];
|
|
25
|
+
unmatched: ChildNode[];
|
|
26
|
+
zeroMatch: boolean;
|
|
27
|
+
query: string;
|
|
28
|
+
hint: Hints;
|
|
29
29
|
};
|
|
30
30
|
export type Hints = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
max?: number;
|
|
32
|
+
not?: ChildNode;
|
|
33
|
+
transparent?: Element;
|
|
34
|
+
missing?: {
|
|
35
|
+
barelyMatchedElements?: number;
|
|
36
|
+
need?: string;
|
|
37
|
+
};
|
|
38
38
|
};
|
|
39
39
|
export type MatchedReason = 'MATCHED' | 'MATCHED_ZERO';
|
|
40
40
|
export type UnmatchedReason = 'NOTHING' | 'UNEXPECTED_EXTRA_NODE' | 'TRANSPARENT_MODEL_DISALLOWS' | MissingNodeReason;
|
|
41
41
|
export type MissingNodeReason = 'MISSING_NODE_REQUIRED' | 'MISSING_NODE_ONE_OR_MORE';
|
|
42
42
|
export type RepeatSign = '' | '?' | '+' | '*' | `{${number},${number}}`;
|
|
43
43
|
export type TransparentModel = {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
el: Element;
|
|
45
|
+
additionalCondition: string;
|
|
46
46
|
};
|
|
47
47
|
export type TagRule = {
|
|
48
|
-
|
|
48
|
+
readonly tag: string;
|
|
49
49
|
} & ReadonlyDeep<ContentModel>;
|
|
50
50
|
export type Options = {
|
|
51
|
-
|
|
51
|
+
readonly ignoreHasMutableChildren: boolean;
|
|
52
52
|
};
|
|
@@ -43,7 +43,7 @@ function matches(selector,
|
|
|
43
43
|
node, specs) {
|
|
44
44
|
const selectorResult = (0, selector_1.createSelector)(selector, specs).search(node);
|
|
45
45
|
const matched = selectorResult.filter((r) => r.matched);
|
|
46
|
-
if (matched.length) {
|
|
46
|
+
if (matched.length > 0) {
|
|
47
47
|
return {
|
|
48
48
|
matched: true,
|
|
49
49
|
};
|
|
@@ -64,9 +64,9 @@ function descendants(
|
|
|
64
64
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
65
65
|
selectorResult) {
|
|
66
66
|
let nodes = selectorResult.nodes.slice();
|
|
67
|
-
while (selectorResult.has.length) {
|
|
67
|
+
while (selectorResult.has.length > 0) {
|
|
68
68
|
for (const dep of selectorResult.has) {
|
|
69
|
-
if (
|
|
69
|
+
if (dep.has.length === 0) {
|
|
70
70
|
nodes = dep.nodes;
|
|
71
71
|
continue;
|
|
72
72
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: Readonly<import(
|
|
1
|
+
declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, undefined>>;
|
|
2
2
|
export default _default;
|