@markuplint/rules 2.4.8 → 2.4.9-canary.2
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/package.json +6 -6
- package/lib/label-has-control/index.d.ts +0 -2
- package/lib/label-has-control/index.js +0 -28
- package/lib/no-empty-palpable-content/index.d.ts +0 -6
- package/lib/no-empty-palpable-content/index.js +0 -34
- package/lib/permitted-contents/choice.d.ts +0 -3
- package/lib/permitted-contents/choice.js +0 -37
- package/lib/permitted-contents/complex-branch.d.ts +0 -13
- package/lib/permitted-contents/complex-branch.js +0 -27
- package/lib/permitted-contents/content-model.d.ts +0 -2
- package/lib/permitted-contents/content-model.js +0 -49
- package/lib/permitted-contents/count-pattern.d.ts +0 -13
- package/lib/permitted-contents/count-pattern.js +0 -155
- package/lib/permitted-contents/debug.d.ts +0 -2
- package/lib/permitted-contents/debug.js +0 -5
- package/lib/permitted-contents/matches-selector.d.ts +0 -3
- package/lib/permitted-contents/matches-selector.js +0 -185
- package/lib/permitted-contents/order.d.ts +0 -13
- package/lib/permitted-contents/order.js +0 -89
- package/lib/permitted-contents/recursive-branch.d.ts +0 -4
- package/lib/permitted-contents/recursive-branch.js +0 -43
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +0 -6
- package/lib/permitted-contents/represent-transparent-nodes.js +0 -79
- package/lib/permitted-contents/start.d.ts +0 -12
- package/lib/permitted-contents/start.js +0 -71
- package/lib/permitted-contents/transparent.d.ts +0 -2
- package/lib/permitted-contents/transparent.js +0 -34
- package/lib/permitted-contents/types.d.ts +0 -45
- package/lib/permitted-contents/types.js +0 -2
- package/lib/permitted-contents/utils.d.ts +0 -32
- package/lib/permitted-contents/utils.js +0 -184
- package/lib/wai-aria/checkings/abstract-role.d.ts +0 -3
- package/lib/wai-aria/checkings/abstract-role.js +0 -22
- package/lib/wai-aria/checkings/default-value.d.ts +0 -6
- package/lib/wai-aria/checkings/default-value.js +0 -17
- package/lib/wai-aria/checkings/deprecated-props.d.ts +0 -7
- package/lib/wai-aria/checkings/deprecated-props.js +0 -18
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +0 -7
- package/lib/wai-aria/checkings/disallowed-prop.js +0 -22
- package/lib/wai-aria/checkings/implicit-props.d.ts +0 -7
- package/lib/wai-aria/checkings/implicit-props.js +0 -50
- package/lib/wai-aria/checkings/implicit-role.d.ts +0 -3
- package/lib/wai-aria/checkings/implicit-role.js +0 -21
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +0 -11
- package/lib/wai-aria/checkings/interaction-in-hidden.js +0 -47
- package/lib/wai-aria/checkings/no-global-prop.d.ts +0 -6
- package/lib/wai-aria/checkings/no-global-prop.js +0 -14
- package/lib/wai-aria/checkings/non-existent-role.d.ts +0 -3
- package/lib/wai-aria/checkings/non-existent-role.js +0 -28
- package/lib/wai-aria/checkings/permitted-roles.d.ts +0 -3
- package/lib/wai-aria/checkings/permitted-roles.js +0 -28
- package/lib/wai-aria/checkings/presentational-children.d.ts +0 -29
- package/lib/wai-aria/checkings/presentational-children.js +0 -60
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +0 -11
- package/lib/wai-aria/checkings/required-owned-elements.js +0 -87
- package/lib/wai-aria/checkings/required-prop.d.ts +0 -9
- package/lib/wai-aria/checkings/required-prop.js +0 -27
- package/lib/wai-aria/checkings/value.d.ts +0 -13
- package/lib/wai-aria/checkings/value.js +0 -91
- package/lib/wai-aria/types.d.ts +0 -13
- package/lib/wai-aria/types.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/rules",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.9-canary.2+353c7e93",
|
|
4
4
|
"description": "Rules for markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"clean": "tsc --build --clean"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@markuplint/html-spec": "2.9.
|
|
21
|
-
"@markuplint/ml-core": "2.3.
|
|
22
|
-
"@markuplint/ml-spec": "2.1.
|
|
23
|
-
"@markuplint/types": "2.2.
|
|
20
|
+
"@markuplint/html-spec": "2.9.2-canary.4+353c7e93",
|
|
21
|
+
"@markuplint/ml-core": "2.3.7-canary.4+353c7e93",
|
|
22
|
+
"@markuplint/ml-spec": "2.1.3-canary.4+353c7e93",
|
|
23
|
+
"@markuplint/types": "2.2.2-canary.4+353c7e93",
|
|
24
24
|
"debug": "^4.3.4",
|
|
25
25
|
"html-entities": "^2.3.3",
|
|
26
26
|
"tslib": "^2.3.1"
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/debug": "^4.1.7"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "353c7e9360a16203b79539b2f5ffeca03ddc3e9e"
|
|
32
32
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
-
const controlSelector = ["input:not([type='hidden' i])", 'select', 'textarea'].join(',');
|
|
5
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
6
|
-
defaultSeverity: 'warning',
|
|
7
|
-
async verify({ document, report, t }) {
|
|
8
|
-
await document.walkOn('Element', el => {
|
|
9
|
-
if (el.localName !== 'label') {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (el.children.length === 0 && !el.hasAttribute('for')) {
|
|
13
|
-
report({
|
|
14
|
-
scope: el,
|
|
15
|
-
message: t('{0} should associate with {1}', t('The "{0*}" {1}', 'label', 'element'), t('a {0}', 'control')),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const controls = el.querySelectorAll(controlSelector);
|
|
19
|
-
const secondControl = controls[1];
|
|
20
|
-
if (secondControl) {
|
|
21
|
-
report({
|
|
22
|
-
scope: secondControl,
|
|
23
|
-
message: t('{0} associates only {1}', t('The "{0*}" {1}', 'label', 'element'), t('first {0}', 'control')),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
exports.default = (0, ml_core_1.createRule)({
|
|
6
|
-
defaultSeverity: 'warning',
|
|
7
|
-
defaultOptions: {
|
|
8
|
-
extendsExposableElements: true,
|
|
9
|
-
ignoreIfAriaBusy: true,
|
|
10
|
-
},
|
|
11
|
-
async verify({ document, report, t }) {
|
|
12
|
-
await document.walkOn('Element', el => {
|
|
13
|
-
if (!(0, ml_spec_1.isPalpableElement)(el, el.ownerMLDocument.specs, {
|
|
14
|
-
extendsSvg: false,
|
|
15
|
-
extendsExposableElements: el.rule.option.extendsExposableElements,
|
|
16
|
-
})) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if ((0, ml_spec_1.isVoidElement)(el)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (el.rule.option.ignoreIfAriaBusy && el.getAttribute('aria-busy') === 'true') {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const isEmpty = Array.from(el.childNodes).every(node => node.is(node.TEXT_NODE) && node.isWhitespace());
|
|
26
|
-
if (isEmpty) {
|
|
27
|
-
report({
|
|
28
|
-
scope: el,
|
|
29
|
-
message: t('{0} should not {1}', t('the {0}', 'element'), 'empty'),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
});
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
import type { PermittedContentChoice } from '@markuplint/ml-spec';
|
|
3
|
-
export declare function choice(pattern: PermittedContentChoice, elements: ChildNode[], specs: Specs, options: Options, depth: number): Result;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.choice = void 0;
|
|
4
|
-
const order_1 = require("./order");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
function choice(pattern, elements, specs, options, depth) {
|
|
7
|
-
const collection = new utils_1.Collection(elements);
|
|
8
|
-
const unmatchedResults = [];
|
|
9
|
-
for (const some of pattern.choice) {
|
|
10
|
-
const result = (0, order_1.order)(some, collection.unmatched, specs, options, depth + 1);
|
|
11
|
-
if (result.type === 'UNEXPECTED_EXTRA_NODE' || result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
|
|
12
|
-
collection.addMatched(result.matched);
|
|
13
|
-
return {
|
|
14
|
-
type: result.type,
|
|
15
|
-
matched: collection.matched,
|
|
16
|
-
unmatched: collection.unmatched,
|
|
17
|
-
zeroMatch: result.zeroMatch,
|
|
18
|
-
query: result.query,
|
|
19
|
-
hint: result.hint,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
unmatchedResults.push(result);
|
|
23
|
-
}
|
|
24
|
-
const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
|
|
25
|
-
if (!barelyMatchedResult) {
|
|
26
|
-
throw new Error('Unreachable code');
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
type: barelyMatchedResult.type,
|
|
30
|
-
matched: collection.matched,
|
|
31
|
-
unmatched: collection.unmatched,
|
|
32
|
-
zeroMatch: barelyMatchedResult.zeroMatch,
|
|
33
|
-
query: barelyMatchedResult.query,
|
|
34
|
-
hint: barelyMatchedResult.hint,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
exports.choice = choice;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
import type { PermittedContentPattern } from '@markuplint/ml-spec';
|
|
3
|
-
/**
|
|
4
|
-
* Check content condition
|
|
5
|
-
*
|
|
6
|
-
* @param pattern
|
|
7
|
-
* @param elements
|
|
8
|
-
* @param specs
|
|
9
|
-
* @param options
|
|
10
|
-
* @param depth
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export declare function complexBranch(pattern: PermittedContentPattern, elements: ChildNode[], specs: Specs, options: Options, depth: number): Result;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.complexBranch = void 0;
|
|
4
|
-
const choice_1 = require("./choice");
|
|
5
|
-
const count_pattern_1 = require("./count-pattern");
|
|
6
|
-
const transparent_1 = require("./transparent");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
/**
|
|
9
|
-
* Check content condition
|
|
10
|
-
*
|
|
11
|
-
* @param pattern
|
|
12
|
-
* @param elements
|
|
13
|
-
* @param specs
|
|
14
|
-
* @param options
|
|
15
|
-
* @param depth
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
function complexBranch(pattern, elements, specs, options, depth) {
|
|
19
|
-
if ((0, utils_1.isChoice)(pattern)) {
|
|
20
|
-
return (0, choice_1.choice)(pattern, elements, specs, options, depth);
|
|
21
|
-
}
|
|
22
|
-
if ((0, utils_1.isTransparent)(pattern)) {
|
|
23
|
-
return (0, transparent_1.transparent)(elements, specs, options, depth);
|
|
24
|
-
}
|
|
25
|
-
return (0, count_pattern_1.countPattern)(pattern, elements, specs, options, depth);
|
|
26
|
-
}
|
|
27
|
-
exports.complexBranch = complexBranch;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.contentModel = void 0;
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
const start_1 = require("./start");
|
|
6
|
-
function contentModel(el, rules, options) {
|
|
7
|
-
const model = createModel(el, rules);
|
|
8
|
-
if (model == null) {
|
|
9
|
-
return [
|
|
10
|
-
{
|
|
11
|
-
type: 'MATCHED',
|
|
12
|
-
scope: el,
|
|
13
|
-
query: '*',
|
|
14
|
-
hint: {},
|
|
15
|
-
},
|
|
16
|
-
];
|
|
17
|
-
}
|
|
18
|
-
const result = (0, start_1.start)(model, el, el.ownerMLDocument.specs, options);
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
exports.contentModel = contentModel;
|
|
22
|
-
function createModel(el, rules) {
|
|
23
|
-
const specs = cachedSpecs(el.ownerMLDocument.specs, rules);
|
|
24
|
-
const model = (0, ml_spec_1.getContentModel)(el, specs.specs);
|
|
25
|
-
return model;
|
|
26
|
-
}
|
|
27
|
-
const caches = new Map();
|
|
28
|
-
function cachedSpecs(specs, rules) {
|
|
29
|
-
if (!rules.length) {
|
|
30
|
-
return specs;
|
|
31
|
-
}
|
|
32
|
-
const key = JSON.stringify(rules);
|
|
33
|
-
const cached = caches.get(key);
|
|
34
|
-
if (cached) {
|
|
35
|
-
return cached;
|
|
36
|
-
}
|
|
37
|
-
const merged = {
|
|
38
|
-
...specs,
|
|
39
|
-
specs: [
|
|
40
|
-
...specs.specs,
|
|
41
|
-
...rules.map(tag => ({
|
|
42
|
-
name: tag.tag,
|
|
43
|
-
contentModel: tag,
|
|
44
|
-
})),
|
|
45
|
-
],
|
|
46
|
-
};
|
|
47
|
-
caches.set(key, merged);
|
|
48
|
-
return merged;
|
|
49
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
import type { PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentZeroOrMore } from '@markuplint/ml-spec';
|
|
3
|
-
/**
|
|
4
|
-
* Check count
|
|
5
|
-
*
|
|
6
|
-
* @param pattern
|
|
7
|
-
* @param elements
|
|
8
|
-
* @param specs
|
|
9
|
-
* @param options
|
|
10
|
-
* @param depth
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export declare function countPattern(pattern: PermittedContentOneOrMore | PermittedContentOptional | PermittedContentRequire | PermittedContentZeroOrMore, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.countPattern = void 0;
|
|
4
|
-
const debug_1 = require("./debug");
|
|
5
|
-
const recursive_branch_1 = require("./recursive-branch");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
/**
|
|
8
|
-
* Check count
|
|
9
|
-
*
|
|
10
|
-
* @param pattern
|
|
11
|
-
* @param elements
|
|
12
|
-
* @param specs
|
|
13
|
-
* @param options
|
|
14
|
-
* @param depth
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
function countPattern(pattern, elements, specs, options, depth) {
|
|
18
|
-
var _a, _b, _c, _d, _e;
|
|
19
|
-
const ptLog = debug_1.cmLog.extend(`countPattern#${depth}`);
|
|
20
|
-
const collection = new utils_1.Collection(elements);
|
|
21
|
-
let min;
|
|
22
|
-
let max;
|
|
23
|
-
let model;
|
|
24
|
-
let type;
|
|
25
|
-
let _type;
|
|
26
|
-
if ((0, utils_1.isRequire)(pattern)) {
|
|
27
|
-
min = (_a = pattern.min) !== null && _a !== void 0 ? _a : 1;
|
|
28
|
-
max = Math.max((_b = pattern.max) !== null && _b !== void 0 ? _b : 1, min);
|
|
29
|
-
model = pattern.require;
|
|
30
|
-
type = 'MISSING_NODE_REQUIRED';
|
|
31
|
-
_type = 'require';
|
|
32
|
-
}
|
|
33
|
-
else if ((0, utils_1.isOptional)(pattern)) {
|
|
34
|
-
min = 0;
|
|
35
|
-
max = Math.max((_c = pattern.max) !== null && _c !== void 0 ? _c : 1, 1);
|
|
36
|
-
model = pattern.optional;
|
|
37
|
-
_type = 'optional';
|
|
38
|
-
}
|
|
39
|
-
else if ((0, utils_1.isOneOrMore)(pattern)) {
|
|
40
|
-
min = 1;
|
|
41
|
-
max = Math.max((_d = pattern.max) !== null && _d !== void 0 ? _d : Infinity, 1);
|
|
42
|
-
model = pattern.oneOrMore;
|
|
43
|
-
type = 'MISSING_NODE_ONE_OR_MORE';
|
|
44
|
-
_type = 'one or more';
|
|
45
|
-
}
|
|
46
|
-
else if ((0, utils_1.isZeroOrMore)(pattern)) {
|
|
47
|
-
min = 0;
|
|
48
|
-
max = Math.max((_e = pattern.max) !== null && _e !== void 0 ? _e : Infinity, 1);
|
|
49
|
-
model = pattern.zeroOrMore;
|
|
50
|
-
_type = 'zero or more';
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
throw new Error('Unreachable code');
|
|
54
|
-
}
|
|
55
|
-
ptLog('%s: %o', _type, model);
|
|
56
|
-
let prevResult = null;
|
|
57
|
-
// eslint-disable-next-line no-constant-condition
|
|
58
|
-
while (true) {
|
|
59
|
-
ptLog('%s', collection);
|
|
60
|
-
const result = (0, recursive_branch_1.recursiveBranch)(model, collection.unmatched, specs, options, depth);
|
|
61
|
-
const added = collection.addMatched(result.matched);
|
|
62
|
-
if (result.type === 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY') {
|
|
63
|
-
ptLog('MATCHED_ZERO: %s', result.query);
|
|
64
|
-
return {
|
|
65
|
-
type: 'MATCHED_ZERO',
|
|
66
|
-
matched: collection.matched,
|
|
67
|
-
unmatched: collection.unmatched,
|
|
68
|
-
zeroMatch: true,
|
|
69
|
-
query: result.query,
|
|
70
|
-
hint: result.hint,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (max < collection.matchedCount) {
|
|
74
|
-
collection.max(max);
|
|
75
|
-
ptLog('UNEXPECTED_EXTRA_NODE (max: %s): %s', max, result.query);
|
|
76
|
-
return {
|
|
77
|
-
type: 'UNEXPECTED_EXTRA_NODE',
|
|
78
|
-
matched: collection.matched,
|
|
79
|
-
unmatched: collection.unmatched,
|
|
80
|
-
zeroMatch: result.zeroMatch,
|
|
81
|
-
query: result.query,
|
|
82
|
-
hint: {
|
|
83
|
-
...result.hint,
|
|
84
|
-
max,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
if (prevResult) {
|
|
89
|
-
if (result.type === 'MISSING_NODE_ONE_OR_MORE' ||
|
|
90
|
-
result.type === 'MISSING_NODE_REQUIRED' ||
|
|
91
|
-
result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
|
|
92
|
-
ptLog('%s(continued): %s', result.type, collection);
|
|
93
|
-
return {
|
|
94
|
-
type: result.type,
|
|
95
|
-
matched: collection.matched,
|
|
96
|
-
unmatched: collection.unmatched,
|
|
97
|
-
zeroMatch: result.zeroMatch,
|
|
98
|
-
query: result.query,
|
|
99
|
-
hint: result.hint,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
ptLog('%s(continued): %s', prevResult.type, collection);
|
|
103
|
-
return prevResult;
|
|
104
|
-
}
|
|
105
|
-
if (added && collection.unmatched.length > 0) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (collection.matchedCount + (result.zeroMatch ? 1 : 0) < min) {
|
|
109
|
-
const resultType = result.type === 'MISSING_NODE_REQUIRED' ||
|
|
110
|
-
result.type === 'MISSING_NODE_ONE_OR_MORE' ||
|
|
111
|
-
result.type === 'TRANSPARENT_MODEL_DISALLOWS'
|
|
112
|
-
? result.type
|
|
113
|
-
: type !== null && type !== void 0 ? type : 'MISSING_NODE_REQUIRED';
|
|
114
|
-
ptLog('%s(in %s): %s', resultType, type, result.query);
|
|
115
|
-
return {
|
|
116
|
-
type: resultType,
|
|
117
|
-
matched: collection.matched,
|
|
118
|
-
unmatched: collection.unmatched,
|
|
119
|
-
zeroMatch: result.zeroMatch,
|
|
120
|
-
query: result.query,
|
|
121
|
-
hint: result.hint,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const resultType = collection.matched.length === 0 ? 'MATCHED_ZERO' : 'MATCHED';
|
|
125
|
-
const zeroMatch = result.zeroMatch || min === 0 || resultType === 'MATCHED_ZERO';
|
|
126
|
-
const matchedResult = {
|
|
127
|
-
type: resultType,
|
|
128
|
-
matched: collection.matched,
|
|
129
|
-
unmatched: collection.unmatched,
|
|
130
|
-
zeroMatch,
|
|
131
|
-
query: result.query,
|
|
132
|
-
hint: result.hint,
|
|
133
|
-
};
|
|
134
|
-
if (!prevResult && collection.unmatched.length) {
|
|
135
|
-
ptLog('continue checking');
|
|
136
|
-
prevResult = matchedResult;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
ptLog('%s: %s', resultType, collection);
|
|
140
|
-
if (result.type === 'MISSING_NODE_REQUIRED' ||
|
|
141
|
-
result.type === 'MISSING_NODE_ONE_OR_MORE' ||
|
|
142
|
-
result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
|
|
143
|
-
return {
|
|
144
|
-
type: result.type,
|
|
145
|
-
matched: collection.matched,
|
|
146
|
-
unmatched: collection.unmatched,
|
|
147
|
-
zeroMatch: result.zeroMatch,
|
|
148
|
-
query: result.query,
|
|
149
|
-
hint: result.hint,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
return matchedResult;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.countPattern = countPattern;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
export type SelectorResult = Result<'UNMATCHED_SELECTOR_BUT_MAY_EMPTY' | 'MISSING_NODE' | 'UNMATCHED_SELECTORS'>;
|
|
3
|
-
export declare function matchesSelector(query: string, node: ChildNode | undefined, specs: Specs, options: Options, depth: number): SelectorResult;
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.matchesSelector = void 0;
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
const debug_1 = require("./debug");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
function matchesSelector(query, node, specs, options, depth) {
|
|
8
|
-
const nodeLog = debug_1.cmLog.extend(`node#${depth}`);
|
|
9
|
-
const { selector, hasText, hasCustom } = optCondition(query, specs);
|
|
10
|
-
if (node == null) {
|
|
11
|
-
if (hasText) {
|
|
12
|
-
nodeLog('<#text>.matches(%s) => ""', query);
|
|
13
|
-
return {
|
|
14
|
-
type: 'MATCHED_ZERO',
|
|
15
|
-
matched: node ? [node] : [],
|
|
16
|
-
unmatched: [],
|
|
17
|
-
zeroMatch: true,
|
|
18
|
-
query,
|
|
19
|
-
hint: {},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
type: 'MISSING_NODE',
|
|
24
|
-
matched: [],
|
|
25
|
-
unmatched: [],
|
|
26
|
-
zeroMatch: false,
|
|
27
|
-
query,
|
|
28
|
-
hint: {},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
if (node.is(node.TEXT_NODE)) {
|
|
32
|
-
if (hasText) {
|
|
33
|
-
nodeLog('<#text>.matches(%s) => "%s"', query, node.raw.trim());
|
|
34
|
-
return {
|
|
35
|
-
type: 'MATCHED',
|
|
36
|
-
matched: [node],
|
|
37
|
-
unmatched: [],
|
|
38
|
-
zeroMatch: true,
|
|
39
|
-
query,
|
|
40
|
-
hint: {},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (node.isWhitespace()) {
|
|
44
|
-
nodeLog('<#text>.matches(%s) => WHITESPACE', query);
|
|
45
|
-
return {
|
|
46
|
-
type: 'MATCHED',
|
|
47
|
-
matched: [node],
|
|
48
|
-
unmatched: [],
|
|
49
|
-
zeroMatch: true,
|
|
50
|
-
query,
|
|
51
|
-
hint: {},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
// Disallows a text node
|
|
55
|
-
return {
|
|
56
|
-
type: 'UNEXPECTED_EXTRA_NODE',
|
|
57
|
-
matched: [],
|
|
58
|
-
unmatched: [node],
|
|
59
|
-
zeroMatch: false,
|
|
60
|
-
query,
|
|
61
|
-
hint: {},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
65
|
-
nodeLog('%s.matches(%s) => PBlock', node.raw, query);
|
|
66
|
-
return {
|
|
67
|
-
type: 'MATCHED',
|
|
68
|
-
matched: [node],
|
|
69
|
-
unmatched: [],
|
|
70
|
-
zeroMatch: !!hasText,
|
|
71
|
-
query,
|
|
72
|
-
hint: {},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (node.is(node.ELEMENT_NODE)) {
|
|
76
|
-
if (node.elementType !== 'html' && hasCustom) {
|
|
77
|
-
nodeLog('%s.matches(%s) => CustomElement', node.raw, query);
|
|
78
|
-
return {
|
|
79
|
-
type: 'MATCHED',
|
|
80
|
-
matched: [node],
|
|
81
|
-
unmatched: [],
|
|
82
|
-
zeroMatch: !!hasText,
|
|
83
|
-
query,
|
|
84
|
-
hint: {},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const result = (0, utils_1.matches)(selector, node, specs);
|
|
88
|
-
nodeLog('%s.matches(%s) => %s', node.raw, query, result.matched);
|
|
89
|
-
if (result.matched) {
|
|
90
|
-
return {
|
|
91
|
-
type: 'MATCHED',
|
|
92
|
-
matched: [node],
|
|
93
|
-
unmatched: [],
|
|
94
|
-
zeroMatch: !!hasText,
|
|
95
|
-
query,
|
|
96
|
-
hint: {},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (hasText) {
|
|
100
|
-
return {
|
|
101
|
-
type: 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY',
|
|
102
|
-
matched: [],
|
|
103
|
-
unmatched: [node],
|
|
104
|
-
zeroMatch: true,
|
|
105
|
-
query,
|
|
106
|
-
hint: {
|
|
107
|
-
not: result.not,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
type: 'UNMATCHED_SELECTORS',
|
|
113
|
-
matched: [],
|
|
114
|
-
unmatched: [node],
|
|
115
|
-
zeroMatch: false,
|
|
116
|
-
query,
|
|
117
|
-
hint: {
|
|
118
|
-
not: result.not,
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
type: 'MATCHED',
|
|
124
|
-
matched: [node],
|
|
125
|
-
unmatched: [],
|
|
126
|
-
zeroMatch: !!hasText,
|
|
127
|
-
query,
|
|
128
|
-
hint: {},
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
exports.matchesSelector = matchesSelector;
|
|
132
|
-
const conditionWithoutSpecs = {
|
|
133
|
-
'#custom': {
|
|
134
|
-
selector: '#custom',
|
|
135
|
-
hasCustom: true,
|
|
136
|
-
hasText: false,
|
|
137
|
-
},
|
|
138
|
-
'#text': {
|
|
139
|
-
selector: '#text',
|
|
140
|
-
hasCustom: false,
|
|
141
|
-
hasText: true,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const optConditionSpecsBaseCaches = new Map();
|
|
145
|
-
function optCondition(query, specs) {
|
|
146
|
-
var _a;
|
|
147
|
-
const condWithoutSpecs = conditionWithoutSpecs[query];
|
|
148
|
-
if (condWithoutSpecs) {
|
|
149
|
-
return condWithoutSpecs;
|
|
150
|
-
}
|
|
151
|
-
const queryCaches = (_a = optConditionSpecsBaseCaches.get(specs)) !== null && _a !== void 0 ? _a : new Map();
|
|
152
|
-
const cached = queryCaches.get(query);
|
|
153
|
-
if (cached) {
|
|
154
|
-
return cached;
|
|
155
|
-
}
|
|
156
|
-
let hasCustom = false;
|
|
157
|
-
let hasText = false;
|
|
158
|
-
const selector = query.replace(/^(?::model\(([^)]+)\)|#([a-z-]+))(.*)$/, (_, $model, _model, $last) => {
|
|
159
|
-
const _selectors = (0, ml_spec_1.contentModelCategoryToTagNames)(`#${$model !== null && $model !== void 0 ? $model : _model}`, specs.def);
|
|
160
|
-
if (_selectors.length === 0) {
|
|
161
|
-
throw new Error(`${$model !== null && $model !== void 0 ? $model : _model} is empty`);
|
|
162
|
-
}
|
|
163
|
-
const selectors = [];
|
|
164
|
-
for (const selector of _selectors) {
|
|
165
|
-
if (selector === '#custom') {
|
|
166
|
-
hasCustom = true;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (selector === '#text') {
|
|
170
|
-
hasText = true;
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
selectors.push(selector);
|
|
174
|
-
}
|
|
175
|
-
return `:is(${selectors.join(',')})${$last !== null && $last !== void 0 ? $last : ''}`;
|
|
176
|
-
});
|
|
177
|
-
const result = {
|
|
178
|
-
selector,
|
|
179
|
-
hasCustom,
|
|
180
|
-
hasText,
|
|
181
|
-
};
|
|
182
|
-
queryCaches.set(query, result);
|
|
183
|
-
optConditionSpecsBaseCaches.set(specs, queryCaches);
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
2
|
-
import type { PermittedContentPattern } from '@markuplint/ml-spec';
|
|
3
|
-
/**
|
|
4
|
-
* Check ordered array
|
|
5
|
-
*
|
|
6
|
-
* @param contents
|
|
7
|
-
* @param nodes
|
|
8
|
-
* @param specs
|
|
9
|
-
* @param options
|
|
10
|
-
* @param depth
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export declare function order(contents: ReadonlyArray<PermittedContentPattern>, nodes: ReadonlyArray<ChildNode>, specs: Specs, options: Options, depth: number): Result;
|