@markuplint/ml-core 3.0.0-alpha.66 → 3.0.0-dev.24

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 (94) hide show
  1. package/README.md +12 -3
  2. package/lib/configs.browser.d.ts +2 -0
  3. package/lib/configs.browser.js +12 -0
  4. package/lib/configs.js +5 -1
  5. package/lib/ml-core.d.ts +3 -3
  6. package/lib/ml-core.js +13 -7
  7. package/lib/ml-dom/helper/accname.d.ts +2 -1
  8. package/lib/ml-dom/helper/accname.js +51 -2
  9. package/lib/ml-dom/helper/create-node.d.ts +2 -2
  10. package/lib/ml-dom/helper/create-node.js +1 -1
  11. package/lib/ml-dom/helper/debug.js +1 -1
  12. package/lib/ml-dom/helper/getIndent.d.ts +1 -1
  13. package/lib/ml-dom/helper/walkers.d.ts +2 -2
  14. package/lib/ml-dom/index.d.ts +1 -0
  15. package/lib/ml-dom/node/attr.d.ts +5 -5
  16. package/lib/ml-dom/node/attr.js +18 -12
  17. package/lib/ml-dom/node/block.d.ts +1 -1
  18. package/lib/ml-dom/node/character-data.d.ts +2 -2
  19. package/lib/ml-dom/node/child-node.d.ts +1 -1
  20. package/lib/ml-dom/node/document-fragment.d.ts +2 -2
  21. package/lib/ml-dom/node/document-type.d.ts +1 -1
  22. package/lib/ml-dom/node/document.d.ts +66 -21
  23. package/lib/ml-dom/node/document.js +72 -17
  24. package/lib/ml-dom/node/dom-token-list.d.ts +3 -3
  25. package/lib/ml-dom/node/dom-token-list.js +6 -6
  26. package/lib/ml-dom/node/element.d.ts +105 -30
  27. package/lib/ml-dom/node/element.js +279 -58
  28. package/lib/ml-dom/node/node-list.d.ts +1 -1
  29. package/lib/ml-dom/node/node-store.d.ts +3 -3
  30. package/lib/ml-dom/node/node.d.ts +21 -14
  31. package/lib/ml-dom/node/node.js +38 -29
  32. package/lib/ml-dom/node/parent-node.d.ts +2 -2
  33. package/lib/ml-dom/node/rule-mapper.d.ts +2 -2
  34. package/lib/ml-dom/node/types.d.ts +25 -15
  35. package/lib/ml-dom/token/token.d.ts +1 -1
  36. package/lib/ml-rule/ml-rule-context.d.ts +2 -1
  37. package/lib/ml-rule/ml-rule-context.js +19 -2
  38. package/lib/ml-rule/ml-rule.d.ts +5 -5
  39. package/lib/ml-rule/ml-rule.js +11 -12
  40. package/lib/ml-rule/types.d.ts +7 -7
  41. package/lib/plugin/types.d.ts +3 -3
  42. package/lib/test/index.d.ts +3 -2
  43. package/lib/test/index.js +5 -3
  44. package/lib/types.d.ts +5 -4
  45. package/package.json +14 -12
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/lib/ml-dom/document.d.ts +0 -94
  48. package/lib/ml-dom/document.js +0 -273
  49. package/lib/ml-dom/helper/index.d.ts +0 -4
  50. package/lib/ml-dom/helper/index.js +0 -12
  51. package/lib/ml-dom/helper/mapped-nodes.d.ts +0 -52
  52. package/lib/ml-dom/helper/mapped-nodes.js +0 -2
  53. package/lib/ml-dom/helper/match-selector.d.ts +0 -20
  54. package/lib/ml-dom/helper/match-selector.js +0 -233
  55. package/lib/ml-dom/helper/node-store.d.ts +0 -12
  56. package/lib/ml-dom/helper/node-store.js +0 -28
  57. package/lib/ml-dom/helper/selector.d.ts +0 -11
  58. package/lib/ml-dom/helper/selector.js +0 -549
  59. package/lib/ml-dom/rule-mapper.d.ts +0 -16
  60. package/lib/ml-dom/rule-mapper.js +0 -57
  61. package/lib/ml-dom/tokens/abstract-element.d.ts +0 -54
  62. package/lib/ml-dom/tokens/abstract-element.js +0 -249
  63. package/lib/ml-dom/tokens/attribute.d.ts +0 -42
  64. package/lib/ml-dom/tokens/attribute.js +0 -85
  65. package/lib/ml-dom/tokens/comment.d.ts +0 -12
  66. package/lib/ml-dom/tokens/comment.js +0 -15
  67. package/lib/ml-dom/tokens/doctype.d.ts +0 -18
  68. package/lib/ml-dom/tokens/doctype.js +0 -32
  69. package/lib/ml-dom/tokens/element-close-tag.d.ts +0 -27
  70. package/lib/ml-dom/tokens/element-close-tag.js +0 -45
  71. package/lib/ml-dom/tokens/element.d.ts +0 -26
  72. package/lib/ml-dom/tokens/element.js +0 -66
  73. package/lib/ml-dom/tokens/index.d.ts +0 -10
  74. package/lib/ml-dom/tokens/index.js +0 -26
  75. package/lib/ml-dom/tokens/node.d.ts +0 -46
  76. package/lib/ml-dom/tokens/node.js +0 -126
  77. package/lib/ml-dom/tokens/omitted-element.d.ts +0 -13
  78. package/lib/ml-dom/tokens/omitted-element.js +0 -12
  79. package/lib/ml-dom/tokens/preprocessor-specific-attribute.d.ts +0 -24
  80. package/lib/ml-dom/tokens/preprocessor-specific-attribute.js +0 -37
  81. package/lib/ml-dom/tokens/preprocessor-specific-block.d.ts +0 -14
  82. package/lib/ml-dom/tokens/preprocessor-specific-block.js +0 -16
  83. package/lib/ml-dom/tokens/text.d.ts +0 -19
  84. package/lib/ml-dom/tokens/text.js +0 -26
  85. package/lib/ml-dom/tokens/token.d.ts +0 -16
  86. package/lib/ml-dom/tokens/token.js +0 -55
  87. package/lib/ml-dom/types.d.ts +0 -49
  88. package/lib/ml-dom/types.js +0 -2
  89. package/lib/selector/is-pure-html-element.d.ts +0 -1
  90. package/lib/selector/is-pure-html-element.js +0 -7
  91. package/lib/selector/match-selector.d.ts +0 -14
  92. package/lib/selector/match-selector.js +0 -230
  93. package/lib/selector/selector.d.ts +0 -9
  94. package/lib/selector/selector.js +0 -561
@@ -11,21 +11,6 @@ const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-ca
11
11
  class MLNode extends token_1.MLToken {
12
12
  constructor(astNode, document) {
13
13
  super(astNode);
14
- /**
15
- * Cached `childNodes` property
16
- */
17
- _MLNode_childNodes.set(this, void 0);
18
- /**
19
- * Owner `Document`
20
- *
21
- * @implements DOM API: `Node`
22
- * @see https://dom.spec.whatwg.org/#ref-for-dom-node-ownerdocument
23
- */
24
- _MLNode_ownerDocument.set(this, void 0);
25
- /**
26
- * Cached `prevToken` property
27
- */
28
- _MLNode_prevToken.set(this, void 0);
29
14
  /**
30
15
  * @implements DOM API: `Node`
31
16
  * @see https://dom.spec.whatwg.org/#interface-node
@@ -118,12 +103,30 @@ class MLNode extends token_1.MLToken {
118
103
  * @see https://dom.spec.whatwg.org/#interface-node
119
104
  */
120
105
  this.PROCESSING_INSTRUCTION_NODE = 7;
121
- this.rules = {};
122
106
  /**
123
107
  * @implements DOM API: `Node`
124
108
  * @see https://dom.spec.whatwg.org/#interface-node
125
109
  */
126
110
  this.TEXT_NODE = 3;
111
+ /**
112
+ * Cached `childNodes` property
113
+ */
114
+ _MLNode_childNodes.set(this, void 0);
115
+ /**
116
+ * Owner `Document`
117
+ *
118
+ * @implements DOM API: `Node`
119
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-node-ownerdocument
120
+ */
121
+ _MLNode_ownerDocument.set(this, void 0);
122
+ /**
123
+ * Cached `prevToken` property
124
+ */
125
+ _MLNode_prevToken.set(this, void 0);
126
+ /**
127
+ *
128
+ */
129
+ this.rules = {};
127
130
  this._astToken = astNode;
128
131
  tslib_1.__classPrivateFieldSet(this, _MLNode_ownerDocument, document, "f");
129
132
  node_store_1.nodeStore.setNode(astNode, this);
@@ -333,7 +336,7 @@ class MLNode extends token_1.MLToken {
333
336
  * @see https://dom.spec.whatwg.org/#ref-for-dom-node-parentnode%E2%91%A0
334
337
  */
335
338
  get parentNode() {
336
- const parentNode = this.syntaxicalParentNode;
339
+ const parentNode = this.syntacticalParentNode;
337
340
  if (!parentNode) {
338
341
  return null;
339
342
  }
@@ -351,16 +354,6 @@ class MLNode extends token_1.MLToken {
351
354
  }
352
355
  return parentNode;
353
356
  }
354
- /**
355
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
356
- *
357
- * @unsupported
358
- * @implements DOM API: `Node`
359
- * @see https://dom.spec.whatwg.org/#ref-for-dom-node-previoussibling%E2%91%A0
360
- */
361
- get previousSibling() {
362
- throw new unexpected_call_error_1.default('Not supported "previousSibling" property');
363
- }
364
357
  /**
365
358
  * @implements `@markuplint/ml-core` API: `MLNode`
366
359
  */
@@ -398,6 +391,16 @@ class MLNode extends token_1.MLToken {
398
391
  tslib_1.__classPrivateFieldSet(this, _MLNode_prevToken, this.ownerMLDocument.nodeList[index - 1] || null, "f");
399
392
  return tslib_1.__classPrivateFieldGet(this, _MLNode_prevToken, "f") || null;
400
393
  }
394
+ /**
395
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
396
+ *
397
+ * @unsupported
398
+ * @implements DOM API: `Node`
399
+ * @see https://dom.spec.whatwg.org/#ref-for-dom-node-previoussibling%E2%91%A0
400
+ */
401
+ get previousSibling() {
402
+ throw new unexpected_call_error_1.default('Not supported "previousSibling" property');
403
+ }
401
404
  /**
402
405
  * @implements `@markuplint/ml-core` API: `MLNode`
403
406
  */
@@ -410,7 +413,7 @@ class MLNode extends token_1.MLToken {
410
413
  return this.ownerMLDocument.currentRule.optimizeOption(rule);
411
414
  }
412
415
  /**
413
- * Returns a syntaxical parent node
416
+ * Returns a syntactical parent node
414
417
  *
415
418
  * ## HTML:
416
419
  *
@@ -447,7 +450,7 @@ class MLNode extends token_1.MLToken {
447
450
  *
448
451
  * @implements `@markuplint/ml-core` API: `MLNode`
449
452
  */
450
- get syntaxicalParentNode() {
453
+ get syntacticalParentNode() {
451
454
  if (!this._astToken.parentNode) {
452
455
  return this.ownerMLDocument;
453
456
  }
@@ -661,6 +664,12 @@ class MLNode extends token_1.MLToken {
661
664
  replaceChild(node, child) {
662
665
  throw new unexpected_call_error_1.default('Not supported "removeChild" method');
663
666
  }
667
+ /**
668
+ * @implements `@markuplint/ml-core` API: `MLNode`
669
+ */
670
+ resetChildren(childNodes) {
671
+ tslib_1.__classPrivateFieldSet(this, _MLNode_childNodes, childNodes !== null && childNodes !== void 0 ? childNodes : tslib_1.__classPrivateFieldGet(this, _MLNode_childNodes, "f"), "f");
672
+ }
664
673
  }
665
674
  exports.MLNode = MLNode;
666
675
  _MLNode_childNodes = new WeakMap(), _MLNode_ownerDocument = new WeakMap(), _MLNode_prevToken = new WeakMap();
@@ -1,12 +1,12 @@
1
1
  import type { MLElement } from './element';
2
- import type { MLASTAbstructNode } from '@markuplint/ml-ast';
2
+ import type { MLASTAbstractNode } from '@markuplint/ml-ast';
3
3
  import type { RuleConfigValue } from '@markuplint/ml-config';
4
4
  import { MLNode } from './node';
5
5
  /**
6
6
  *
7
7
  * @see https://dom.spec.whatwg.org/#interface-parentnode
8
8
  */
9
- export declare abstract class MLParentNode<T extends RuleConfigValue, O = null, A extends MLASTAbstructNode = MLASTAbstructNode> extends MLNode<T, O, A> implements ParentNode {
9
+ export declare abstract class MLParentNode<T extends RuleConfigValue, O = null, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLNode<T, O, A> implements ParentNode {
10
10
  #private;
11
11
  /**
12
12
  * @implements DOM API: `Element`, `Document`, `DocumentFragment`
@@ -2,8 +2,8 @@ import type { MLDocument } from './document';
2
2
  import type { MLNode } from './node';
3
3
  import type { AnyRule } from '@markuplint/ml-config';
4
4
  import type { Specificity } from '@markuplint/selector';
5
- declare type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
6
- declare type MappingLayer = {
5
+ type RuleType = 'rules' | 'nodeRules' | 'childNodeRules';
6
+ type MappingLayer = {
7
7
  from: RuleType;
8
8
  specificity: Specificity;
9
9
  rule: AnyRule;
@@ -8,18 +8,28 @@ import type { MLDocumentType } from './document-type';
8
8
  import type { MLElement } from './element';
9
9
  import type { MLNode } from './node';
10
10
  import type { MLText } from './text';
11
- import type { MLASTAbstructNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken as MLASTToken } from '@markuplint/ml-ast/';
12
- import type { RuleConfigValue } from '@markuplint/ml-config';
13
- export declare 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 MLASTAbstructNode ? MLNode<T, O, MLASTAbstructNode> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTToken ? MLToken : never;
14
- export declare 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;
15
- export declare type ElementNodeType = 1;
16
- export declare type AttributeNodeType = 2;
17
- export declare type TextNodeType = 3;
18
- export declare type CDATASectionNodeType = 4;
19
- export declare type ProcessingInstructionNodeType = 7;
20
- export declare type CommentNodeType = 8;
21
- export declare type DocumentNodeType = 9;
22
- export declare type DocumentTypeNodeType = 10;
23
- export declare type DocumentFragmentNodeType = 11;
24
- export declare type MarkuplintPreprocessorBlockType = 101;
25
- export declare type NodeType = ElementNodeType | AttributeNodeType | TextNodeType | CDATASectionNodeType | ProcessingInstructionNodeType | CommentNodeType | DocumentNodeType | DocumentTypeNodeType | DocumentFragmentNodeType | MarkuplintPreprocessorBlockType;
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;
15
+ export type ElementNodeType = 1;
16
+ export type AttributeNodeType = 2;
17
+ export type TextNodeType = 3;
18
+ export type CDATASectionNodeType = 4;
19
+ export type ProcessingInstructionNodeType = 7;
20
+ export type CommentNodeType = 8;
21
+ export type DocumentNodeType = 9;
22
+ export type DocumentTypeNodeType = 10;
23
+ export type DocumentFragmentNodeType = 11;
24
+ export type MarkuplintPreprocessorBlockType = 101;
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> = {
28
+ readonly type: 'pretender';
29
+ readonly as: N;
30
+ readonly aria?: PretenderARIA;
31
+ };
32
+ export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O = null> = {
33
+ readonly type: 'origin';
34
+ readonly origin: N;
35
+ };
@@ -3,6 +3,7 @@ export declare class MLToken<A extends MLASTToken = MLASTToken> {
3
3
  #private;
4
4
  readonly uuid: string;
5
5
  protected readonly _astToken: A;
6
+ constructor(astToken: A);
6
7
  /**
7
8
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
8
9
  */
@@ -35,7 +36,6 @@ export declare class MLToken<A extends MLASTToken = MLASTToken> {
35
36
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
36
37
  */
37
38
  get startOffset(): number;
38
- constructor(astToken: A);
39
39
  /**
40
40
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
41
41
  */
@@ -7,6 +7,7 @@ export declare class MLRuleContext<T extends RuleConfigValue, O = null> {
7
7
  readonly document: MLDocument<T, O>;
8
8
  readonly locale: string;
9
9
  readonly translate: Translator;
10
+ constructor(document: MLDocument<T, O>, locale: LocaleSet);
10
11
  get reports(): ({
11
12
  message: string;
12
13
  line: number;
@@ -22,7 +23,6 @@ export declare class MLRuleContext<T extends RuleConfigValue, O = null> {
22
23
  col: number;
23
24
  raw: string;
24
25
  })[];
25
- constructor(document: MLDocument<T, O>, locale: LocaleSet);
26
26
  provide(): {
27
27
  document: MLDocument<T, O>;
28
28
  translate: Translator;
@@ -49,4 +49,5 @@ export declare class MLRuleContext<T extends RuleConfigValue, O = null> {
49
49
  };
50
50
  report(report: Report<T, O>): undefined;
51
51
  report(report: CheckerReport<T, O>): boolean;
52
+ private _push;
52
53
  }
@@ -30,12 +30,17 @@ class MLRuleContext {
30
30
  if (typeof report === 'function') {
31
31
  const r = report(this.translate);
32
32
  if (r) {
33
- tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(r);
33
+ this._push(r);
34
34
  return true;
35
35
  }
36
36
  return false;
37
37
  }
38
- tslib_1.__classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
38
+ this._push(report);
39
+ }
40
+ _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);
43
+ }
39
44
  }
40
45
  }
41
46
  exports.MLRuleContext = MLRuleContext;
@@ -48,3 +53,15 @@ function finish(message, locale = 'en') {
48
53
  }
49
54
  return message;
50
55
  }
56
+ function is(r1, r2) {
57
+ if ('col' in r1 && 'col' in r2) {
58
+ return r1.col === r2.col && r1.line === r2.line && r1.message === r2.message && r1.raw === r2.raw;
59
+ }
60
+ if ('scope' in r1) {
61
+ if (!('scope' in r2)) {
62
+ return false;
63
+ }
64
+ return r1.scope === r2.scope && r1.message === r2.message;
65
+ }
66
+ return false;
67
+ }
@@ -6,9 +6,12 @@ import type { GlobalRuleInfo, RuleConfig, RuleConfigValue, RuleInfo, Severity, V
6
6
  export declare class MLRule<T extends RuleConfigValue, O = null> {
7
7
  #private;
8
8
  readonly defaultOptions: O;
9
- readonly defaultServerity: Severity;
9
+ readonly defaultSeverity: Severity;
10
10
  readonly defaultValue: T;
11
11
  readonly name: string;
12
+ constructor(o: RuleSeed<T, O> & {
13
+ name: string;
14
+ });
12
15
  /**
13
16
  * The following getter is unused internally,
14
17
  * only for extending from 3rd party library
@@ -19,12 +22,9 @@ export declare class MLRule<T extends RuleConfigValue, O = null> {
19
22
  * only for extending from 3rd party library
20
23
  */
21
24
  protected get v(): RuleSeed<T, O>['verify'];
22
- constructor(o: RuleSeed<T, O> & {
23
- name: string;
24
- });
25
25
  getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
26
26
  optimizeOption(configSettings: T | RuleConfig<T, O> | 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 declare type AnyMLRule = MLRule<RuleConfigValue, unknown>;
30
+ export type AnyMLRule = MLRule<RuleConfigValue, unknown>;
@@ -10,7 +10,7 @@ class MLRule {
10
10
  _MLRule_f.set(this, void 0);
11
11
  _MLRule_v.set(this, void 0);
12
12
  this.name = o.name;
13
- this.defaultServerity = o.defaultServerity || 'error';
13
+ this.defaultSeverity = o.defaultSeverity || 'error';
14
14
  this.defaultValue = (_a = o.defaultValue) !== null && _a !== void 0 ? _a : true;
15
15
  this.defaultOptions = (_b = o.defaultOptions) !== null && _b !== void 0 ? _b : null;
16
16
  tslib_1.__classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
@@ -42,19 +42,19 @@ class MLRule {
42
42
  if (configSettings === undefined || typeof configSettings === 'boolean') {
43
43
  return {
44
44
  disabled: !configSettings,
45
- severity: this.defaultServerity,
45
+ severity: this.defaultSeverity,
46
46
  value: this.defaultValue,
47
- option: this.defaultOptions,
47
+ options: this.defaultOptions,
48
48
  reason: undefined,
49
49
  };
50
50
  }
51
51
  if (!Array.isArray(configSettings) && typeof configSettings === 'object' && configSettings !== null) {
52
52
  return {
53
53
  disabled: false,
54
- severity: configSettings.severity || this.defaultServerity,
54
+ severity: configSettings.severity || this.defaultSeverity,
55
55
  value: configSettings.value !== undefined ? configSettings.value : this.defaultValue,
56
- option: Array.isArray(this.defaultOptions)
57
- ? configSettings.option
56
+ options: Array.isArray(this.defaultOptions)
57
+ ? configSettings.options
58
58
  ? // prettier-ignore
59
59
  // @ts-ignore for "as" casting
60
60
  this.defaultOptions.concat(configSettings.option)
@@ -62,18 +62,17 @@ class MLRule {
62
62
  : this.defaultOptions !== null &&
63
63
  typeof this.defaultOptions === 'object' &&
64
64
  // for example `configSettings.option === true`
65
- (configSettings.option == null || typeof configSettings.option === 'object')
66
- ? { ...this.defaultOptions, ...(configSettings.option || {}) }
67
- : configSettings.option || this.defaultOptions,
65
+ (configSettings.options == null || typeof configSettings.options === 'object')
66
+ ? { ...this.defaultOptions, ...(configSettings.options || {}) }
67
+ : configSettings.options || this.defaultOptions,
68
68
  reason: configSettings.reason,
69
69
  };
70
70
  }
71
71
  return {
72
72
  disabled: false,
73
- severity: this.defaultServerity,
74
- // @ts-ignore TODO: Wait for fix to bug of type guards in TypeScript
73
+ severity: this.defaultSeverity,
75
74
  value: configSettings == null ? this.defaultValue : configSettings,
76
- option: this.defaultOptions,
75
+ options: this.defaultOptions,
77
76
  reason: undefined,
78
77
  };
79
78
  }
@@ -2,19 +2,19 @@ import type { Attr, Element } from '../ml-dom';
2
2
  import type { MLRuleContext } from './ml-rule-context';
3
3
  import type { Translator } from '@markuplint/i18n';
4
4
  import type { Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
- export declare type RuleSeed<T extends RuleConfigValue = boolean, O = null> = {
6
- defaultServerity?: Severity;
5
+ export type RuleSeed<T extends RuleConfigValue = boolean, O = null> = {
6
+ defaultSeverity?: Severity;
7
7
  defaultValue?: T;
8
8
  defaultOptions?: O;
9
9
  verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
10
10
  fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
11
11
  };
12
- export declare type Checker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P) => CheckerReport<T, O>;
13
- export declare type ElementChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P & {
12
+ export type Checker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P) => CheckerReport<T, O>;
13
+ export type ElementChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P & {
14
14
  el: Element<T, O>;
15
15
  }) => CheckerReport<T, O>;
16
- export declare type AttrChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P & {
16
+ export type AttrChecker<T extends RuleConfigValue, O = null, P extends Record<string, unknown> = {}> = (params: P & {
17
17
  attr: Attr<T, O>;
18
18
  }) => CheckerReport<T, O>;
19
- export declare type CheckerReport<T extends RuleConfigValue, O = null> = (t: Translator) => Report<T, O> | undefined | null;
20
- export declare type AnyRuleSeed = RuleSeed<any, any>;
19
+ export type CheckerReport<T extends RuleConfigValue, O = null> = (t: Translator) => Report<T, O> | undefined | null;
20
+ export type AnyRuleSeed = RuleSeed<any, any>;
@@ -1,12 +1,12 @@
1
1
  import type { AnyRuleSeed } from '../ml-rule';
2
2
  import type { Config } from '@markuplint/ml-config';
3
- export declare type Plugin = {
3
+ export type Plugin = {
4
4
  name: string;
5
5
  rules?: Record<string, AnyRuleSeed>;
6
6
  configs?: Record<string, Config>;
7
7
  };
8
- export declare type PluginCreator<S extends CreatePluginSettings> = {
8
+ export type PluginCreator<S extends CreatePluginSettings> = {
9
9
  name: string;
10
10
  create(setting: S): Omit<Plugin, 'name'>;
11
11
  };
12
- export declare type CreatePluginSettings = Record<string, unknown>;
12
+ export type CreatePluginSettings = Record<string, unknown>;
@@ -2,12 +2,13 @@ import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
2
2
  import type { Config, RuleConfigValue } from '@markuplint/ml-config';
3
3
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
4
4
  import { Document } from '../ml-dom';
5
- export declare type CreateTestOptions = {
5
+ export type CreateTestOptions = {
6
6
  config?: Config;
7
7
  parser?: MLMarkupLanguageParser;
8
+ specs?: MLMLSpec;
8
9
  };
9
10
  export declare function createTestDocument<T extends RuleConfigValue = any, O = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>;
10
- export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstructNode>[];
11
+ export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstractNode>[];
11
12
  export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token").MLToken<import("@markuplint/ml-ast").MLToken>[];
12
13
  export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom").Element<any, any>;
13
14
  /**
package/lib/test/index.js CHANGED
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dummySchemas = exports.createTestElement = exports.createTestTokenList = exports.createTestNodeList = exports.createTestDocument = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const html_parser_1 = require("@markuplint/html-parser");
6
+ const html_spec_1 = tslib_1.__importDefault(require("@markuplint/html-spec"));
5
7
  const convert_ruleset_1 = require("../convert-ruleset");
6
8
  const ml_dom_1 = require("../ml-dom");
7
9
  function createTestDocument(sourceCode, options) {
10
+ var _a;
8
11
  const ast = (options === null || options === void 0 ? void 0 : options.parser) ? options.parser.parse(sourceCode) : (0, html_parser_1.parse)(sourceCode);
9
12
  const ruleset = (0, convert_ruleset_1.convertRuleset)(options === null || options === void 0 ? void 0 : options.config);
10
- const document = new ml_dom_1.Document(ast, ruleset, [{}, {}]);
13
+ const document = new ml_dom_1.Document(ast, ruleset, [(_a = options === null || options === void 0 ? void 0 : options.specs) !== null && _a !== void 0 ? _a : {}, {}]);
11
14
  return document;
12
15
  }
13
16
  exports.createTestDocument = createTestDocument;
@@ -34,7 +37,6 @@ exports.createTestElement = createTestElement;
34
37
  * for test suite
35
38
  */
36
39
  function dummySchemas() {
37
- // @ts-ignore
38
- return [{}, {}];
40
+ return [html_spec_1.default];
39
41
  }
40
42
  exports.dummySchemas = dummySchemas;
package/lib/types.d.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  import type { AnyMLRule } from './ml-rule';
2
2
  import type Ruleset from './ruleset';
3
3
  import type { LocaleSet } from '@markuplint/i18n';
4
- import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
5
- import type { ParserOptions } from '@markuplint/ml-config';
4
+ import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
5
+ import type { Pretender } from '@markuplint/ml-config';
6
6
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
7
- export declare type MLSchema = Readonly<[MLMLSpec, ...ExtendedSpec[]]>;
8
- export declare type MLFabric = {
7
+ export type MLSchema = Readonly<[MLMLSpec, ...ExtendedSpec[]]>;
8
+ export type MLFabric = {
9
9
  parser: MLMarkupLanguageParser;
10
10
  ruleset: Partial<Ruleset>;
11
11
  rules: AnyMLRule[];
12
12
  locale: LocaleSet;
13
13
  schemas: MLSchema;
14
14
  parserOptions: ParserOptions;
15
+ pretenders: Pretender[];
15
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "3.0.0-alpha.66+6cde1134",
3
+ "version": "3.0.0-dev.24+f55f5eff",
4
4
  "description": "The core module of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -16,21 +16,23 @@
16
16
  "dev": "tsc --build --watch",
17
17
  "clean": "tsc --build --clean"
18
18
  },
19
+ "browser": {
20
+ "./lib/configs.js": "./lib/configs.browser.js"
21
+ },
19
22
  "dependencies": {
20
- "@markuplint/config-presets": "3.0.0-alpha",
21
- "@markuplint/i18n": "2.1.1",
22
- "@markuplint/ml-ast": "2.0.1-dev.20220307.0",
23
- "@markuplint/ml-config": "3.0.0-alpha.66+6cde1134",
24
- "@markuplint/ml-spec": "3.0.0-alpha.82+6cde1134",
25
- "@markuplint/parser-utils": "2.2.0",
26
- "@markuplint/selector": "3.0.0-alpha.2105+6cde1134",
23
+ "@markuplint/config-presets": "3.0.0-rc.0",
24
+ "@markuplint/i18n": "3.0.0-rc.0",
25
+ "@markuplint/ml-ast": "3.0.0-rc.0",
26
+ "@markuplint/ml-config": "3.0.0-dev.24+f55f5eff",
27
+ "@markuplint/ml-spec": "3.0.0-dev.24+f55f5eff",
28
+ "@markuplint/parser-utils": "3.0.0-dev.24+f55f5eff",
29
+ "@markuplint/selector": "3.0.0-dev.24+f55f5eff",
27
30
  "debug": "^4.3.4",
28
- "postcss-selector-parser": "^6.0.10",
29
- "tslib": "^2.3.1"
31
+ "tslib": "^2.4.1"
30
32
  },
31
33
  "devDependencies": {
32
- "@markuplint/html-parser": "2.2.1",
34
+ "@markuplint/html-parser": "3.0.0-dev.24+f55f5eff",
33
35
  "@types/debug": "^4.1.7"
34
36
  },
35
- "gitHead": "6cde113402758a8fdbd6a0fcf98e78efd2cdb778"
37
+ "gitHead": "f55f5eff289296feba26f20b0c085e0528c80ac4"
36
38
  }