@markuplint/ml-core 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/LICENSE +1 -1
- package/lib/configs.browser.js +11 -11
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +3 -8
- package/lib/debug.js +9 -14
- package/lib/index.d.ts +13 -23
- package/lib/index.js +12 -29
- package/lib/ml-core.d.ts +5 -5
- package/lib/ml-core.js +94 -76
- package/lib/ml-dom/helper/accname.d.ts +1 -1
- package/lib/ml-dom/helper/accname.js +12 -19
- package/lib/ml-dom/helper/create-node.d.ts +4 -8
- package/lib/ml-dom/helper/create-node.js +38 -17
- package/lib/ml-dom/helper/debug.d.ts +1 -1
- package/lib/ml-dom/helper/debug.js +13 -22
- package/lib/ml-dom/helper/get-indent.d.ts +18 -0
- package/lib/ml-dom/helper/get-indent.js +112 -0
- package/lib/ml-dom/helper/walkers.d.ts +5 -15
- package/lib/ml-dom/helper/walkers.js +3 -8
- package/lib/ml-dom/index.d.ts +9 -9
- package/lib/ml-dom/index.js +1 -5
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +7 -20
- package/lib/ml-dom/manipulations/child-node-methods.js +13 -25
- package/lib/ml-dom/manipulations/get-children.d.ts +3 -5
- package/lib/ml-dom/manipulations/get-children.js +3 -7
- package/lib/ml-dom/node/attr.d.ts +113 -98
- package/lib/ml-dom/node/attr.js +93 -50
- package/lib/ml-dom/node/block.d.ts +35 -39
- package/lib/ml-dom/node/block.js +8 -14
- package/lib/ml-dom/node/character-data.d.ts +55 -62
- package/lib/ml-dom/node/character-data.js +11 -16
- package/lib/ml-dom/node/child-node.d.ts +8 -15
- package/lib/ml-dom/node/child-node.js +1 -5
- package/lib/ml-dom/node/comment.d.ts +14 -17
- package/lib/ml-dom/node/comment.js +2 -6
- package/lib/ml-dom/node/document-fragment.d.ts +22 -25
- package/lib/ml-dom/node/document-fragment.js +4 -9
- package/lib/ml-dom/node/document-type.d.ts +35 -38
- package/lib/ml-dom/node/document-type.js +8 -14
- package/lib/ml-dom/node/document.d.ts +1598 -1614
- package/lib/ml-dom/node/document.js +330 -275
- package/lib/ml-dom/node/dom-token-list.d.ts +27 -27
- package/lib/ml-dom/node/dom-token-list.js +36 -32
- package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
- package/lib/ml-dom/node/element-close-tag.js +39 -0
- package/lib/ml-dom/node/element.d.ts +1957 -1951
- package/lib/ml-dom/node/element.js +364 -348
- package/lib/ml-dom/node/named-node-map.d.ts +40 -45
- package/lib/ml-dom/node/named-node-map.js +10 -18
- package/lib/ml-dom/node/node-list.d.ts +5 -11
- package/lib/ml-dom/node/node-list.js +8 -16
- package/lib/ml-dom/node/node-store.d.ts +6 -11
- package/lib/ml-dom/node/node-store.js +14 -13
- package/lib/ml-dom/node/node.d.ts +480 -500
- package/lib/ml-dom/node/node.js +83 -73
- package/lib/ml-dom/node/parent-node.d.ts +60 -69
- package/lib/ml-dom/node/parent-node.js +32 -29
- package/lib/ml-dom/node/rule-mapper.d.ts +9 -9
- package/lib/ml-dom/node/rule-mapper.js +26 -21
- package/lib/ml-dom/node/text.d.ts +48 -51
- package/lib/ml-dom/node/text.js +8 -13
- package/lib/ml-dom/node/types.d.ts +42 -90
- package/lib/ml-dom/node/types.js +1 -2
- package/lib/ml-dom/node/unexpected-call-error.d.ts +2 -1
- package/lib/ml-dom/node/unexpected-call-error.js +1 -4
- package/lib/ml-dom/token/token.d.ts +45 -45
- package/lib/ml-dom/token/token.js +32 -26
- package/lib/ml-rule/create-rule.d.ts +2 -4
- package/lib/ml-rule/create-rule.js +1 -5
- package/lib/ml-rule/create-test-rule.d.ts +5 -7
- package/lib/ml-rule/create-test-rule.js +3 -7
- package/lib/ml-rule/index.d.ts +3 -3
- package/lib/ml-rule/index.js +3 -6
- package/lib/ml-rule/ml-rule-context.d.ts +49 -57
- package/lib/ml-rule/ml-rule-context.js +11 -11
- package/lib/ml-rule/ml-rule.d.ts +26 -36
- package/lib/ml-rule/ml-rule.js +34 -31
- package/lib/ml-rule/types.d.ts +18 -33
- package/lib/ml-rule/types.js +1 -2
- package/lib/plugin/index.d.ts +2 -2
- package/lib/plugin/index.js +2 -5
- package/lib/plugin/plugin.d.ts +2 -4
- package/lib/plugin/plugin.js +1 -5
- package/lib/plugin/types.d.ts +6 -6
- package/lib/plugin/types.js +1 -2
- package/lib/ruleset/index.d.ts +5 -5
- package/lib/ruleset/index.js +4 -8
- package/lib/test/index.d.ts +11 -21
- package/lib/test/index.js +18 -24
- package/lib/types.d.ts +11 -11
- package/lib/types.js +1 -2
- package/lib/utils/get-location-from-chars.d.ts +4 -9
- package/lib/utils/get-location-from-chars.js +4 -8
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -5
- package/lib/utils/string-splice.js +1 -5
- package/package.json +19 -15
- package/lib/configs.d.ts +0 -2
- package/lib/configs.js +0 -34
- package/lib/ml-dom/helper/getIndent.d.ts +0 -18
- package/lib/ml-dom/helper/getIndent.js +0 -106
- package/test/ml-dom/helper/accname.spec.js +0 -85
- package/test/ml-dom/helper/create-node.spec.js +0 -18
- package/test/ml-dom/index.spec.js +0 -680
- package/test/ml-dom/ml-rule/create-rule.spec.js +0 -108
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { 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 fixed(): 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(fixed?: boolean): string;
|
|
47
47
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
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 _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
|
|
3
|
-
|
|
4
|
-
exports.MLToken = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
class MLToken {
|
|
13
|
+
export class MLToken {
|
|
7
14
|
constructor(astToken) {
|
|
8
15
|
_MLToken_endCol.set(this, void 0);
|
|
9
16
|
_MLToken_endLine.set(this, void 0);
|
|
@@ -14,76 +21,75 @@ class MLToken {
|
|
|
14
21
|
_MLToken_startLine.set(this, void 0);
|
|
15
22
|
_MLToken_startOffset.set(this, void 0);
|
|
16
23
|
this._astToken = astToken;
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
__classPrivateFieldSet(this, _MLToken_raw, astToken.raw, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _MLToken_fixed, astToken.raw, "f");
|
|
19
26
|
this.uuid = astToken.uuid;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
__classPrivateFieldSet(this, _MLToken_startLine, astToken.startLine, "f");
|
|
28
|
+
__classPrivateFieldSet(this, _MLToken_endLine, astToken.endLine, "f");
|
|
29
|
+
__classPrivateFieldSet(this, _MLToken_startCol, astToken.startCol, "f");
|
|
30
|
+
__classPrivateFieldSet(this, _MLToken_endCol, astToken.endCol, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _MLToken_startOffset, astToken.startOffset, "f");
|
|
32
|
+
__classPrivateFieldSet(this, _MLToken_endOffset, astToken.endOffset, "f");
|
|
26
33
|
}
|
|
27
34
|
/**
|
|
28
35
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
29
36
|
*/
|
|
30
37
|
get endCol() {
|
|
31
|
-
return
|
|
38
|
+
return __classPrivateFieldGet(this, _MLToken_endCol, "f");
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
35
42
|
*/
|
|
36
43
|
get endLine() {
|
|
37
|
-
return
|
|
44
|
+
return __classPrivateFieldGet(this, _MLToken_endLine, "f");
|
|
38
45
|
}
|
|
39
46
|
/**
|
|
40
47
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
41
48
|
*/
|
|
42
49
|
get endOffset() {
|
|
43
|
-
return
|
|
50
|
+
return __classPrivateFieldGet(this, _MLToken_endOffset, "f");
|
|
44
51
|
}
|
|
45
52
|
/**
|
|
46
53
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
47
54
|
*/
|
|
48
|
-
get
|
|
49
|
-
return
|
|
55
|
+
get fixed() {
|
|
56
|
+
return __classPrivateFieldGet(this, _MLToken_fixed, "f");
|
|
50
57
|
}
|
|
51
58
|
/**
|
|
52
59
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
53
60
|
*/
|
|
54
61
|
get raw() {
|
|
55
|
-
return
|
|
62
|
+
return __classPrivateFieldGet(this, _MLToken_raw, "f");
|
|
56
63
|
}
|
|
57
64
|
/**
|
|
58
65
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
59
66
|
*/
|
|
60
67
|
get startCol() {
|
|
61
|
-
return
|
|
68
|
+
return __classPrivateFieldGet(this, _MLToken_startCol, "f");
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
65
72
|
*/
|
|
66
73
|
get startLine() {
|
|
67
|
-
return
|
|
74
|
+
return __classPrivateFieldGet(this, _MLToken_startLine, "f");
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
77
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
71
78
|
*/
|
|
72
79
|
get startOffset() {
|
|
73
|
-
return
|
|
80
|
+
return __classPrivateFieldGet(this, _MLToken_startOffset, "f");
|
|
74
81
|
}
|
|
75
82
|
/**
|
|
76
83
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
77
84
|
*/
|
|
78
85
|
fix(raw) {
|
|
79
|
-
|
|
86
|
+
__classPrivateFieldSet(this, _MLToken_fixed, raw, "f");
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
89
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
83
90
|
*/
|
|
84
|
-
toString() {
|
|
85
|
-
return this
|
|
91
|
+
toString(fixed = false) {
|
|
92
|
+
return fixed ? __classPrivateFieldGet(this, _MLToken_fixed, "f") : __classPrivateFieldGet(this, _MLToken_raw, "f");
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
|
-
exports.MLToken = MLToken;
|
|
89
95
|
_MLToken_endCol = new WeakMap(), _MLToken_endLine = new WeakMap(), _MLToken_endOffset = new WeakMap(), _MLToken_fixed = new WeakMap(), _MLToken_raw = new WeakMap(), _MLToken_startCol = new WeakMap(), _MLToken_startLine = new WeakMap(), _MLToken_startOffset = new WeakMap();
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { RuleSeed } from './types';
|
|
1
|
+
import type { RuleSeed } from './types.js';
|
|
2
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>>;
|
|
3
|
+
export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>>): Readonly<RuleSeed<T, O>>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { RuleSeed } from './types';
|
|
1
|
+
import type { RuleSeed } from './types.js';
|
|
2
2
|
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
import { MLRule } from './ml-rule';
|
|
4
|
-
export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
): MLRule<T, O>;
|
|
3
|
+
import { MLRule } from './ml-rule.js';
|
|
4
|
+
export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>> & {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
}): MLRule<T, O>;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ml_rule_1 = require("./ml-rule");
|
|
5
|
-
function createRule(seed) {
|
|
6
|
-
return new ml_rule_1.MLRule(seed);
|
|
1
|
+
import { MLRule } from './ml-rule.js';
|
|
2
|
+
export function createRule(seed) {
|
|
3
|
+
return new MLRule(seed);
|
|
7
4
|
}
|
|
8
|
-
exports.createRule = createRule;
|
package/lib/ml-rule/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './create-rule';
|
|
2
|
-
export * from './ml-rule';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './create-rule.js';
|
|
2
|
+
export * from './ml-rule.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/ml-rule/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./create-rule"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./ml-rule"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './create-rule.js';
|
|
2
|
+
export * from './ml-rule.js';
|
|
3
|
+
export * from './types.js';
|
|
@@ -1,61 +1,53 @@
|
|
|
1
|
-
import type { CheckerReport } from './types';
|
|
2
|
-
import type { MLDocument } from '../ml-dom/node/document';
|
|
1
|
+
import type { CheckerReport } from './types.js';
|
|
2
|
+
import type { MLDocument } from '../ml-dom/node/document.js';
|
|
3
3
|
import type { LocaleSet, Translator } from '@markuplint/i18n';
|
|
4
4
|
import type { PlainData, Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
export declare class MLRuleContext<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
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
|
-
|
|
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;
|
|
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
|
+
message: string;
|
|
13
|
+
line: number;
|
|
14
|
+
col: number;
|
|
15
|
+
raw: string;
|
|
16
|
+
} | {
|
|
17
|
+
message: string;
|
|
18
|
+
scope: import("@markuplint/ml-config").Scope<T, O>;
|
|
19
|
+
} | {
|
|
20
|
+
message: string;
|
|
21
|
+
scope: import("@markuplint/ml-config").Scope<T, O>;
|
|
22
|
+
line: number;
|
|
23
|
+
col: number;
|
|
24
|
+
raw: string;
|
|
25
|
+
})[];
|
|
26
|
+
provide(): {
|
|
27
|
+
document: MLDocument<T, O>;
|
|
28
|
+
translate: Translator;
|
|
29
|
+
t: Translator;
|
|
30
|
+
reports: ({
|
|
31
|
+
message: string;
|
|
32
|
+
line: number;
|
|
33
|
+
col: number;
|
|
34
|
+
raw: string;
|
|
35
|
+
} | {
|
|
36
|
+
message: string;
|
|
37
|
+
scope: import("@markuplint/ml-config").Scope<T, O>;
|
|
38
|
+
} | {
|
|
39
|
+
message: string;
|
|
40
|
+
scope: import("@markuplint/ml-config").Scope<T, O>;
|
|
41
|
+
line: number;
|
|
42
|
+
col: number;
|
|
43
|
+
raw: string;
|
|
44
|
+
})[];
|
|
45
|
+
report: {
|
|
46
|
+
(report: Report<T, O>): undefined;
|
|
47
|
+
(report: CheckerReport<T, O>): boolean;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
report(report: Report<T, O>): undefined;
|
|
51
|
+
report(report: CheckerReport<T, O>): boolean;
|
|
52
|
+
private _push;
|
|
61
53
|
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
2
6
|
var _MLRuleContext_reports;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const i18n_1 = require("@markuplint/i18n");
|
|
7
|
-
class MLRuleContext {
|
|
7
|
+
import { translator } from '@markuplint/i18n';
|
|
8
|
+
export class MLRuleContext {
|
|
8
9
|
constructor(
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
11
|
document, locale) {
|
|
11
12
|
_MLRuleContext_reports.set(this, []);
|
|
12
13
|
this.document = document;
|
|
13
|
-
this.translate =
|
|
14
|
+
this.translate = translator(locale);
|
|
14
15
|
this.locale = locale.locale;
|
|
15
16
|
}
|
|
16
17
|
get reports() {
|
|
17
|
-
return
|
|
18
|
+
return __classPrivateFieldGet(this, _MLRuleContext_reports, "f").map(report => ({
|
|
18
19
|
...report,
|
|
19
20
|
message: finish(report.message, this.locale),
|
|
20
21
|
}));
|
|
@@ -40,12 +41,11 @@ class MLRuleContext {
|
|
|
40
41
|
this._push(report);
|
|
41
42
|
}
|
|
42
43
|
_push(report) {
|
|
43
|
-
if (!
|
|
44
|
-
|
|
44
|
+
if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").some(r => is(r, report))) {
|
|
45
|
+
__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
exports.MLRuleContext = MLRuleContext;
|
|
49
49
|
_MLRuleContext_reports = new WeakMap();
|
|
50
50
|
function finish(message, locale = 'en') {
|
|
51
51
|
switch (locale) {
|
package/lib/ml-rule/ml-rule.d.ts
CHANGED
|
@@ -1,40 +1,30 @@
|
|
|
1
|
-
import type { RuleSeed } from './types';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { RuleSeed } from './types.js';
|
|
2
|
+
import type { MLDocument } from '../ml-dom/node/document.js';
|
|
3
|
+
import type { Ruleset } from '../ruleset/index.js';
|
|
4
4
|
import type { LocaleSet } from '@markuplint/i18n';
|
|
5
|
-
import type {
|
|
6
|
-
GlobalRuleInfo,
|
|
7
|
-
PlainData,
|
|
8
|
-
Rule,
|
|
9
|
-
RuleConfigValue,
|
|
10
|
-
RuleInfo,
|
|
11
|
-
Severity,
|
|
12
|
-
Violation,
|
|
13
|
-
} from '@markuplint/ml-config';
|
|
5
|
+
import type { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
|
|
14
6
|
export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
|
|
38
|
-
private _optimize;
|
|
7
|
+
#private;
|
|
8
|
+
readonly defaultOptions: O;
|
|
9
|
+
readonly defaultSeverity: Severity;
|
|
10
|
+
readonly defaultValue: T;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
constructor(o: Readonly<RuleSeed<T, O>> & {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* The following getter is unused internally,
|
|
17
|
+
* only for extending from 3rd party library
|
|
18
|
+
*/
|
|
19
|
+
protected get f(): RuleSeed<T, O>['fix'];
|
|
20
|
+
/**
|
|
21
|
+
* The following getter is unused internally,
|
|
22
|
+
* only for extending from 3rd party library
|
|
23
|
+
*/
|
|
24
|
+
protected get v(): RuleSeed<T, O>['verify'];
|
|
25
|
+
getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
|
|
26
|
+
optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
|
|
27
|
+
verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
|
|
28
|
+
private _optimize;
|
|
39
29
|
}
|
|
40
30
|
export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
|
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
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 _MLRule_f, _MLRule_v;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ml_rule_context_1 = require("./ml-rule-context");
|
|
9
|
-
class MLRule {
|
|
13
|
+
import { deleteUndefProp } from '@markuplint/ml-config';
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import { isPlainObject } from 'is-plain-object';
|
|
16
|
+
import { MLRuleContext } from './ml-rule-context.js';
|
|
17
|
+
export class MLRule {
|
|
10
18
|
constructor(o) {
|
|
11
|
-
var _a;
|
|
12
19
|
_MLRule_f.set(this, void 0);
|
|
13
20
|
_MLRule_v.set(this, void 0);
|
|
14
21
|
this.name = o.name;
|
|
15
|
-
this.defaultSeverity =
|
|
22
|
+
this.defaultSeverity = o.defaultSeverity ?? 'error';
|
|
16
23
|
// TODO: https://github.com/markuplint/markuplint/issues/808
|
|
17
|
-
this.defaultValue = (o.defaultValue
|
|
24
|
+
this.defaultValue = (o.defaultValue === undefined ? true : o.defaultValue);
|
|
18
25
|
this.defaultOptions = o.defaultOptions;
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
|
|
27
|
+
__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
|
|
21
28
|
}
|
|
22
29
|
/**
|
|
23
30
|
* The following getter is unused internally,
|
|
24
31
|
* only for extending from 3rd party library
|
|
25
32
|
*/
|
|
26
33
|
get f() {
|
|
27
|
-
return
|
|
34
|
+
return __classPrivateFieldGet(this, _MLRule_f, "f");
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
37
|
* The following getter is unused internally,
|
|
31
38
|
* only for extending from 3rd party library
|
|
32
39
|
*/
|
|
33
40
|
get v() {
|
|
34
|
-
return
|
|
41
|
+
return __classPrivateFieldGet(this, _MLRule_v, "f");
|
|
35
42
|
}
|
|
36
43
|
getRuleInfo(ruleSet, ruleName) {
|
|
37
44
|
const info = this._optimize(ruleSet.rules, ruleName);
|
|
@@ -42,7 +49,6 @@ class MLRule {
|
|
|
42
49
|
};
|
|
43
50
|
}
|
|
44
51
|
optimizeOption(configSettings) {
|
|
45
|
-
var _a;
|
|
46
52
|
if (configSettings === undefined || typeof configSettings === 'boolean') {
|
|
47
53
|
return {
|
|
48
54
|
disabled: !configSettings,
|
|
@@ -55,7 +61,7 @@ class MLRule {
|
|
|
55
61
|
if (isRuleConfig(configSettings)) {
|
|
56
62
|
return {
|
|
57
63
|
disabled: false,
|
|
58
|
-
severity:
|
|
64
|
+
severity: configSettings.severity ?? this.defaultSeverity,
|
|
59
65
|
value: configSettings.value === undefined ||
|
|
60
66
|
// @ts-ignore
|
|
61
67
|
configSettings.value === true
|
|
@@ -77,14 +83,13 @@ class MLRule {
|
|
|
77
83
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
78
84
|
document, locale, fix) {
|
|
79
85
|
document.setRule(this);
|
|
80
|
-
const context = new
|
|
86
|
+
const context = new MLRuleContext(document, locale);
|
|
81
87
|
const providableContext = context.provide();
|
|
82
|
-
await
|
|
83
|
-
if (
|
|
84
|
-
await
|
|
88
|
+
await __classPrivateFieldGet(this, _MLRule_v, "f").call(this, providableContext);
|
|
89
|
+
if (__classPrivateFieldGet(this, _MLRule_f, "f") && fix) {
|
|
90
|
+
await __classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
|
|
85
91
|
}
|
|
86
92
|
const violation = context.reports.map(report => {
|
|
87
|
-
var _a;
|
|
88
93
|
if ('scope' in report) {
|
|
89
94
|
let line = report.scope.startLine;
|
|
90
95
|
let col = report.scope.startCol;
|
|
@@ -101,9 +106,9 @@ class MLRule {
|
|
|
101
106
|
col,
|
|
102
107
|
raw,
|
|
103
108
|
ruleId: this.name,
|
|
104
|
-
reason:
|
|
109
|
+
reason: report.scope.rule.reason ?? document.rule.reason,
|
|
105
110
|
};
|
|
106
|
-
|
|
111
|
+
deleteUndefProp(violation);
|
|
107
112
|
return violation;
|
|
108
113
|
}
|
|
109
114
|
const violation = {
|
|
@@ -115,32 +120,30 @@ class MLRule {
|
|
|
115
120
|
ruleId: this.name,
|
|
116
121
|
reason: document.rule.reason,
|
|
117
122
|
};
|
|
118
|
-
|
|
123
|
+
deleteUndefProp(violation);
|
|
119
124
|
return violation;
|
|
120
125
|
});
|
|
121
126
|
document.setRule(null);
|
|
122
127
|
return violation;
|
|
123
128
|
}
|
|
124
129
|
_optimize(rules, ruleName) {
|
|
125
|
-
|
|
126
|
-
const rule = ((_a = rules === null || rules === void 0 ? void 0 : rules[ruleName]) !== null && _a !== void 0 ? _a : false);
|
|
130
|
+
const rule = (rules?.[ruleName] ?? false);
|
|
127
131
|
const info = this.optimizeOption(rule);
|
|
128
132
|
return info;
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
|
-
exports.MLRule = MLRule;
|
|
132
135
|
_MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
|
|
133
136
|
function isRuleConfig(data) {
|
|
134
|
-
return
|
|
137
|
+
return isPlainObject(data);
|
|
135
138
|
}
|
|
136
139
|
function mergeOptions(a, b) {
|
|
137
140
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
138
141
|
// @ts-ignore
|
|
139
142
|
return [...a, ...b];
|
|
140
143
|
}
|
|
141
|
-
if (
|
|
144
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
142
145
|
// @ts-ignore
|
|
143
146
|
return { ...a, ...b };
|
|
144
147
|
}
|
|
145
|
-
return b
|
|
148
|
+
return b ?? a;
|
|
146
149
|
}
|