|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Pharmica.AssetGen is a **Roslyn incremental source generator** and **diagnostic analyzer** for ASP.NET Core. It generates strongly-typed constants for wwwroot static assets (e.g., `StaticAssets.Images.LogoPng` instead of `"/images/logo.png"`), providing compile-time safety and IntelliSense. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +dotnet tool restore # Install CSharpier, Husky, ReportGenerator |
| 13 | +dotnet husky install # Install pre-commit/commit-msg git hooks |
| 14 | +dotnet restore # Restore NuGet packages |
| 15 | +dotnet build # Build the solution |
| 16 | +dotnet csharpier . # Auto-format code |
| 17 | +dotnet csharpier check . # Check formatting (used by pre-commit hook) |
| 18 | +``` |
| 19 | + |
| 20 | +## Testing |
| 21 | + |
| 22 | +Uses **TUnit** (not xUnit/NUnit). Tests are async and use `Assert.That(value).IsEqualTo(expected)` style assertions. |
| 23 | + |
| 24 | +```bash |
| 25 | +dotnet test # Run all tests |
| 26 | +dotnet test --filter "FullyQualifiedName~AssetGenerator" # Run tests matching a pattern |
| 27 | +dotnet test --collect:"XPlat Code Coverage" # Run with coverage |
| 28 | +``` |
| 29 | + |
| 30 | +- **Unit tests** (`Pharmica.AssetGen.Tests/Unit/`): Test generator and analyzer with mocked Roslyn APIs via `TestHelpers.cs` |
| 31 | +- **Integration tests** (`Pharmica.AssetGen.Tests/Integration/`): Build real ASP.NET Core fixture projects in `Fixtures/` and verify generated output |
| 32 | + |
| 33 | +## Architecture |
| 34 | + |
| 35 | +### Source Generator (`AssetGenerator.cs`) |
| 36 | +Implements `IIncrementalGenerator`. Pipeline: |
| 37 | +1. Filters `AdditionalTexts` for files matching `*/wwwroot/*` |
| 38 | +2. Reads build properties: `AssetGen_ClassName` (default: "StaticAssets"), `AssetGen_FlattenExtensions` (default: true) |
| 39 | +3. Builds a hierarchical tree from file paths → nested static classes with `const string` fields |
| 40 | +4. Reports `ASSET001` (error) on duplicate key collisions |
| 41 | + |
| 42 | +### Diagnostic Analyzer (`HardcodedPathAnalyzer.cs`) |
| 43 | +Implements `DiagnosticAnalyzer`. Reports `ASSET002` (warning) when string literals contain hardcoded wwwroot paths (e.g., `"/css/site.css"`). Context-aware: suppresses in StaticAssets references, test code, and generated code. |
| 44 | + |
| 45 | +### Key Design Constraints |
| 46 | +- Generator targets **netstandard2.0** (Roslyn requirement for source generators) |
| 47 | +- Tests target **net9.0** |
| 48 | +- NuGet package ships as analyzer: DLLs go into `analyzers/dotnet/cs` in the package |
| 49 | +- Default build properties are set in `build/Pharmica.AssetGen.props` |
| 50 | +- Central package versioning via `Directory.Packages.props` |
| 51 | + |
| 52 | +## Code Style & Commit Conventions |
| 53 | + |
| 54 | +- **Formatter:** CSharpier (enforced by pre-commit hook — code will be rejected if not formatted) |
| 55 | +- **Commits:** Conventional Commits required (enforced by commit-msg hook). Format: `type(scope): description`. Valid types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert` |
| 56 | +- **No co-authored-by lines** — never add `Co-Authored-By` trailers to commit messages |
| 57 | +- **CHANGELOG.md** is auto-generated from commits — do not edit manually |
| 58 | +- Naming: PascalCase for public APIs, `_camelCase` for private fields, `s_camelCase` for static fields |
0 commit comments