custom-linter-creator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseカスタムリンタークリエイター
Custom Linter Creator
各言語の既存リンターエコシステムを活用し、 ディレクトリにカスタムlintルールを作成する。
エラーメッセージはAIエージェントへの修正指示プロンプトとして設計する。
lints/Leverage the existing linter ecosystems of each language to create custom lint rules in the directory.
Error messages are designed as correction instruction prompts for AI Agents.
lints/基本概念
Core Concepts
- 既存エコシステム活用: フルスクラッチではなく、各言語の標準リンターにカスタムルールを追加する
- AI向けエラーメッセージ: lint違反メッセージをAIが理解・実行できる修正指示として記述する
- ディレクトリ: プロジェクトルートの
lints/にカスタムルールを配置するlints/
- Leverage existing ecosystems: Add custom rules to the standard linter of each language instead of building a linter from scratch
- AI-oriented error messages: Write lint violation messages as correction instructions that AI can understand and execute
- directory: Place custom rules in the
lints/directory at the project rootlints/
言語別ガイド(クイックリンク)
Language-specific Guides (Quick Links)
詳細な実装手順は references/language-ecosystems.md を参照。
| 言語 | リンターツール | 詳細リンク |
|---|---|---|
| Rust | dylint | Rust (dylint) |
| TypeScript/JavaScript | ESLint | ESLint |
| Python | pylint | Python (pylint) |
| Go | golangci-lint | Go (golangci-lint) |
Refer to references/language-ecosystems.md for detailed implementation steps.
| Language | Linter Tool | Details Link |
|---|---|---|
| Rust | dylint | Rust (dylint) |
| TypeScript/JavaScript | ESLint | ESLint |
| Python | pylint | Python (pylint) |
| Go | golangci-lint | Go (golangci-lint) |
ワークフロー
Workflow
1. 対象言語の特定
1. Identify the target language
プロジェクトの言語を確認し、上記テーブルから適切なリンターを選択する。
確認項目:
- プロジェクトのメイン言語を特定した
- 対応するリンターツールがインストール可能か確認した
Confirm the language of the project, and select the appropriate linter from the table above.
Check items:
- Identified the main language of the project
- Confirmed that the corresponding linter tool can be installed
2. lints/
ディレクトリの初期化
lints/2. Initialize the lints/
directory
lints/言語別ガイドに従い、 ディレクトリを初期化する。
lints/確認項目:
- ディレクトリを作成した
lints/ - 言語固有の設定ファイル(Cargo.toml / package.json 等)を配置した
- エントリポイントファイルを作成した
検証: でファイル構造を確認する。
ls -la lints/Initialize the directory according to the language-specific guide.
lints/Check items:
- Created the directory
lints/ - Placed language-specific configuration files (such as Cargo.toml / package.json)
- Created the entry point file
Verification: Check the file structure with .
ls -la lints/3. カスタムルールの実装
3. Implement custom rules
AI向けエラーメッセージテンプレートに従い、ルールを実装する。
確認項目:
- ルールファイルを作成した
- エラーメッセージをAI向け修正指示として記述した
- テンプレートの5要素(違反内容・修正手順・コンテキスト・スコープ制限・理由)を含めた
検証: ルールファイルの構文エラーがないことを確認する。
Implement the rules according to the AI-oriented error message template.
Check items:
- Created the rule file
- Wrote the error message as a correction instruction for AI
- Included the 5 elements of the template (violation content, correction steps, context, scope restriction, reason)
Verification: Confirm that there are no syntax errors in the rule file.
4. リンター設定への統合
4. Integrate into linter configuration
プロジェクトのリンター設定にカスタムルールを追加する。
確認項目:
- プロジェクトの設定ファイルにカスタムルールを登録した
- ルールの重大度(error/warning)を設定した
検証: リンターの設定読み込みエラーがないことを確認する。
Add custom rules to the project's linter configuration.
Check items:
- Registered custom rules in the project's configuration file
- Set the severity level (error/warning) of the rules
Verification: Confirm that there are no errors when the linter loads the configuration.
5. 動作確認
5. Verify functionality
実行→検証→修正ループ:
- 実行: 意図的に違反コードを書き、リンターを実行する
- 検証: AI向けエラーメッセージが正しく出力されるか確認する
- 修正: メッセージが不明瞭なら修正し、再度実行する
言語別実行コマンド:
| 言語 | 実行コマンド | 期待される出力 |
|---|---|---|
| Rust | | 違反箇所のファイルパス・行番号とAI向けメッセージ |
| TypeScript/JS | | 違反箇所とmessageIdに対応するメッセージ |
| Python | | メッセージコード(C9001等)と詳細メッセージ |
| Go | | 違反箇所の位置情報とメッセージ |
確認項目:
- 違反コードでエラーが検出された
- エラーメッセージに5要素(違反内容・修正手順・コンテキスト・スコープ・理由)が含まれている
- 修正後、エラーが解消された
Execution → Verification → Correction Loop:
- Execution: Write code that intentionally violates the rule, then run the linter
- Verification: Confirm that the AI-oriented error message is output correctly
- Correction: If the message is unclear, modify it and run the linter again
Language-specific execution commands:
| Language | Execution Command | Expected Output |
|---|---|---|
| Rust | | File path, line number of the violation, and AI-oriented message |
| TypeScript/JS | | Violation location and message corresponding to the messageId |
| Python | | Message code (such as C9001) and detailed message |
| Go | | Location information of the violation and message |
Check items:
- The error is detected in the intentionally violating code
- The error message contains the 5 elements (violation content, correction steps, context, scope, reason)
- The error is resolved after correction
AI向けエラーメッセージテンプレート
AI-oriented Error Message Template
すべてのカスタムルールは以下のテンプレートに従ってエラーメッセージを記述する。
All custom rules shall write error messages according to the following template.
テンプレート構造
Template Structure
[違反内容]: 何が違反しているかを1文で説明
修正手順:
1. [具体的なアクション1]
2. [具体的なアクション2]
3. [具体的なアクション3]
コンテキスト: {file_path}:{line_number} の {identifier}
スコープ: 修正対象以外のコードは変更しないこと
理由: このルールが存在する理由を簡潔に記載注意: はルールに応じた識別子名(モジュール名、クラス名、関数名等)に置き換える。
{identifier}[違反内容]: 何が違反しているかを1文で説明
修正手順:
1. [具体的なアクション1]
2. [具体的なアクション2]
3. [具体的なアクション3]
コンテキスト: {file_path}:{line_number} の {identifier}
スコープ: 修正対象以外のコードは変更しないこと
理由: このルールが存在する理由を簡潔に記載Note: Replace with the identifier name corresponding to the rule (module name, class name, function name, etc.).
{identifier}具体例
Specific Examples
Rust (mod.rs禁止ルール):
このファイルは mod.rs を使用しているが、プロジェクト規約で禁止されている。
修正手順:
1. このファイルの内容を親ディレクトリ名.rs にコピーする
2. 例: src/actors/mod.rs → src/actors.rs に移動する
3. mod.rs ファイルを削除する
4. 他ファイルの use/mod 宣言に変更は不要(パスは同じ)
コンテキスト: {file_path}:{line_number} の {module_name}
スコープ: 対象ファイルとその移動先のみ変更すること
理由: Rust 2018 エディションのモジュールスタイルに統一するためESLint (曖昧サフィックス禁止ルール):
クラス '{class_name}' は曖昧なサフィックス '{suffix}' を使用している。
修正手順:
1. このクラスの責務を特定する(データアクセス?認証?調整?)
2. 責務を具体的に表す名前に変更する
例: UserManager → UserRepository / UserAuthenticator / UserCoordinator
3. このクラスへの全参照を新しい名前に更新する
コンテキスト: {file_path}:{line_number} の {class_name}
スコープ: クラス定義とその参照のみ変更すること
理由: Managerは責務が曖昧で、コードの意図が伝わりにくいためRust (mod.rs prohibition rule):
このファイルは mod.rs を使用しているが、プロジェクト規約で禁止されている。
修正手順:
1. このファイルの内容を親ディレクトリ名.rs にコピーする
2. 例: src/actors/mod.rs → src/actors.rs に移動する
3. mod.rs ファイルを削除する
4. 他ファイルの use/mod 宣言に変更は不要(パスは同じ)
コンテキスト: {file_path}:{line_number} の {module_name}
スコープ: 対象ファイルとその移動先のみ変更すること
理由: Rust 2018 エディションのモジュールスタイルに統一するためESLint (ambiguous suffix prohibition rule):
クラス '{class_name}' は曖昧なサフィックス '{suffix}' を使用している。
修正手順:
1. このクラスの責務を特定する(データアクセス?認証?調整?)
2. 責務を具体的に表す名前に変更する
例: UserManager → UserRepository / UserAuthenticator / UserCoordinator
3. このクラスへの全参照を新しい名前に更新する
コンテキスト: {file_path}:{line_number} の {class_name}
スコープ: クラス定義とその参照のみ変更すること
理由: Managerは責務が曖昧で、コードの意図が伝わりにくいため設計指針
Design Guidelines
- 具体的な修正手順: 「修正してください」ではなく「snake_caseに変換し、全参照を更新する」
- ステップ番号付き: 複数手順がある場合は番号で順序を示す
- コンテキスト情報: 違反箇所のファイルパス・シンボル名・行番号を含める
- スコープ制限: 「修正対象以外のコードは変更しない」旨を明記する
- 理由の説明: なぜこのルールが存在するかを簡潔に記載する
- Specific correction steps: Do not use vague descriptions like "Please fix it", use specific instructions such as "Convert to snake_case and update all references"
- Numbered steps: Use numbers to indicate the order when there are multiple steps
- Context information: Include the file path, symbol name, and line number of the violation location
- Scope restriction: Clearly state that "code other than the correction target shall not be modified"
- Explanation of reason: Briefly describe why this rule exists