@markuplint/rules 3.15.0 → 4.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +5 -0
- package/LICENSE +1 -1
- package/lib/attr-check.d.ts +8 -19
- package/lib/attr-check.js +16 -21
- package/lib/attr-duplication/index.d.ts +1 -3
- package/lib/attr-duplication/index.js +6 -6
- package/lib/attr-value-quotes/index.d.ts +2 -2
- package/lib/attr-value-quotes/index.js +8 -10
- package/lib/case-sensitive-attr-name/index.d.ts +1 -1
- package/lib/case-sensitive-attr-name/index.js +12 -13
- package/lib/case-sensitive-tag-name/index.d.ts +1 -1
- package/lib/case-sensitive-tag-name/index.js +5 -4
- package/lib/character-reference/index.d.ts +1 -1
- package/lib/character-reference/index.js +13 -12
- package/lib/class-naming/index.d.ts +1 -1
- package/lib/class-naming/index.js +14 -13
- package/lib/create-message.d.ts +2 -12
- package/lib/create-message.js +26 -26
- package/lib/debug.js +2 -6
- package/lib/deprecated-attr/index.d.ts +1 -3
- package/lib/deprecated-attr/index.js +9 -9
- package/lib/deprecated-element/index.d.ts +1 -3
- package/lib/deprecated-element/index.js +7 -6
- package/lib/disallowed-element/index.d.ts +1 -1
- package/lib/disallowed-element/index.js +9 -8
- package/lib/doctype/index.d.ts +2 -2
- package/lib/doctype/index.js +5 -4
- package/lib/end-tag/index.d.ts +1 -1
- package/lib/end-tag/index.js +8 -8
- package/lib/helpers.d.ts +17 -35
- package/lib/helpers.js +25 -32
- package/lib/id-duplication/index.d.ts +1 -3
- package/lib/id-duplication/index.js +5 -4
- package/lib/index.d.ts +21 -17
- package/lib/index.js +63 -66
- package/lib/ineffective-attr/index.d.ts +1 -3
- package/lib/ineffective-attr/index.js +8 -7
- package/lib/invalid-attr/index.d.ts +31 -38
- package/lib/invalid-attr/index.js +33 -33
- package/lib/label-has-control/index.d.ts +1 -3
- package/lib/label-has-control/index.js +5 -4
- package/lib/landmark-roles/index.d.ts +3 -3
- package/lib/landmark-roles/index.js +16 -18
- package/lib/no-boolean-attr-value/index.d.ts +1 -3
- package/lib/no-boolean-attr-value/index.js +9 -9
- package/lib/no-default-value/index.d.ts +1 -3
- package/lib/no-default-value/index.js +12 -12
- package/lib/no-empty-palpable-content/index.d.ts +3 -3
- package/lib/no-empty-palpable-content/index.js +9 -8
- package/lib/no-hard-code-id/index.d.ts +1 -3
- package/lib/no-hard-code-id/index.js +5 -4
- package/lib/no-refer-to-non-existent-id/index.d.ts +1 -1
- package/lib/no-refer-to-non-existent-id/index.js +37 -38
- package/lib/no-use-event-handler-attr/index.d.ts +2 -2
- package/lib/no-use-event-handler-attr/index.js +7 -6
- package/lib/permitted-contents/choice.d.ts +2 -8
- package/lib/permitted-contents/choice.js +14 -19
- package/lib/permitted-contents/complex-branch.d.ts +2 -8
- package/lib/permitted-contents/complex-branch.js +10 -14
- package/lib/permitted-contents/content-model.d.ts +1 -1
- package/lib/permitted-contents/content-model.js +10 -11
- package/lib/permitted-contents/count-pattern.d.ts +3 -18
- package/lib/permitted-contents/count-pattern.js +19 -24
- package/lib/permitted-contents/debug.browser.d.ts +16 -16
- package/lib/permitted-contents/debug.browser.js +9 -12
- package/lib/permitted-contents/debug.d.ts +10 -3
- package/lib/permitted-contents/debug.js +12 -13
- package/lib/permitted-contents/index.d.ts +2 -2
- package/lib/permitted-contents/index.js +13 -13
- package/lib/permitted-contents/matches-selector.d.ts +2 -7
- package/lib/permitted-contents/matches-selector.js +13 -18
- package/lib/permitted-contents/order.d.ts +2 -8
- package/lib/permitted-contents/order.js +19 -24
- package/lib/permitted-contents/recursive-branch.d.ts +3 -9
- package/lib/permitted-contents/recursive-branch.js +9 -13
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +4 -8
- package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
- package/lib/permitted-contents/start.d.ts +2 -7
- package/lib/permitted-contents/start.js +13 -21
- package/lib/permitted-contents/transparent.d.ts +1 -1
- package/lib/permitted-contents/transparent.js +6 -11
- package/lib/permitted-contents/types.d.ts +29 -29
- package/lib/permitted-contents/types.js +1 -2
- package/lib/permitted-contents/utils.d.ts +42 -79
- package/lib/permitted-contents/utils.js +72 -82
- package/lib/placeholder-label-option/index.d.ts +1 -1
- package/lib/placeholder-label-option/index.js +12 -13
- package/lib/require-accessible-name/index.d.ts +2 -2
- package/lib/require-accessible-name/index.js +12 -15
- package/lib/require-datetime/index.d.ts +3 -3
- package/lib/require-datetime/index.js +14 -13
- package/lib/require-datetime/types.d.ts +2 -2
- package/lib/require-datetime/types.js +1 -2
- package/lib/require-datetime/utils.d.ts +1 -1
- package/lib/require-datetime/utils.js +5 -12
- package/lib/required-attr/index.d.ts +3 -3
- package/lib/required-attr/index.js +11 -11
- package/lib/required-element/index.d.ts +2 -2
- package/lib/required-element/index.js +7 -7
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/required-h1/index.js +6 -6
- package/lib/use-list/index.d.ts +6 -2
- package/lib/use-list/index.js +27 -11
- package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
- package/lib/wai-aria/checkings/abstract-role.js +5 -10
- package/lib/wai-aria/checkings/default-value.d.ts +4 -8
- package/lib/wai-aria/checkings/default-value.js +2 -6
- package/lib/wai-aria/checkings/deprecated-props.d.ts +5 -9
- package/lib/wai-aria/checkings/deprecated-props.js +3 -8
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +5 -9
- package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
- package/lib/wai-aria/checkings/implicit-props.d.ts +5 -9
- package/lib/wai-aria/checkings/implicit-props.js +12 -17
- package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
- package/lib/wai-aria/checkings/implicit-role.js +4 -9
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
- package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
- package/lib/wai-aria/checkings/no-global-prop.d.ts +4 -8
- package/lib/wai-aria/checkings/no-global-prop.js +2 -7
- package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
- package/lib/wai-aria/checkings/non-existent-role.js +4 -9
- package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
- package/lib/wai-aria/checkings/permitted-roles.js +4 -9
- package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
- package/lib/wai-aria/checkings/presentational-children.js +5 -10
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +4 -8
- package/lib/wai-aria/checkings/required-owned-elements.js +7 -11
- package/lib/wai-aria/checkings/required-prop.d.ts +7 -13
- package/lib/wai-aria/checkings/required-prop.js +2 -7
- package/lib/wai-aria/checkings/value.d.ts +7 -16
- package/lib/wai-aria/checkings/value.js +7 -13
- package/lib/wai-aria/index.d.ts +2 -2
- package/lib/wai-aria/index.js +41 -40
- package/lib/wai-aria/types.d.ts +10 -10
- package/lib/wai-aria/types.js +1 -2
- package/package.json +17 -13
- package/test/attr-check.spec.js +0 -77
- package/test/attr-duplication/index.spec.js +0 -159
- package/test/attr-value-quotes/index.spec.js +0 -133
- package/test/case-sensitive-attr-name/index.spec.js +0 -65
- package/test/case-sensitive-tag-name/index.spec.js +0 -80
- package/test/character-reference/index.spec.js +0 -72
- package/test/class-naming/index.spec.js +0 -470
- package/test/create-message.spec.js +0 -497
- package/test/deprecated-attr/index.spec.js +0 -48
- package/test/deprecated-element/index.spec.js +0 -35
- package/test/disallowed-element/index.spec.js +0 -90
- package/test/doctype/index.spec.js +0 -50
- package/test/end-tag/index.spec.js +0 -162
- package/test/id-duplication/index.spec.js +0 -47
- package/test/ineffective-attr/index.spec.js +0 -31
- package/test/invalid-attr/index.spec.js +0 -1631
- package/test/label-has-control/index.spec.js +0 -29
- package/test/landmark-roles/index.spec.js +0 -187
- package/test/no-boolean-attr-value/index.spec.js +0 -41
- package/test/no-default-value/index.spec.js +0 -74
- package/test/no-empty-palpable-content/index.spec.js +0 -115
- package/test/no-hard-code-id/index.spec.js +0 -100
- package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
- package/test/no-use-event-handler-attr/index.spec.js +0 -57
- package/test/permitted-contents/choice.spec.js +0 -174
- package/test/permitted-contents/count-pattern.spec.js +0 -308
- package/test/permitted-contents/index.spec.js +0 -1395
- package/test/permitted-contents/matches-selector.spec.js +0 -59
- package/test/permitted-contents/order.spec.js +0 -351
- package/test/permitted-contents/recursive-branch.spec.js +0 -41
- package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
- package/test/permitted-contents/start.spec.js +0 -67
- package/test/placeholder-label-option/index.spec.js +0 -113
- package/test/require-accessible-name/index.spec.js +0 -444
- package/test/require-datetime/index.spec.js +0 -54
- package/test/require-datetime/utils.spec.js +0 -52
- package/test/required-attr/index.spec.js +0 -414
- package/test/required-element/index.spec.js +0 -188
- package/test/required-h1/index.spec.js +0 -69
- package/test/use-list/index.spec.js +0 -109
- package/test/wai-aria/checkings/value.spec.js +0 -33
- package/test/wai-aria/index.spec.js +0 -1203
|
@@ -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
|
};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,88 +1,51 @@
|
|
|
1
|
-
import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types';
|
|
2
|
-
import type {
|
|
3
|
-
PermittedContentPattern,
|
|
4
|
-
PermittedContentChoice,
|
|
5
|
-
PermittedContentOneOrMore,
|
|
6
|
-
PermittedContentOptional,
|
|
7
|
-
PermittedContentRequire,
|
|
8
|
-
PermittedContentTransparent,
|
|
9
|
-
PermittedContentZeroOrMore,
|
|
10
|
-
Model,
|
|
11
|
-
} from '@markuplint/ml-spec';
|
|
1
|
+
import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types.js';
|
|
2
|
+
import type { PermittedContentPattern, PermittedContentChoice, PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentTransparent, PermittedContentZeroOrMore, Model } from '@markuplint/ml-spec';
|
|
12
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
13
4
|
export declare function getChildNodesWithoutWhitespaces(el: Element): ChildNode[];
|
|
14
5
|
export declare function isModel(model: ReadonlyDeep<Model | PermittedContentPattern[]>): model is ReadonlyDeep<Model>;
|
|
15
|
-
export declare function matches(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
matched: boolean;
|
|
22
|
-
not?: undefined;
|
|
23
|
-
}
|
|
24
|
-
| {
|
|
25
|
-
matched: boolean;
|
|
26
|
-
not: ChildNode | undefined;
|
|
27
|
-
};
|
|
28
|
-
export declare function isRequire(
|
|
29
|
-
content: ReadonlyDeep<PermittedContentPattern>,
|
|
30
|
-
): content is ReadonlyDeep<PermittedContentRequire>;
|
|
31
|
-
export declare function isOptional(
|
|
32
|
-
content: ReadonlyDeep<PermittedContentPattern>,
|
|
33
|
-
): content is ReadonlyDeep<PermittedContentOptional>;
|
|
34
|
-
export declare function isOneOrMore(
|
|
35
|
-
content: ReadonlyDeep<PermittedContentPattern>,
|
|
36
|
-
): content is ReadonlyDeep<PermittedContentOneOrMore>;
|
|
37
|
-
export declare function isZeroOrMore(
|
|
38
|
-
content: ReadonlyDeep<PermittedContentPattern>,
|
|
39
|
-
): content is ReadonlyDeep<PermittedContentZeroOrMore>;
|
|
40
|
-
export declare function isChoice(
|
|
41
|
-
content: ReadonlyDeep<PermittedContentPattern>,
|
|
42
|
-
): content is ReadonlyDeep<PermittedContentChoice>;
|
|
43
|
-
export declare function isTransparent(
|
|
44
|
-
content: ReadonlyDeep<PermittedContentPattern>,
|
|
45
|
-
): content is ReadonlyDeep<PermittedContentTransparent>;
|
|
46
|
-
export declare function normalizeModel(
|
|
47
|
-
pattern:
|
|
48
|
-
| ReadonlyDeep<PermittedContentRequire>
|
|
49
|
-
| ReadonlyDeep<PermittedContentOptional>
|
|
50
|
-
| ReadonlyDeep<PermittedContentOneOrMore>
|
|
51
|
-
| ReadonlyDeep<PermittedContentZeroOrMore>,
|
|
52
|
-
): {
|
|
53
|
-
model: ReadonlyDeep<PermittedContentPattern[] | Model>;
|
|
54
|
-
min: number;
|
|
55
|
-
max: number;
|
|
56
|
-
repeat: RepeatSign;
|
|
57
|
-
missingType: MissingNodeReason | undefined;
|
|
6
|
+
export declare function matches(selector: string, node: ChildNode, specs: Specs): {
|
|
7
|
+
matched: boolean;
|
|
8
|
+
not?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
matched: boolean;
|
|
11
|
+
not: ChildNode | undefined;
|
|
58
12
|
};
|
|
59
|
-
export declare function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
):
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
13
|
+
export declare function isRequire(content: ReadonlyDeep<PermittedContentPattern>): content is ReadonlyDeep<PermittedContentRequire>;
|
|
14
|
+
export declare function isOptional(content: ReadonlyDeep<PermittedContentPattern>): content is ReadonlyDeep<PermittedContentOptional>;
|
|
15
|
+
export declare function isOneOrMore(content: ReadonlyDeep<PermittedContentPattern>): content is ReadonlyDeep<PermittedContentOneOrMore>;
|
|
16
|
+
export declare function isZeroOrMore(content: ReadonlyDeep<PermittedContentPattern>): content is ReadonlyDeep<PermittedContentZeroOrMore>;
|
|
17
|
+
export declare function isChoice(content: ReadonlyDeep<PermittedContentPattern>): content is ReadonlyDeep<PermittedContentChoice>;
|
|
18
|
+
export declare function isTransparent(content: ReadonlyDeep<PermittedContentPattern>): content is ReadonlyDeep<PermittedContentTransparent>;
|
|
19
|
+
export declare function normalizeModel(pattern: ReadonlyDeep<PermittedContentRequire> | ReadonlyDeep<PermittedContentOptional> | ReadonlyDeep<PermittedContentOneOrMore> | ReadonlyDeep<PermittedContentZeroOrMore>): {
|
|
20
|
+
model: ReadonlyDeep<PermittedContentPattern[] | Model>;
|
|
21
|
+
min: number;
|
|
22
|
+
max: number;
|
|
23
|
+
repeat: RepeatSign;
|
|
24
|
+
missingType: MissingNodeReason | undefined;
|
|
25
|
+
};
|
|
26
|
+
export declare function mergeHints(a: Readonly<Hints>, b: Readonly<Hints>): Partial<{
|
|
27
|
+
missing: Partial<{
|
|
28
|
+
barelyMatchedElements?: number | undefined;
|
|
29
|
+
need?: string | undefined;
|
|
30
|
+
}> | undefined;
|
|
31
|
+
max?: number | undefined;
|
|
32
|
+
not?: ChildNode | undefined;
|
|
33
|
+
transparent?: Element | undefined;
|
|
72
34
|
}>;
|
|
73
35
|
export declare function cleanObject<T extends Object>(object: T): Partial<T>;
|
|
74
36
|
export declare class Collection {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
37
|
+
#private;
|
|
38
|
+
constructor(origin: readonly ChildNode[]);
|
|
39
|
+
get matched(): ChildNode[];
|
|
40
|
+
get matchedCount(): number;
|
|
41
|
+
get nodes(): ChildNode[];
|
|
42
|
+
get unmatched(): ChildNode[];
|
|
43
|
+
addMatched(nodes: ChildNode[]): boolean;
|
|
44
|
+
back(): void;
|
|
45
|
+
lock(): void;
|
|
46
|
+
max(max: number): void;
|
|
47
|
+
toString(highlightExtraNodes?: boolean): string;
|
|
48
|
+
}
|
|
49
|
+
export declare class UnsupportedError extends Error {
|
|
86
50
|
}
|
|
87
|
-
export declare class UnsupportedError extends Error {}
|
|
88
51
|
export declare function modelLog(model: ReadonlyDeep<Model | PermittedContentPattern[]>, repeat: RepeatSign): string;
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
2
12
|
var _Collection_locked, _Collection_matched, _Collection_nodes, _Collection_origin;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const selector_1 = require("@markuplint/selector");
|
|
7
|
-
const debug_1 = require("./debug");
|
|
8
|
-
const represent_transparent_nodes_1 = require("./represent-transparent-nodes");
|
|
13
|
+
import { createSelector } from '@markuplint/selector';
|
|
14
|
+
import { bgGreen, green, bgRed, bgBlue, blue, bgMagenta, cyan } from './debug.js';
|
|
15
|
+
import { transparentMode } from './represent-transparent-nodes.js';
|
|
9
16
|
const getChildNodesWithoutWhitespacesCaches = new Map();
|
|
10
|
-
function getChildNodesWithoutWhitespaces(
|
|
17
|
+
export function getChildNodesWithoutWhitespaces(
|
|
11
18
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
12
19
|
el) {
|
|
13
20
|
let nodes = getChildNodesWithoutWhitespacesCaches.get(el);
|
|
14
21
|
if (nodes) {
|
|
15
22
|
return nodes;
|
|
16
23
|
}
|
|
17
|
-
nodes =
|
|
24
|
+
nodes = [...el.childNodes].filter(node => {
|
|
18
25
|
return !(node.is(node.TEXT_NODE) && node.isWhitespace());
|
|
19
26
|
});
|
|
20
27
|
getChildNodesWithoutWhitespacesCaches.set(el, nodes);
|
|
21
28
|
return nodes;
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
function isModel(model) {
|
|
30
|
+
export function isModel(model) {
|
|
25
31
|
if (typeof model === 'string') {
|
|
26
32
|
return true;
|
|
27
33
|
}
|
|
@@ -37,11 +43,10 @@ function isModel(model) {
|
|
|
37
43
|
}
|
|
38
44
|
return modelMode;
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
function matches(selector,
|
|
46
|
+
export function matches(selector,
|
|
42
47
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
43
48
|
node, specs) {
|
|
44
|
-
const selectorResult =
|
|
49
|
+
const selectorResult = createSelector(selector, specs).search(node);
|
|
45
50
|
const matched = selectorResult.filter((r) => r.matched);
|
|
46
51
|
if (matched.length > 0) {
|
|
47
52
|
return {
|
|
@@ -49,21 +54,18 @@ node, specs) {
|
|
|
49
54
|
};
|
|
50
55
|
}
|
|
51
56
|
const not = selectorResult
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
-
.map(descendants)
|
|
55
|
-
.flat()
|
|
57
|
+
.flatMap(r => (r.matched ? [] : r.not ?? []))
|
|
58
|
+
.flatMap(descendants)
|
|
56
59
|
.shift();
|
|
57
60
|
return {
|
|
58
61
|
matched: false,
|
|
59
62
|
not,
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
|
-
exports.matches = matches;
|
|
63
65
|
function descendants(
|
|
64
66
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
65
67
|
selectorResult) {
|
|
66
|
-
let nodes = selectorResult.nodes
|
|
68
|
+
let nodes = [...selectorResult.nodes];
|
|
67
69
|
while (selectorResult.has.length > 0) {
|
|
68
70
|
for (const dep of selectorResult.has) {
|
|
69
71
|
if (dep.has.length === 0) {
|
|
@@ -77,32 +79,25 @@ selectorResult) {
|
|
|
77
79
|
}
|
|
78
80
|
return nodes;
|
|
79
81
|
}
|
|
80
|
-
function isRequire(content) {
|
|
82
|
+
export function isRequire(content) {
|
|
81
83
|
return 'require' in content;
|
|
82
84
|
}
|
|
83
|
-
|
|
84
|
-
function isOptional(content) {
|
|
85
|
+
export function isOptional(content) {
|
|
85
86
|
return 'optional' in content;
|
|
86
87
|
}
|
|
87
|
-
|
|
88
|
-
function isOneOrMore(content) {
|
|
88
|
+
export function isOneOrMore(content) {
|
|
89
89
|
return 'oneOrMore' in content;
|
|
90
90
|
}
|
|
91
|
-
|
|
92
|
-
function isZeroOrMore(content) {
|
|
91
|
+
export function isZeroOrMore(content) {
|
|
93
92
|
return 'zeroOrMore' in content;
|
|
94
93
|
}
|
|
95
|
-
|
|
96
|
-
function isChoice(content) {
|
|
94
|
+
export function isChoice(content) {
|
|
97
95
|
return 'choice' in content;
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
function isTransparent(content) {
|
|
97
|
+
export function isTransparent(content) {
|
|
101
98
|
return 'transparent' in content;
|
|
102
99
|
}
|
|
103
|
-
|
|
104
|
-
function normalizeModel(pattern) {
|
|
105
|
-
var _a, _b, _c, _d, _e;
|
|
100
|
+
export function normalizeModel(pattern) {
|
|
106
101
|
let model;
|
|
107
102
|
let min;
|
|
108
103
|
let max;
|
|
@@ -110,25 +105,25 @@ function normalizeModel(pattern) {
|
|
|
110
105
|
let missingType;
|
|
111
106
|
if (isRequire(pattern)) {
|
|
112
107
|
model = pattern.require;
|
|
113
|
-
min =
|
|
114
|
-
max = Math.max(
|
|
108
|
+
min = pattern.min ?? 1;
|
|
109
|
+
max = Math.max(pattern.max ?? 1, min);
|
|
115
110
|
missingType = 'MISSING_NODE_REQUIRED';
|
|
116
111
|
}
|
|
117
112
|
else if (isOptional(pattern)) {
|
|
118
113
|
model = pattern.optional;
|
|
119
114
|
min = 0;
|
|
120
|
-
max = Math.max(
|
|
115
|
+
max = Math.max(pattern.max ?? 1, 1);
|
|
121
116
|
}
|
|
122
117
|
else if (isOneOrMore(pattern)) {
|
|
123
118
|
model = pattern.oneOrMore;
|
|
124
119
|
min = 1;
|
|
125
|
-
max = Math.max(
|
|
120
|
+
max = Math.max(pattern.max ?? Number.POSITIVE_INFINITY, 1);
|
|
126
121
|
missingType = 'MISSING_NODE_ONE_OR_MORE';
|
|
127
122
|
}
|
|
128
123
|
else if (isZeroOrMore(pattern)) {
|
|
129
124
|
model = pattern.zeroOrMore;
|
|
130
125
|
min = 0;
|
|
131
|
-
max = Math.max(
|
|
126
|
+
max = Math.max(pattern.max ?? Number.POSITIVE_INFINITY, 1);
|
|
132
127
|
}
|
|
133
128
|
else {
|
|
134
129
|
throw new Error('Unreachable code');
|
|
@@ -156,31 +151,28 @@ function normalizeModel(pattern) {
|
|
|
156
151
|
missingType,
|
|
157
152
|
};
|
|
158
153
|
}
|
|
159
|
-
|
|
160
|
-
function mergeHints(
|
|
154
|
+
export function mergeHints(
|
|
161
155
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
162
156
|
a,
|
|
163
157
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
164
158
|
b) {
|
|
165
|
-
const missing = [a.missing, b.missing].sort((a, b) =>
|
|
159
|
+
const missing = [a.missing, b.missing].sort((a, b) => (b?.barelyMatchedElements ?? 0) - (a?.barelyMatchedElements ?? 0))[0];
|
|
166
160
|
return cleanObject({
|
|
167
161
|
...a,
|
|
168
162
|
...b,
|
|
169
163
|
missing: missing && cleanObject(missing),
|
|
170
164
|
});
|
|
171
165
|
}
|
|
172
|
-
|
|
173
|
-
function cleanObject(object) {
|
|
166
|
+
export function cleanObject(object) {
|
|
174
167
|
const newObject = {};
|
|
175
|
-
|
|
168
|
+
for (const [key, value] of Object.entries(object)) {
|
|
176
169
|
if (value !== undefined) {
|
|
177
170
|
newObject[key] = value;
|
|
178
171
|
}
|
|
179
|
-
}
|
|
172
|
+
}
|
|
180
173
|
return newObject;
|
|
181
174
|
}
|
|
182
|
-
|
|
183
|
-
class Collection {
|
|
175
|
+
export class Collection {
|
|
184
176
|
constructor(
|
|
185
177
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
186
178
|
origin) {
|
|
@@ -188,76 +180,77 @@ class Collection {
|
|
|
188
180
|
_Collection_matched.set(this, new Set());
|
|
189
181
|
_Collection_nodes.set(this, void 0);
|
|
190
182
|
_Collection_origin.set(this, void 0);
|
|
191
|
-
|
|
192
|
-
|
|
183
|
+
__classPrivateFieldSet(this, _Collection_origin, [...origin], "f");
|
|
184
|
+
__classPrivateFieldSet(this, _Collection_nodes, new Set(__classPrivateFieldGet(this, _Collection_origin, "f")), "f");
|
|
193
185
|
}
|
|
194
186
|
get matched() {
|
|
195
|
-
return
|
|
187
|
+
return [...__classPrivateFieldGet(this, _Collection_matched, "f")];
|
|
196
188
|
}
|
|
197
189
|
get matchedCount() {
|
|
198
|
-
return
|
|
190
|
+
return __classPrivateFieldGet(this, _Collection_matched, "f").size;
|
|
199
191
|
}
|
|
200
192
|
get nodes() {
|
|
201
|
-
return
|
|
193
|
+
return [...__classPrivateFieldGet(this, _Collection_origin, "f")];
|
|
202
194
|
}
|
|
203
195
|
get unmatched() {
|
|
204
|
-
return
|
|
196
|
+
return [...__classPrivateFieldGet(this, _Collection_nodes, "f")].filter(n => !__classPrivateFieldGet(this, _Collection_matched, "f").has(n));
|
|
205
197
|
}
|
|
206
198
|
addMatched(
|
|
207
199
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
208
200
|
nodes) {
|
|
209
|
-
const i =
|
|
201
|
+
const i = __classPrivateFieldGet(this, _Collection_matched, "f").size;
|
|
210
202
|
for (const node of nodes) {
|
|
211
|
-
if (!
|
|
203
|
+
if (!__classPrivateFieldGet(this, _Collection_nodes, "f").has(node)) {
|
|
212
204
|
throw new ReferenceError(`External Node: ${node.nodeName}`);
|
|
213
205
|
}
|
|
214
|
-
|
|
206
|
+
__classPrivateFieldGet(this, _Collection_matched, "f").add(node);
|
|
215
207
|
}
|
|
216
|
-
return i <
|
|
208
|
+
return i < __classPrivateFieldGet(this, _Collection_matched, "f").size;
|
|
217
209
|
}
|
|
218
210
|
back() {
|
|
219
|
-
|
|
211
|
+
__classPrivateFieldSet(this, _Collection_matched, new Set(__classPrivateFieldGet(this, _Collection_locked, "f")), "f");
|
|
220
212
|
}
|
|
221
213
|
lock() {
|
|
222
|
-
|
|
214
|
+
__classPrivateFieldSet(this, _Collection_locked, new Set(__classPrivateFieldGet(this, _Collection_matched, "f")), "f");
|
|
223
215
|
}
|
|
224
216
|
max(max) {
|
|
225
|
-
const sliced =
|
|
226
|
-
|
|
217
|
+
const sliced = [...__classPrivateFieldGet(this, _Collection_matched, "f")].slice(max);
|
|
218
|
+
for (const n of sliced)
|
|
219
|
+
__classPrivateFieldGet(this, _Collection_matched, "f").delete(n);
|
|
227
220
|
}
|
|
228
221
|
toString(highlightExtraNodes = false) {
|
|
229
222
|
const out = [];
|
|
230
|
-
for (const n of
|
|
231
|
-
const raw = n.is(n.TEXT_NODE) ? `:text(${n.raw.
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
234
|
-
out.push(
|
|
223
|
+
for (const n of __classPrivateFieldGet(this, _Collection_origin, "f")) {
|
|
224
|
+
const raw = n.is(n.TEXT_NODE) ? `:text(${n.raw.replaceAll('\n', '\\n')})` : n.raw;
|
|
225
|
+
if (__classPrivateFieldGet(this, _Collection_locked, "f").has(n)) {
|
|
226
|
+
if (transparentMode.has(n)) {
|
|
227
|
+
out.push(bgBlue.bold(raw));
|
|
235
228
|
}
|
|
236
229
|
else {
|
|
237
|
-
out.push(
|
|
230
|
+
out.push(bgGreen.bold(raw));
|
|
238
231
|
}
|
|
239
232
|
continue;
|
|
240
233
|
}
|
|
241
|
-
if (
|
|
242
|
-
if (
|
|
243
|
-
out.push(
|
|
234
|
+
if (__classPrivateFieldGet(this, _Collection_matched, "f").has(n)) {
|
|
235
|
+
if (transparentMode.has(n)) {
|
|
236
|
+
out.push(blue.bold(raw));
|
|
244
237
|
}
|
|
245
238
|
else {
|
|
246
|
-
out.push(
|
|
239
|
+
out.push(green.bold(raw));
|
|
247
240
|
}
|
|
248
241
|
continue;
|
|
249
242
|
}
|
|
250
243
|
if (highlightExtraNodes) {
|
|
251
|
-
if (
|
|
252
|
-
out.push(
|
|
244
|
+
if (transparentMode.has(n)) {
|
|
245
|
+
out.push(bgMagenta.bold(raw));
|
|
253
246
|
}
|
|
254
247
|
else {
|
|
255
|
-
out.push(
|
|
248
|
+
out.push(bgRed.bold(raw));
|
|
256
249
|
}
|
|
257
250
|
continue;
|
|
258
251
|
}
|
|
259
|
-
if (
|
|
260
|
-
out.push(
|
|
252
|
+
if (transparentMode.has(n)) {
|
|
253
|
+
out.push(cyan(raw));
|
|
261
254
|
}
|
|
262
255
|
else {
|
|
263
256
|
out.push(raw);
|
|
@@ -266,12 +259,10 @@ class Collection {
|
|
|
266
259
|
return `[ ${out.join(', ')} ]`;
|
|
267
260
|
}
|
|
268
261
|
}
|
|
269
|
-
exports.Collection = Collection;
|
|
270
262
|
_Collection_locked = new WeakMap(), _Collection_matched = new WeakMap(), _Collection_nodes = new WeakMap(), _Collection_origin = new WeakMap();
|
|
271
|
-
class UnsupportedError extends Error {
|
|
263
|
+
export class UnsupportedError extends Error {
|
|
272
264
|
}
|
|
273
|
-
|
|
274
|
-
function modelLog(model, repeat) {
|
|
265
|
+
export function modelLog(model, repeat) {
|
|
275
266
|
if (!isModel(model)) {
|
|
276
267
|
return orderLog(model, repeat);
|
|
277
268
|
}
|
|
@@ -280,7 +271,6 @@ function modelLog(model, repeat) {
|
|
|
280
271
|
}
|
|
281
272
|
return `(<${model.join('>|<')}>)${repeat}`;
|
|
282
273
|
}
|
|
283
|
-
exports.modelLog = modelLog;
|
|
284
274
|
function orderLog(order, repeat) {
|
|
285
275
|
return order.length === 1 && order[0]
|
|
286
276
|
? markRepeat(patternLog(order[0]), repeat)
|
|
@@ -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;
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
export default createRule({
|
|
3
|
+
meta: {
|
|
4
|
+
category: 'validation',
|
|
5
|
+
},
|
|
5
6
|
verify({ document, report, t }) {
|
|
6
|
-
document.querySelectorAll('select')
|
|
7
|
+
for (const select of document.querySelectorAll('select')) {
|
|
7
8
|
if (hasPlaceholderLabelOption(select)) {
|
|
8
|
-
|
|
9
|
+
continue;
|
|
9
10
|
}
|
|
10
11
|
if (!needPlaceholderLabelOption(select)) {
|
|
11
|
-
|
|
12
|
+
continue;
|
|
12
13
|
}
|
|
13
14
|
report({
|
|
14
15
|
scope: select,
|
|
15
16
|
message: t('need {0}', t('the {0}', 'placeholder label option')),
|
|
16
17
|
});
|
|
17
|
-
}
|
|
18
|
+
}
|
|
18
19
|
},
|
|
19
20
|
});
|
|
20
21
|
/**
|
|
@@ -29,7 +30,6 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
29
30
|
function needPlaceholderLabelOption(
|
|
30
31
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
31
32
|
select) {
|
|
32
|
-
var _a;
|
|
33
33
|
const hasRequired = select.hasAttribute('required');
|
|
34
34
|
if (!hasRequired) {
|
|
35
35
|
return false;
|
|
@@ -38,7 +38,7 @@ select) {
|
|
|
38
38
|
if (hasMultiple) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
|
-
const size =
|
|
41
|
+
const size = select.getAttribute('size') ?? '1';
|
|
42
42
|
if (size !== '1') {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
@@ -59,7 +59,6 @@ select) {
|
|
|
59
59
|
function hasPlaceholderLabelOption(
|
|
60
60
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
61
61
|
select) {
|
|
62
|
-
var _a, _b;
|
|
63
62
|
// > has a required attribute specified
|
|
64
63
|
if (!select.hasAttribute('required')) {
|
|
65
64
|
return false;
|
|
@@ -69,7 +68,7 @@ select) {
|
|
|
69
68
|
return false;
|
|
70
69
|
}
|
|
71
70
|
// > has a display size of 1
|
|
72
|
-
const size =
|
|
71
|
+
const size = select.getAttribute('size') ?? '1';
|
|
73
72
|
if (size !== '1') {
|
|
74
73
|
return false;
|
|
75
74
|
}
|
|
@@ -80,7 +79,7 @@ select) {
|
|
|
80
79
|
return true;
|
|
81
80
|
}
|
|
82
81
|
// > that option element's parent node is the select element (and not an optgroup element)
|
|
83
|
-
if (
|
|
82
|
+
if (firstOption.parentElement?.localName === 'optgroup') {
|
|
84
83
|
return false;
|
|
85
84
|
}
|
|
86
85
|
const value = firstOption.getAttribute('value');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ARIAVersion } from '@markuplint/ml-spec';
|
|
2
2
|
type Option = {
|
|
3
|
-
|
|
3
|
+
ariaVersion: ARIAVersion;
|
|
4
4
|
};
|
|
5
|
-
declare const _default: Readonly<import(
|
|
5
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Option>>;
|
|
6
6
|
export default _default;
|