@markuplint/ml-core 4.13.2 → 4.18.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 (80) hide show
  1. package/ARCHITECTURE.ja.md +467 -0
  2. package/ARCHITECTURE.md +467 -0
  3. package/CHANGELOG.md +14 -2
  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 +98 -4
  55. package/lib/ml-dom/node/document.js +87 -2
  56. package/lib/ml-dom/node/element.d.ts +164 -11
  57. package/lib/ml-dom/node/element.js +135 -6
  58. package/lib/ml-dom/node/node.d.ts +23 -0
  59. package/lib/ml-dom/node/node.js +29 -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 +14 -14
@@ -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];
package/lib/test/index.js CHANGED
@@ -2,6 +2,15 @@ import { parser } from '@markuplint/html-parser';
2
2
  import spec from '@markuplint/html-spec';
3
3
  import { convertRuleset } from '../convert-ruleset.js';
4
4
  import { MLDocument } from '../ml-dom/node/document.js';
5
+ /**
6
+ * Parses markup source code and returns a test document for use in rule tests.
7
+ *
8
+ * @template T - The rule config value type
9
+ * @template O - The rule options type
10
+ * @param sourceCode - The markup source code to parse
11
+ * @param options - Options for parser, config, specs, and pretenders
12
+ * @returns A parsed MLDocument instance
13
+ */
5
14
  export function createTestDocument(sourceCode, options) {
6
15
  const ast = options?.parser
7
16
  ? 'parser' in options.parser
@@ -12,14 +21,37 @@ export function createTestDocument(sourceCode, options) {
12
21
  const document = new MLDocument(ast, ruleset, [options?.specs ?? {}, {}]);
13
22
  return document;
14
23
  }
24
+ /**
25
+ * Parses markup source code and returns the flat list of AST nodes.
26
+ *
27
+ * @param sourceCode - The markup source code to parse
28
+ * @param options - Options for parser, config, specs, and pretenders
29
+ * @returns A readonly array of all nodes in the parsed document
30
+ */
15
31
  export function createTestNodeList(sourceCode, options) {
16
32
  const document = createTestDocument(sourceCode, options);
17
33
  return document.nodeList;
18
34
  }
35
+ /**
36
+ * Parses markup source code and returns the flat list of tokens.
37
+ *
38
+ * @param sourceCode - The markup source code to parse
39
+ * @param options - Options for parser, config, specs, and pretenders
40
+ * @returns A readonly array of all tokens in the parsed document
41
+ */
19
42
  export function createTestTokenList(sourceCode, options) {
20
43
  const document = createTestDocument(sourceCode, options);
21
44
  return document.getTokenList();
22
45
  }
46
+ /**
47
+ * Parses markup source code and returns the first element node.
48
+ * Throws if the source does not produce an element as its first node.
49
+ *
50
+ * @param sourceCode - The markup source code containing an element
51
+ * @param options - Options for parser, config, specs, and pretenders
52
+ * @returns The first element in the parsed document
53
+ * @throws {TypeError} If the first node is not an element
54
+ */
23
55
  export function createTestElement(sourceCode, options) {
24
56
  const document = createTestDocument(sourceCode, options);
25
57
  const el = document.nodeList[0];
@@ -29,7 +61,9 @@ export function createTestElement(sourceCode, options) {
29
61
  throw new TypeError(`Could not parse it to be an element from: ${sourceCode}`);
30
62
  }
31
63
  /**
32
- * for test suite
64
+ * Returns the default HTML spec as a schema tuple for use in test suites.
65
+ *
66
+ * @returns A single-element tuple containing the HTML specification
33
67
  */
34
68
  export function dummySchemas() {
35
69
  return [spec];
package/lib/types.d.ts CHANGED
@@ -4,7 +4,15 @@ import type { LocaleSet } from '@markuplint/i18n';
4
4
  import type { MLParser, ParserOptions } from '@markuplint/ml-ast';
5
5
  import type { Pretender, SeverityOptions } from '@markuplint/ml-config';
6
6
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
7
+ /**
8
+ * A tuple of the base HTML/ARIA specification and zero or more
9
+ * framework-specific extended specs (e.g. React, Vue, Svelte).
10
+ */
7
11
  export type MLSchema = readonly [MLMLSpec, ...ExtendedSpec[]];
12
+ /**
13
+ * The set of dependencies required by {@link MLCore} to perform linting.
14
+ * Includes the parser, ruleset, rules, locale, schemas, and other settings.
15
+ */
8
16
  export type MLFabric = {
9
17
  readonly parser: Readonly<MLParser>;
10
18
  readonly ruleset: Partial<Readonly<Ruleset>>;
@@ -1,12 +1,45 @@
1
1
  import type { Violation } from '@markuplint/ml-config';
2
+ /**
3
+ * Collects and manages lint violations across multiple files.
4
+ * Supports a maximum violation count to stop collecting early.
5
+ */
2
6
  export declare class ViolationCollector {
3
7
  #private;
8
+ /**
9
+ * @param maxCount - Maximum number of violations to collect; 0 means unlimited
10
+ */
4
11
  constructor(maxCount?: number);
12
+ /**
13
+ * Adds violations associated with a specific file path.
14
+ * Stops collecting once the maximum count is reached.
15
+ *
16
+ * @param filePath - The file that produced these violations
17
+ * @param violations - The violations to add
18
+ * @returns The current total number of collected violations
19
+ */
5
20
  pushWithFile(filePath: string, ...violations: readonly Violation[]): number;
21
+ /**
22
+ * The total number of collected violations.
23
+ */
6
24
  get length(): number;
25
+ /**
26
+ * Whether the collector has reached its maximum count and will no longer accept violations.
27
+ *
28
+ * @returns `true` if the collector is locked
29
+ */
7
30
  isLocked(): boolean;
31
+ /**
32
+ * Returns a copy of all collected violations as an array.
33
+ *
34
+ * @returns An array of violations with their associated file paths
35
+ */
8
36
  toArray(): (Violation & {
9
37
  filePath: string;
10
38
  })[];
39
+ /**
40
+ * Groups collected violations by their file path.
41
+ *
42
+ * @returns A Map from file path to an array of violations for that file
43
+ */
11
44
  groupByFile(): Map<string, Violation[]>;
12
45
  }
@@ -10,7 +10,14 @@ 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 _ViolationCollector_violations, _ViolationCollector_maxCount, _ViolationCollector_locked;
13
+ /**
14
+ * Collects and manages lint violations across multiple files.
15
+ * Supports a maximum violation count to stop collecting early.
16
+ */
13
17
  export class ViolationCollector {
18
+ /**
19
+ * @param maxCount - Maximum number of violations to collect; 0 means unlimited
20
+ */
14
21
  constructor(maxCount = 0) {
15
22
  _ViolationCollector_violations.set(this, []);
16
23
  _ViolationCollector_maxCount.set(this, 0);
@@ -18,6 +25,14 @@ export class ViolationCollector {
18
25
  __classPrivateFieldSet(this, _ViolationCollector_maxCount, maxCount, "f");
19
26
  __classPrivateFieldSet(this, _ViolationCollector_locked, false, "f");
20
27
  }
28
+ /**
29
+ * Adds violations associated with a specific file path.
30
+ * Stops collecting once the maximum count is reached.
31
+ *
32
+ * @param filePath - The file that produced these violations
33
+ * @param violations - The violations to add
34
+ * @returns The current total number of collected violations
35
+ */
21
36
  pushWithFile(filePath, ...violations) {
22
37
  if (__classPrivateFieldGet(this, _ViolationCollector_locked, "f")) {
23
38
  return __classPrivateFieldGet(this, _ViolationCollector_violations, "f").length;
@@ -31,15 +46,33 @@ export class ViolationCollector {
31
46
  }
32
47
  return __classPrivateFieldGet(this, _ViolationCollector_violations, "f").length;
33
48
  }
49
+ /**
50
+ * The total number of collected violations.
51
+ */
34
52
  get length() {
35
53
  return __classPrivateFieldGet(this, _ViolationCollector_violations, "f").length;
36
54
  }
55
+ /**
56
+ * Whether the collector has reached its maximum count and will no longer accept violations.
57
+ *
58
+ * @returns `true` if the collector is locked
59
+ */
37
60
  isLocked() {
38
61
  return __classPrivateFieldGet(this, _ViolationCollector_locked, "f");
39
62
  }
63
+ /**
64
+ * Returns a copy of all collected violations as an array.
65
+ *
66
+ * @returns An array of violations with their associated file paths
67
+ */
40
68
  toArray() {
41
69
  return [...__classPrivateFieldGet(this, _ViolationCollector_violations, "f")];
42
70
  }
71
+ /**
72
+ * Groups collected violations by their file path.
73
+ *
74
+ * @returns A Map from file path to an array of violations for that file
75
+ */
43
76
  groupByFile() {
44
77
  const grouped = new Map();
45
78
  for (const violation of __classPrivateFieldGet(this, _ViolationCollector_violations, "f")) {