@markuplint/ml-core 3.15.0 → 4.0.0-alpha.10

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