@markuplint/ml-core 3.0.0-alpha.66 → 3.0.0-dev.176
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 +12 -3
- package/lib/configs.browser.d.ts +2 -0
- package/lib/configs.browser.js +12 -0
- package/lib/configs.js +4 -1
- package/lib/index.d.ts +11 -1
- package/lib/ml-core.d.ts +24 -13
- package/lib/ml-core.js +16 -10
- package/lib/ml-dom/helper/accname.d.ts +2 -1
- package/lib/ml-dom/helper/accname.js +62 -2
- package/lib/ml-dom/helper/create-node.d.ts +7 -3
- package/lib/ml-dom/helper/create-node.js +4 -2
- package/lib/ml-dom/helper/debug.js +10 -5
- package/lib/ml-dom/helper/getIndent.d.ts +7 -7
- package/lib/ml-dom/helper/getIndent.js +18 -12
- package/lib/ml-dom/helper/walkers.d.ts +15 -5
- package/lib/ml-dom/helper/walkers.js +22 -16
- package/lib/ml-dom/index.d.ts +1 -0
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +20 -7
- package/lib/ml-dom/manipulations/child-node-methods.js +24 -6
- package/lib/ml-dom/manipulations/get-children.d.ts +4 -2
- package/lib/ml-dom/manipulations/get-children.js +3 -1
- package/lib/ml-dom/node/attr.d.ts +94 -91
- package/lib/ml-dom/node/attr.js +26 -16
- package/lib/ml-dom/node/block.d.ts +36 -32
- package/lib/ml-dom/node/block.js +14 -4
- package/lib/ml-dom/node/character-data.d.ts +61 -54
- package/lib/ml-dom/node/character-data.js +9 -3
- package/lib/ml-dom/node/child-node.d.ts +10 -3
- package/lib/ml-dom/node/child-node.js +3 -1
- package/lib/ml-dom/node/comment.d.ts +16 -13
- package/lib/ml-dom/node/document-fragment.d.ts +24 -21
- package/lib/ml-dom/node/document-type.d.ts +35 -32
- package/lib/ml-dom/node/document-type.js +14 -4
- package/lib/ml-dom/node/document.d.ts +1608 -1545
- package/lib/ml-dom/node/document.js +125 -33
- package/lib/ml-dom/node/dom-token-list.d.ts +27 -27
- package/lib/ml-dom/node/dom-token-list.js +15 -13
- package/lib/ml-dom/node/element.d.ts +1906 -1817
- package/lib/ml-dom/node/element.js +345 -75
- package/lib/ml-dom/node/named-node-map.d.ts +45 -40
- package/lib/ml-dom/node/named-node-map.js +13 -5
- package/lib/ml-dom/node/node-list.d.ts +10 -4
- package/lib/ml-dom/node/node-list.js +25 -5
- package/lib/ml-dom/node/node-store.d.ts +10 -5
- package/lib/ml-dom/node/node-store.js +19 -1
- package/lib/ml-dom/node/node.d.ts +494 -467
- package/lib/ml-dom/node/node.js +89 -47
- package/lib/ml-dom/node/parent-node.d.ts +68 -59
- package/lib/ml-dom/node/parent-node.js +15 -6
- package/lib/ml-dom/node/rule-mapper.d.ts +9 -9
- package/lib/ml-dom/node/rule-mapper.js +11 -3
- package/lib/ml-dom/node/text.d.ts +50 -47
- package/lib/ml-dom/node/types.d.ts +94 -16
- package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -2
- package/lib/ml-dom/token/token.d.ts +44 -44
- package/lib/ml-rule/create-rule.d.ts +4 -2
- package/lib/ml-rule/create-test-rule.d.ts +6 -4
- package/lib/ml-rule/ml-rule-context.d.ts +58 -49
- package/lib/ml-rule/ml-rule-context.js +23 -4
- package/lib/ml-rule/ml-rule.d.ts +36 -26
- package/lib/ml-rule/ml-rule.js +39 -34
- package/lib/ml-rule/types.d.ts +35 -17
- package/lib/plugin/plugin.d.ts +3 -1
- package/lib/plugin/types.d.ts +9 -9
- package/lib/ruleset/index.d.ts +4 -4
- package/lib/ruleset/index.js +4 -4
- package/lib/test/index.d.ts +21 -8
- package/lib/test/index.js +6 -4
- package/lib/types.d.ts +12 -10
- package/lib/utils/get-location-from-chars.d.ts +9 -4
- package/package.json +21 -15
- package/test/ml-dom/helper/accname.spec.js +85 -0
- package/test/ml-dom/helper/create-node.spec.js +18 -0
- package/test/ml-dom/index.spec.js +680 -0
- package/lib/ml-dom/document.d.ts +0 -94
- package/lib/ml-dom/document.js +0 -273
- package/lib/ml-dom/helper/index.d.ts +0 -4
- package/lib/ml-dom/helper/index.js +0 -12
- package/lib/ml-dom/helper/mapped-nodes.d.ts +0 -52
- package/lib/ml-dom/helper/mapped-nodes.js +0 -2
- package/lib/ml-dom/helper/match-selector.d.ts +0 -20
- package/lib/ml-dom/helper/match-selector.js +0 -233
- package/lib/ml-dom/helper/node-store.d.ts +0 -12
- package/lib/ml-dom/helper/node-store.js +0 -28
- package/lib/ml-dom/helper/selector.d.ts +0 -11
- package/lib/ml-dom/helper/selector.js +0 -549
- package/lib/ml-dom/rule-mapper.d.ts +0 -16
- package/lib/ml-dom/rule-mapper.js +0 -57
- package/lib/ml-dom/tokens/abstract-element.d.ts +0 -54
- package/lib/ml-dom/tokens/abstract-element.js +0 -249
- package/lib/ml-dom/tokens/attribute.d.ts +0 -42
- package/lib/ml-dom/tokens/attribute.js +0 -85
- package/lib/ml-dom/tokens/comment.d.ts +0 -12
- package/lib/ml-dom/tokens/comment.js +0 -15
- package/lib/ml-dom/tokens/doctype.d.ts +0 -18
- package/lib/ml-dom/tokens/doctype.js +0 -32
- package/lib/ml-dom/tokens/element-close-tag.d.ts +0 -27
- package/lib/ml-dom/tokens/element-close-tag.js +0 -45
- package/lib/ml-dom/tokens/element.d.ts +0 -26
- package/lib/ml-dom/tokens/element.js +0 -66
- package/lib/ml-dom/tokens/index.d.ts +0 -10
- package/lib/ml-dom/tokens/index.js +0 -26
- package/lib/ml-dom/tokens/node.d.ts +0 -46
- package/lib/ml-dom/tokens/node.js +0 -126
- package/lib/ml-dom/tokens/omitted-element.d.ts +0 -13
- package/lib/ml-dom/tokens/omitted-element.js +0 -12
- package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +0 -24
- package/lib/ml-dom/tokens/preprocessor-specific-attribute.js +0 -37
- package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +0 -14
- package/lib/ml-dom/tokens/preprocessor-specific-block.js +0 -16
- package/lib/ml-dom/tokens/text.d.ts +0 -19
- package/lib/ml-dom/tokens/text.js +0 -26
- package/lib/ml-dom/tokens/token.d.ts +0 -16
- package/lib/ml-dom/tokens/token.js +0 -55
- package/lib/ml-dom/types.d.ts +0 -49
- package/lib/ml-dom/types.js +0 -2
- package/lib/selector/is-pure-html-element.d.ts +0 -1
- package/lib/selector/is-pure-html-element.js +0 -7
- package/lib/selector/match-selector.d.ts +0 -14
- package/lib/selector/match-selector.js +0 -230
- package/lib/selector/selector.d.ts +0 -9
- package/lib/selector/selector.js +0 -561
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { MLToken } from '../token/token';
|
|
2
1
|
import type { MLAttr } from './attr';
|
|
3
2
|
import type { MLBlock } from './block';
|
|
4
3
|
import type { MLComment } from './comment';
|
|
@@ -8,18 +7,97 @@ import type { MLDocumentType } from './document-type';
|
|
|
8
7
|
import type { MLElement } from './element';
|
|
9
8
|
import type { MLNode } from './node';
|
|
10
9
|
import type { MLText } from './text';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
|
|
10
|
+
import type { MLToken } from '../token/token';
|
|
11
|
+
import type {
|
|
12
|
+
MLASTAbstractNode,
|
|
13
|
+
MLASTAttr,
|
|
14
|
+
MLASTComment,
|
|
15
|
+
MLASTDoctype,
|
|
16
|
+
MLASTElement,
|
|
17
|
+
MLASTParentNode,
|
|
18
|
+
MLASTPreprocessorSpecificBlock,
|
|
19
|
+
MLASTText,
|
|
20
|
+
MLToken as MLASTToken,
|
|
21
|
+
} from '@markuplint/ml-ast/';
|
|
22
|
+
import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
|
|
23
|
+
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement
|
|
24
|
+
? MLElement<T, O>
|
|
25
|
+
: N extends MLASTParentNode
|
|
26
|
+
? MLElement<T, O>
|
|
27
|
+
: N extends MLASTComment
|
|
28
|
+
? MLComment<T, O>
|
|
29
|
+
: N extends MLASTText
|
|
30
|
+
? MLText<T, O>
|
|
31
|
+
: N extends MLASTDoctype
|
|
32
|
+
? MLDocumentType<T, O>
|
|
33
|
+
: N extends MLASTPreprocessorSpecificBlock
|
|
34
|
+
? MLBlock<T, O>
|
|
35
|
+
: N extends MLASTAbstractNode
|
|
36
|
+
? MLNode<T, O, MLASTAbstractNode>
|
|
37
|
+
: N extends MLASTAttr
|
|
38
|
+
? MLAttr<T, O>
|
|
39
|
+
: N extends MLASTToken
|
|
40
|
+
? MLToken
|
|
41
|
+
: never;
|
|
42
|
+
export type NodeTypeOf<
|
|
43
|
+
NT extends NodeType,
|
|
44
|
+
T extends RuleConfigValue,
|
|
45
|
+
O extends PlainData = undefined,
|
|
46
|
+
> = NT extends ElementNodeType
|
|
47
|
+
? MLElement<T, O>
|
|
48
|
+
: NT extends CommentNodeType
|
|
49
|
+
? MLComment<T, O>
|
|
50
|
+
: NT extends TextNodeType
|
|
51
|
+
? MLText<T, O>
|
|
52
|
+
: NT extends DocumentNodeType
|
|
53
|
+
? MLDocument<T, O>
|
|
54
|
+
: NT extends DocumentTypeNodeType
|
|
55
|
+
? MLDocumentType<T, O>
|
|
56
|
+
: NT extends DocumentFragmentNodeType
|
|
57
|
+
? MLDocumentFragment<T, O>
|
|
58
|
+
: NT extends MarkuplintPreprocessorBlockType
|
|
59
|
+
? MLBlock<T, O>
|
|
60
|
+
: NT extends AttributeNodeType
|
|
61
|
+
? MLAttr<T, O>
|
|
62
|
+
: never;
|
|
63
|
+
export type ElementNodeType = 1;
|
|
64
|
+
export type AttributeNodeType = 2;
|
|
65
|
+
export type TextNodeType = 3;
|
|
66
|
+
export type CDATASectionNodeType = 4;
|
|
67
|
+
export type ProcessingInstructionNodeType = 7;
|
|
68
|
+
export type CommentNodeType = 8;
|
|
69
|
+
export type DocumentNodeType = 9;
|
|
70
|
+
export type DocumentTypeNodeType = 10;
|
|
71
|
+
export type DocumentFragmentNodeType = 11;
|
|
72
|
+
export type MarkuplintPreprocessorBlockType = 101;
|
|
73
|
+
export type NodeType =
|
|
74
|
+
| ElementNodeType
|
|
75
|
+
| AttributeNodeType
|
|
76
|
+
| TextNodeType
|
|
77
|
+
| CDATASectionNodeType
|
|
78
|
+
| ProcessingInstructionNodeType
|
|
79
|
+
| CommentNodeType
|
|
80
|
+
| DocumentNodeType
|
|
81
|
+
| DocumentTypeNodeType
|
|
82
|
+
| DocumentFragmentNodeType
|
|
83
|
+
| MarkuplintPreprocessorBlockType;
|
|
84
|
+
export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
85
|
+
| PretenderContextPretender<N, T, O>
|
|
86
|
+
| PretenderContextPretended<N, T, O>;
|
|
87
|
+
export type PretenderContextPretender<
|
|
88
|
+
N extends MLElement<T, O>,
|
|
89
|
+
T extends RuleConfigValue,
|
|
90
|
+
O extends PlainData = undefined,
|
|
91
|
+
> = {
|
|
92
|
+
readonly type: 'pretender';
|
|
93
|
+
readonly as: N;
|
|
94
|
+
readonly aria?: PretenderARIA;
|
|
95
|
+
};
|
|
96
|
+
export type PretenderContextPretended<
|
|
97
|
+
N extends MLElement<T, O>,
|
|
98
|
+
T extends RuleConfigValue,
|
|
99
|
+
O extends PlainData = undefined,
|
|
100
|
+
> = {
|
|
101
|
+
readonly type: 'origin';
|
|
102
|
+
readonly origin: N;
|
|
103
|
+
};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export default class UnexpectedCallError extends Error {
|
|
2
|
-
}
|
|
1
|
+
export default class UnexpectedCallError extends Error {}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
import type { MLToken as MLASTToken } from '@markuplint/ml-ast';
|
|
2
2
|
export declare class MLToken<A extends MLASTToken = MLASTToken> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
3
|
+
#private;
|
|
4
|
+
readonly uuid: string;
|
|
5
|
+
protected readonly _astToken: A;
|
|
6
|
+
constructor(astToken: A);
|
|
7
|
+
/**
|
|
8
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
9
|
+
*/
|
|
10
|
+
get endCol(): number;
|
|
11
|
+
/**
|
|
12
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
13
|
+
*/
|
|
14
|
+
get endLine(): number;
|
|
15
|
+
/**
|
|
16
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
17
|
+
*/
|
|
18
|
+
get endOffset(): number;
|
|
19
|
+
/**
|
|
20
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
21
|
+
*/
|
|
22
|
+
get originRaw(): string;
|
|
23
|
+
/**
|
|
24
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
25
|
+
*/
|
|
26
|
+
get raw(): string;
|
|
27
|
+
/**
|
|
28
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
29
|
+
*/
|
|
30
|
+
get startCol(): number;
|
|
31
|
+
/**
|
|
32
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
33
|
+
*/
|
|
34
|
+
get startLine(): number;
|
|
35
|
+
/**
|
|
36
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
37
|
+
*/
|
|
38
|
+
get startOffset(): number;
|
|
39
|
+
/**
|
|
40
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
41
|
+
*/
|
|
42
|
+
fix(raw: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
45
|
+
*/
|
|
46
|
+
toString(): string;
|
|
47
47
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { RuleSeed } from './types';
|
|
2
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
export declare function createRule<T extends RuleConfigValue, O =
|
|
2
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
+
export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
4
|
+
seed: Readonly<RuleSeed<T, O>>,
|
|
5
|
+
): Readonly<RuleSeed<T, O>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RuleSeed } from './types';
|
|
2
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
2
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
3
3
|
import { MLRule } from './ml-rule';
|
|
4
|
-
export declare function createRule<T extends RuleConfigValue, O =
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
5
|
+
seed: Readonly<RuleSeed<T, O>> & {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
},
|
|
8
|
+
): MLRule<T, O>;
|
|
@@ -1,52 +1,61 @@
|
|
|
1
|
-
import type { MLDocument } from '../ml-dom/node/document';
|
|
2
1
|
import type { CheckerReport } from './types';
|
|
2
|
+
import type { MLDocument } from '../ml-dom/node/document';
|
|
3
3
|
import type { LocaleSet, Translator } from '@markuplint/i18n';
|
|
4
|
-
import type { Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
-
export declare class MLRuleContext<T extends RuleConfigValue, O =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
4
|
+
import type { PlainData, Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
+
export declare class MLRuleContext<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
6
|
+
#private;
|
|
7
|
+
readonly document: MLDocument<T, O>;
|
|
8
|
+
readonly locale: string;
|
|
9
|
+
readonly translate: Translator;
|
|
10
|
+
constructor(document: MLDocument<T, O>, locale: LocaleSet);
|
|
11
|
+
get reports(): (
|
|
12
|
+
| {
|
|
13
|
+
message: string;
|
|
14
|
+
line: number;
|
|
15
|
+
col: number;
|
|
16
|
+
raw: string;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
message: string;
|
|
20
|
+
scope: import('@markuplint/ml-config').Scope<T, O>;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
message: string;
|
|
24
|
+
scope: import('@markuplint/ml-config').Scope<T, O>;
|
|
25
|
+
line: number;
|
|
26
|
+
col: number;
|
|
27
|
+
raw: string;
|
|
28
|
+
}
|
|
29
|
+
)[];
|
|
30
|
+
provide(): {
|
|
31
|
+
document: MLDocument<T, O>;
|
|
32
|
+
translate: Translator;
|
|
33
|
+
t: Translator;
|
|
34
|
+
reports: (
|
|
35
|
+
| {
|
|
36
|
+
message: string;
|
|
37
|
+
line: number;
|
|
38
|
+
col: number;
|
|
39
|
+
raw: string;
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
message: string;
|
|
43
|
+
scope: import('@markuplint/ml-config').Scope<T, O>;
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
message: string;
|
|
47
|
+
scope: import('@markuplint/ml-config').Scope<T, O>;
|
|
48
|
+
line: number;
|
|
49
|
+
col: number;
|
|
50
|
+
raw: string;
|
|
51
|
+
}
|
|
52
|
+
)[];
|
|
53
|
+
report: {
|
|
54
|
+
(report: Report<T, O>): undefined;
|
|
55
|
+
(report: CheckerReport<T, O>): boolean;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
report(report: Report<T, O>): undefined;
|
|
59
|
+
report(report: CheckerReport<T, O>): boolean;
|
|
60
|
+
private _push;
|
|
52
61
|
}
|
|
@@ -5,7 +5,9 @@ exports.MLRuleContext = void 0;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const i18n_1 = require("@markuplint/i18n");
|
|
7
7
|
class MLRuleContext {
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
|
+
document, locale) {
|
|
9
11
|
_MLRuleContext_reports.set(this, []);
|
|
10
12
|
this.document = document;
|
|
11
13
|
this.translate = (0, i18n_1.translator)(locale);
|
|
@@ -14,7 +16,7 @@ class MLRuleContext {
|
|
|
14
16
|
get reports() {
|
|
15
17
|
return tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").map(report => ({
|
|
16
18
|
...report,
|
|
17
|
-
message: finish(report.message),
|
|
19
|
+
message: finish(report.message, this.locale),
|
|
18
20
|
}));
|
|
19
21
|
}
|
|
20
22
|
provide() {
|
|
@@ -30,12 +32,17 @@ class MLRuleContext {
|
|
|
30
32
|
if (typeof report === 'function') {
|
|
31
33
|
const r = report(this.translate);
|
|
32
34
|
if (r) {
|
|
33
|
-
|
|
35
|
+
this._push(r);
|
|
34
36
|
return true;
|
|
35
37
|
}
|
|
36
38
|
return false;
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
this._push(report);
|
|
41
|
+
}
|
|
42
|
+
_push(report) {
|
|
43
|
+
if (!tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").find(r => is(r, report))) {
|
|
44
|
+
tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
exports.MLRuleContext = MLRuleContext;
|
|
@@ -48,3 +55,15 @@ function finish(message, locale = 'en') {
|
|
|
48
55
|
}
|
|
49
56
|
return message;
|
|
50
57
|
}
|
|
58
|
+
function is(r1, r2) {
|
|
59
|
+
if ('col' in r1 && 'col' in r2) {
|
|
60
|
+
return r1.col === r2.col && r1.line === r2.line && r1.message === r2.message && r1.raw === r2.raw;
|
|
61
|
+
}
|
|
62
|
+
if ('scope' in r1) {
|
|
63
|
+
if (!('scope' in r2)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return r1.scope === r2.scope && r1.message === r2.message;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
package/lib/ml-rule/ml-rule.d.ts
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
|
+
import type { RuleSeed } from './types';
|
|
1
2
|
import type { Ruleset } from '..';
|
|
2
3
|
import type { MLDocument } from '../ml-dom/node/document';
|
|
3
|
-
import type { RuleSeed } from './types';
|
|
4
4
|
import type { LocaleSet } from '@markuplint/i18n';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
import type {
|
|
6
|
+
GlobalRuleInfo,
|
|
7
|
+
PlainData,
|
|
8
|
+
Rule,
|
|
9
|
+
RuleConfigValue,
|
|
10
|
+
RuleInfo,
|
|
11
|
+
Severity,
|
|
12
|
+
Violation,
|
|
13
|
+
} from '@markuplint/ml-config';
|
|
14
|
+
export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
15
|
+
#private;
|
|
16
|
+
readonly defaultOptions: O;
|
|
17
|
+
readonly defaultSeverity: Severity;
|
|
18
|
+
readonly defaultValue: T;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
constructor(
|
|
21
|
+
o: Readonly<RuleSeed<T, O>> & {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
/**
|
|
26
|
+
* The following getter is unused internally,
|
|
27
|
+
* only for extending from 3rd party library
|
|
28
|
+
*/
|
|
29
|
+
protected get f(): RuleSeed<T, O>['fix'];
|
|
30
|
+
/**
|
|
31
|
+
* The following getter is unused internally,
|
|
32
|
+
* only for extending from 3rd party library
|
|
33
|
+
*/
|
|
34
|
+
protected get v(): RuleSeed<T, O>['verify'];
|
|
35
|
+
getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
|
|
36
|
+
optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
|
|
37
|
+
verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
|
|
38
|
+
private _optimize;
|
|
29
39
|
}
|
|
30
|
-
export
|
|
40
|
+
export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
|
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -3,16 +3,19 @@ var _MLRule_f, _MLRule_v;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.MLRule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
+
const ml_config_1 = require("@markuplint/ml-config");
|
|
7
|
+
const is_plain_object_1 = require("is-plain-object");
|
|
6
8
|
const ml_rule_context_1 = require("./ml-rule-context");
|
|
7
9
|
class MLRule {
|
|
8
10
|
constructor(o) {
|
|
9
|
-
var _a
|
|
11
|
+
var _a;
|
|
10
12
|
_MLRule_f.set(this, void 0);
|
|
11
13
|
_MLRule_v.set(this, void 0);
|
|
12
14
|
this.name = o.name;
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
this.
|
|
15
|
+
this.defaultSeverity = (_a = o.defaultSeverity) !== null && _a !== void 0 ? _a : 'error';
|
|
16
|
+
// TODO: https://github.com/markuplint/markuplint/issues/808
|
|
17
|
+
this.defaultValue = (o.defaultValue !== undefined ? o.defaultValue : true);
|
|
18
|
+
this.defaultOptions = o.defaultOptions;
|
|
16
19
|
tslib_1.__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
|
|
17
20
|
tslib_1.__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
|
|
18
21
|
}
|
|
@@ -39,48 +42,36 @@ class MLRule {
|
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
44
|
optimizeOption(configSettings) {
|
|
45
|
+
var _a;
|
|
42
46
|
if (configSettings === undefined || typeof configSettings === 'boolean') {
|
|
43
47
|
return {
|
|
44
48
|
disabled: !configSettings,
|
|
45
|
-
severity: this.
|
|
49
|
+
severity: this.defaultSeverity,
|
|
46
50
|
value: this.defaultValue,
|
|
47
|
-
|
|
51
|
+
options: this.defaultOptions,
|
|
48
52
|
reason: undefined,
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
|
-
if (
|
|
55
|
+
if (isRuleConfig(configSettings)) {
|
|
52
56
|
return {
|
|
53
57
|
disabled: false,
|
|
54
|
-
severity: configSettings.severity
|
|
58
|
+
severity: (_a = configSettings.severity) !== null && _a !== void 0 ? _a : this.defaultSeverity,
|
|
55
59
|
value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
|
|
56
|
-
|
|
57
|
-
? configSettings.option
|
|
58
|
-
? // prettier-ignore
|
|
59
|
-
// @ts-ignore for "as" casting
|
|
60
|
-
this.defaultOptions.concat(configSettings.option)
|
|
61
|
-
: this.defaultOptions
|
|
62
|
-
: this.defaultOptions !== null &&
|
|
63
|
-
typeof this.defaultOptions === 'object' &&
|
|
64
|
-
// for example `configSettings.option === true`
|
|
65
|
-
(configSettings.option == null || typeof configSettings.option === 'object')
|
|
66
|
-
? { ...this.defaultOptions, ...(configSettings.option || {}) }
|
|
67
|
-
: configSettings.option || this.defaultOptions,
|
|
60
|
+
options: mergeOptions(this.defaultOptions, configSettings.options),
|
|
68
61
|
reason: configSettings.reason,
|
|
69
62
|
};
|
|
70
63
|
}
|
|
71
64
|
return {
|
|
72
65
|
disabled: false,
|
|
73
|
-
severity: this.
|
|
74
|
-
// @ts-ignore TODO: Wait for fix to bug of type guards in TypeScript
|
|
66
|
+
severity: this.defaultSeverity,
|
|
75
67
|
value: configSettings == null ? this.defaultValue : configSettings,
|
|
76
|
-
|
|
68
|
+
options: this.defaultOptions,
|
|
77
69
|
reason: undefined,
|
|
78
70
|
};
|
|
79
71
|
}
|
|
80
|
-
async verify(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
72
|
+
async verify(
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
74
|
+
document, locale, fix) {
|
|
84
75
|
document.setRule(this);
|
|
85
76
|
const context = new ml_rule_context_1.MLRuleContext(document, locale);
|
|
86
77
|
const providableContext = context.provide();
|
|
@@ -89,6 +80,7 @@ class MLRule {
|
|
|
89
80
|
await tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
|
|
90
81
|
}
|
|
91
82
|
const violation = context.reports.map(report => {
|
|
83
|
+
var _a;
|
|
92
84
|
if ('scope' in report) {
|
|
93
85
|
let line = report.scope.startLine;
|
|
94
86
|
let col = report.scope.startCol;
|
|
@@ -105,10 +97,9 @@ class MLRule {
|
|
|
105
97
|
col,
|
|
106
98
|
raw,
|
|
107
99
|
ruleId: this.name,
|
|
100
|
+
reason: (_a = report.scope.rule.reason) !== null && _a !== void 0 ? _a : document.rule.reason,
|
|
108
101
|
};
|
|
109
|
-
|
|
110
|
-
violation.reason = report.scope.rule.reason || document.rule.reason;
|
|
111
|
-
}
|
|
102
|
+
(0, ml_config_1.deleteUndefProp)(violation);
|
|
112
103
|
return violation;
|
|
113
104
|
}
|
|
114
105
|
const violation = {
|
|
@@ -118,20 +109,34 @@ class MLRule {
|
|
|
118
109
|
col: report.col,
|
|
119
110
|
raw: report.raw,
|
|
120
111
|
ruleId: this.name,
|
|
112
|
+
reason: document.rule.reason,
|
|
121
113
|
};
|
|
122
|
-
|
|
123
|
-
violation.reason = document.rule.reason;
|
|
124
|
-
}
|
|
114
|
+
(0, ml_config_1.deleteUndefProp)(violation);
|
|
125
115
|
return violation;
|
|
126
116
|
});
|
|
127
117
|
document.setRule(null);
|
|
128
118
|
return violation;
|
|
129
119
|
}
|
|
130
120
|
_optimize(rules, ruleName) {
|
|
131
|
-
|
|
121
|
+
var _a;
|
|
122
|
+
const rule = ((_a = rules === null || rules === void 0 ? void 0 : rules[ruleName]) !== null && _a !== void 0 ? _a : false);
|
|
132
123
|
const info = this.optimizeOption(rule);
|
|
133
124
|
return info;
|
|
134
125
|
}
|
|
135
126
|
}
|
|
136
127
|
exports.MLRule = MLRule;
|
|
137
128
|
_MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
|
|
129
|
+
function isRuleConfig(data) {
|
|
130
|
+
return (0, is_plain_object_1.isPlainObject)(data);
|
|
131
|
+
}
|
|
132
|
+
function mergeOptions(a, b) {
|
|
133
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
return [...a, ...b];
|
|
136
|
+
}
|
|
137
|
+
if ((0, is_plain_object_1.isPlainObject)(a) && (0, is_plain_object_1.isPlainObject)(b)) {
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
return { ...a, ...b };
|
|
140
|
+
}
|
|
141
|
+
return b !== null && b !== void 0 ? b : a;
|
|
142
|
+
}
|