@markuplint/ml-core 3.0.0-dev.24 → 3.0.0-dev.290

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.
Files changed (95) hide show
  1. package/lib/configs.browser.js +1 -5
  2. package/lib/configs.js +33 -31
  3. package/lib/convert-ruleset.d.ts +1 -1
  4. package/lib/convert-ruleset.js +3 -8
  5. package/lib/debug.js +9 -14
  6. package/lib/index.d.ts +13 -12
  7. package/lib/index.js +13 -29
  8. package/lib/ml-core.d.ts +7 -7
  9. package/lib/ml-core.js +60 -66
  10. package/lib/ml-dom/helper/accname.d.ts +1 -1
  11. package/lib/ml-dom/helper/accname.js +23 -19
  12. package/lib/ml-dom/helper/create-node.d.ts +4 -4
  13. package/lib/ml-dom/helper/create-node.js +13 -15
  14. package/lib/ml-dom/helper/debug.d.ts +1 -1
  15. package/lib/ml-dom/helper/debug.js +8 -8
  16. package/lib/ml-dom/helper/getIndent.d.ts +2 -2
  17. package/lib/ml-dom/helper/getIndent.js +30 -28
  18. package/lib/ml-dom/helper/walkers.d.ts +6 -6
  19. package/lib/ml-dom/helper/walkers.js +23 -22
  20. package/lib/ml-dom/index.d.ts +9 -9
  21. package/lib/ml-dom/index.js +1 -5
  22. package/lib/ml-dom/manipulations/child-node-methods.d.ts +9 -9
  23. package/lib/ml-dom/manipulations/child-node-methods.js +31 -25
  24. package/lib/ml-dom/manipulations/get-children.d.ts +4 -4
  25. package/lib/ml-dom/manipulations/get-children.js +5 -7
  26. package/lib/ml-dom/node/attr.d.ts +7 -7
  27. package/lib/ml-dom/node/attr.js +33 -34
  28. package/lib/ml-dom/node/block.d.ts +6 -6
  29. package/lib/ml-dom/node/block.js +21 -15
  30. package/lib/ml-dom/node/character-data.d.ts +4 -4
  31. package/lib/ml-dom/node/character-data.js +20 -19
  32. package/lib/ml-dom/node/child-node.d.ts +9 -9
  33. package/lib/ml-dom/node/child-node.js +3 -5
  34. package/lib/ml-dom/node/comment.d.ts +4 -4
  35. package/lib/ml-dom/node/comment.js +2 -6
  36. package/lib/ml-dom/node/document-fragment.d.ts +4 -4
  37. package/lib/ml-dom/node/document-fragment.js +4 -9
  38. package/lib/ml-dom/node/document-type.d.ts +6 -6
  39. package/lib/ml-dom/node/document-type.js +21 -15
  40. package/lib/ml-dom/node/document.d.ts +32 -29
  41. package/lib/ml-dom/node/document.js +329 -246
  42. package/lib/ml-dom/node/dom-token-list.d.ts +3 -3
  43. package/lib/ml-dom/node/dom-token-list.js +29 -33
  44. package/lib/ml-dom/node/element.d.ts +65 -16
  45. package/lib/ml-dom/node/element.js +396 -306
  46. package/lib/ml-dom/node/named-node-map.d.ts +4 -4
  47. package/lib/ml-dom/node/named-node-map.js +18 -18
  48. package/lib/ml-dom/node/node-list.d.ts +6 -6
  49. package/lib/ml-dom/node/node-list.js +25 -13
  50. package/lib/ml-dom/node/node-store.d.ts +5 -5
  51. package/lib/ml-dom/node/node-store.js +25 -10
  52. package/lib/ml-dom/node/node.d.ts +12 -12
  53. package/lib/ml-dom/node/node.js +101 -76
  54. package/lib/ml-dom/node/parent-node.d.ts +6 -6
  55. package/lib/ml-dom/node/parent-node.js +31 -29
  56. package/lib/ml-dom/node/rule-mapper.d.ts +5 -5
  57. package/lib/ml-dom/node/rule-mapper.js +20 -17
  58. package/lib/ml-dom/node/text.d.ts +4 -4
  59. package/lib/ml-dom/node/text.js +6 -11
  60. package/lib/ml-dom/node/types.d.ts +30 -16
  61. package/lib/ml-dom/node/types.js +1 -2
  62. package/lib/ml-dom/node/unexpected-call-error.js +1 -4
  63. package/lib/ml-dom/token/token.js +19 -23
  64. package/lib/ml-rule/create-rule.d.ts +3 -3
  65. package/lib/ml-rule/create-rule.js +1 -5
  66. package/lib/ml-rule/create-test-rule.d.ts +5 -5
  67. package/lib/ml-rule/create-test-rule.js +3 -7
  68. package/lib/ml-rule/index.d.ts +3 -3
  69. package/lib/ml-rule/index.js +3 -6
  70. package/lib/ml-rule/ml-rule-context.d.ts +4 -4
  71. package/lib/ml-rule/ml-rule-context.js +11 -13
  72. package/lib/ml-rule/ml-rule.d.ts +9 -9
  73. package/lib/ml-rule/ml-rule.js +48 -45
  74. package/lib/ml-rule/types.d.ts +12 -12
  75. package/lib/ml-rule/types.js +1 -2
  76. package/lib/plugin/index.d.ts +2 -2
  77. package/lib/plugin/index.js +2 -5
  78. package/lib/plugin/plugin.d.ts +2 -2
  79. package/lib/plugin/plugin.js +1 -5
  80. package/lib/plugin/types.d.ts +6 -6
  81. package/lib/plugin/types.js +1 -2
  82. package/lib/ruleset/index.d.ts +3 -3
  83. package/lib/ruleset/index.js +4 -8
  84. package/lib/test/index.d.ts +9 -9
  85. package/lib/test/index.js +14 -24
  86. package/lib/types.d.ts +11 -10
  87. package/lib/types.js +1 -2
  88. package/lib/utils/get-location-from-chars.d.ts +1 -1
  89. package/lib/utils/get-location-from-chars.js +1 -5
  90. package/lib/utils/index.d.ts +1 -1
  91. package/lib/utils/index.js +1 -5
  92. package/lib/utils/string-splice.js +1 -5
  93. package/package.json +25 -16
  94. package/tsconfig.test.json +0 -3
  95. package/tsconfig.tsbuildinfo +0 -1
@@ -1,39 +1,43 @@
1
- "use strict";
2
1
  var _RuleMapper_nodeList, _RuleMapper_ruleMap;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.RuleMapper = void 0;
5
- const tslib_1 = require("tslib");
6
- const selector_1 = require("@markuplint/selector");
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(document) {
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
- tslib_1.__classPrivateFieldSet(this, _RuleMapper_nodeList, Object.freeze([document, ...document.nodeList]), "f");
14
+ __classPrivateFieldSet(this, _RuleMapper_nodeList, Object.freeze([document, ...document.nodeList]), "f");
16
15
  }
17
16
  apply() {
18
17
  ruleMapperLog('ruleTree:');
19
- tslib_1.__classPrivateFieldGet(this, _RuleMapper_nodeList, "f").forEach(node => {
20
- const rules = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid);
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(node, ruleName, rule) {
33
- const rules = tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid) || {};
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 = (0, selector_1.compareSpecificity)(currentRule.specificity, rule.specificity);
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
- tslib_1.__classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").set(node.uuid, rules);
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 = null> extends MLCharacterData<T, O, MLASTText> implements Text {
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
  *
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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 character_data_1.MLCharacterData {
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 unexpected_call_error_1.default('Not supported "assignedSlot" property');
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 unexpected_call_error_1.default('Not supported "wholeText" property');
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 unexpected_call_error_1.default('Not supported "splitText" method');
69
+ throw new UnexpectedCallError('Not supported "splitText" method');
74
70
  }
75
71
  }
76
- exports.MLText = MLText;
@@ -1,17 +1,17 @@
1
- import type { MLToken } from '../token/token';
2
- import type { MLAttr } from './attr';
3
- import type { MLBlock } from './block';
4
- import type { MLComment } from './comment';
5
- import type { MLDocument } from './document';
6
- import type { MLDocumentFragment } from './document-fragment';
7
- import type { MLDocumentType } from './document-type';
8
- import type { MLElement } from './element';
9
- import type { MLNode } from './node';
10
- import type { MLText } from './text';
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 = null> = 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 = null> = 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;
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 = null> = PretenderContextPretender<N, T, O> | PretenderContextPretended<N, T, O>;
27
- export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O = null> = {
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 = null> = {
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
+ };
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,5 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class UnexpectedCallError extends Error {
1
+ export default class UnexpectedCallError extends Error {
4
2
  }
5
- exports.default = UnexpectedCallError;
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MLToken = void 0;
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
- tslib_1.__classPrivateFieldSet(this, _MLToken_raw, astToken.raw, "f");
18
- tslib_1.__classPrivateFieldSet(this, _MLToken_fixed, astToken.raw, "f");
14
+ __classPrivateFieldSet(this, _MLToken_raw, astToken.raw, "f");
15
+ __classPrivateFieldSet(this, _MLToken_fixed, astToken.raw, "f");
19
16
  this.uuid = astToken.uuid;
20
- tslib_1.__classPrivateFieldSet(this, _MLToken_startLine, astToken.startLine, "f");
21
- tslib_1.__classPrivateFieldSet(this, _MLToken_endLine, astToken.endLine, "f");
22
- tslib_1.__classPrivateFieldSet(this, _MLToken_startCol, astToken.startCol, "f");
23
- tslib_1.__classPrivateFieldSet(this, _MLToken_endCol, astToken.endCol, "f");
24
- tslib_1.__classPrivateFieldSet(this, _MLToken_startOffset, astToken.startOffset, "f");
25
- tslib_1.__classPrivateFieldSet(this, _MLToken_endOffset, astToken.endOffset, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_endCol, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_endLine, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_endOffset, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_raw, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_fixed, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_startCol, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_startLine, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLToken_startOffset, "f");
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
- tslib_1.__classPrivateFieldSet(this, _MLToken_fixed, raw, "f");
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 = null>(seed: RuleSeed<T, O>): RuleSeed<T, 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,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRule = void 0;
4
- function createRule(seed) {
1
+ export function createRule(seed) {
5
2
  return seed;
6
3
  }
7
- exports.createRule = createRule;
@@ -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 = null>(seed: RuleSeed<T, 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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRule = void 0;
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;
@@ -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';
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
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 { MLDocument } from '../ml-dom/node/document';
2
- import type { CheckerReport } from './types';
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 = null> {
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
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MLRuleContext = void 0;
5
- const tslib_1 = require("tslib");
6
- const i18n_1 = require("@markuplint/i18n");
7
- class MLRuleContext {
8
- constructor(document, locale) {
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 = (0, i18n_1.translator)(locale);
10
+ this.translate = translator(locale);
12
11
  this.locale = locale.locale;
13
12
  }
14
13
  get reports() {
15
- return tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").map(report => ({
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 (!tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").find(r => is(r, report))) {
42
- tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
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) {
@@ -1,16 +1,16 @@
1
- import type { Ruleset } from '..';
2
- import type { MLDocument } from '../ml-dom/node/document';
3
- import type { RuleSeed } from './types';
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, RuleConfig, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
6
- export declare class MLRule<T extends RuleConfigValue, O = null> {
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: T | RuleConfig<T, O> | undefined): RuleInfo<T, O>;
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, unknown>;
30
+ export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
@@ -1,34 +1,34 @@
1
- "use strict";
2
1
  var _MLRule_f, _MLRule_v;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MLRule = void 0;
5
- const tslib_1 = require("tslib");
6
- const ml_rule_context_1 = require("./ml-rule-context");
7
- class MLRule {
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 || 'error';
14
- this.defaultValue = (_a = o.defaultValue) !== null && _a !== void 0 ? _a : true;
15
- this.defaultOptions = (_b = o.defaultOptions) !== null && _b !== void 0 ? _b : null;
16
- tslib_1.__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
17
- tslib_1.__classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f");
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 tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f");
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 (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) {
51
+ if (isRuleConfig(configSettings)) {
52
52
  return {
53
53
  disabled: false,
54
- severity: configSettings.severity || this.defaultSeverity,
55
- value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
56
- options: Array.isArray(this.defaultOptions)
57
- ? configSettings.options
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.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(document, locale, fix) {
80
- if (!tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f")) {
81
- return [];
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 ml_rule_context_1.MLRuleContext(document, locale);
76
+ const context = new MLRuleContext(document, locale);
85
77
  const providableContext = context.provide();
86
- await tslib_1.__classPrivateFieldGet(this, _MLRule_v, "f").call(this, providableContext);
87
- if (tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f") && fix) {
88
- await tslib_1.__classPrivateFieldGet(this, _MLRule_f, "f").call(this, providableContext);
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
- if (report.scope.rule.reason || document.rule.reason) {
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
- if (document.rule.reason) {
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 && rules[ruleName]) || false;
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
+ }