@markuplint/ml-core 3.0.0-dev.25 → 3.0.0-dev.300
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/lib/configs.browser.js +1 -5
- package/lib/configs.js +33 -31
- 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 -12
- package/lib/index.js +13 -29
- package/lib/ml-core.d.ts +7 -7
- package/lib/ml-core.js +60 -66
- package/lib/ml-dom/helper/accname.d.ts +1 -1
- package/lib/ml-dom/helper/accname.js +23 -19
- package/lib/ml-dom/helper/create-node.d.ts +4 -4
- package/lib/ml-dom/helper/create-node.js +13 -15
- package/lib/ml-dom/helper/debug.d.ts +1 -1
- package/lib/ml-dom/helper/debug.js +8 -8
- package/lib/ml-dom/helper/getIndent.d.ts +2 -2
- package/lib/ml-dom/helper/getIndent.js +30 -28
- package/lib/ml-dom/helper/walkers.d.ts +6 -6
- package/lib/ml-dom/helper/walkers.js +23 -22
- 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 +9 -9
- package/lib/ml-dom/manipulations/child-node-methods.js +31 -25
- package/lib/ml-dom/manipulations/get-children.d.ts +4 -4
- package/lib/ml-dom/manipulations/get-children.js +5 -7
- package/lib/ml-dom/node/attr.d.ts +7 -7
- package/lib/ml-dom/node/attr.js +33 -34
- package/lib/ml-dom/node/block.d.ts +6 -6
- package/lib/ml-dom/node/block.js +21 -15
- package/lib/ml-dom/node/character-data.d.ts +4 -4
- package/lib/ml-dom/node/character-data.js +20 -19
- package/lib/ml-dom/node/child-node.d.ts +9 -9
- package/lib/ml-dom/node/child-node.js +3 -5
- package/lib/ml-dom/node/comment.d.ts +4 -4
- package/lib/ml-dom/node/comment.js +2 -6
- package/lib/ml-dom/node/document-fragment.d.ts +4 -4
- package/lib/ml-dom/node/document-fragment.js +4 -9
- package/lib/ml-dom/node/document-type.d.ts +6 -6
- package/lib/ml-dom/node/document-type.js +21 -15
- package/lib/ml-dom/node/document.d.ts +32 -29
- package/lib/ml-dom/node/document.js +329 -246
- package/lib/ml-dom/node/dom-token-list.d.ts +3 -3
- package/lib/ml-dom/node/dom-token-list.js +29 -33
- package/lib/ml-dom/node/element.d.ts +65 -16
- package/lib/ml-dom/node/element.js +396 -306
- package/lib/ml-dom/node/named-node-map.d.ts +4 -4
- package/lib/ml-dom/node/named-node-map.js +18 -18
- package/lib/ml-dom/node/node-list.d.ts +6 -6
- package/lib/ml-dom/node/node-list.js +25 -13
- package/lib/ml-dom/node/node-store.d.ts +5 -5
- package/lib/ml-dom/node/node-store.js +25 -10
- package/lib/ml-dom/node/node.d.ts +12 -12
- package/lib/ml-dom/node/node.js +101 -76
- package/lib/ml-dom/node/parent-node.d.ts +6 -6
- package/lib/ml-dom/node/parent-node.js +31 -29
- package/lib/ml-dom/node/rule-mapper.d.ts +5 -5
- package/lib/ml-dom/node/rule-mapper.js +20 -17
- package/lib/ml-dom/node/text.d.ts +4 -4
- package/lib/ml-dom/node/text.js +6 -11
- package/lib/ml-dom/node/types.d.ts +30 -16
- package/lib/ml-dom/node/types.js +1 -2
- package/lib/ml-dom/node/unexpected-call-error.js +1 -4
- package/lib/ml-dom/token/token.js +19 -23
- package/lib/ml-rule/create-rule.d.ts +3 -3
- package/lib/ml-rule/create-rule.js +1 -5
- package/lib/ml-rule/create-test-rule.d.ts +5 -5
- 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 +4 -4
- package/lib/ml-rule/ml-rule-context.js +11 -13
- package/lib/ml-rule/ml-rule.d.ts +9 -9
- package/lib/ml-rule/ml-rule.js +48 -45
- package/lib/ml-rule/types.d.ts +12 -12
- 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 -2
- 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 +3 -3
- package/lib/ruleset/index.js +4 -8
- package/lib/test/index.d.ts +9 -9
- package/lib/test/index.js +14 -24
- package/lib/types.d.ts +11 -10
- package/lib/types.js +1 -2
- package/lib/utils/get-location-from-chars.d.ts +1 -1
- package/lib/utils/get-location-from-chars.js +1 -5
- 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 +25 -16
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _RuleMapper_nodeList, _RuleMapper_ruleMap;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const debug_1 = require("../../debug");
|
|
8
|
-
const ruleMapperLog = debug_1.log.extend('rule-mapper');
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { compareSpecificity } from '@markuplint/selector';
|
|
4
|
+
import { log as coreLog } from '../../debug.js';
|
|
5
|
+
const ruleMapperLog = coreLog.extend('rule-mapper');
|
|
9
6
|
const ruleMapperNodeLog = ruleMapperLog.extend('node');
|
|
10
7
|
const ruleMapperNodeRuleLog = ruleMapperNodeLog.extend('rule');
|
|
11
|
-
class RuleMapper {
|
|
12
|
-
constructor(
|
|
8
|
+
export class RuleMapper {
|
|
9
|
+
constructor(
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
11
|
+
document) {
|
|
13
12
|
_RuleMapper_nodeList.set(this, void 0);
|
|
14
13
|
_RuleMapper_ruleMap.set(this, new Map());
|
|
15
|
-
|
|
14
|
+
__classPrivateFieldSet(this, _RuleMapper_nodeList, Object.freeze([document, ...document.nodeList]), "f");
|
|
16
15
|
}
|
|
17
16
|
apply() {
|
|
18
17
|
ruleMapperLog('ruleTree:');
|
|
19
|
-
|
|
20
|
-
const rules =
|
|
18
|
+
__classPrivateFieldGet(this, _RuleMapper_nodeList, "f").forEach(node => {
|
|
19
|
+
const rules = __classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid);
|
|
21
20
|
if (!rules) {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
23
|
ruleMapperNodeLog('<%s>', node.nodeName);
|
|
25
24
|
Object.keys(rules).forEach(ruleName => {
|
|
26
25
|
const rule = rules[ruleName];
|
|
26
|
+
if (!rule) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
27
29
|
node.rules[ruleName] = rule.rule;
|
|
28
30
|
ruleMapperNodeRuleLog('[from: %s(%s)] %s: %o', rule.from, rule.specificity, ruleName, rule.rule);
|
|
29
31
|
});
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
set(
|
|
33
|
-
|
|
34
|
+
set(
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
36
|
+
node, ruleName, rule) {
|
|
37
|
+
const rules = __classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid) ?? {};
|
|
34
38
|
const currentRule = rules[ruleName];
|
|
35
39
|
if (currentRule) {
|
|
36
|
-
const order =
|
|
40
|
+
const order = compareSpecificity(currentRule.specificity, rule.specificity);
|
|
37
41
|
if (order === 1) {
|
|
38
42
|
ruleMapperLog("Don't set %o ([%s] vs [%s])", rule, currentRule.specificity, rule.specificity);
|
|
39
43
|
return;
|
|
@@ -41,9 +45,8 @@ class RuleMapper {
|
|
|
41
45
|
ruleMapperLog('Unset %o from %s', currentRule, node);
|
|
42
46
|
}
|
|
43
47
|
rules[ruleName] = rule;
|
|
44
|
-
|
|
48
|
+
__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").set(node.uuid, rules);
|
|
45
49
|
ruleMapperLog('Set to %s from %s (%o): %O', node.nodeName, rule.from, rule.specificity, rule.rule);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
exports.RuleMapper = RuleMapper;
|
|
49
52
|
_RuleMapper_nodeList = new WeakMap(), _RuleMapper_ruleMap = new WeakMap();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { TextNodeType } from './types';
|
|
1
|
+
import type { TextNodeType } from './types.js';
|
|
2
2
|
import type { MLASTText } from '@markuplint/ml-ast';
|
|
3
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
-
import { MLCharacterData } from './character-data';
|
|
5
|
-
export declare class MLText<T extends RuleConfigValue, O =
|
|
3
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
4
|
+
import { MLCharacterData } from './character-data.js';
|
|
5
|
+
export declare class MLText<T extends RuleConfigValue, O extends PlainData = undefined> extends MLCharacterData<T, O, MLASTText> implements Text {
|
|
6
6
|
/**
|
|
7
7
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
8
8
|
*
|
package/lib/ml-dom/node/text.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MLText = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const character_data_1 = require("./character-data");
|
|
6
|
-
const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
|
|
1
|
+
import { MLCharacterData } from './character-data.js';
|
|
2
|
+
import UnexpectedCallError from './unexpected-call-error.js';
|
|
7
3
|
/**
|
|
8
4
|
* Raw text elements
|
|
9
5
|
*
|
|
10
6
|
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
|
11
7
|
*/
|
|
12
8
|
const rawTextElements = ['script', 'style'];
|
|
13
|
-
class MLText extends
|
|
9
|
+
export class MLText extends MLCharacterData {
|
|
14
10
|
/**
|
|
15
11
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
16
12
|
*
|
|
@@ -18,7 +14,7 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
18
14
|
* @implements DOM API: `Text`
|
|
19
15
|
*/
|
|
20
16
|
get assignedSlot() {
|
|
21
|
-
throw new
|
|
17
|
+
throw new UnexpectedCallError('Not supported "assignedSlot" property');
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
20
|
* Returns a string appropriate for the type of node as `Text`
|
|
@@ -45,7 +41,7 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
45
41
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-splittext%E2%91%A0
|
|
46
42
|
*/
|
|
47
43
|
get wholeText() {
|
|
48
|
-
throw new
|
|
44
|
+
throw new UnexpectedCallError('Not supported "wholeText" property');
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
51
47
|
* Returns `true` if a parent element is `<script>` or `<style>`
|
|
@@ -70,7 +66,6 @@ class MLText extends character_data_1.MLCharacterData {
|
|
|
70
66
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-text-wholetext%E2%91%A0
|
|
71
67
|
*/
|
|
72
68
|
splitText(offset) {
|
|
73
|
-
throw new
|
|
69
|
+
throw new UnexpectedCallError('Not supported "splitText" method');
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
|
-
exports.MLText = MLText;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
1
|
+
import type { MLAttr } from './attr.js';
|
|
2
|
+
import type { MLBlock } from './block.js';
|
|
3
|
+
import type { MLComment } from './comment.js';
|
|
4
|
+
import type { MLDocumentFragment } from './document-fragment.js';
|
|
5
|
+
import type { MLDocumentType } from './document-type.js';
|
|
6
|
+
import type { MLDocument } from './document.js';
|
|
7
|
+
import type { MLElement } from './element.js';
|
|
8
|
+
import type { MLNode } from './node.js';
|
|
9
|
+
import type { MLText } from './text.js';
|
|
10
|
+
import type { MLToken } from '../token/token.js';
|
|
11
11
|
import type { MLASTAbstractNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken as MLASTToken } from '@markuplint/ml-ast/';
|
|
12
|
-
import type { PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
|
|
13
|
-
export type MappedNode<N, T extends RuleConfigValue, O =
|
|
14
|
-
export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O =
|
|
12
|
+
import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
|
|
13
|
+
export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAbstractNode ? MLNode<T, O, MLASTAbstractNode> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTToken ? MLToken : never;
|
|
14
|
+
export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O extends PlainData = undefined> = NT extends ElementNodeType ? MLElement<T, O> : NT extends CommentNodeType ? MLComment<T, O> : NT extends TextNodeType ? MLText<T, O> : NT extends DocumentNodeType ? MLDocument<T, O> : NT extends DocumentTypeNodeType ? MLDocumentType<T, O> : NT extends DocumentFragmentNodeType ? MLDocumentFragment<T, O> : NT extends MarkuplintPreprocessorBlockType ? MLBlock<T, O> : NT extends AttributeNodeType ? MLAttr<T, O> : never;
|
|
15
15
|
export type ElementNodeType = 1;
|
|
16
16
|
export type AttributeNodeType = 2;
|
|
17
17
|
export type TextNodeType = 3;
|
|
@@ -23,13 +23,27 @@ export type DocumentTypeNodeType = 10;
|
|
|
23
23
|
export type DocumentFragmentNodeType = 11;
|
|
24
24
|
export type MarkuplintPreprocessorBlockType = 101;
|
|
25
25
|
export type NodeType = ElementNodeType | AttributeNodeType | TextNodeType | CDATASectionNodeType | ProcessingInstructionNodeType | CommentNodeType | DocumentNodeType | DocumentTypeNodeType | DocumentFragmentNodeType | MarkuplintPreprocessorBlockType;
|
|
26
|
-
export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O =
|
|
27
|
-
export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O =
|
|
26
|
+
export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = PretenderContextPretender<N, T, O> | PretenderContextPretended<N, T, O>;
|
|
27
|
+
export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
28
28
|
readonly type: 'pretender';
|
|
29
29
|
readonly as: N;
|
|
30
30
|
readonly aria?: PretenderARIA;
|
|
31
31
|
};
|
|
32
|
-
export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O =
|
|
32
|
+
export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
33
33
|
readonly type: 'origin';
|
|
34
34
|
readonly origin: N;
|
|
35
35
|
};
|
|
36
|
+
export type AccessibilityProperties = {
|
|
37
|
+
exposedToTree: boolean;
|
|
38
|
+
role?: string;
|
|
39
|
+
roleDescription?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
nameRequired?: boolean;
|
|
42
|
+
nameProhibited?: boolean;
|
|
43
|
+
focusable?: boolean;
|
|
44
|
+
props?: Record<string, AccessibilityProperty>;
|
|
45
|
+
};
|
|
46
|
+
export type AccessibilityProperty = {
|
|
47
|
+
value: string | null;
|
|
48
|
+
required: boolean;
|
|
49
|
+
};
|
package/lib/ml-dom/node/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
class MLToken {
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
export class MLToken {
|
|
7
4
|
constructor(astToken) {
|
|
8
5
|
_MLToken_endCol.set(this, void 0);
|
|
9
6
|
_MLToken_endLine.set(this, void 0);
|
|
@@ -14,69 +11,69 @@ class MLToken {
|
|
|
14
11
|
_MLToken_startLine.set(this, void 0);
|
|
15
12
|
_MLToken_startOffset.set(this, void 0);
|
|
16
13
|
this._astToken = astToken;
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
__classPrivateFieldSet(this, _MLToken_raw, astToken.raw, "f");
|
|
15
|
+
__classPrivateFieldSet(this, _MLToken_fixed, astToken.raw, "f");
|
|
19
16
|
this.uuid = astToken.uuid;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
__classPrivateFieldSet(this, _MLToken_startLine, astToken.startLine, "f");
|
|
18
|
+
__classPrivateFieldSet(this, _MLToken_endLine, astToken.endLine, "f");
|
|
19
|
+
__classPrivateFieldSet(this, _MLToken_startCol, astToken.startCol, "f");
|
|
20
|
+
__classPrivateFieldSet(this, _MLToken_endCol, astToken.endCol, "f");
|
|
21
|
+
__classPrivateFieldSet(this, _MLToken_startOffset, astToken.startOffset, "f");
|
|
22
|
+
__classPrivateFieldSet(this, _MLToken_endOffset, astToken.endOffset, "f");
|
|
26
23
|
}
|
|
27
24
|
/**
|
|
28
25
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
29
26
|
*/
|
|
30
27
|
get endCol() {
|
|
31
|
-
return
|
|
28
|
+
return __classPrivateFieldGet(this, _MLToken_endCol, "f");
|
|
32
29
|
}
|
|
33
30
|
/**
|
|
34
31
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
35
32
|
*/
|
|
36
33
|
get endLine() {
|
|
37
|
-
return
|
|
34
|
+
return __classPrivateFieldGet(this, _MLToken_endLine, "f");
|
|
38
35
|
}
|
|
39
36
|
/**
|
|
40
37
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
41
38
|
*/
|
|
42
39
|
get endOffset() {
|
|
43
|
-
return
|
|
40
|
+
return __classPrivateFieldGet(this, _MLToken_endOffset, "f");
|
|
44
41
|
}
|
|
45
42
|
/**
|
|
46
43
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
47
44
|
*/
|
|
48
45
|
get originRaw() {
|
|
49
|
-
return
|
|
46
|
+
return __classPrivateFieldGet(this, _MLToken_raw, "f");
|
|
50
47
|
}
|
|
51
48
|
/**
|
|
52
49
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
53
50
|
*/
|
|
54
51
|
get raw() {
|
|
55
|
-
return
|
|
52
|
+
return __classPrivateFieldGet(this, _MLToken_fixed, "f");
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
55
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
59
56
|
*/
|
|
60
57
|
get startCol() {
|
|
61
|
-
return
|
|
58
|
+
return __classPrivateFieldGet(this, _MLToken_startCol, "f");
|
|
62
59
|
}
|
|
63
60
|
/**
|
|
64
61
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
65
62
|
*/
|
|
66
63
|
get startLine() {
|
|
67
|
-
return
|
|
64
|
+
return __classPrivateFieldGet(this, _MLToken_startLine, "f");
|
|
68
65
|
}
|
|
69
66
|
/**
|
|
70
67
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
71
68
|
*/
|
|
72
69
|
get startOffset() {
|
|
73
|
-
return
|
|
70
|
+
return __classPrivateFieldGet(this, _MLToken_startOffset, "f");
|
|
74
71
|
}
|
|
75
72
|
/**
|
|
76
73
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
77
74
|
*/
|
|
78
75
|
fix(raw) {
|
|
79
|
-
|
|
76
|
+
__classPrivateFieldSet(this, _MLToken_fixed, raw, "f");
|
|
80
77
|
}
|
|
81
78
|
/**
|
|
82
79
|
* @implements `@markuplint/ml-core` API: `MLDOMToken`
|
|
@@ -85,5 +82,4 @@ class MLToken {
|
|
|
85
82
|
return this.raw;
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
|
-
exports.MLToken = MLToken;
|
|
89
85
|
_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,3 +1,3 @@
|
|
|
1
|
-
import type { RuleSeed } from './types';
|
|
2
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
export declare function createRule<T extends RuleConfigValue, O =
|
|
1
|
+
import type { RuleSeed } from './types.js';
|
|
2
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
+
export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>>): Readonly<RuleSeed<T, O>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { RuleSeed } from './types';
|
|
2
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
3
|
-
import { MLRule } from './ml-rule';
|
|
4
|
-
export declare function createRule<T extends RuleConfigValue, O =
|
|
5
|
-
name: string;
|
|
1
|
+
import type { RuleSeed } from './types.js';
|
|
2
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
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
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,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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
|
-
import type { Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
-
export declare class MLRuleContext<T extends RuleConfigValue, O =
|
|
4
|
+
import type { PlainData, Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
+
export declare class MLRuleContext<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
6
6
|
#private;
|
|
7
7
|
readonly document: MLDocument<T, O>;
|
|
8
8
|
readonly locale: string;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _MLRuleContext_reports;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { __classPrivateFieldGet } from "tslib";
|
|
3
|
+
import { translator } from '@markuplint/i18n';
|
|
4
|
+
export class MLRuleContext {
|
|
5
|
+
constructor(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
7
|
+
document, locale) {
|
|
9
8
|
_MLRuleContext_reports.set(this, []);
|
|
10
9
|
this.document = document;
|
|
11
|
-
this.translate =
|
|
10
|
+
this.translate = translator(locale);
|
|
12
11
|
this.locale = locale.locale;
|
|
13
12
|
}
|
|
14
13
|
get reports() {
|
|
15
|
-
return
|
|
14
|
+
return __classPrivateFieldGet(this, _MLRuleContext_reports, "f").map(report => ({
|
|
16
15
|
...report,
|
|
17
|
-
message: finish(report.message),
|
|
16
|
+
message: finish(report.message, this.locale),
|
|
18
17
|
}));
|
|
19
18
|
}
|
|
20
19
|
provide() {
|
|
@@ -38,12 +37,11 @@ class MLRuleContext {
|
|
|
38
37
|
this._push(report);
|
|
39
38
|
}
|
|
40
39
|
_push(report) {
|
|
41
|
-
if (!
|
|
42
|
-
|
|
40
|
+
if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").find(r => is(r, report))) {
|
|
41
|
+
__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
exports.MLRuleContext = MLRuleContext;
|
|
47
45
|
_MLRuleContext_reports = new WeakMap();
|
|
48
46
|
function finish(message, locale = 'en') {
|
|
49
47
|
switch (locale) {
|
package/lib/ml-rule/ml-rule.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { MLDocument } from '../ml-dom/node/document';
|
|
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 { GlobalRuleInfo,
|
|
6
|
-
export declare class MLRule<T extends RuleConfigValue, O =
|
|
5
|
+
import type { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
|
|
6
|
+
export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
|
|
7
7
|
#private;
|
|
8
8
|
readonly defaultOptions: O;
|
|
9
9
|
readonly defaultSeverity: Severity;
|
|
10
10
|
readonly defaultValue: T;
|
|
11
11
|
readonly name: string;
|
|
12
|
-
constructor(o: RuleSeed<T, O
|
|
13
|
-
name: string;
|
|
12
|
+
constructor(o: Readonly<RuleSeed<T, O>> & {
|
|
13
|
+
readonly name: string;
|
|
14
14
|
});
|
|
15
15
|
/**
|
|
16
16
|
* The following getter is unused internally,
|
|
@@ -23,8 +23,8 @@ export declare class MLRule<T extends RuleConfigValue, O = null> {
|
|
|
23
23
|
*/
|
|
24
24
|
protected get v(): RuleSeed<T, O>['verify'];
|
|
25
25
|
getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
|
|
26
|
-
optimizeOption(configSettings:
|
|
26
|
+
optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
|
|
27
27
|
verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
|
|
28
28
|
private _optimize;
|
|
29
29
|
}
|
|
30
|
-
export type AnyMLRule = MLRule<RuleConfigValue,
|
|
30
|
+
export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
|
package/lib/ml-rule/ml-rule.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _MLRule_f, _MLRule_v;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { deleteUndefProp } from '@markuplint/ml-config';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import { isPlainObject } from 'is-plain-object';
|
|
6
|
+
import { MLRuleContext } from './ml-rule-context.js';
|
|
7
|
+
export class MLRule {
|
|
8
8
|
constructor(o) {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
_MLRule_f.set(this, void 0);
|
|
11
10
|
_MLRule_v.set(this, void 0);
|
|
12
11
|
this.name = o.name;
|
|
13
|
-
this.defaultSeverity = o.defaultSeverity
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
this.defaultSeverity = o.defaultSeverity ?? 'error';
|
|
13
|
+
// TODO: https://github.com/markuplint/markuplint/issues/808
|
|
14
|
+
this.defaultValue = (o.defaultValue !== undefined ? o.defaultValue : true);
|
|
15
|
+
this.defaultOptions = o.defaultOptions;
|
|
16
|
+
__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
|
|
17
|
+
__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* The following getter is unused internally,
|
|
21
21
|
* only for extending from 3rd party library
|
|
22
22
|
*/
|
|
23
23
|
get f() {
|
|
24
|
-
return
|
|
24
|
+
return __classPrivateFieldGet(this, _MLRule_f, "f");
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* The following getter is unused internally,
|
|
28
28
|
* only for extending from 3rd party library
|
|
29
29
|
*/
|
|
30
30
|
get v() {
|
|
31
|
-
return
|
|
31
|
+
return __classPrivateFieldGet(this, _MLRule_v, "f");
|
|
32
32
|
}
|
|
33
33
|
getRuleInfo(ruleSet, ruleName) {
|
|
34
34
|
const info = this._optimize(ruleSet.rules, ruleName);
|
|
@@ -48,23 +48,16 @@ class MLRule {
|
|
|
48
48
|
reason: undefined,
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
if (
|
|
51
|
+
if (isRuleConfig(configSettings)) {
|
|
52
52
|
return {
|
|
53
53
|
disabled: false,
|
|
54
|
-
severity: configSettings.severity
|
|
55
|
-
value: configSettings.value
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
: this.defaultOptions
|
|
62
|
-
: this.defaultOptions !== null &&
|
|
63
|
-
typeof this.defaultOptions === 'object' &&
|
|
64
|
-
// for example `configSettings.option === true`
|
|
65
|
-
(configSettings.options == null || typeof configSettings.options === 'object')
|
|
66
|
-
? { ...this.defaultOptions, ...(configSettings.options || {}) }
|
|
67
|
-
: configSettings.options || this.defaultOptions,
|
|
54
|
+
severity: configSettings.severity ?? this.defaultSeverity,
|
|
55
|
+
value: configSettings.value === undefined ||
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
configSettings.value === true
|
|
58
|
+
? this.defaultValue
|
|
59
|
+
: configSettings.value,
|
|
60
|
+
options: mergeOptions(this.defaultOptions, configSettings.options),
|
|
68
61
|
reason: configSettings.reason,
|
|
69
62
|
};
|
|
70
63
|
}
|
|
@@ -76,16 +69,15 @@ class MLRule {
|
|
|
76
69
|
reason: undefined,
|
|
77
70
|
};
|
|
78
71
|
}
|
|
79
|
-
async verify(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
72
|
+
async verify(
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
74
|
+
document, locale, fix) {
|
|
83
75
|
document.setRule(this);
|
|
84
|
-
const context = new
|
|
76
|
+
const context = new MLRuleContext(document, locale);
|
|
85
77
|
const providableContext = context.provide();
|
|
86
|
-
await
|
|
87
|
-
if (
|
|
88
|
-
await
|
|
78
|
+
await __classPrivateFieldGet(this, _MLRule_v, "f").call(this, providableContext);
|
|
79
|
+
if (__classPrivateFieldGet(this, _MLRule_f, "f") && fix) {
|
|
80
|
+
await __classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
|
|
89
81
|
}
|
|
90
82
|
const violation = context.reports.map(report => {
|
|
91
83
|
if ('scope' in report) {
|
|
@@ -104,10 +96,9 @@ class MLRule {
|
|
|
104
96
|
col,
|
|
105
97
|
raw,
|
|
106
98
|
ruleId: this.name,
|
|
99
|
+
reason: report.scope.rule.reason ?? document.rule.reason,
|
|
107
100
|
};
|
|
108
|
-
|
|
109
|
-
violation.reason = report.scope.rule.reason || document.rule.reason;
|
|
110
|
-
}
|
|
101
|
+
deleteUndefProp(violation);
|
|
111
102
|
return violation;
|
|
112
103
|
}
|
|
113
104
|
const violation = {
|
|
@@ -117,20 +108,32 @@ class MLRule {
|
|
|
117
108
|
col: report.col,
|
|
118
109
|
raw: report.raw,
|
|
119
110
|
ruleId: this.name,
|
|
111
|
+
reason: document.rule.reason,
|
|
120
112
|
};
|
|
121
|
-
|
|
122
|
-
violation.reason = document.rule.reason;
|
|
123
|
-
}
|
|
113
|
+
deleteUndefProp(violation);
|
|
124
114
|
return violation;
|
|
125
115
|
});
|
|
126
116
|
document.setRule(null);
|
|
127
117
|
return violation;
|
|
128
118
|
}
|
|
129
119
|
_optimize(rules, ruleName) {
|
|
130
|
-
const rule = (rules
|
|
120
|
+
const rule = (rules?.[ruleName] ?? false);
|
|
131
121
|
const info = this.optimizeOption(rule);
|
|
132
122
|
return info;
|
|
133
123
|
}
|
|
134
124
|
}
|
|
135
|
-
exports.MLRule = MLRule;
|
|
136
125
|
_MLRule_f = new WeakMap(), _MLRule_v = new WeakMap();
|
|
126
|
+
function isRuleConfig(data) {
|
|
127
|
+
return isPlainObject(data);
|
|
128
|
+
}
|
|
129
|
+
function mergeOptions(a, b) {
|
|
130
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
return [...a, ...b];
|
|
133
|
+
}
|
|
134
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
return { ...a, ...b };
|
|
137
|
+
}
|
|
138
|
+
return b ?? a;
|
|
139
|
+
}
|