@markuplint/ml-config 5.0.0-alpha.2 → 5.0.0-dev.5

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.
@@ -96,6 +96,13 @@ type RuleConfig<T, O> = {
96
96
  - `OriginalNode` -- 要素名、スロット、名前空間、属性、継承属性、ARIA プロパティを定義
97
97
  - `PretenderDetails` -- マージ後に使用される正規化形式 `{data?, files?, imports?}`
98
98
 
99
+ ### 自動修正型
100
+
101
+ - `TextEdit` -- ソースコードの単一置換: `{ range: [start, end), text }`。`text` が空文字列の場合は削除を意味する
102
+ - `FixData` -- 1つ以上の `TextEdit` をアトミックに適用する単位。`FixData` 内のいずれかの edit が他の `FixData` と重複すると、グループ全体がスキップされる
103
+ - `FixToken` -- `IRuleFixer` メソッドが受け付ける最小トークン型(`{ startOffset, raw }`)。すべての MLDOM トークンはこの制約を満たす
104
+ - `IRuleFixer` -- fix コールバック内で `TextEdit` を構築するためのインターフェース。`replaceText`、`replaceRange`、`insertBefore`、`insertAfter`、`remove`、`removeRange` を提供
105
+
99
106
  ## マージアルゴリズム
100
107
 
101
108
  このパッケージの中核です。`mergeConfig()` 関数はプロパティごとの戦略で2つの設定を統合します。
@@ -225,7 +232,7 @@ Mustache テンプレート文字列を提供されたデータでレンダリ
225
232
 
226
233
  | ファイル | 目的 |
227
234
  | --------------------- | ------------------------------------------------------------------------------------------------------- |
228
- | `src/types.ts` | 全型定義(Config, Rule, Pretender, Violation 等) |
235
+ | `src/types.ts` | 全型定義(Config, Rule, Pretender, Violation, FixToken, IRuleFixer 等) |
229
236
  | `src/merge-config.ts` | `mergeConfig()`、`mergeRule()`、全ヘルパー関数 |
230
237
  | `src/utils.ts` | `provideValue()`、`exchangeValueOnRule()`、`cleanOptions()`、`isRuleConfigValue()`、`deleteUndefProp()` |
231
238
  | `src/index.ts` | 全公開 API の再エクスポート |
package/ARCHITECTURE.md CHANGED
@@ -96,6 +96,13 @@ type RuleConfig<T, O> = {
96
96
  - `OriginalNode` -- Defines an element's name, slots, namespace, attributes, inherited attributes, and ARIA properties
97
97
  - `PretenderDetails` -- Normalized form `{data?, files?, imports?}` used after merging
98
98
 
99
+ ### Autofix Types
100
+
101
+ - `TextEdit` -- A single source code replacement: `{ range: [start, end), text }`. An empty `text` means deletion
102
+ - `FixData` -- Contains one or more `TextEdit`s to apply atomically. If any edit in a `FixData` overlaps with another `FixData`, the entire group is skipped
103
+ - `FixToken` -- Minimal token shape (`{ startOffset, raw }`) accepted by `IRuleFixer` methods. Any MLDOM token satisfies this constraint
104
+ - `IRuleFixer` -- Interface for building `TextEdit`s inside fix callbacks. Provides `replaceText`, `replaceRange`, `insertBefore`, `insertAfter`, `remove`, and `removeRange`
105
+
99
106
  ## Merge Algorithm
100
107
 
101
108
  This is the core of the package. The `mergeConfig()` function combines two configurations with property-specific strategies.
@@ -225,7 +232,7 @@ This function is used by `nodeRules` and `childNodeRules` with `regexSelector`,
225
232
 
226
233
  | File | Purpose |
227
234
  | --------------------- | ------------------------------------------------------------------------------------------------------- |
228
- | `src/types.ts` | All type definitions (Config, Rule, Pretender, Violation, etc.) |
235
+ | `src/types.ts` | All type definitions (Config, Rule, Pretender, Violation, FixToken, IRuleFixer, etc.) |
229
236
  | `src/merge-config.ts` | `mergeConfig()`, `mergeRule()`, and all helper functions |
230
237
  | `src/utils.ts` | `provideValue()`, `exchangeValueOnRule()`, `cleanOptions()`, `isRuleConfigValue()`, `deleteUndefProp()` |
231
238
  | `src/index.ts` | Re-exports all public APIs |
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.0.0-alpha.3](https://github.com/markuplint/markuplint/compare/v5.0.0-alpha.2...v5.0.0-alpha.3) (2026-02-26)
7
+
8
+ ### Features
9
+
10
+ - **ml-config:** add FixToken type and JSDoc to IRuleFixer methods ([c39d3ce](https://github.com/markuplint/markuplint/commit/c39d3ceaf81ba131d4c1d0efb500d36f327081c4))
11
+
6
12
  # [5.0.0-alpha.2](https://github.com/markuplint/markuplint/compare/v5.0.0-alpha.1...v5.0.0-alpha.2) (2026-02-23)
7
13
 
8
14
  ### Features
@@ -35,7 +35,8 @@ export function mergeConfig(a, b) {
35
35
  severity: mergeObject(a.severity, b.severity),
36
36
  pretenders: mergePretenders(a.pretenders, b.pretenders),
37
37
  rules: mergeRules(
38
- // TODO: Deep merge
38
+ // Shallow merge: rule-level options are replaced entirely by the overriding config.
39
+ // Deep merging individual rule options would require schema-aware merging logic.
39
40
  a.rules, b.rules),
40
41
  nodeRules: concatArray(a.nodeRules, b.nodeRules, true, 'name'),
41
42
  childNodeRules: concatArray(a.childNodeRules, b.childNodeRules, true, 'name'),
package/lib/types.d.ts CHANGED
@@ -472,27 +472,64 @@ export type TextEdit = {
472
472
  export type FixData = {
473
473
  readonly edits: readonly TextEdit[];
474
474
  };
475
+ /**
476
+ * Minimal token shape required by {@link IRuleFixer} methods.
477
+ * Any object with a character offset and raw source text satisfies this constraint.
478
+ */
479
+ export type FixToken = {
480
+ readonly startOffset: number;
481
+ readonly raw: string;
482
+ };
475
483
  /**
476
484
  * A helper interface for building {@link TextEdit}s inside a fix callback.
477
485
  * Passed to the `fix` function on {@link Report1} and {@link Report2}.
478
486
  */
479
487
  export interface IRuleFixer {
480
- replaceText(token: {
481
- readonly startOffset: number;
482
- readonly raw: string;
483
- }, text: string): TextEdit;
488
+ /**
489
+ * Replaces a token's entire text with new content.
490
+ *
491
+ * @param token - The token whose range will be replaced
492
+ * @param text - The replacement text
493
+ * @returns A TextEdit spanning the token's range
494
+ */
495
+ replaceText(token: FixToken, text: string): TextEdit;
496
+ /**
497
+ * Replaces an explicit character range with new content.
498
+ *
499
+ * @param range - The `[start, end)` character offsets to replace
500
+ * @param text - The replacement text
501
+ * @returns A TextEdit spanning the given range
502
+ */
484
503
  replaceRange(range: readonly [number, number], text: string): TextEdit;
485
- insertBefore(token: {
486
- readonly startOffset: number;
487
- }, text: string): TextEdit;
488
- insertAfter(token: {
489
- readonly startOffset: number;
490
- readonly raw: string;
491
- }, text: string): TextEdit;
492
- remove(token: {
493
- readonly startOffset: number;
494
- readonly raw: string;
495
- }): TextEdit;
504
+ /**
505
+ * Inserts text immediately before a token.
506
+ *
507
+ * @param token - The token before which to insert
508
+ * @param text - The text to insert
509
+ * @returns A zero-width TextEdit at the token's start offset
510
+ */
511
+ insertBefore(token: Pick<FixToken, 'startOffset'>, text: string): TextEdit;
512
+ /**
513
+ * Inserts text immediately after a token.
514
+ *
515
+ * @param token - The token after which to insert
516
+ * @param text - The text to insert
517
+ * @returns A zero-width TextEdit at the token's end offset
518
+ */
519
+ insertAfter(token: FixToken, text: string): TextEdit;
520
+ /**
521
+ * Removes a token's entire text from the source.
522
+ *
523
+ * @param token - The token to remove
524
+ * @returns A TextEdit that replaces the token's range with an empty string
525
+ */
526
+ remove(token: FixToken): TextEdit;
527
+ /**
528
+ * Removes an explicit character range from the source.
529
+ *
530
+ * @param range - The `[start, end)` character offsets to remove
531
+ * @returns A TextEdit that replaces the range with an empty string
532
+ */
496
533
  removeRange(range: readonly [number, number]): TextEdit;
497
534
  }
498
535
  /**
package/lib/utils.js CHANGED
@@ -138,7 +138,7 @@ export function deleteUndefProp(obj) {
138
138
  if (!isPlainObject(obj)) {
139
139
  return;
140
140
  }
141
- for (const key in obj) {
141
+ for (const key of Object.keys(obj)) {
142
142
  if (obj[key] === undefined) {
143
143
  delete obj[key];
144
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-config",
3
- "version": "5.0.0-alpha.2",
3
+ "version": "5.0.0-dev.5+e96392f56",
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>",
@@ -27,14 +27,14 @@
27
27
  "clean": "tsc --build --clean tsconfig.build.json"
28
28
  },
29
29
  "dependencies": {
30
- "@markuplint/ml-ast": "5.0.0-alpha.2",
31
- "@markuplint/ml-spec": "5.0.0-alpha.2",
32
- "@markuplint/selector": "5.0.0-alpha.2",
33
- "@markuplint/shared": "5.0.0-alpha.2",
30
+ "@markuplint/ml-ast": "5.0.0-dev.5+e96392f56",
31
+ "@markuplint/ml-spec": "5.0.0-dev.5+e96392f56",
32
+ "@markuplint/selector": "5.0.0-dev.5+e96392f56",
33
+ "@markuplint/shared": "5.0.0-dev.5+e96392f56",
34
34
  "@types/mustache": "4.2.6",
35
35
  "is-plain-object": "5.0.0",
36
36
  "mustache": "4.2.0",
37
37
  "type-fest": "5.4.4"
38
38
  },
39
- "gitHead": "31ccf1e81443ea3f93597d287595211f1823ddcf"
39
+ "gitHead": "e96392f56e4bc8165ba59622b41c822703a96372"
40
40
  }