@markuplint/create-rule 5.0.0-rc.2 → 5.0.0-rc.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.
@@ -1,135 +0,0 @@
1
- # @markuplint/create-rule メンテナンスガイド
2
-
3
- ## 概要
4
-
5
- `@markuplint/create-rule` パッケージは、新しい markuplint ルールのボイラープレートファイルを生成する CLI スキャフォルディングツールです。3つのモードをサポートしています:
6
-
7
- - **プロジェクトに追加** — 現在のプロジェクトにローカルプラグインディレクトリを作成
8
- - **パッケージとして公開** — スタンドアロンの npm パッケージをスキャフォルド
9
- - **コアに貢献** — モノレポ内の `@markuplint/rules` にルールを追加
10
-
11
- ### ファイル構成
12
-
13
- ```
14
- packages/@markuplint/create-rule/
15
- ├── bin/
16
- │ └── create-rule.mjs # CLI 実行ファイル
17
- ├── src/
18
- │ ├── cli.ts # 対話ウィザード
19
- │ ├── types.ts # 型定義
20
- │ ├── create-rule-helper.ts # 目的ベースルーター
21
- │ ├── create-rule-to-project.ts
22
- │ ├── create-rule-package.ts
23
- │ ├── create-rule-to-core.ts
24
- │ ├── install-scaffold.ts # スキャフォルドインストーラー
25
- │ └── transfer.ts # テンプレート処理
26
- └── scaffold/
27
- ├── core/ # コアルールテンプレート
28
- ├── project/ # プロジェクトプラグインテンプレート
29
- └── package/ # パッケージテンプレート
30
- ```
31
-
32
- ## テンプレートファイルの編集
33
-
34
- テンプレートファイルは `scaffold/{core,project,package}/` に配置されています。ユーザーが CLI を実行すると、これらのファイルがプレースホルダーを実際の値に置換してコピーされます。
35
-
36
- ### プレースホルダー一覧
37
-
38
- | プレースホルダー | 置換内容 | 入力例 | 出力例 |
39
- | ----------------- | ------------------------------ | -------------- | -------------- |
40
- | `__pluginName__` | プラグイン名(そのまま) | `my-plugin` | `my-plugin` |
41
- | `__pluginName__c` | プラグイン名(キャメルケース) | `my-plugin` | `myPlugin` |
42
- | `__ruleName__` | ルール名(そのまま) | `no-empty-alt` | `no-empty-alt` |
43
- | `__ruleName__c` | ルール名(キャメルケース) | `no-empty-alt` | `noEmptyAlt` |
44
- | `__description__` | ルールの説明(コアのみ) | — | — |
45
- | `__category__` | ルールカテゴリ(コアのみ) | — | — |
46
- | `__severity__` | デフォルト重大度(コアのみ) | — | — |
47
-
48
- ### キャメルケース変換
49
-
50
- `__<name>__c` サフィックスはキャメルケース変換をトリガーします。ハイフンが除去され、次の文字が大文字化されます。例えば、`__ruleName__c` に値 `no-empty-alt` を指定すると `noEmptyAlt` になります。これは生成コード内の変数名に使用されます。
51
-
52
- ### ファイル名の置換
53
-
54
- テンプレートファイル名に含まれる `__ruleName__` は実際のルール名に置換されます。例えば、`rules/__ruleName__.ts` は `rules/no-empty-alt.ts` になります。
55
-
56
- ### TypeScript から JavaScript へのトランスパイル
57
-
58
- ユーザーが JavaScript を選択した場合、すべての `.ts` テンプレートファイルが TypeScript コンパイラ API で `.js` にトランスパイルされます。テンプレートを編集する際は、生成される TypeScript がトランスパイル後も有効な JavaScript になることを確認してください。
59
-
60
- ### Prettier フォーマット
61
-
62
- 生成されるすべてのファイルは Prettier でフォーマットされます。テンプレート内の `// prettier-ignore` コメントはフォーマット前に自動削除されます。これにより、プレースホルダー式がリフォーマットされないようにテンプレート内で `// prettier-ignore` を使用できます。
63
-
64
- ## CLI フローの変更
65
-
66
- 対話的な質問シーケンスは `src/cli.ts` で定義されています。新しい質問を追加するには:
67
-
68
- 1. `@markuplint/cli-utils` のヘルパー(`input()`、`select()`、`confirm()`)を使って質問を追加
69
- 2. `src/types.ts` に対応する型を追加(例: `CreateRuleCreatorParams` の新しいフィールド)
70
- 3. `createRuleHelper()` の呼び出しに値を渡す
71
- 4. 値を `replacer` オプションに渡す必要がある場合は `install-scaffold.ts` を更新
72
- 5. 値がスキャフォルド戦略の動作に影響する場合は、関連する戦略ファイルを更新
73
-
74
- ## i18n の活用
75
-
76
- ルール実装を書く際(テンプレートでも実際のルールでも)、ハードコードされた文字列ではなく、ルールコンテキストの `t()` 翻訳関数を使用してすべてのユーザー向けメッセージを生成してください。
77
-
78
- ### 翻訳関数の使い方
79
-
80
- `t()` 関数はすべてのルールの `verify` コンテキストで利用可能です:
81
-
82
- ```typescript
83
- async verify({ document, report, t }) {
84
- await document.walkOn('Element', el => {
85
- report({
86
- scope: el,
87
- // t() で文テンプレートとキーワード引数を使用
88
- message: t('{0} is {1:c}', 'attribute', 'deprecated'),
89
- });
90
- });
91
- }
92
- ```
93
-
94
- 文テンプレートとキーワードは `@markuplint/i18n` で定義されています。このアプローチには以下の利点があります:
95
-
96
- - 日本語(およびその他のサポート言語)への自動翻訳
97
- - すべてのルールで一貫したメッセージフォーマット
98
- - 補語形式のサポート(日本語の述語接続に使う `:c` フラグ)
99
-
100
- ### 新しいキーワードやフレーズの追加
101
-
102
- ルールに必要なキーワードや文テンプレートが存在しない場合は、`@markuplint/i18n` に追加してください。手順は [i18n メンテナンススキル](../i18n/SKILL.md) を参照してください。主なポイント:
103
-
104
- 1. キーワードを `locales/ja.json` と `$schema.json` に追加(3ファイル同期ルール)
105
- 2. 文テンプレートは `{0}`, `{1}` プレースホルダーで設計
106
- 3. 補語形式には `{0:c}`、翻訳スキップには `{0*}` を使用
107
-
108
- ## 既存ルールの参考
109
-
110
- 新しいルールを作成する際は、`packages/@markuplint/rules/src/` の既存の実装をパターンやベストプラクティスの参考にしてください。
111
-
112
- ### 推奨例
113
-
114
- シンプルなルール:
115
-
116
- - `id-duplication` — 要素走査と重複検出のシンプルな実装
117
- - `class-naming` — 正規表現パターンを使った属性値チェック
118
-
119
- i18n を多用するルール:
120
-
121
- - `deprecated-attr` — 補語キーワード(`{0:c}`)と複数の文テンプレートを使用
122
- - `required-attr` — 要素/属性コンテキストでのキーワードベースメッセージを実装
123
-
124
- `packages/@markuplint/rules/src/` ディレクトリを参照して、作成しようとしているルールに類似した実装を探してください。
125
-
126
- ## fix コールバックについて
127
-
128
- 自動修正は `verify()` 内の個々の `report()` 呼び出しにインライン `fix` コールバックとして提供され、独立した `RuleSeed` メソッドではありません。コールバックは `TextEdit` オブジェクトを構築するための `IRuleFixer` ヘルパーを受け取ります。新しいルールを作成する際は、まず `verify` 関数に注力してください。`fix` コールバックは自動修正の動作が明確で単純な場合にのみ `report()` に追加してください。
129
-
130
- ## コマンドリファレンス
131
-
132
- | コマンド | 説明 |
133
- | -------------------------------------------- | ------------------ |
134
- | `yarn test --scope @markuplint/create-rule` | テスト実行 |
135
- | `yarn build --scope @markuplint/create-rule` | パッケージのビルド |
@@ -1,135 +0,0 @@
1
- # @markuplint/create-rule Maintenance Guide
2
-
3
- ## Overview
4
-
5
- The `@markuplint/create-rule` package is a CLI scaffolding tool that generates boilerplate files for new markuplint rules. It supports three modes:
6
-
7
- - **Add to project** — Creates a local plugin directory in the current project
8
- - **Publish as package** — Scaffolds a standalone npm package
9
- - **Contribute to core** — Adds a rule to `@markuplint/rules` within the monorepo
10
-
11
- ### File Structure
12
-
13
- ```
14
- packages/@markuplint/create-rule/
15
- ├── bin/
16
- │ └── create-rule.mjs # CLI executable
17
- ├── src/
18
- │ ├── cli.ts # Interactive wizard
19
- │ ├── types.ts # Type definitions
20
- │ ├── create-rule-helper.ts # Purpose-based router
21
- │ ├── create-rule-to-project.ts
22
- │ ├── create-rule-package.ts
23
- │ ├── create-rule-to-core.ts
24
- │ ├── install-scaffold.ts # Scaffold installer
25
- │ └── transfer.ts # Template processing
26
- └── scaffold/
27
- ├── core/ # Core rule templates
28
- ├── project/ # Project plugin templates
29
- └── package/ # Package templates
30
- ```
31
-
32
- ## Editing Template Files
33
-
34
- Template files live in `scaffold/{core,project,package}/`. When a user runs the CLI, these files are copied to the destination with placeholders replaced by actual values.
35
-
36
- ### Placeholder Reference
37
-
38
- | Placeholder | Replaced with | Example input | Example output |
39
- | ----------------- | ---------------------------- | -------------- | -------------- |
40
- | `__pluginName__` | Plugin name (as-is) | `my-plugin` | `my-plugin` |
41
- | `__pluginName__c` | Plugin name (camelCase) | `my-plugin` | `myPlugin` |
42
- | `__ruleName__` | Rule name (as-is) | `no-empty-alt` | `no-empty-alt` |
43
- | `__ruleName__c` | Rule name (camelCase) | `no-empty-alt` | `noEmptyAlt` |
44
- | `__description__` | Rule description (core only) | — | — |
45
- | `__category__` | Rule category (core only) | — | — |
46
- | `__severity__` | Default severity (core only) | — | — |
47
-
48
- ### CamelCase Conversion
49
-
50
- The `__<name>__c` suffix triggers camelCase conversion: hyphens are removed and the following letter is uppercased. For example, `__ruleName__c` with value `no-empty-alt` becomes `noEmptyAlt`. This is used for variable names in generated code.
51
-
52
- ### File Name Replacement
53
-
54
- Template file names containing `__ruleName__` are renamed to the actual rule name. For example, `rules/__ruleName__.ts` becomes `rules/no-empty-alt.ts`.
55
-
56
- ### TypeScript-to-JavaScript Transpilation
57
-
58
- When the user selects JavaScript, all `.ts` template files are transpiled to `.js` using the TypeScript compiler API. Keep this in mind when editing templates: the generated TypeScript must also produce valid JavaScript after transpilation.
59
-
60
- ### Prettier Formatting
61
-
62
- All generated files are formatted with Prettier. Any `// prettier-ignore` comments in templates are automatically stripped before formatting. This means `// prettier-ignore` can be used in templates to preserve formatting of placeholder expressions that would otherwise be reformatted.
63
-
64
- ## Changing the CLI Flow
65
-
66
- The interactive question sequence is defined in `src/cli.ts`. To add a new question:
67
-
68
- 1. Add the question using helpers from `@markuplint/cli-utils` (`input()`, `select()`, `confirm()`)
69
- 2. Add the corresponding type to `src/types.ts` (e.g., a new field on `CreateRuleCreatorParams`)
70
- 3. Pass the value through the `createRuleHelper()` call
71
- 4. Update `install-scaffold.ts` if the value needs to be passed to the `replacer` options
72
- 5. Update the relevant scaffold strategy files if the value affects their behavior
73
-
74
- ## Leveraging i18n
75
-
76
- When writing rule implementations (whether in templates or actual rules), use the `t()` translator function from the rule context for all user-facing messages rather than hardcoded strings.
77
-
78
- ### Using the Translator
79
-
80
- The `t()` function is available in the `verify` context of every rule:
81
-
82
- ```typescript
83
- async verify({ document, report, t }) {
84
- await document.walkOn('Element', el => {
85
- report({
86
- scope: el,
87
- // Use t() with a sentence template and keyword arguments
88
- message: t('{0} is {1:c}', 'attribute', 'deprecated'),
89
- });
90
- });
91
- }
92
- ```
93
-
94
- The sentence templates and keywords are defined in `@markuplint/i18n`. This approach provides:
95
-
96
- - Automatic translation to Japanese (and other supported languages)
97
- - Consistent message formatting across all rules
98
- - Complement form support (`:c` flag for Japanese predicate attachment)
99
-
100
- ### Adding New Keywords or Sentences
101
-
102
- If your rule needs a keyword or sentence template that does not exist yet, add it to `@markuplint/i18n`. See the [i18n maintenance skill](../i18n/SKILL.md) for the procedure. The key points are:
103
-
104
- 1. Add the keyword to `locales/ja.json` and `$schema.json` (three-file sync rule)
105
- 2. Design sentence templates with `{0}`, `{1}` placeholders
106
- 3. Use `{0:c}` for complement forms and `{0*}` to skip translation
107
-
108
- ## Referencing Existing Rules
109
-
110
- When creating a new rule, refer to existing implementations in `packages/@markuplint/rules/src/` for patterns and best practices.
111
-
112
- ### Recommended Examples
113
-
114
- Simple rules to start with:
115
-
116
- - `id-duplication` — Straightforward element traversal with duplicate detection
117
- - `class-naming` — Attribute value checking with regex patterns
118
-
119
- Rules with rich i18n usage:
120
-
121
- - `deprecated-attr` — Uses complement keywords (`{0:c}`) and multiple sentence templates
122
- - `required-attr` — Demonstrates keyword-based messages with element/attribute context
123
-
124
- Browse the `packages/@markuplint/rules/src/` directory to find rules similar to what you are building.
125
-
126
- ## About the `fix` Callback
127
-
128
- Auto-fix is provided as an inline `fix` callback on individual `report()` calls within `verify()`, not as a separate `RuleSeed` method. The callback receives an `IRuleFixer` helper for building `TextEdit` objects. When creating a new rule, focus on the `verify` function first. Add a `fix` callback to `report()` only if the auto-fix behavior is straightforward and well-defined.
129
-
130
- ## Command Reference
131
-
132
- | Command | Description |
133
- | -------------------------------------------- | ----------------- |
134
- | `yarn test --scope @markuplint/create-rule` | Run tests |
135
- | `yarn build --scope @markuplint/create-rule` | Build the package |