Convention Learner

codewithmukesh/dotnet-claude-kit/skills/convention-learner

作者 codewithmukesh23300897f4d1無授權條款754 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 個月前更新

Detects and enforces project-specific coding conventions by analyzing existing codebase patterns. Learns naming conventions, folder structure, test organization, and coding style from the existing code. Load when: "conventions", "coding standards", "project patterns", "enforce style", "detect patterns", "learn conventions", "code consistency".

AI 產生的概覽

分析現有程式碼庫以辨識專案編碼慣例,並在產生或審查程式碼時套用這些慣例。

功能
透過 get_public_api、get_project_graph、detect_antipatterns 等 MCP 工具以及讀取檔案,分析現有程式碼庫中的命名慣例、資料夾與分層結構、測試組織方式和程式碼風格。將發現整理成結構化的慣例摘要,在產生新程式碼時比對這些模式,並在審查時標示偏離慣例之處。也會建議 .editorconfig 規則和 CLAUDE.md 條目來強制執行並記錄偵測到的慣例,並持續追蹤反覆出現的反模式。
適用情境
適用於加入現有專案、產生新程式碼之前,或審查程式碼是否符合專案風格時。也適合新成員上手、解決通用預設規則與專案規則之間的衝突,以及記錄原本沒有文件的慣例。
執行需求
需要 MCP 工具 get_public_api、get_project_graph 和 detect_antipatterns,並需要讀取專案檔案系統以存取 .editorconfig、Directory.Build.props、global.json 等設定檔。不附帶指令碼,僅為說明性指示。

Convention Learner

Core Principles

  1. Observe before enforcing — Never impose conventions without first analyzing the existing codebase. A project with 200 internal sealed class handlers should not get a new public class handler. Detect first, then match.
  2. Project conventions override generic rules — If the project uses *Service instead of *Handler, follow the project's convention even if the kit default is different. Explicit .editorconfig and Directory.Build.props rules always win.
  3. Use MCP tools for analysis — get_public_api reveals naming patterns, get_project_graph shows structure conventions, detect_antipatterns tracks quality trends. Tools provide objective data; file reads provide confirmation.
  4. Document findings — After detecting conventions, suggest adding them to the project's CLAUDE.md. Undocumented conventions are lost when the original developers leave.
  5. Consistency over perfection — A project with consistent snake_case database columns is better than a project with half snake_case and half PascalCase. Match the existing pattern, even if another convention is theoretically superior.

Patterns

Convention Detection Flow

Systematic analysis to understand a project's coding conventions. Run this when joining an existing project or before generating new code.

Step 1: Project Structure Analysis

→ get_project_graph  Detect:  - Project naming: PascalCase? Dots? (MyApp.Domain vs Domain)  - Layer organization: by layer (Domain/Application/Infrastructure) or by feature?  - Test project naming: *.Tests, *.UnitTests, *.IntegrationTests?  - Shared project: Common/, Shared/, BuildingBlocks/?

Step 2: Type Naming Patterns

→ get_public_api (on 3-5 key types across different layers)  Detect:  - Class modifiers: sealed? internal? internal sealed?  - Interface prefix: I* (standard) or no prefix?  - Suffix conventions: Handler, Service, Repository, Validator, Endpoint?  - Record usage: for DTOs? for value objects? for commands/queries?  - Primary constructor usage: consistently? selectively?

Step 3: Folder Structure Patterns Scan the file system for structural conventions:

  • Feature folders: Features/{FeatureName}/ with all files together?
  • Layer folders: Controllers/, Services/, Repositories/ separate?
  • Shared patterns: Common/, Extensions/, Middleware/?
  • Configuration location: root? Config/ folder? Infrastructure/?

Step 4: Configuration Detection Check for explicit convention enforcers:

→ Look for Directory.Build.props  - TreatWarningsAsErrors?  - Nullable enabled globally?  - ImplicitUsings?  - AnalysisLevel?
→ Look for .editorconfig  - Naming rules: camelCase fields? _prefixed privates?  - Code style: var preferences, expression bodies, using placement
→ Look for global.json  - SDK version pinned?  - Roll-forward policy?

Step 5: Build Convention Summary Compile findings into a structured summary:

markdown
## Detected Conventions
### Naming- Classes: `internal sealed class` (95% of handlers/services)- Suffixes: Handlers end in `Handler`, validators in `Validator`- Records: Used for DTOs and commands/queries
### Structure- Architecture: Vertical Slice Architecture- Features: `Features/{Name}/` with command, handler, validator, endpoint in one file
### Code Style- Primary constructors: Used consistently for DI injection- Nullable: Enabled globally, no suppressions (`!`) used- File-scoped namespaces: 100% consistent

Add categories as needed: EF Core (configurations, naming, migrations), Testing (framework, naming, fixtures), etc.

Convention Enforcement

Apply detected conventions when generating new code or reviewing existing code.

When Generating Code: Match every detected pattern:

csharp
// If existing handlers are: internal sealed class + primary constructor// Generate matching:internal sealed class CreateProductHandler(AppDbContext db, TimeProvider clock){    // Not: public class CreateProductHandler    // Not: internal class CreateProductHandler (missing sealed)}
csharp
// If existing DTOs are records with init properties// Generate matching:public record ProductResponse(Guid Id, string Name, decimal Price);// Not: public class ProductResponse { public Guid Id { get; set; } }

When Reviewing Code: Flag deviations from detected conventions:

⚠️ Convention violation: CreateOrderHandler is `public class` but project convention   is `internal sealed class` (detected in 12/12 existing handlers).   Change to: internal sealed class CreateOrderHandler

Suggesting Enforcement Rules: After detecting conventions, suggest .editorconfig rules to enforce them automatically:

ini
# Key .editorconfig rules to suggest based on detected conventionsdotnet_diagnostic.CA1852.severity = warning           # Seal internal typescsharp_style_namespace_declarations = file_scoped:warningcsharp_style_prefer_primary_constructors = true:suggestion# Add dotnet_naming_rule entries for private field prefix (_camelCase) if detected

Anti-pattern Tracking

Use detect_antipatterns to track recurring quality issues across sessions.

Periodic Check:

→ detect_antipatterns (scope: solution)  Track over time:  - Are the same patterns recurring? (DateTime.Now keeps appearing)  - Are new patterns emerging? (new HttpClient() in a new module)  - Is the count trending up or down?

Prioritization:

| Anti-pattern | Count | Trend | Priority ||-------------|-------|-------|----------|| DateTime.Now | 12 | ↑ +3 | High — add to CLAUDE.md conventions || async void | 1 | → same | Medium — one-off fix || new HttpClient | 0 | ↓ -2 | Low — already fixing |

When patterns recur, add explicit rules to CLAUDE.md:

markdown
## Conventions- **NEVER use DateTime.Now** — Use TimeProvider.GetUtcNow() (12 violations found, fixing)

Anti-patterns

Enforcing Without Detecting

# BAD — Imposing kit defaults on a project with its own conventions"All handlers should be internal sealed class"# But this project uses public class with interfaces for testing
# GOOD — Detect first, then follow what exists→ get_public_api reveals: 8/8 handlers are `public class` implementing `IHandler<T>`"This project uses public handlers with interfaces. Matching that convention."

Overriding Explicit Project Rules

# BAD — Ignoring .editorconfig because kit says otherwise# .editorconfig says: csharp_style_expression_bodied_methods = false# But generating expression-bodied methods anyway
# GOOD — .editorconfig and Directory.Build.props always win"Your .editorconfig disables expression-bodied methods.I'll use block-bodied methods to match your project settings."

Applying Generic Conventions to Unconventional Projects

# BAD — Forcing Clean Architecture naming on a VSA project"You need a Services/ folder and a Repositories/ folder"# But this project uses feature folders with everything co-located
# GOOD — Match the project's organizational convention"This project uses feature folders. I'll add the new featureat Features/Shipping/ with all related files together."

Documenting Conventions Without Evidence

# BAD — "Conventions" based on reading one file"Convention: Use var everywhere" (based on seeing var in one method)
# GOOD — Document only patterns confirmed across multiple files→ get_public_api on 5 types: 100% use explicit types for non-obvious cases"Convention: Use explicit types for non-obvious cases (e.g., method returns),var for obvious cases (e.g., new MyClass()). Confirmed across 5 files."

Decision Guide

ScenarioActionTool
Joining existing projectRun full convention detection flowget_project_graph, get_public_api
Generating new codeCheck detected conventions firstPrevious detection results
Reviewing codeFlag convention deviationsget_public_api + comparison
Convention conflict (kit vs project)Project wins—
Convention conflict (team disagreement)Document both, suggest .editorconfig—
No conventions detectedUse kit defaults, document themarchitecture-advisor skill
Recurring anti-patternAdd to CLAUDE.md conventionsdetect_antipatterns
New team member onboardingRun detection, generate convention docFull detection flow
.editorconfig existsTrust it, don't overrideRead .editorconfig
No .editorconfigSuggest creating one based on detected patternsDetection + generation
Pattern seen onceCreate instinct at 0.3 confidence via instinct-system skillinstinct-system
Pattern confirmed 3+ timesInstinct auto-promotes to 0.7, suggest adding to CLAUDE.mdinstinct-system

來源與署名

來源:codewithmukesh/dotnet-claude-kit位於skills/convention-learner提交2330089

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架

更多來自 codewithmukesh/dotnet-claude-kit 的技能

Wrap Up

codewithmukesh

在 session 結束時把已完成工作、待辦事項與經驗寫入交接檔案,並在 session 開始時重新載入。

Productivity & Workflow7542 個月前更新

Workflow Mastery

codewithmukesh

Claude Code workflow mastery for .NET developers. Covers parallel execution with git worktrees, plan mode strategy, verification loops, auto-formatting hooks, permission setup for dotnet CLI, prompting techniques, subagent patterns, and context discipline — token budget management, MCP-first navigation, lazy loading, and subagent isolation — all adapted for the .NET ecosystem. Load this skill when setting up Claude Code for a .NET project, optimizing workflows, running parallel sessions, when context is running low or sessions feel sluggish, when exploring a large codebase efficiently, or when the user mentions "productivity", "workflow", "parallel", "worktree", "plan mode", "permissions", "hooks", "10x", "setup Claude Code", "speed up development", "context", "tokens", "budget", "running out of context", "too many files", or "large codebase". Inspired by tips from Boris Cherny (creator of Claude Code) and the Anthropic team.

待分類7542 個月前更新

Vertical Slice

codewithmukesh

指導 .NET 開發者以垂直切片架構組織應用程式,涵蓋功能資料夾、端點分組與處理常式模式。

Software Development7542 個月前更新

Testing

codewithmukesh

Testing strategy for .NET 10 applications. Covers xUnit v3, WebApplicationFactory for integration tests, Testcontainers for real database testing, Verify for snapshot testing, and the AAA pattern. Load this skill when writing tests, setting up test infrastructure, reviewing test coverage, or when the user mentions "test", "xUnit", "WebApplicationFactory", "Testcontainers", "integration test", "unit test", "bUnit", "snapshot test", "Verify", "test coverage", "AAA pattern", "WireMock", or "FakeTimeProvider".

待分類7542 個月前更新

Tdd

codewithmukesh

Guided test-driven development workflow for .NET 10 using xUnit v3, WebApplicationFactory, Testcontainers, and Verify snapshots. Follows the strict red-green-refactor cycle. Use when: "TDD", "test-driven", "let's TDD this", "red green refactor", "write the test first", or when building a feature with clear acceptance criteria.

待分類7542 個月前更新

Spec

codewithmukesh

透過結構化提問,把模糊的功能想法轉化為雙方確認並持久化的規格文件。

Productivity & Workflow7542 個月前更新