@markuplint/ml-core 4.13.2 → 5.0.0-alpha.0

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 (92) hide show
  1. package/ARCHITECTURE.ja.md +524 -0
  2. package/ARCHITECTURE.md +524 -0
  3. package/CHANGELOG.md +52 -2
  4. package/README.md +5 -0
  5. package/SKILL.md +61 -0
  6. package/docs/linting-pipeline.ja.md +307 -0
  7. package/docs/linting-pipeline.md +307 -0
  8. package/docs/maintenance.ja.md +210 -0
  9. package/docs/maintenance.md +210 -0
  10. package/docs/ml-dom/attr.ja.md +103 -0
  11. package/docs/ml-dom/attr.md +103 -0
  12. package/docs/ml-dom/block.ja.md +272 -0
  13. package/docs/ml-dom/block.md +272 -0
  14. package/docs/ml-dom/document.ja.md +141 -0
  15. package/docs/ml-dom/document.md +141 -0
  16. package/docs/ml-dom/element.ja.md +176 -0
  17. package/docs/ml-dom/element.md +176 -0
  18. package/docs/ml-dom/helpers.ja.md +203 -0
  19. package/docs/ml-dom/helpers.md +203 -0
  20. package/docs/ml-dom/node.ja.md +199 -0
  21. package/docs/ml-dom/node.md +199 -0
  22. package/docs/ml-dom/others.ja.md +120 -0
  23. package/docs/ml-dom/others.md +120 -0
  24. package/docs/ml-dom/overview.ja.md +102 -0
  25. package/docs/ml-dom/overview.md +102 -0
  26. package/docs/ml-dom/pretender.ja.md +269 -0
  27. package/docs/ml-dom/pretender.md +269 -0
  28. package/docs/ml-dom/rule-mapping.ja.md +371 -0
  29. package/docs/ml-dom/rule-mapping.md +371 -0
  30. package/docs/ml-dom.ja.md +18 -0
  31. package/docs/ml-dom.md +18 -0
  32. package/docs/rule-system.ja.md +287 -0
  33. package/docs/rule-system.md +287 -0
  34. package/lib/convert-ruleset.d.ts +7 -0
  35. package/lib/convert-ruleset.js +7 -0
  36. package/lib/debug.d.ts +4 -0
  37. package/lib/debug.js +4 -0
  38. package/lib/index.d.ts +4 -3
  39. package/lib/index.js +1 -1
  40. package/lib/ml-core.d.ts +37 -1
  41. package/lib/ml-core.js +171 -82
  42. package/lib/ml-dom/helper/accname.d.ts +8 -0
  43. package/lib/ml-dom/helper/accname.js +71 -55
  44. package/lib/ml-dom/helper/create-node.js +1 -0
  45. package/lib/ml-dom/helper/get-indent.d.ts +4 -1
  46. package/lib/ml-dom/helper/get-indent.js +21 -30
  47. package/lib/ml-dom/node/attr.d.ts +65 -4
  48. package/lib/ml-dom/node/attr.js +151 -53
  49. package/lib/ml-dom/node/block.d.ts +23 -2
  50. package/lib/ml-dom/node/block.js +24 -1
  51. package/lib/ml-dom/node/child-node.d.ts +9 -0
  52. package/lib/ml-dom/node/child-node.js +9 -0
  53. package/lib/ml-dom/node/comment.d.ts +7 -0
  54. package/lib/ml-dom/node/comment.js +7 -0
  55. package/lib/ml-dom/node/document-fragment.d.ts +8 -0
  56. package/lib/ml-dom/node/document-fragment.js +8 -0
  57. package/lib/ml-dom/node/document-type.d.ts +22 -0
  58. package/lib/ml-dom/node/document-type.js +25 -0
  59. package/lib/ml-dom/node/document.d.ts +88 -7
  60. package/lib/ml-dom/node/document.js +128 -32
  61. package/lib/ml-dom/node/dom-token-list.js +17 -30
  62. package/lib/ml-dom/node/element-close-tag.js +1 -0
  63. package/lib/ml-dom/node/element.d.ts +151 -5
  64. package/lib/ml-dom/node/element.js +242 -50
  65. package/lib/ml-dom/node/node-store.js +6 -15
  66. package/lib/ml-dom/node/node.d.ts +19 -1
  67. package/lib/ml-dom/node/node.js +175 -166
  68. package/lib/ml-dom/node/parent-node.js +14 -30
  69. package/lib/ml-dom/node/rule-mapper.js +7 -20
  70. package/lib/ml-dom/node/text.d.ts +19 -0
  71. package/lib/ml-dom/node/text.js +21 -0
  72. package/lib/ml-dom/node/types.d.ts +68 -0
  73. package/lib/ml-dom/token/token.d.ts +42 -0
  74. package/lib/ml-dom/token/token.js +59 -39
  75. package/lib/ml-rule/create-rule.d.ts +17 -1
  76. package/lib/ml-rule/ml-rule-context.js +7 -11
  77. package/lib/ml-rule/ml-rule.d.ts +66 -1
  78. package/lib/ml-rule/ml-rule.js +95 -25
  79. package/lib/ml-rule/types.d.ts +41 -0
  80. package/lib/plugin/plugin.d.ts +8 -0
  81. package/lib/plugin/plugin.js +8 -0
  82. package/lib/plugin/types.d.ts +21 -0
  83. package/lib/ruleset/index.d.ts +10 -0
  84. package/lib/ruleset/index.js +13 -0
  85. package/lib/test/index.d.ts +42 -1
  86. package/lib/test/index.js +39 -2
  87. package/lib/types.d.ts +10 -1
  88. package/lib/violation-collector.d.ts +33 -0
  89. package/lib/violation-collector.js +48 -28
  90. package/lib/virtual-rule.d.ts +72 -0
  91. package/lib/virtual-rule.js +233 -0
  92. package/package.json +16 -13
@@ -6,6 +6,14 @@ import { UnexpectedCallError } from './unexpected-call-error.js';
6
6
  * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
7
7
  */
8
8
  const rawTextElements = new Set(['script', 'style']);
9
+ /**
10
+ * Represents a DOM Text node wrapper in the markuplint DOM tree.
11
+ * Wraps an AST text token and provides text-specific operations such as
12
+ * detecting raw text element content and whitespace-only nodes.
13
+ *
14
+ * @template T - The rule configuration value type
15
+ * @template O - The rule options type
16
+ */
9
17
  export class MLText extends MLCharacterData {
10
18
  /**
11
19
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -16,6 +24,15 @@ export class MLText extends MLCharacterData {
16
24
  get assignedSlot() {
17
25
  throw new UnexpectedCallError('Not supported "assignedSlot" property');
18
26
  }
27
+ /**
28
+ * Returns `true` if this text node originated from an invalid (bogus) AST
29
+ * node, such as an orphaned end tag.
30
+ *
31
+ * @implements `@markuplint/ml-core` API: `MLText`
32
+ */
33
+ get isBogus() {
34
+ return this._astToken.isBogus ?? false;
35
+ }
19
36
  /**
20
37
  * Returns a string appropriate for the type of node as `Text`
21
38
  *
@@ -45,12 +62,16 @@ export class MLText extends MLCharacterData {
45
62
  *
46
63
  * @implements `@markuplint/ml-core` API: `MLText`
47
64
  * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
65
+ * @returns True if this text node is the content of a raw text element
48
66
  */
49
67
  isRawTextElementContent() {
50
68
  return this.parentElement ? rawTextElements.has(this.parentElement.nodeName.toLowerCase()) : false;
51
69
  }
52
70
  /**
71
+ * Checks whether this text node contains only whitespace characters.
72
+ *
53
73
  * @implements `@markuplint/ml-core` API: `MLText`
74
+ * @returns True if the raw content is composed entirely of whitespace
54
75
  */
55
76
  isWhitespace() {
56
77
  return /^\s+$/.test(this.raw);
@@ -9,30 +9,91 @@ import type { MLText } from './text.js';
9
9
  import type { MLToken } from '../token/token.js';
10
10
  import type { MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTInvalid, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLASTToken as MLASTToken } from '@markuplint/ml-ast/';
11
11
  import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
12
+ /**
13
+ * Maps an AST node type to its corresponding markuplint DOM node wrapper type.
14
+ *
15
+ * @template N - The AST node type to map from
16
+ * @template T - The rule configuration value type
17
+ * @template O - The rule options type
18
+ */
12
19
  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 MLASTAttr ? MLAttr<T, O> : N extends MLASTInvalid ? MLText<T, O> : N extends MLASTToken ? MLToken : never;
20
+ /**
21
+ * Resolves a numeric node type constant to its corresponding markuplint DOM node class type.
22
+ * Used for type narrowing via the `is()` method on nodes.
23
+ *
24
+ * @template NT - The numeric node type constant
25
+ * @template T - The rule configuration value type
26
+ * @template O - The rule options type
27
+ */
13
28
  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;
29
+ /** Numeric constant representing an Element node (corresponds to DOM `Node.ELEMENT_NODE`). */
14
30
  export type ElementNodeType = 1;
31
+ /** Numeric constant representing an Attribute node (corresponds to DOM `Node.ATTRIBUTE_NODE`). */
15
32
  export type AttributeNodeType = 2;
33
+ /** Numeric constant representing a Text node (corresponds to DOM `Node.TEXT_NODE`). */
16
34
  export type TextNodeType = 3;
35
+ /** Numeric constant representing a CDATA Section node (corresponds to DOM `Node.CDATA_SECTION_NODE`). */
17
36
  export type CDATASectionNodeType = 4;
37
+ /** Numeric constant representing a Processing Instruction node (corresponds to DOM `Node.PROCESSING_INSTRUCTION_NODE`). */
18
38
  export type ProcessingInstructionNodeType = 7;
39
+ /** Numeric constant representing a Comment node (corresponds to DOM `Node.COMMENT_NODE`). */
19
40
  export type CommentNodeType = 8;
41
+ /** Numeric constant representing a Document node (corresponds to DOM `Node.DOCUMENT_NODE`). */
20
42
  export type DocumentNodeType = 9;
43
+ /** Numeric constant representing a DocumentType node (corresponds to DOM `Node.DOCUMENT_TYPE_NODE`). */
21
44
  export type DocumentTypeNodeType = 10;
45
+ /** Numeric constant representing a DocumentFragment node (corresponds to DOM `Node.DOCUMENT_FRAGMENT_NODE`). */
22
46
  export type DocumentFragmentNodeType = 11;
47
+ /** Numeric constant representing a markuplint preprocessor block node, used for template engine constructs. */
23
48
  export type MarkuplintPreprocessorBlockType = 101;
49
+ /**
50
+ * Union of all supported node type constants in the markuplint DOM,
51
+ * including standard DOM node types and the markuplint-specific preprocessor block type.
52
+ */
24
53
  export type NodeType = ElementNodeType | AttributeNodeType | TextNodeType | CDATASectionNodeType | ProcessingInstructionNodeType | CommentNodeType | DocumentNodeType | DocumentTypeNodeType | DocumentFragmentNodeType | MarkuplintPreprocessorBlockType;
54
+ /**
55
+ * Represents the pretender context for an element, which can be either
56
+ * a pretender (an element acting as another) or a pretended element (the original).
57
+ *
58
+ * @template N - The element type
59
+ * @template T - The rule configuration value type
60
+ * @template O - The rule options type
61
+ */
25
62
  export type PretenderContext<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = PretenderContextPretender<N, T, O> | PretenderContextPretended<N, T, O>;
63
+ /**
64
+ * Context for an element that is pretending to be another element.
65
+ * Contains the target element it is pretending to be and optional ARIA overrides.
66
+ *
67
+ * @template N - The element type
68
+ * @template T - The rule configuration value type
69
+ * @template O - The rule options type
70
+ */
26
71
  export type PretenderContextPretender<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
27
72
  readonly type: 'pretender';
28
73
  readonly as: N;
29
74
  readonly aria?: PretenderARIA;
30
75
  };
76
+ /**
77
+ * Context for the original element that has been pretended by another element.
78
+ * Contains a reference back to the pretending origin element.
79
+ *
80
+ * @template N - The element type
81
+ * @template T - The rule configuration value type
82
+ * @template O - The rule options type
83
+ */
31
84
  export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleConfigValue, O extends PlainData = undefined> = {
32
85
  readonly type: 'origin';
33
86
  readonly origin: N;
34
87
  };
88
+ /**
89
+ * Represents the computed accessibility properties for a node,
90
+ * which may be clearly resolved or unknown.
91
+ */
35
92
  export type AccessibilityProperties = ClearlyAccessibilityProperties | UnknownAccessibilityProperties;
93
+ /**
94
+ * Resolved accessibility properties for a node, including its ARIA role,
95
+ * accessible name, focusability, and related ARIA property values.
96
+ */
36
97
  export type ClearlyAccessibilityProperties = {
37
98
  unknown: false;
38
99
  exposedToTree: boolean;
@@ -46,9 +107,16 @@ export type ClearlyAccessibilityProperties = {
46
107
  focusable?: boolean;
47
108
  props?: Record<string, AccessibilityProperty>;
48
109
  };
110
+ /**
111
+ * Represents accessibility properties that could not be resolved,
112
+ * typically when the element or its role is not recognized.
113
+ */
49
114
  export type UnknownAccessibilityProperties = {
50
115
  unknown: true;
51
116
  };
117
+ /**
118
+ * A single ARIA property with its computed value and whether it is required for the role.
119
+ */
52
120
  export type AccessibilityProperty = {
53
121
  value: string | null;
54
122
  required: boolean;
@@ -1,47 +1,89 @@
1
1
  import type { MLASTToken } from '@markuplint/ml-ast';
2
+ /**
3
+ * Represents a single token in the markuplint AST.
4
+ * Wraps an AST token with positional information (line, column, offset)
5
+ * and provides both raw and fixed string representations.
6
+ *
7
+ * @template A - The AST token type this token wraps
8
+ */
2
9
  export declare class MLToken<A extends MLASTToken = MLASTToken> {
3
10
  #private;
11
+ /**
12
+ * The unique identifier for this token.
13
+ */
4
14
  readonly uuid: string;
15
+ /**
16
+ * The underlying AST token that this token wraps.
17
+ */
5
18
  protected readonly _astToken: A;
19
+ /**
20
+ * Creates a new MLToken instance from an AST token.
21
+ *
22
+ * @param astToken - The AST token to wrap
23
+ */
6
24
  constructor(astToken: A);
7
25
  /**
26
+ * The ending column number (1-based) of this token in the source.
27
+ *
8
28
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
9
29
  */
10
30
  get endCol(): number;
11
31
  /**
32
+ * The ending line number (1-based) of this token in the source.
33
+ *
12
34
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
13
35
  */
14
36
  get endLine(): number;
15
37
  /**
38
+ * The ending character offset (0-based) of this token in the source.
39
+ *
16
40
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
17
41
  */
18
42
  get endOffset(): number;
19
43
  /**
44
+ * The fixed (potentially modified) string content of this token.
45
+ *
20
46
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
21
47
  */
22
48
  get fixed(): string;
23
49
  /**
50
+ * The original raw string content of this token from the source.
51
+ *
24
52
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
25
53
  */
26
54
  get raw(): string;
27
55
  /**
56
+ * The starting column number (1-based) of this token in the source.
57
+ *
28
58
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
29
59
  */
30
60
  get startCol(): number;
31
61
  /**
62
+ * The starting line number (1-based) of this token in the source.
63
+ *
32
64
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
33
65
  */
34
66
  get startLine(): number;
35
67
  /**
68
+ * The starting character offset (0-based) of this token in the source.
69
+ *
36
70
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
37
71
  */
38
72
  get startOffset(): number;
39
73
  /**
74
+ * Replaces the fixed content of this token with the given string,
75
+ * used when applying lint fixes.
76
+ *
40
77
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
78
+ * @param raw - The new string content to set as the fixed value
41
79
  */
42
80
  fix(raw: string): void;
43
81
  /**
82
+ * Returns the string representation of this token.
83
+ *
44
84
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
85
+ * @param fixed - When true, returns the fixed content; otherwise returns the original raw content
86
+ * @returns The string content of this token
45
87
  */
46
88
  toString(fixed?: boolean): string;
47
89
  }
@@ -1,95 +1,115 @@
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
- };
12
- var _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
1
+ import { getEndCol, getEndLine } from '@markuplint/parser-utils/location';
2
+ /**
3
+ * Represents a single token in the markuplint AST.
4
+ * Wraps an AST token with positional information (line, column, offset)
5
+ * and provides both raw and fixed string representations.
6
+ *
7
+ * @template A - The AST token type this token wraps
8
+ */
13
9
  export class MLToken {
10
+ #fixed;
11
+ #raw;
12
+ /**
13
+ * The unique identifier for this token.
14
+ */
15
+ uuid;
16
+ /**
17
+ * The underlying AST token that this token wraps.
18
+ */
19
+ _astToken;
20
+ /**
21
+ * Creates a new MLToken instance from an AST token.
22
+ *
23
+ * @param astToken - The AST token to wrap
24
+ */
14
25
  constructor(astToken) {
15
- _MLToken_endCol.set(this, void 0);
16
- _MLToken_endLine.set(this, void 0);
17
- _MLToken_endOffset.set(this, void 0);
18
- _MLToken_fixed.set(this, void 0);
19
- _MLToken_raw.set(this, void 0);
20
- _MLToken_startCol.set(this, void 0);
21
- _MLToken_startLine.set(this, void 0);
22
- _MLToken_startOffset.set(this, void 0);
23
26
  this._astToken = astToken;
24
- __classPrivateFieldSet(this, _MLToken_raw, astToken.raw, "f");
25
- __classPrivateFieldSet(this, _MLToken_fixed, astToken.raw, "f");
27
+ this.#raw = astToken.raw;
28
+ this.#fixed = astToken.raw;
26
29
  this.uuid = astToken.uuid;
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");
33
30
  }
34
31
  /**
32
+ * The ending column number (1-based) of this token in the source.
33
+ *
35
34
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
36
35
  */
37
36
  get endCol() {
38
- return __classPrivateFieldGet(this, _MLToken_endCol, "f");
37
+ return getEndCol(this.fixed, this.startCol);
39
38
  }
40
39
  /**
40
+ * The ending line number (1-based) of this token in the source.
41
+ *
41
42
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
42
43
  */
43
44
  get endLine() {
44
- return __classPrivateFieldGet(this, _MLToken_endLine, "f");
45
+ return getEndLine(this.fixed, this.startLine);
45
46
  }
46
47
  /**
48
+ * The ending character offset (0-based) of this token in the source.
49
+ *
47
50
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
48
51
  */
49
52
  get endOffset() {
50
- return __classPrivateFieldGet(this, _MLToken_endOffset, "f");
53
+ return this.startOffset + this.fixed.length;
51
54
  }
52
55
  /**
56
+ * The fixed (potentially modified) string content of this token.
57
+ *
53
58
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
54
59
  */
55
60
  get fixed() {
56
- return __classPrivateFieldGet(this, _MLToken_fixed, "f");
61
+ return this.#fixed;
57
62
  }
58
63
  /**
64
+ * The original raw string content of this token from the source.
65
+ *
59
66
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
60
67
  */
61
68
  get raw() {
62
- return __classPrivateFieldGet(this, _MLToken_raw, "f");
69
+ return this.#raw;
63
70
  }
64
71
  /**
72
+ * The starting column number (1-based) of this token in the source.
73
+ *
65
74
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
66
75
  */
67
76
  get startCol() {
68
- return __classPrivateFieldGet(this, _MLToken_startCol, "f");
77
+ return this._astToken.col;
69
78
  }
70
79
  /**
80
+ * The starting line number (1-based) of this token in the source.
81
+ *
71
82
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
72
83
  */
73
84
  get startLine() {
74
- return __classPrivateFieldGet(this, _MLToken_startLine, "f");
85
+ return this._astToken.line;
75
86
  }
76
87
  /**
88
+ * The starting character offset (0-based) of this token in the source.
89
+ *
77
90
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
78
91
  */
79
92
  get startOffset() {
80
- return __classPrivateFieldGet(this, _MLToken_startOffset, "f");
93
+ return this._astToken.offset;
81
94
  }
82
95
  /**
96
+ * Replaces the fixed content of this token with the given string,
97
+ * used when applying lint fixes.
98
+ *
83
99
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
100
+ * @param raw - The new string content to set as the fixed value
84
101
  */
85
102
  fix(raw) {
86
- __classPrivateFieldSet(this, _MLToken_fixed, raw, "f");
103
+ this.#fixed = raw;
87
104
  }
88
105
  /**
106
+ * Returns the string representation of this token.
107
+ *
89
108
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
109
+ * @param fixed - When true, returns the fixed content; otherwise returns the original raw content
110
+ * @returns The string content of this token
90
111
  */
91
112
  toString(fixed = false) {
92
- return fixed ? __classPrivateFieldGet(this, _MLToken_fixed, "f") : __classPrivateFieldGet(this, _MLToken_raw, "f");
113
+ return fixed ? this.#fixed : this.#raw;
93
114
  }
94
115
  }
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,3 +1,19 @@
1
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>(seed: Readonly<RuleSeed<T, O>>): Readonly<RuleSeed<T, O>>;
3
+ /**
4
+ * Factory function for creating a type-safe rule seed.
5
+ * Returns the seed object as-is; primarily used for type inference.
6
+ *
7
+ * When `T` is `boolean` (or includes `boolean`), `defaultValue` is optional because
8
+ * the runtime default is `true`. For all other value types, `defaultValue` is required
9
+ * so that the rule always has a well-typed default.
10
+ *
11
+ * @see https://github.com/markuplint/markuplint/issues/808
12
+ * @template T - The type of the rule's configuration value
13
+ * @template O - The type of the rule's options
14
+ * @param seed - The rule seed definition containing verify/fix functions and defaults
15
+ * @returns The same seed object, now fully typed
16
+ */
17
+ export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>> & (boolean extends T ? {} : {
18
+ readonly defaultValue: T;
19
+ })): Readonly<RuleSeed<T, O>>;
@@ -1,21 +1,18 @@
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
- };
6
- var _MLRuleContext_reports;
7
1
  import { translator } from '@markuplint/i18n';
8
2
  export class MLRuleContext {
3
+ document;
4
+ locale;
5
+ #reports = [];
6
+ translate;
9
7
  constructor(
10
8
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
11
9
  document, locale) {
12
- _MLRuleContext_reports.set(this, []);
13
10
  this.document = document;
14
11
  this.translate = translator(locale);
15
12
  this.locale = locale.locale;
16
13
  }
17
14
  get reports() {
18
- return __classPrivateFieldGet(this, _MLRuleContext_reports, "f").map(report => ({
15
+ return this.#reports.map(report => ({
19
16
  ...report,
20
17
  message: finish(report.message, this.locale),
21
18
  }));
@@ -41,12 +38,11 @@ export class MLRuleContext {
41
38
  this._push(report);
42
39
  }
43
40
  _push(report) {
44
- if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").some(r => is(r, report))) {
45
- __classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
41
+ if (!this.#reports.some(r => is(r, report))) {
42
+ this.#reports.push(report);
46
43
  }
47
44
  }
48
45
  }
49
- _MLRuleContext_reports = new WeakMap();
50
46
  function finish(message, locale = 'en') {
51
47
  switch (locale) {
52
48
  case 'en': {
@@ -2,16 +2,54 @@ import type { RuleSeed } from './types.js';
2
2
  import type { MLDocument } from '../ml-dom/node/document.js';
3
3
  import type { Ruleset } from '../ruleset/index.js';
4
4
  import type { LocaleSet } from '@markuplint/i18n';
5
- import type { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
5
+ import type { GlobalRuleInfo, SpecConformance, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
6
+ /**
7
+ * Represents a single markuplint rule that can verify documents and report violations.
8
+ *
9
+ * @template T - The type of the rule's configuration value
10
+ * @template O - The type of the rule's options
11
+ */
6
12
  export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
7
13
  #private;
14
+ /**
15
+ * For virtual rules, the name of the base rule whose verify/fix logic is reused.
16
+ * When set, violations report this as `ruleId` for backwards compatibility.
17
+ */
18
+ readonly baseRuleId?: string;
8
19
  readonly defaultOptions: O;
9
20
  readonly defaultSeverity: Severity;
10
21
  readonly defaultValue: T;
22
+ /**
23
+ * For multi-entry named nodeRules, the group name shared by all derived virtual rules.
24
+ * Allows `rules["groupName"]: false` to disable all rules in the group.
25
+ */
26
+ readonly groupName?: string;
11
27
  readonly name: string;
28
+ /**
29
+ * The spec conformance classification of this rule, based on RFC 2119 keyword strength.
30
+ * Set on virtual rules derived from named nodeRules in presets.
31
+ */
32
+ readonly specConformance?: SpecConformance;
12
33
  constructor(o: Readonly<RuleSeed<T, O>> & {
13
34
  readonly name: string;
35
+ readonly baseRuleId?: string;
36
+ readonly specConformance?: SpecConformance;
37
+ readonly groupName?: string;
14
38
  });
39
+ /**
40
+ * Creates a virtual rule that reuses this rule's verify/fix logic
41
+ * under a different name (alias). Used by named nodeRules to produce
42
+ * independent rule instances that can be individually configured.
43
+ *
44
+ * @param aliasName - The alias name (must contain `/`)
45
+ * @param options - Override options for the virtual rule
46
+ * @returns A new MLRule instance sharing the same verify/fix logic
47
+ */
48
+ createAlias(aliasName: string, options?: {
49
+ readonly defaultSeverity?: Severity;
50
+ readonly specConformance?: SpecConformance;
51
+ readonly groupName?: string;
52
+ }): MLRule<T, O>;
15
53
  /**
16
54
  * The following getter is unused internally,
17
55
  * only for extending from 3rd party library
@@ -22,9 +60,36 @@ export declare class MLRule<T extends RuleConfigValue, O extends PlainData = und
22
60
  * only for extending from 3rd party library
23
61
  */
24
62
  protected get v(): RuleSeed<T, O>['verify'];
63
+ /**
64
+ * Resolves the full rule information from a ruleset, including node-level
65
+ * and child-node-level overrides.
66
+ *
67
+ * @param ruleSet - The ruleset containing rule definitions and overrides
68
+ * @param ruleName - The name of this rule
69
+ * @returns The global rule info with node and child-node overrides
70
+ */
25
71
  getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
72
+ /**
73
+ * Normalizes a raw rule setting into a fully resolved {@link RuleInfo} object,
74
+ * applying defaults for any unspecified fields.
75
+ *
76
+ * @param configSettings - The raw rule configuration value
77
+ * @returns The resolved rule info with defaults applied
78
+ */
26
79
  optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
80
+ /**
81
+ * Executes this rule's verify (and optionally fix) function against a document,
82
+ * then collects and returns the resulting violations.
83
+ *
84
+ * @param document - The parsed document to verify
85
+ * @param locale - The locale set for translating violation messages
86
+ * @param fix - Whether to also run the fix function
87
+ * @returns An array of violations found by this rule
88
+ */
27
89
  verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
28
90
  private _optimize;
29
91
  }
92
+ /**
93
+ * An MLRule with any value and option types. Used when the specific types are not known.
94
+ */
30
95
  export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;