@markuplint/rules 3.0.0-alpha.0 → 3.0.0-alpha.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/README.md +1 -1
- package/lib/attr-check.js +1 -1
- package/lib/attr-duplication/index.js +1 -1
- package/lib/attr-value-quotes/index.js +1 -1
- package/lib/case-sensitive-attr-name/index.js +3 -3
- package/lib/case-sensitive-tag-name/index.js +3 -3
- 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/deprecated-element/index.js +2 -2
- package/lib/doctype/index.d.ts +1 -1
- package/lib/doctype/index.js +1 -1
- package/lib/end-tag/index.js +1 -1
- package/lib/helpers.d.ts +7 -2
- package/lib/helpers.js +17 -11
- package/lib/index.d.ts +2 -6
- package/lib/ineffective-attr/index.js +1 -1
- package/lib/invalid-attr/index.js +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-hard-code-id/index.js +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.js +5 -1
- package/lib/required-attr/index.js +1 -1
- package/lib/use-list/index.js +2 -2
- package/lib/wai-aria/checkings/implicit-role.js +2 -2
- package/lib/wai-aria/checkings/required-owned-elements.js +25 -17
- package/lib/wai-aria/index.js +1 -1
- package/package.json +8 -7
- 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
- package/lib/wai-aria/checkings/checking-required-owned-elements.d.ts +0 -11
- package/lib/wai-aria/checkings/checking-required-owned-elements.js +0 -63
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
## Install
|
|
51
51
|
|
|
52
|
-
Generally, you **don't have to install** this package because markuplint dependents it
|
|
52
|
+
Generally, you **don't have to install** this package because markuplint dependents it by default.
|
|
53
53
|
|
|
54
54
|
```sh
|
|
55
55
|
$ npm install -D @markuplint/rules
|
package/lib/attr-check.js
CHANGED
|
@@ -11,7 +11,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
11
11
|
continue;
|
|
12
12
|
}
|
|
13
13
|
const attrName = attr.name;
|
|
14
|
-
const name = node.
|
|
14
|
+
const name = node.elementType === 'html' ? attrName.toLowerCase() : attrName;
|
|
15
15
|
if (attrNameStack.includes(name)) {
|
|
16
16
|
const scope = attr.nameNode || attr;
|
|
17
17
|
report({
|
|
@@ -2,13 +2,13 @@
|
|
|
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
|
defaultValue: 'lower',
|
|
7
7
|
async verify({ document, report, t }) {
|
|
8
8
|
await document.walkOn('Attr', attr => {
|
|
9
9
|
var _a, _b, _c, _d;
|
|
10
10
|
const el = attr.ownerElement;
|
|
11
|
-
if (el.isForeignElement || el.
|
|
11
|
+
if (el.isForeignElement || el.elementType !== 'html') {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
const value = attr.rule.value;
|
|
@@ -46,7 +46,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
46
46
|
await document.walkOn('Attr', attr => {
|
|
47
47
|
var _a;
|
|
48
48
|
const el = attr.ownerElement;
|
|
49
|
-
if (el.isForeignElement || el.
|
|
49
|
+
if (el.isForeignElement || el.elementType !== 'html') {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
const attrSpecs = (0, ml_core_1.getAttrSpecs)(el, document.specs);
|
|
@@ -2,11 +2,11 @@
|
|
|
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
|
defaultValue: 'lower',
|
|
7
7
|
async verify({ document, report, t }) {
|
|
8
8
|
await document.walkOn('Element', el => {
|
|
9
|
-
if (el.isForeignElement || el.
|
|
9
|
+
if (el.isForeignElement || el.elementType !== 'html') {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
const ms = el.rule.severity === 'error' ? 'must' : 'should';
|
|
@@ -38,7 +38,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
38
38
|
},
|
|
39
39
|
async fix({ document }) {
|
|
40
40
|
await document.walkOn('Element', el => {
|
|
41
|
-
if (el.isForeignElement || el.
|
|
41
|
+
if (el.isForeignElement || el.elementType !== 'html') {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
const deny = el.rule.value === 'lower' ? /[A-Z]/ : /[a-z]/;
|
|
@@ -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
|
defaultValue: null,
|
|
8
8
|
async verify({ document, report, t }) {
|
|
9
9
|
await document.walkOn('Element', el => {
|
package/lib/create-message.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import type { Translator } from '@markuplint/i18n';
|
|
|
2
2
|
import type { AttributeType } from '@markuplint/ml-spec';
|
|
3
3
|
import type { UnmatchedResult } from '@markuplint/types';
|
|
4
4
|
export declare function createMessageValueExpected(t: Translator, baseTarget: string, type: AttributeType, matches: UnmatchedResult): string;
|
|
5
|
-
export declare function __createMessageValueExpected(t: Translator, baseTarget: string, expected: string | null, matches: Pick<UnmatchedResult, 'partName' | 'reason' | 'raw' | '
|
|
5
|
+
export declare function __createMessageValueExpected(t: Translator, baseTarget: string, expected: string | null, matches: Pick<UnmatchedResult, 'partName' | 'reason' | 'raw' | 'candidate' | 'ref' | 'extra'>): string;
|
package/lib/create-message.js
CHANGED
|
@@ -26,7 +26,7 @@ function __createMessageValueExpected(t, baseTarget, expected, matches) {
|
|
|
26
26
|
let reasonPart;
|
|
27
27
|
let expectPart;
|
|
28
28
|
let unnecessaryPart;
|
|
29
|
-
let
|
|
29
|
+
let candidatePart;
|
|
30
30
|
let expectOrNeed = 'expects';
|
|
31
31
|
if (matches.partName) {
|
|
32
32
|
if (matches.partName === 'the content of the list') {
|
|
@@ -188,10 +188,10 @@ function __createMessageValueExpected(t, baseTarget, expected, matches) {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
|
-
if (matches.
|
|
192
|
-
|
|
191
|
+
if (matches.candidate) {
|
|
192
|
+
candidatePart = t('Did you mean "{0*}"?', matches.candidate);
|
|
193
193
|
}
|
|
194
|
-
let message = [reasonPart, unnecessaryPart, expectPart,
|
|
194
|
+
let message = [reasonPart, unnecessaryPart, expectPart, candidatePart].filter(s => s).join(t('. '));
|
|
195
195
|
if (matches.ref) {
|
|
196
196
|
message += ` (${matches.ref})`;
|
|
197
197
|
}
|
|
@@ -232,7 +232,7 @@ function expectValueToWord(t, expect, type) {
|
|
|
232
232
|
return expect.value ? `%${expect.value}%` : '';
|
|
233
233
|
case 'format':
|
|
234
234
|
return t('the {0} format', expect.value);
|
|
235
|
-
case '
|
|
235
|
+
case 'regexp':
|
|
236
236
|
return t('{0} ({1})', 'regular expression', expect.value);
|
|
237
237
|
case 'syntax':
|
|
238
238
|
if ((0, types_1.isKeyword)(type) && type[0] === '<') {
|
|
@@ -6,10 +6,10 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
6
6
|
await document.walkOn('Element', el => {
|
|
7
7
|
if (!(el.namespaceURI === 'http://www.w3.org/1999/xhtml' ||
|
|
8
8
|
el.namespaceURI === 'http://www.w3.org/2000/svg') ||
|
|
9
|
-
el.
|
|
9
|
+
el.elementType !== 'html') {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const spec = (0, ml_core_1.getSpec)(el, document.specs);
|
|
12
|
+
const spec = (0, ml_core_1.getSpec)(el, document.specs.specs);
|
|
13
13
|
if (spec && (spec.obsolete || spec.deprecated || spec.nonStandard)) {
|
|
14
14
|
const message = t('{0} is {1:c}', t('the "{0*}" {1}', el.localName, 'element'), spec.deprecated ? 'deprecated' : spec.obsolete ? 'obsolete' : 'non-standard');
|
|
15
15
|
report({
|
package/lib/doctype/index.d.ts
CHANGED
package/lib/doctype/index.js
CHANGED
package/lib/end-tag/index.js
CHANGED
package/lib/helpers.d.ts
CHANGED
|
@@ -60,12 +60,17 @@ export declare function checkAria(specs: Readonly<MLMLSpec>, attrName: string, c
|
|
|
60
60
|
valueDescriptions?: Record<string, string> | undefined;
|
|
61
61
|
};
|
|
62
62
|
export declare function accnameMayBeMutable(el: Element<any, any>, document: Document<any, any>): boolean;
|
|
63
|
-
export declare function getOwnedLabel<V extends RuleConfigValue, O>(el: Element<V, O>,
|
|
63
|
+
export declare function getOwnedLabel<V extends RuleConfigValue, O>(el: Element<V, O>, document: Document<V, O>): Element<V, O> | null;
|
|
64
64
|
export declare function decodeCharRef(characterReference: string): string;
|
|
65
65
|
export declare class Collection<T> {
|
|
66
66
|
#private;
|
|
67
67
|
constructor(...items: (T | null | undefined)[]);
|
|
68
|
+
[Symbol.iterator](): Iterator<T>;
|
|
68
69
|
add(...items: (T | null | undefined)[]): void;
|
|
69
70
|
toArray(): readonly T[];
|
|
70
|
-
[Symbol.iterator](): Iterator<T>;
|
|
71
71
|
}
|
|
72
|
+
declare type Writeable<T> = {
|
|
73
|
+
-readonly [P in keyof T]: T[P];
|
|
74
|
+
};
|
|
75
|
+
export declare function deepCopy<T>(value: T): Writeable<T>;
|
|
76
|
+
export {};
|
package/lib/helpers.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _Collection_items;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Collection = exports.decodeCharRef = exports.getOwnedLabel = exports.accnameMayBeMutable = exports.checkAria = exports.checkAriaValue = exports.toNormalizedValue = exports.isValidAttr = exports.rePCENChar = exports.match = exports.attrMatches = void 0;
|
|
4
|
+
exports.deepCopy = exports.Collection = exports.decodeCharRef = exports.getOwnedLabel = exports.accnameMayBeMutable = exports.checkAria = exports.checkAriaValue = exports.toNormalizedValue = exports.isValidAttr = exports.rePCENChar = exports.match = exports.attrMatches = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const structured_clone_1 = tslib_1.__importDefault(require("@ungap/structured-clone"));
|
|
7
9
|
const html_entities_1 = require("html-entities");
|
|
8
10
|
const attr_check_1 = require("./attr-check");
|
|
9
11
|
function attrMatches(node, condition) {
|
|
@@ -178,26 +180,26 @@ function accnameMayBeMutable(el, document) {
|
|
|
178
180
|
if (el.hasMutableAttributes() || el.hasMutableChildren(true)) {
|
|
179
181
|
return true;
|
|
180
182
|
}
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
+
const ownedLabel = getOwnedLabel(el, document);
|
|
184
|
+
if (ownedLabel && (ownedLabel.hasMutableAttributes() || ownedLabel.hasMutableChildren(true))) {
|
|
183
185
|
return true;
|
|
184
186
|
}
|
|
185
187
|
return false;
|
|
186
188
|
}
|
|
187
189
|
exports.accnameMayBeMutable = accnameMayBeMutable;
|
|
188
190
|
const labelable = ['button', 'input:not([type=hidden])', 'meter', 'output', 'progress', 'select', 'textarea'];
|
|
189
|
-
function getOwnedLabel(el,
|
|
191
|
+
function getOwnedLabel(el, document) {
|
|
190
192
|
if (!labelable.some(cond => el.matches(cond))) {
|
|
191
193
|
return null;
|
|
192
194
|
}
|
|
193
|
-
let
|
|
194
|
-
if (!
|
|
195
|
+
let ownedLabel = el.closest('label');
|
|
196
|
+
if (!ownedLabel) {
|
|
195
197
|
const id = el.getAttribute('id');
|
|
196
198
|
if (id) {
|
|
197
|
-
|
|
199
|
+
ownedLabel = document.querySelector(`label[for="${id}"]`);
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
|
-
return
|
|
202
|
+
return ownedLabel;
|
|
201
203
|
}
|
|
202
204
|
exports.getOwnedLabel = getOwnedLabel;
|
|
203
205
|
function decodeCharRef(characterReference) {
|
|
@@ -209,6 +211,9 @@ class Collection {
|
|
|
209
211
|
_Collection_items.set(this, new Set());
|
|
210
212
|
this.add(...items);
|
|
211
213
|
}
|
|
214
|
+
[(_Collection_items = new WeakMap(), Symbol.iterator)]() {
|
|
215
|
+
return tslib_1.__classPrivateFieldGet(this, _Collection_items, "f").values();
|
|
216
|
+
}
|
|
212
217
|
add(...items) {
|
|
213
218
|
for (const item of items) {
|
|
214
219
|
if (item == null) {
|
|
@@ -220,8 +225,9 @@ class Collection {
|
|
|
220
225
|
toArray() {
|
|
221
226
|
return Object.freeze(Array.from(tslib_1.__classPrivateFieldGet(this, _Collection_items, "f")));
|
|
222
227
|
}
|
|
223
|
-
[(_Collection_items = new WeakMap(), Symbol.iterator)]() {
|
|
224
|
-
return tslib_1.__classPrivateFieldGet(this, _Collection_items, "f").values();
|
|
225
|
-
}
|
|
226
228
|
}
|
|
227
229
|
exports.Collection = Collection;
|
|
230
|
+
function deepCopy(value) {
|
|
231
|
+
return (0, structured_clone_1.default)(value);
|
|
232
|
+
}
|
|
233
|
+
exports.deepCopy = deepCopy;
|
package/lib/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
'deprecated-element': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
|
|
10
10
|
'disallowed-element': import("packages/@markuplint/ml-core/lib").RuleSeed<string[], null>;
|
|
11
11
|
doctype: import("packages/@markuplint/ml-core/lib").RuleSeed<"always", {
|
|
12
|
-
|
|
12
|
+
denyObsoleteType: boolean;
|
|
13
13
|
}>;
|
|
14
14
|
'end-tag': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, null>;
|
|
15
15
|
'id-duplication': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
|
|
@@ -39,11 +39,7 @@ declare const _default: {
|
|
|
39
39
|
'no-use-event-handler-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
|
|
40
40
|
ignore?: string | string[] | undefined;
|
|
41
41
|
}>;
|
|
42
|
-
'permitted-contents': import("packages/@markuplint/ml-core/lib").RuleSeed<(import("
|
|
43
|
-
tag: string;
|
|
44
|
-
})[], {
|
|
45
|
-
ignoreHasMutableChildren: boolean;
|
|
46
|
-
}>;
|
|
42
|
+
'permitted-contents': import("packages/@markuplint/ml-core/lib").RuleSeed<import("./permitted-contents/types").TagRule[], import("./permitted-contents/types").Options>;
|
|
47
43
|
'require-accessible-name': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
|
|
48
44
|
ariaVersion: import("packages/@markuplint/ml-spec/lib").ARIAVersion;
|
|
49
45
|
}>;
|
|
@@ -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
|
const attrSpec = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
|
|
@@ -16,7 +16,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
16
16
|
const attrSpecs = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
|
|
17
17
|
const attrName = attr.nameNode;
|
|
18
18
|
const name = attr.name;
|
|
19
|
-
if (
|
|
19
|
+
if (attr.ownerElement.elementType === 'html' && attr.candidate) {
|
|
20
20
|
const message = t('{0} is {1:c}', t('the "{0*}" {1}', name, 'attribute'), 'disallowed') +
|
|
21
21
|
t('. ') +
|
|
22
22
|
t('Did you mean "{0}"?', attr.candidate);
|
|
@@ -69,7 +69,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
else if (
|
|
72
|
+
else if (attr.ownerElement.elementType === 'html' && attrSpecs) {
|
|
73
73
|
log('Checking %s[%s="%s"]', attr.nodeName, name, value);
|
|
74
74
|
invalid = (0, helpers_1.isValidAttr)(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
|
|
75
75
|
}
|
|
@@ -91,7 +91,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
93
|
case 'non-existent': {
|
|
94
|
-
const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs);
|
|
94
|
+
const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs.specs);
|
|
95
95
|
if (spec === null || spec === void 0 ? void 0 : spec.possibleToAddProperties) {
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
@@ -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;
|
|
@@ -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;
|