@markuplint/rules 3.0.0-alpha.66 → 3.0.0-rc.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/README.md +9 -43
- package/lib/attr-check.d.ts +2 -2
- package/lib/attr-check.js +1 -1
- package/lib/attr-duplication/index.js +1 -1
- package/lib/attr-value-quotes/index.d.ts +3 -3
- package/lib/attr-value-quotes/index.js +1 -1
- package/lib/case-sensitive-attr-name/index.d.ts +1 -1
- package/lib/case-sensitive-attr-name/index.js +3 -3
- package/lib/case-sensitive-tag-name/index.d.ts +1 -1
- package/lib/case-sensitive-tag-name/index.js +3 -3
- package/lib/character-reference/index.js +1 -1
- package/lib/class-naming/index.d.ts +1 -1
- package/lib/class-naming/index.js +1 -1
- package/lib/create-message.d.ts +1 -1
- package/lib/create-message.js +5 -5
- package/lib/debug.d.ts +1 -1
- package/lib/deprecated-element/index.js +2 -2
- package/lib/doctype/index.d.ts +2 -2
- package/lib/doctype/index.js +2 -2
- package/lib/end-tag/index.js +3 -18
- package/lib/helpers.d.ts +8 -32
- package/lib/helpers.js +17 -81
- package/lib/index.d.ts +2 -62
- package/lib/index.js +4 -0
- package/lib/ineffective-attr/index.js +1 -1
- package/lib/invalid-attr/index.d.ts +3 -2
- package/lib/invalid-attr/index.js +14 -9
- package/lib/label-has-control/index.d.ts +2 -0
- package/lib/label-has-control/index.js +28 -0
- package/lib/landmark-roles/index.d.ts +3 -3
- package/lib/landmark-roles/index.js +1 -1
- package/lib/no-boolean-attr-value/index.js +1 -1
- package/lib/no-default-value/index.js +1 -1
- package/lib/no-empty-palpable-content/index.d.ts +6 -0
- package/lib/no-empty-palpable-content/index.js +34 -0
- package/lib/no-hard-code-id/index.js +1 -1
- package/lib/no-use-event-handler-attr/index.d.ts +1 -1
- package/lib/no-use-event-handler-attr/index.js +2 -2
- package/lib/permitted-contents/choice.d.ts +3 -0
- package/lib/permitted-contents/choice.js +37 -0
- package/lib/permitted-contents/complex-branch.d.ts +13 -0
- package/lib/permitted-contents/complex-branch.js +27 -0
- package/lib/permitted-contents/content-model.d.ts +2 -0
- package/lib/permitted-contents/content-model.js +49 -0
- package/lib/permitted-contents/count-pattern.d.ts +13 -0
- package/lib/permitted-contents/count-pattern.js +155 -0
- package/lib/permitted-contents/debug.d.ts +2 -0
- package/lib/permitted-contents/debug.js +5 -0
- package/lib/permitted-contents/index.d.ts +1 -7
- package/lib/permitted-contents/index.js +75 -245
- package/lib/permitted-contents/matches-selector.d.ts +3 -0
- package/lib/permitted-contents/matches-selector.js +185 -0
- package/lib/permitted-contents/order.d.ts +13 -0
- package/lib/permitted-contents/order.js +89 -0
- package/lib/permitted-contents/recursive-branch.d.ts +4 -0
- package/lib/permitted-contents/recursive-branch.js +43 -0
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +6 -0
- package/lib/permitted-contents/represent-transparent-nodes.js +79 -0
- package/lib/permitted-contents/start.d.ts +12 -0
- package/lib/permitted-contents/start.js +71 -0
- package/lib/permitted-contents/transparent.d.ts +2 -0
- package/lib/permitted-contents/transparent.js +34 -0
- package/lib/permitted-contents/types.d.ts +45 -0
- package/lib/permitted-contents/types.js +2 -0
- package/lib/permitted-contents/utils.d.ts +32 -0
- package/lib/permitted-contents/utils.js +184 -0
- package/lib/require-accessible-name/index.d.ts +1 -1
- package/lib/require-accessible-name/index.js +9 -1
- package/lib/required-attr/index.d.ts +2 -2
- package/lib/required-attr/index.js +1 -1
- package/lib/required-element/index.d.ts +1 -1
- package/lib/use-list/index.d.ts +2 -2
- package/lib/use-list/index.js +2 -2
- package/lib/wai-aria/checkings/implicit-role.js +2 -2
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
- package/lib/wai-aria/checkings/interaction-in-hidden.js +47 -0
- package/lib/wai-aria/checkings/{non-existant-role.d.ts → non-existent-role.d.ts} +1 -1
- package/lib/wai-aria/checkings/{non-existant-role.js → non-existent-role.js} +3 -3
- package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
- package/lib/wai-aria/checkings/presentational-children.js +60 -0
- package/lib/wai-aria/checkings/{checking-required-owned-elements.d.ts → required-owned-elements.d.ts} +0 -0
- package/lib/wai-aria/checkings/{checking-required-owned-elements.js → required-owned-elements.js} +41 -17
- package/lib/wai-aria/checkings/value.d.ts +6 -0
- package/lib/wai-aria/checkings/value.js +74 -4
- package/lib/wai-aria/index.js +16 -6
- package/lib/wai-aria/types.d.ts +3 -1
- package/package.json +9 -8
- package/schema.json +6 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/__foo/index.d.ts +0 -2
- package/lib/__foo/index.js +0 -46
- package/lib/attr-equal-space-after/index.d.ts +0 -3
- package/lib/attr-equal-space-after/index.js +0 -90
- package/lib/attr-equal-space-before/index.d.ts +0 -3
- package/lib/attr-equal-space-before/index.js +0 -90
- package/lib/attr-spacing/index.d.ts +0 -6
- package/lib/attr-spacing/index.js +0 -100
- package/lib/helper/aria/get-aria.d.ts +0 -7
- package/lib/helper/aria/get-aria.js +0 -53
- package/lib/helper/aria/get-computed-role.d.ts +0 -10
- package/lib/helper/aria/get-computed-role.js +0 -24
- package/lib/helper/aria/get-implicit-role.d.ts +0 -7
- package/lib/helper/aria/get-implicit-role.js +0 -12
- package/lib/helper/aria/get-permitted-roles.d.ts +0 -14
- package/lib/helper/aria/get-permitted-roles.js +0 -26
- package/lib/helper/aria/resolve-version.d.ts +0 -2
- package/lib/helper/aria/resolve-version.js +0 -21
- package/lib/helper/spec/aria-spec.d.ts +0 -5
- package/lib/helper/spec/aria-spec.js +0 -12
- package/lib/helper/spec/get-role-spec.d.ts +0 -11
- package/lib/helper/spec/get-role-spec.js +0 -39
- package/lib/helper/spec/html-spec.d.ts +0 -2
- package/lib/helper/spec/html-spec.js +0 -14
- package/lib/indentation/index.d.ts +0 -7
- package/lib/indentation/index.js +0 -208
- package/lib/permitted-contents/array.combination.d.ts +0 -1
- package/lib/permitted-contents/array.combination.js +0 -33
- package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +0 -11
- package/lib/permitted-contents/permitted-content.spec-to-regexp.js +0 -230
- package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +0 -2
- package/lib/permitted-contents/unfold-content-models-to-tags.js +0 -8
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AttributeType } from '@markuplint/ml-spec';
|
|
2
|
-
|
|
2
|
+
type Option = {
|
|
3
3
|
attrs?: Record<string, Rule>;
|
|
4
4
|
ignoreAttrNamePrefix?: string | string[];
|
|
5
|
+
allowToAddPropertiesForPretender?: boolean;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
+
type Rule = {
|
|
7
8
|
enum: [string, ...string[]];
|
|
8
9
|
} | {
|
|
9
10
|
pattern: string;
|
|
@@ -9,14 +9,16 @@ 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;
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
13
|
+
// Default
|
|
14
|
+
const allowToAddPropertiesForPretender = (_a = attr.rule.option.allowToAddPropertiesForPretender) !== null && _a !== void 0 ? _a : true;
|
|
13
15
|
if (attr.isDirective) {
|
|
14
16
|
return;
|
|
15
17
|
}
|
|
16
18
|
const attrSpecs = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
|
|
17
19
|
const attrName = attr.nameNode;
|
|
18
20
|
const name = attr.name;
|
|
19
|
-
if (
|
|
21
|
+
if (attr.ownerElement.elementType === 'html' && attr.candidate) {
|
|
20
22
|
const message = t('{0} is {1:c}', t('the "{0*}" {1}', name, 'attribute'), 'disallowed') +
|
|
21
23
|
t('. ') +
|
|
22
24
|
t('Did you mean "{0}"?', attr.candidate);
|
|
@@ -69,7 +71,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
|
-
else if (
|
|
74
|
+
else if (attr.ownerElement.elementType === 'html' && attrSpecs) {
|
|
73
75
|
log('Checking %s[%s="%s"]', attr.nodeName, name, value);
|
|
74
76
|
invalid = (0, helpers_1.isValidAttr)(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
|
|
75
77
|
}
|
|
@@ -82,16 +84,19 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
82
84
|
report({
|
|
83
85
|
scope: attr,
|
|
84
86
|
message: invalid.message,
|
|
85
|
-
line: ((
|
|
86
|
-
col: ((
|
|
87
|
-
? ((
|
|
88
|
-
: ((
|
|
89
|
-
raw: (
|
|
87
|
+
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),
|
|
88
|
+
col: ((_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.line)
|
|
89
|
+
? ((_f = invalid.loc) === null || _f === void 0 ? void 0 : _f.col) + 1
|
|
90
|
+
: ((_g = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _g !== void 0 ? _g : 0) + ((_j = (_h = invalid.loc) === null || _h === void 0 ? void 0 : _h.col) !== null && _j !== void 0 ? _j : 0),
|
|
91
|
+
raw: (_l = (_k = invalid.loc) === null || _k === void 0 ? void 0 : _k.raw) !== null && _l !== void 0 ? _l : value,
|
|
90
92
|
});
|
|
91
93
|
break;
|
|
92
94
|
}
|
|
93
95
|
case 'non-existent': {
|
|
94
|
-
|
|
96
|
+
if (allowToAddPropertiesForPretender && ((_m = attr.ownerElement.pretenderContext) === null || _m === void 0 ? void 0 : _m.type) === 'origin') {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs.specs);
|
|
95
100
|
if (spec === null || spec === void 0 ? void 0 : spec.possibleToAddProperties) {
|
|
96
101
|
return;
|
|
97
102
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
type Options = {
|
|
2
2
|
ignoreRoles: Roles[];
|
|
3
3
|
labelEachArea: boolean;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type TopLevelRoles = 'banner' | 'main' | 'complementary' | 'contentinfo';
|
|
6
|
+
type Roles = TopLevelRoles | 'form' | 'navigation' | 'region';
|
|
7
7
|
declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, Options>;
|
|
8
8
|
export default _default;
|
|
@@ -12,7 +12,7 @@ const selectors = {
|
|
|
12
12
|
};
|
|
13
13
|
const topLevelRoles = ['banner', 'main', 'complementary', 'contentinfo'];
|
|
14
14
|
exports.default = (0, ml_core_1.createRule)({
|
|
15
|
-
|
|
15
|
+
defaultSeverity: 'warning',
|
|
16
16
|
defaultOptions: {
|
|
17
17
|
ignoreRoles: [],
|
|
18
18
|
labelEachArea: true,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
4
|
exports.default = (0, ml_core_1.createRule)({
|
|
5
|
-
|
|
5
|
+
defaultSeverity: 'warning',
|
|
6
6
|
async verify({ document, report, t }) {
|
|
7
7
|
await document.walkOn('Attr', attr => {
|
|
8
8
|
var _a, _b;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
exports.default = (0, ml_core_1.createRule)({
|
|
6
|
-
|
|
6
|
+
defaultSeverity: 'warning',
|
|
7
7
|
async verify({ document, report, t }) {
|
|
8
8
|
await document.walkOn('Attr', attr => {
|
|
9
9
|
var _a, _b, _c;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
4
|
exports.default = (0, ml_core_1.createRule)({
|
|
5
|
-
|
|
5
|
+
defaultSeverity: 'warning',
|
|
6
6
|
async verify({ document, report, t }) {
|
|
7
7
|
if (!document.isFragment) {
|
|
8
8
|
return;
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
4
4
|
const helpers_1 = require("../helpers");
|
|
5
5
|
exports.default = (0, ml_core_1.createRule)({
|
|
6
|
-
|
|
6
|
+
defaultSeverity: 'warning',
|
|
7
7
|
defaultOptions: {},
|
|
8
8
|
async verify({ document, report, t }) {
|
|
9
9
|
await document.walkOn('Attr', attr => {
|
|
10
|
-
if (attr.ownerElement.
|
|
10
|
+
if (attr.ownerElement.elementType !== 'html') {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const ignoreList = Array.isArray(attr.rule.option.ignore)
|
|
@@ -0,0 +1,3 @@
|
|
|
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;
|
|
@@ -0,0 +1,37 @@
|
|
|
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
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;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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;
|
|
@@ -0,0 +1,155 @@
|
|
|
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,9 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare type TagRule = ContentModel & {
|
|
3
|
-
tag: string;
|
|
4
|
-
};
|
|
5
|
-
declare type Options = {
|
|
6
|
-
ignoreHasMutableChildren: boolean;
|
|
7
|
-
};
|
|
1
|
+
import type { Options, TagRule } from './types';
|
|
8
2
|
declare const _default: import("@markuplint/ml-core").RuleSeed<TagRule[], Options>;
|
|
9
3
|
export default _default;
|