@markuplint/ml-config 4.8.13 → 4.8.15

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.
package/lib/types.d.ts CHANGED
@@ -2,6 +2,10 @@ import type { ParserOptions } from '@markuplint/ml-ast';
2
2
  import type { RegexSelector } from '@markuplint/selector';
3
3
  import type { Nullable } from '@markuplint/shared';
4
4
  export type { RegexSelector } from '@markuplint/selector';
5
+ /**
6
+ * The root configuration object for markuplint.
7
+ * Defines rules, parsers, specs, plugins, and overrides for linting markup.
8
+ */
5
9
  export type Config = {
6
10
  readonly $schema?: string;
7
11
  readonly extends?: string | readonly string[];
@@ -18,32 +22,65 @@ export type Config = {
18
22
  readonly overrideMode?: 'merge' | 'reset';
19
23
  readonly overrides?: Readonly<Record<string, OverrideConfig>>;
20
24
  };
25
+ /**
26
+ * A primitive scalar value that can appear in rule configuration.
27
+ */
21
28
  export type PrimitiveScalar = string | number | boolean;
29
+ /**
30
+ * A JSON-compatible data structure used for rule options and plugin settings.
31
+ * Can be a primitive, null/undefined, an array of `PlainData`, or a plain object.
32
+ */
22
33
  export type PlainData = Nullable<PrimitiveScalar> | readonly PlainData[] | {
23
34
  readonly [key: string]: PlainData | any;
24
35
  };
36
+ /**
37
+ * A non-nullable variant of {@link PlainData}, excluding `null` and `undefined`.
38
+ */
25
39
  export type NonNullablePlainData = PrimitiveScalar | readonly NonNullablePlainData[] | {
26
40
  readonly [key: string]: NonNullablePlainData;
27
41
  };
28
42
  type NoInherit = '$schema' | 'extends' | 'overrideMode' | 'overrides';
43
+ /**
44
+ * Configuration applied to specific file patterns via the `overrides` field.
45
+ * Excludes top-level-only properties like `$schema`, `extends`, `overrideMode`, and `overrides`.
46
+ */
29
47
  export type OverrideConfig = Omit<Config, NoInherit>;
48
+ /**
49
+ * A fully resolved and optimized configuration after merging.
50
+ * Plugins are normalized to objects, and pretenders are converted to {@link PretenderDetails}.
51
+ */
30
52
  export type OptimizedConfig = Omit<Config, '$schema' | 'extends' | 'plugins' | 'pretenders' | 'overrides'> & {
31
53
  readonly extends?: readonly string[];
32
54
  readonly plugins?: readonly PluginConfig[];
33
55
  readonly pretenders?: PretenderDetails;
34
56
  readonly overrides?: Readonly<Record<string, OptimizedOverrideConfig>>;
35
57
  };
58
+ /**
59
+ * An optimized override configuration, excluding top-level-only properties.
60
+ */
36
61
  export type OptimizedOverrideConfig = Omit<OptimizedConfig, NoInherit>;
62
+ /**
63
+ * Configuration for a single markuplint plugin.
64
+ */
37
65
  export type PluginConfig = {
38
66
  readonly name: string;
39
67
  readonly settings?: Readonly<Record<string, NonNullablePlainData>>;
40
68
  };
69
+ /**
70
+ * Maps file extension patterns to parser module names or paths.
71
+ */
41
72
  export type ParserConfig = {
42
73
  readonly [extensionPattern: string]: string;
43
74
  };
75
+ /**
76
+ * Maps file extension patterns to spec module names or paths.
77
+ */
44
78
  export type SpecConfig = {
45
79
  readonly [extensionPattern: string]: string;
46
80
  };
81
+ /**
82
+ * Options for controlling the severity of specific diagnostic categories.
83
+ */
47
84
  export type SeverityOptions = {
48
85
  readonly parseError?: Severity | 'off' | boolean;
49
86
  };
@@ -58,6 +95,9 @@ export type PretenderDetails = {
58
95
  readonly imports?: readonly string[];
59
96
  readonly data?: readonly Pretender[];
60
97
  };
98
+ /**
99
+ * Data structure for a pretender definition file.
100
+ */
61
101
  export type PretenderFileData = {
62
102
  readonly version: string;
63
103
  readonly data: readonly Pretender[];
@@ -218,23 +258,45 @@ export interface PretenderScanOptions {
218
258
  readonly cwd?: string;
219
259
  readonly ignoreComponentNames?: readonly string[];
220
260
  }
261
+ /**
262
+ * A rule setting: either a full {@link RuleConfig} object, a direct value, or a boolean to enable/disable.
263
+ *
264
+ * @template T - The type of the rule's value
265
+ * @template O - The type of the rule's options
266
+ */
221
267
  export type Rule<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfig<T, O> | Readonly<T> | boolean;
222
268
  /**
223
269
  * @deprecated
224
270
  */
225
271
  export type RuleV2<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfigV2<T, O> | Readonly<T> | boolean;
272
+ /**
273
+ * A rule setting with any value and option types.
274
+ */
226
275
  export type AnyRule = Rule<RuleConfigValue, PlainData>;
227
276
  /**
228
277
  * @deprecated
229
278
  */
230
279
  export type AnyRuleV2 = RuleV2<RuleConfigValue, PlainData>;
280
+ /**
281
+ * A dictionary mapping rule names to their configurations.
282
+ */
231
283
  export type Rules = {
232
284
  readonly [ruleName: string]: AnyRule;
233
285
  };
286
+ /**
287
+ * Full configuration for a single rule, specifying severity, value, options, and reason.
288
+ *
289
+ * @template T - The type of the rule's value
290
+ * @template O - The type of the rule's options
291
+ */
234
292
  export type RuleConfig<T extends RuleConfigValue, O extends PlainData = undefined> = {
293
+ /** The severity level for violations of this rule */
235
294
  readonly severity?: Severity;
295
+ /** The rule's primary configuration value */
236
296
  readonly value?: Readonly<T>;
297
+ /** Additional options for the rule */
237
298
  readonly options?: Readonly<O>;
299
+ /** A human-readable reason for this rule configuration, included in violation messages */
238
300
  readonly reason?: string;
239
301
  };
240
302
  /**
@@ -252,8 +314,18 @@ export type RuleConfigV2<T extends RuleConfigValue, O extends PlainData = undefi
252
314
  */
253
315
  readonly option?: Readonly<O>;
254
316
  };
317
+ /**
318
+ * The severity level of a lint violation.
319
+ */
255
320
  export type Severity = 'error' | 'warning' | 'info';
321
+ /**
322
+ * The value portion of a rule configuration. Can be a primitive scalar,
323
+ * an array of scalars or objects, or `null` to represent no value.
324
+ */
256
325
  export type RuleConfigValue = PrimitiveScalar | readonly (PrimitiveScalar | Readonly<Record<string, any>>)[] | null;
326
+ /**
327
+ * A rule override that targets specific nodes by CSS selector, regex selector, ARIA roles, or categories.
328
+ */
257
329
  export type NodeRule = {
258
330
  readonly selector?: string;
259
331
  readonly regexSelector?: RegexSelector;
@@ -262,29 +334,57 @@ export type NodeRule = {
262
334
  readonly obsolete?: boolean;
263
335
  readonly rules?: Rules;
264
336
  };
337
+ /**
338
+ * A rule override that targets child nodes of elements matching the selector.
339
+ */
265
340
  export type ChildNodeRule = {
266
341
  readonly selector?: string;
267
342
  readonly regexSelector?: RegexSelector;
268
343
  readonly inheritance?: boolean;
269
344
  readonly rules?: Rules;
270
345
  };
346
+ /**
347
+ * A violation report from a rule. Can report against a scope (node-based)
348
+ * or against explicit line/column coordinates, or both.
349
+ *
350
+ * @template T - The type of the rule's value
351
+ * @template O - The type of the rule's options
352
+ */
271
353
  export type Report<T extends RuleConfigValue, O extends PlainData = undefined> = Report1<T, O> | Report2 | (Report1<T, O> & Report2);
354
+ /**
355
+ * A scope-based violation report, referencing the rule info and position via a {@link Scope}.
356
+ *
357
+ * @template T - The type of the rule's value
358
+ * @template O - The type of the rule's options
359
+ */
272
360
  export type Report1<T extends RuleConfigValue, O extends PlainData = undefined> = {
273
361
  readonly message: string;
274
362
  readonly scope: Scope<T, O>;
275
363
  };
364
+ /**
365
+ * A coordinate-based violation report with explicit line, column, and raw text.
366
+ */
276
367
  export type Report2 = {
277
368
  readonly message: string;
278
369
  readonly line: number;
279
370
  readonly col: number;
280
371
  readonly raw: string;
281
372
  };
373
+ /**
374
+ * Identifies the location and rule context of a reported violation.
375
+ *
376
+ * @template T - The type of the rule's value
377
+ * @template O - The type of the rule's options
378
+ */
282
379
  export type Scope<T extends RuleConfigValue, O extends PlainData = undefined> = {
283
380
  readonly rule: RuleInfo<T, O>;
284
381
  readonly startLine: number;
285
382
  readonly startCol: number;
286
383
  readonly raw: string;
287
384
  };
385
+ /**
386
+ * A fully resolved lint violation with all information needed for reporting.
387
+ */
288
388
  export type Violation = {
289
389
  readonly ruleId: string;
290
390
  readonly severity: Severity;
@@ -294,6 +394,12 @@ export type Violation = {
294
394
  readonly col: number;
295
395
  readonly raw: string;
296
396
  };
397
+ /**
398
+ * Resolved rule information after configuration merging, used at runtime by rules.
399
+ *
400
+ * @template T - The type of the rule's value
401
+ * @template O - The type of the rule's options
402
+ */
297
403
  export type RuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = {
298
404
  readonly disabled: boolean;
299
405
  readonly severity: Severity;
@@ -301,6 +407,12 @@ export type RuleInfo<T extends RuleConfigValue, O extends PlainData = undefined>
301
407
  readonly options: Readonly<O>;
302
408
  readonly reason?: string;
303
409
  };
410
+ /**
411
+ * Extended rule information that includes node-level and child-node-level overrides.
412
+ *
413
+ * @template T - The type of the rule's value
414
+ * @template O - The type of the rule's options
415
+ */
304
416
  export type GlobalRuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = RuleInfo<T, O> & {
305
417
  nodeRules: RuleInfo<T, O>[];
306
418
  childNodeRules: RuleInfo<T, O>[];
package/lib/utils.d.ts CHANGED
@@ -1,18 +1,45 @@
1
1
  import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfigValue } from './types.js';
2
2
  /**
3
- * Return undefined if the template doesn't include the variable that is set as a property in data.
4
- * But return template string without changes if it doesn't have a variable.
3
+ * Renders a Mustache template with the provided data.
5
4
  *
6
- * @param template Mustache template string
7
- * @param data Captured string for replacement
5
+ * Returns `undefined` if the template contains variables but none of them
6
+ * are present in `data`. Returns the template unchanged if it has no variables.
7
+ *
8
+ * @param template - A Mustache template string with `{{variable}}` placeholders
9
+ * @param data - Key-value pairs for template variable replacement
10
+ * @returns The rendered string, or `undefined` if no matching variables were found
8
11
  */
9
12
  export declare function provideValue(template: string, data: Readonly<Record<string, string>>): string | undefined;
13
+ /**
14
+ * Applies Mustache template rendering to all string values within a rule configuration,
15
+ * including the rule's value, options, and reason fields.
16
+ *
17
+ * @param rule - The rule configuration containing potential template strings
18
+ * @param data - Key-value pairs for template variable replacement
19
+ * @returns The rule with all template strings rendered, or `undefined` if rendering fails
20
+ */
10
21
  export declare function exchangeValueOnRule(rule: AnyRule | AnyRuleV2, data: Readonly<Record<string, string>>): AnyRule | undefined;
22
+ /**
23
+ * Normalizes a rule configuration by extracting the standard fields
24
+ * (`severity`, `value`, `options`, `reason`) and removing `undefined` properties.
25
+ * Also handles the deprecated `option` field by mapping it to `options`.
26
+ *
27
+ * @param rule - The rule configuration to normalize
28
+ * @returns A clean rule configuration with only defined properties
29
+ */
11
30
  export declare function cleanOptions(rule: RuleConfig<RuleConfigValue, PlainData> | RuleConfigV2<RuleConfigValue, PlainData>): RuleConfig<RuleConfigValue, PlainData>;
31
+ /**
32
+ * Type guard that checks whether a value is a {@link RuleConfigValue}
33
+ * (i.e. a primitive, `null`, or an array) rather than a full {@link RuleConfig} object.
34
+ *
35
+ * @param v - The value to check
36
+ * @returns `true` if `v` is a rule config value (string, number, boolean, null, or array)
37
+ */
12
38
  export declare function isRuleConfigValue(v: any): v is RuleConfigValue;
13
39
  /**
40
+ * Removes all properties with `undefined` values from a plain object in-place.
41
+ * Has no effect on non-plain-object values.
14
42
  *
15
- * @param obj
16
- * @returns
43
+ * @param obj - The object to clean up
17
44
  */
18
45
  export declare function deleteUndefProp(obj: any): void;
package/lib/utils.js CHANGED
@@ -2,11 +2,14 @@
2
2
  import { isPlainObject } from 'is-plain-object';
3
3
  import mustache from 'mustache';
4
4
  /**
5
- * Return undefined if the template doesn't include the variable that is set as a property in data.
6
- * But return template string without changes if it doesn't have a variable.
5
+ * Renders a Mustache template with the provided data.
7
6
  *
8
- * @param template Mustache template string
9
- * @param data Captured string for replacement
7
+ * Returns `undefined` if the template contains variables but none of them
8
+ * are present in `data`. Returns the template unchanged if it has no variables.
9
+ *
10
+ * @param template - A Mustache template string with `{{variable}}` placeholders
11
+ * @param data - Key-value pairs for template variable replacement
12
+ * @returns The rendered string, or `undefined` if no matching variables were found
10
13
  */
11
14
  export function provideValue(template, data) {
12
15
  const ast = mustache.parse(template);
@@ -22,6 +25,14 @@ export function provideValue(template, data) {
22
25
  }
23
26
  return result;
24
27
  }
28
+ /**
29
+ * Applies Mustache template rendering to all string values within a rule configuration,
30
+ * including the rule's value, options, and reason fields.
31
+ *
32
+ * @param rule - The rule configuration containing potential template strings
33
+ * @param data - Key-value pairs for template variable replacement
34
+ * @returns The rule with all template strings rendered, or `undefined` if rendering fails
35
+ */
25
36
  export function exchangeValueOnRule(rule, data) {
26
37
  if (isRuleConfigValue(rule)) {
27
38
  return exchangeValue(rule, data);
@@ -55,6 +66,14 @@ export function exchangeValueOnRule(rule, data) {
55
66
  deleteUndefProp(result);
56
67
  return result;
57
68
  }
69
+ /**
70
+ * Normalizes a rule configuration by extracting the standard fields
71
+ * (`severity`, `value`, `options`, `reason`) and removing `undefined` properties.
72
+ * Also handles the deprecated `option` field by mapping it to `options`.
73
+ *
74
+ * @param rule - The rule configuration to normalize
75
+ * @returns A clean rule configuration with only defined properties
76
+ */
58
77
  export function cleanOptions(rule) {
59
78
  const res = {
60
79
  severity: rule.severity,
@@ -65,6 +84,13 @@ export function cleanOptions(rule) {
65
84
  deleteUndefProp(res);
66
85
  return res;
67
86
  }
87
+ /**
88
+ * Type guard that checks whether a value is a {@link RuleConfigValue}
89
+ * (i.e. a primitive, `null`, or an array) rather than a full {@link RuleConfig} object.
90
+ *
91
+ * @param v - The value to check
92
+ * @returns `true` if `v` is a rule config value (string, number, boolean, null, or array)
93
+ */
68
94
  export function isRuleConfigValue(v) {
69
95
  switch (typeof v) {
70
96
  case 'string':
@@ -79,9 +105,10 @@ export function isRuleConfigValue(v) {
79
105
  return Array.isArray(v);
80
106
  }
81
107
  /**
108
+ * Removes all properties with `undefined` values from a plain object in-place.
109
+ * Has no effect on non-plain-object values.
82
110
  *
83
- * @param obj
84
- * @returns
111
+ * @param obj - The object to clean up
85
112
  */
86
113
  export function deleteUndefProp(obj) {
87
114
  if (!isPlainObject(obj)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-config",
3
- "version": "4.8.13",
3
+ "version": "4.8.15",
4
4
  "description": "JSON Schema and TypeScript types of markuplint configure JSON",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -24,15 +24,15 @@
24
24
  "clean": "tsc --build --clean tsconfig.build.json"
25
25
  },
26
26
  "dependencies": {
27
- "@markuplint/ml-ast": "4.4.10",
28
- "@markuplint/ml-spec": "4.10.0",
29
- "@markuplint/selector": "4.7.6",
30
- "@markuplint/shared": "4.4.12",
27
+ "@markuplint/ml-ast": "4.4.11",
28
+ "@markuplint/ml-spec": "4.10.2",
29
+ "@markuplint/selector": "4.7.8",
30
+ "@markuplint/shared": "4.4.13",
31
31
  "@types/mustache": "4.2.6",
32
32
  "deepmerge": "4.3.1",
33
33
  "is-plain-object": "5.0.0",
34
34
  "mustache": "4.2.0",
35
35
  "type-fest": "4.41.0"
36
36
  },
37
- "gitHead": "ae97eb2d31ecedf4f0800fbbf18588aad4ebca04"
37
+ "gitHead": "193ee7c1262bbed95424e38efdf1a8e56ff049f4"
38
38
  }