@markuplint/ml-core 4.13.2 → 4.13.3

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 (80) hide show
  1. package/ARCHITECTURE.ja.md +467 -0
  2. package/ARCHITECTURE.md +467 -0
  3. package/CHANGELOG.md +3 -3
  4. package/README.md +5 -0
  5. package/SKILL.md +61 -0
  6. package/docs/linting-pipeline.ja.md +303 -0
  7. package/docs/linting-pipeline.md +303 -0
  8. package/docs/maintenance.ja.md +210 -0
  9. package/docs/maintenance.md +210 -0
  10. package/docs/ml-dom/attr.ja.md +95 -0
  11. package/docs/ml-dom/attr.md +95 -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 +200 -0
  21. package/docs/ml-dom/node.md +200 -0
  22. package/docs/ml-dom/others.ja.md +119 -0
  23. package/docs/ml-dom/others.md +119 -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 +270 -0
  33. package/docs/rule-system.md +270 -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/ml-core.d.ts +36 -0
  39. package/lib/ml-core.js +29 -0
  40. package/lib/ml-dom/helper/get-indent.d.ts +4 -1
  41. package/lib/ml-dom/helper/get-indent.js +4 -1
  42. package/lib/ml-dom/node/attr.d.ts +65 -4
  43. package/lib/ml-dom/node/attr.js +53 -4
  44. package/lib/ml-dom/node/block.d.ts +21 -0
  45. package/lib/ml-dom/node/block.js +14 -0
  46. package/lib/ml-dom/node/child-node.d.ts +9 -0
  47. package/lib/ml-dom/node/child-node.js +9 -0
  48. package/lib/ml-dom/node/comment.d.ts +7 -0
  49. package/lib/ml-dom/node/comment.js +7 -0
  50. package/lib/ml-dom/node/document-fragment.d.ts +8 -0
  51. package/lib/ml-dom/node/document-fragment.js +8 -0
  52. package/lib/ml-dom/node/document-type.d.ts +22 -0
  53. package/lib/ml-dom/node/document-type.js +13 -0
  54. package/lib/ml-dom/node/document.d.ts +74 -4
  55. package/lib/ml-dom/node/document.js +57 -2
  56. package/lib/ml-dom/node/element.d.ts +136 -2
  57. package/lib/ml-dom/node/element.js +115 -2
  58. package/lib/ml-dom/node/node.d.ts +16 -0
  59. package/lib/ml-dom/node/node.js +16 -0
  60. package/lib/ml-dom/node/text.d.ts +12 -0
  61. package/lib/ml-dom/node/text.js +12 -0
  62. package/lib/ml-dom/node/types.d.ts +68 -0
  63. package/lib/ml-dom/token/token.d.ts +42 -0
  64. package/lib/ml-dom/token/token.js +36 -0
  65. package/lib/ml-rule/create-rule.d.ts +9 -0
  66. package/lib/ml-rule/create-rule.js +9 -0
  67. package/lib/ml-rule/ml-rule.d.ts +33 -0
  68. package/lib/ml-rule/ml-rule.js +30 -0
  69. package/lib/ml-rule/types.d.ts +41 -0
  70. package/lib/plugin/plugin.d.ts +8 -0
  71. package/lib/plugin/plugin.js +8 -0
  72. package/lib/plugin/types.d.ts +21 -0
  73. package/lib/ruleset/index.d.ts +10 -0
  74. package/lib/ruleset/index.js +7 -0
  75. package/lib/test/index.d.ts +42 -1
  76. package/lib/test/index.js +35 -1
  77. package/lib/types.d.ts +8 -0
  78. package/lib/violation-collector.d.ts +33 -0
  79. package/lib/violation-collector.js +33 -0
  80. package/package.json +12 -12
@@ -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
  }
@@ -10,7 +10,19 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
13
+ /**
14
+ * Represents a single token in the markuplint AST.
15
+ * Wraps an AST token with positional information (line, column, offset)
16
+ * and provides both raw and fixed string representations.
17
+ *
18
+ * @template A - The AST token type this token wraps
19
+ */
13
20
  export class MLToken {
21
+ /**
22
+ * Creates a new MLToken instance from an AST token.
23
+ *
24
+ * @param astToken - The AST token to wrap
25
+ */
14
26
  constructor(astToken) {
15
27
  _MLToken_endCol.set(this, void 0);
16
28
  _MLToken_endLine.set(this, void 0);
@@ -32,61 +44,85 @@ export class MLToken {
32
44
  __classPrivateFieldSet(this, _MLToken_endOffset, astToken.endOffset, "f");
33
45
  }
34
46
  /**
47
+ * The ending column number (1-based) of this token in the source.
48
+ *
35
49
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
36
50
  */
37
51
  get endCol() {
38
52
  return __classPrivateFieldGet(this, _MLToken_endCol, "f");
39
53
  }
40
54
  /**
55
+ * The ending line number (1-based) of this token in the source.
56
+ *
41
57
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
42
58
  */
43
59
  get endLine() {
44
60
  return __classPrivateFieldGet(this, _MLToken_endLine, "f");
45
61
  }
46
62
  /**
63
+ * The ending character offset (0-based) of this token in the source.
64
+ *
47
65
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
48
66
  */
49
67
  get endOffset() {
50
68
  return __classPrivateFieldGet(this, _MLToken_endOffset, "f");
51
69
  }
52
70
  /**
71
+ * The fixed (potentially modified) string content of this token.
72
+ *
53
73
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
54
74
  */
55
75
  get fixed() {
56
76
  return __classPrivateFieldGet(this, _MLToken_fixed, "f");
57
77
  }
58
78
  /**
79
+ * The original raw string content of this token from the source.
80
+ *
59
81
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
60
82
  */
61
83
  get raw() {
62
84
  return __classPrivateFieldGet(this, _MLToken_raw, "f");
63
85
  }
64
86
  /**
87
+ * The starting column number (1-based) of this token in the source.
88
+ *
65
89
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
66
90
  */
67
91
  get startCol() {
68
92
  return __classPrivateFieldGet(this, _MLToken_startCol, "f");
69
93
  }
70
94
  /**
95
+ * The starting line number (1-based) of this token in the source.
96
+ *
71
97
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
72
98
  */
73
99
  get startLine() {
74
100
  return __classPrivateFieldGet(this, _MLToken_startLine, "f");
75
101
  }
76
102
  /**
103
+ * The starting character offset (0-based) of this token in the source.
104
+ *
77
105
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
78
106
  */
79
107
  get startOffset() {
80
108
  return __classPrivateFieldGet(this, _MLToken_startOffset, "f");
81
109
  }
82
110
  /**
111
+ * Replaces the fixed content of this token with the given string,
112
+ * used when applying lint fixes.
113
+ *
83
114
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
115
+ * @param raw - The new string content to set as the fixed value
84
116
  */
85
117
  fix(raw) {
86
118
  __classPrivateFieldSet(this, _MLToken_fixed, raw, "f");
87
119
  }
88
120
  /**
121
+ * Returns the string representation of this token.
122
+ *
89
123
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
124
+ * @param fixed - When true, returns the fixed content; otherwise returns the original raw content
125
+ * @returns The string content of this token
90
126
  */
91
127
  toString(fixed = false) {
92
128
  return fixed ? __classPrivateFieldGet(this, _MLToken_fixed, "f") : __classPrivateFieldGet(this, _MLToken_raw, "f");
@@ -1,3 +1,12 @@
1
1
  import type { RuleSeed } from './types.js';
2
2
  import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
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
+ * @template T - The type of the rule's configuration value
8
+ * @template O - The type of the rule's options
9
+ * @param seed - The rule seed definition containing verify/fix functions and defaults
10
+ * @returns The same seed object, now fully typed
11
+ */
3
12
  export declare function createRule<T extends RuleConfigValue, O extends PlainData = undefined>(seed: Readonly<RuleSeed<T, O>>): Readonly<RuleSeed<T, O>>;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Factory function for creating a type-safe rule seed.
3
+ * Returns the seed object as-is; primarily used for type inference.
4
+ *
5
+ * @template T - The type of the rule's configuration value
6
+ * @template O - The type of the rule's options
7
+ * @param seed - The rule seed definition containing verify/fix functions and defaults
8
+ * @returns The same seed object, now fully typed
9
+ */
1
10
  export function createRule(seed) {
2
11
  return seed;
3
12
  }
@@ -3,6 +3,12 @@ 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
5
  import type { GlobalRuleInfo, 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;
8
14
  readonly defaultOptions: O;
@@ -22,9 +28,36 @@ export declare class MLRule<T extends RuleConfigValue, O extends PlainData = und
22
28
  * only for extending from 3rd party library
23
29
  */
24
30
  protected get v(): RuleSeed<T, O>['verify'];
31
+ /**
32
+ * Resolves the full rule information from a ruleset, including node-level
33
+ * and child-node-level overrides.
34
+ *
35
+ * @param ruleSet - The ruleset containing rule definitions and overrides
36
+ * @param ruleName - The name of this rule
37
+ * @returns The global rule info with node and child-node overrides
38
+ */
25
39
  getRuleInfo(ruleSet: Ruleset, ruleName: string): GlobalRuleInfo<T, O>;
40
+ /**
41
+ * Normalizes a raw rule setting into a fully resolved {@link RuleInfo} object,
42
+ * applying defaults for any unspecified fields.
43
+ *
44
+ * @param configSettings - The raw rule configuration value
45
+ * @returns The resolved rule info with defaults applied
46
+ */
26
47
  optimizeOption(configSettings: Rule<T, O> | null | undefined): RuleInfo<T, O>;
48
+ /**
49
+ * Executes this rule's verify (and optionally fix) function against a document,
50
+ * then collects and returns the resulting violations.
51
+ *
52
+ * @param document - The parsed document to verify
53
+ * @param locale - The locale set for translating violation messages
54
+ * @param fix - Whether to also run the fix function
55
+ * @returns An array of violations found by this rule
56
+ */
27
57
  verify(document: MLDocument<T, O>, locale: LocaleSet, fix: boolean): Promise<Violation[]>;
28
58
  private _optimize;
29
59
  }
60
+ /**
61
+ * An MLRule with any value and option types. Used when the specific types are not known.
62
+ */
30
63
  export type AnyMLRule = MLRule<RuleConfigValue, PlainData>;
@@ -14,6 +14,12 @@ import { deleteUndefProp } from '@markuplint/ml-config';
14
14
  // @ts-ignore
15
15
  import { isPlainObject } from 'is-plain-object';
16
16
  import { MLRuleContext } from './ml-rule-context.js';
17
+ /**
18
+ * Represents a single markuplint rule that can verify documents and report violations.
19
+ *
20
+ * @template T - The type of the rule's configuration value
21
+ * @template O - The type of the rule's options
22
+ */
17
23
  export class MLRule {
18
24
  constructor(o) {
19
25
  _MLRule_f.set(this, void 0);
@@ -40,6 +46,14 @@ export class MLRule {
40
46
  get v() {
41
47
  return __classPrivateFieldGet(this, _MLRule_v, "f");
42
48
  }
49
+ /**
50
+ * Resolves the full rule information from a ruleset, including node-level
51
+ * and child-node-level overrides.
52
+ *
53
+ * @param ruleSet - The ruleset containing rule definitions and overrides
54
+ * @param ruleName - The name of this rule
55
+ * @returns The global rule info with node and child-node overrides
56
+ */
43
57
  getRuleInfo(ruleSet, ruleName) {
44
58
  const info = this._optimize(ruleSet.rules, ruleName);
45
59
  return {
@@ -48,6 +62,13 @@ export class MLRule {
48
62
  childNodeRules: ruleSet.childNodeRules.map(r => this._optimize(r.rules, ruleName)).filter(r => !r.disabled),
49
63
  };
50
64
  }
65
+ /**
66
+ * Normalizes a raw rule setting into a fully resolved {@link RuleInfo} object,
67
+ * applying defaults for any unspecified fields.
68
+ *
69
+ * @param configSettings - The raw rule configuration value
70
+ * @returns The resolved rule info with defaults applied
71
+ */
51
72
  optimizeOption(configSettings) {
52
73
  if (configSettings === undefined || typeof configSettings === 'boolean') {
53
74
  return {
@@ -79,6 +100,15 @@ export class MLRule {
79
100
  reason: undefined,
80
101
  };
81
102
  }
103
+ /**
104
+ * Executes this rule's verify (and optionally fix) function against a document,
105
+ * then collects and returns the resulting violations.
106
+ *
107
+ * @param document - The parsed document to verify
108
+ * @param locale - The locale set for translating violation messages
109
+ * @param fix - Whether to also run the fix function
110
+ * @returns An array of violations found by this rule
111
+ */
82
112
  async verify(
83
113
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
84
114
  document, locale, fix) {
@@ -2,6 +2,13 @@ import type { MLRuleContext } from './ml-rule-context.js';
2
2
  import type { Attr, Element } from '../ml-dom/index.js';
3
3
  import type { Translator } from '@markuplint/i18n';
4
4
  import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
+ /**
6
+ * The definition of a markuplint rule, including verification logic, optional fix logic,
7
+ * and default configuration values.
8
+ *
9
+ * @template T - The type of the rule's configuration value (defaults to boolean)
10
+ * @template O - The type of the rule's options
11
+ */
5
12
  export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
6
13
  readonly meta?: {
7
14
  readonly category?: 'validation' | 'style' | 'naming-convention' | 'a11y' | 'maintainability';
@@ -12,12 +19,46 @@ export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData =
12
19
  verify(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
13
20
  fix?(context: ReturnType<MLRuleContext<T, O>['provide']>): void | Promise<void>;
14
21
  };
22
+ /**
23
+ * A generic checker function that produces a violation report from parameters.
24
+ *
25
+ * @template T - The type of the rule's configuration value
26
+ * @template O - The type of the rule's options
27
+ * @template P - Additional parameters passed to the checker
28
+ */
15
29
  export type Checker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P) => CheckerReport<T, O>;
30
+ /**
31
+ * A checker function that verifies a specific element and produces a violation report.
32
+ *
33
+ * @template T - The type of the rule's configuration value
34
+ * @template O - The type of the rule's options
35
+ * @template P - Additional parameters passed alongside the element
36
+ */
16
37
  export type ElementChecker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P & {
17
38
  el: Element<T, O>;
18
39
  }) => CheckerReport<T, O>;
40
+ /**
41
+ * A checker function that verifies a specific attribute and produces a violation report.
42
+ *
43
+ * @template T - The type of the rule's configuration value
44
+ * @template O - The type of the rule's options
45
+ * @template P - Additional parameters passed alongside the attribute
46
+ */
19
47
  export type AttrChecker<T extends RuleConfigValue, O extends PlainData = undefined, P extends Record<string, unknown> = {}> = (params: P & {
20
48
  attr: Attr<T, O>;
21
49
  }) => CheckerReport<T, O>;
50
+ /**
51
+ * A function that receives a translator and returns a violation report, or `null`/`undefined`
52
+ * if no violation was found.
53
+ *
54
+ * @template T - The type of the rule's configuration value
55
+ * @template O - The type of the rule's options
56
+ */
22
57
  export type CheckerReport<T extends RuleConfigValue, O extends PlainData = undefined> = (t: Translator) => Report<T, O> | undefined | null;
58
+ /**
59
+ * A RuleSeed with wildcard value and option types.
60
+ *
61
+ * @template T - The type of the rule's configuration value
62
+ * @template O - The type of the rule's options
63
+ */
23
64
  export type AnyRuleSeed<T extends RuleConfigValue = RuleConfigValue, O extends PlainData = PlainData> = RuleSeed<T, O>;
@@ -1,2 +1,10 @@
1
1
  import type { PluginCreator, CreatePluginSettings } from './types.js';
2
+ /**
3
+ * Factory function for creating a type-safe plugin creator.
4
+ * Returns the creator object as-is; primarily used for type inference.
5
+ *
6
+ * @template S - The settings type accepted by the plugin
7
+ * @param fn - The plugin creator definition
8
+ * @returns The same creator object, now fully typed
9
+ */
2
10
  export declare function createPlugin<S extends CreatePluginSettings>(fn: Readonly<PluginCreator<S>>): Readonly<PluginCreator<S>>;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Factory function for creating a type-safe plugin creator.
3
+ * Returns the creator object as-is; primarily used for type inference.
4
+ *
5
+ * @template S - The settings type accepted by the plugin
6
+ * @param fn - The plugin creator definition
7
+ * @returns The same creator object, now fully typed
8
+ */
1
9
  export function createPlugin(fn) {
2
10
  return fn;
3
11
  }
@@ -1,12 +1,33 @@
1
1
  import type { RuleSeed } from '../ml-rule/index.js';
2
2
  import type { Config } from '@markuplint/ml-config';
3
+ /**
4
+ * A resolved markuplint plugin containing named rules and/or shared configurations.
5
+ */
3
6
  export type Plugin = {
7
+ /** The plugin name, used as a prefix for its rules (e.g. `"my-plugin/rule-name"`) */
4
8
  readonly name: string;
9
+ /** Custom rules provided by this plugin */
5
10
  readonly rules?: Readonly<Record<string, Readonly<RuleSeed<any, any>>>>;
11
+ /** Shared configurations that users can extend from */
6
12
  readonly configs?: Readonly<Record<string, Config>>;
7
13
  };
14
+ /**
15
+ * A factory interface for creating plugins with custom settings.
16
+ *
17
+ * @template S - The settings type accepted by the plugin creator
18
+ */
8
19
  export type PluginCreator<S extends CreatePluginSettings> = {
20
+ /** The plugin name */
9
21
  readonly name: string;
22
+ /**
23
+ * Creates the plugin's rules and configs from the given settings.
24
+ *
25
+ * @param setting - The user-provided settings for this plugin
26
+ * @returns The plugin's rules and configurations
27
+ */
10
28
  create(setting: S): Omit<Plugin, 'name'>;
11
29
  };
30
+ /**
31
+ * Base type for plugin settings. A readonly record of string keys to unknown values.
32
+ */
12
33
  export type CreatePluginSettings = Readonly<Record<string, unknown>>;
@@ -1,7 +1,17 @@
1
1
  import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config';
2
+ /**
3
+ * A resolved set of rules, node-specific rule overrides, and child-node-specific
4
+ * rule overrides extracted from a markuplint {@link Config}.
5
+ */
2
6
  export declare class Ruleset {
7
+ /** Rule overrides that apply to child nodes matching specific selectors */
3
8
  readonly childNodeRules: readonly ChildNodeRule[];
9
+ /** Rule overrides that apply to nodes matching specific selectors */
4
10
  readonly nodeRules: readonly NodeRule[];
11
+ /** The global rule definitions */
5
12
  readonly rules: Rules;
13
+ /**
14
+ * @param config - The markuplint configuration to extract rules from
15
+ */
6
16
  constructor(config: Config);
7
17
  }
@@ -1,4 +1,11 @@
1
+ /**
2
+ * A resolved set of rules, node-specific rule overrides, and child-node-specific
3
+ * rule overrides extracted from a markuplint {@link Config}.
4
+ */
1
5
  export class Ruleset {
6
+ /**
7
+ * @param config - The markuplint configuration to extract rules from
8
+ */
2
9
  constructor(config) {
3
10
  this.rules = config.rules ?? {};
4
11
  this.nodeRules = config.nodeRules ?? [];
@@ -5,19 +5,60 @@ import type { MLASTNode, MLASTToken, MLParser } from '@markuplint/ml-ast';
5
5
  import type { Config, PlainData, Pretender, RuleConfigValue } from '@markuplint/ml-config';
6
6
  import type { MLMLSpec } from '@markuplint/ml-spec';
7
7
  import { MLDocument } from '../ml-dom/node/document.js';
8
+ /**
9
+ * Options for creating test documents and elements.
10
+ */
8
11
  export type CreateTestOptions = {
12
+ /** The markuplint configuration to apply */
9
13
  readonly config?: Config;
14
+ /** A parser module or parser instance to use instead of the default HTML parser */
10
15
  readonly parser?: {
11
16
  readonly parser: Readonly<MLParser>;
12
17
  } | Readonly<MLParser>;
18
+ /** The HTML/ARIA specification data to use */
13
19
  readonly specs?: MLMLSpec;
20
+ /** Pretender definitions for component mapping */
14
21
  readonly pretenders?: readonly Pretender[];
15
22
  };
23
+ /**
24
+ * Parses markup source code and returns a test document for use in rule tests.
25
+ *
26
+ * @template T - The rule config value type
27
+ * @template O - The rule options type
28
+ * @param sourceCode - The markup source code to parse
29
+ * @param options - Options for parser, config, specs, and pretenders
30
+ * @returns A parsed MLDocument instance
31
+ */
16
32
  export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(sourceCode: string, options?: CreateTestOptions): MLDocument<T, O>;
33
+ /**
34
+ * Parses markup source code and returns the flat list of AST nodes.
35
+ *
36
+ * @param sourceCode - The markup source code to parse
37
+ * @param options - Options for parser, config, specs, and pretenders
38
+ * @returns A readonly array of all nodes in the parsed document
39
+ */
17
40
  export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly MLNode<any, any, MLASTNode>[];
41
+ /**
42
+ * Parses markup source code and returns the flat list of tokens.
43
+ *
44
+ * @param sourceCode - The markup source code to parse
45
+ * @param options - Options for parser, config, specs, and pretenders
46
+ * @returns A readonly array of all tokens in the parsed document
47
+ */
18
48
  export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly MLToken<MLASTToken>[];
49
+ /**
50
+ * Parses markup source code and returns the first element node.
51
+ * Throws if the source does not produce an element as its first node.
52
+ *
53
+ * @param sourceCode - The markup source code containing an element
54
+ * @param options - Options for parser, config, specs, and pretenders
55
+ * @returns The first element in the parsed document
56
+ * @throws {TypeError} If the first node is not an element
57
+ */
19
58
  export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): MLElement<any, any>;
20
59
  /**
21
- * for test suite
60
+ * Returns the default HTML spec as a schema tuple for use in test suites.
61
+ *
62
+ * @returns A single-element tuple containing the HTML specification
22
63
  */
23
64
  export declare function dummySchemas(): [MLMLSpec];