# Refactor: add dotnet format, NetAnalyzers, Coverlet tooling

**Task**: AZ-372_refactor_format_analyzers_coverage
**Name**: Wire formatter, analyzer ruleset, and coverage runner
**Description**: Add `Microsoft.CodeAnalysis.NetAnalyzers` and `coverlet.collector`; add a root `.editorconfig` if absent; wire `dotnet format --verify-no-changes` into the test script.
**Complexity**: 3 points
**Dependencies**: None (sequenced last in the run so analyzer noise lands on the post-refactor code)
**Component**: Tooling (solution root, all `*.csproj`)
**Tracker**: AZ-372
**Epic**: AZ-350

## Problem

The repository has no `dotnet format` gate, no Roslyn analyzers beyond defaults, and no Coverlet for coverage. Style drift and easy-to-miss bugs slip through.

## Outcome

- `dotnet format --verify-no-changes` succeeds against the post-refactor codebase.
- Test runs emit a coverage report via Coverlet.
- An initial NetAnalyzers ruleset (warning severity) is active across all projects.
- 37 unit + 5 smoke tests stay green.

## Scope

### Included
- Add `Microsoft.CodeAnalysis.NetAnalyzers` package reference to all `*.csproj` (or via `Directory.Build.props`).
- Add `coverlet.collector` to the test projects.
- Add a root `.editorconfig` (only if absent) with conservative defaults matching existing code style.
- Pick an initial analyzer ruleset (CA1001, CA1051, CA2007, CA2227, etc.) at warning severity.
- Wire `dotnet format --verify-no-changes` into `scripts/run-tests.sh` (non-blocking warning if it fails to run, blocking if format violations exist).
- Run formatter once and commit any whitespace cleanup as a separate batch.

### Excluded
- Promoting any analyzer warning to error severity in this run.
- Adopting a third-party style guide.

## Acceptance Criteria

**AC-1: Formatter is clean**
Given the post-refactor codebase
When `dotnet format --verify-no-changes` runs
Then it exits 0.

**AC-2: Coverage runs**
Given the test projects
When `dotnet test --collect:"XPlat Code Coverage"` runs
Then a coverage report is produced.

**AC-3: Analyzers active but non-blocking**
Given the build output
When inspected
Then NetAnalyzers warnings are visible; no warnings have been promoted to errors; build succeeds.

**AC-4: Tests stay green**
Given the post-refactor build
When `scripts/run-tests.sh --smoke` runs
Then all 37 unit + 5 smoke scenarios pass.

## Constraints

- No analyzer warning becomes an error in this run.
- `.editorconfig` defaults must not force whitespace churn beyond what one initial format pass produces.

## Risks & Mitigation

**Risk 1: analyzer flood**
- *Risk*: a strict ruleset will surface hundreds of warnings on a 3700-LOC codebase.
- *Mitigation*: start with a small named ruleset and expand later.

Full change entry: `_docs/04_refactoring/03-code-quality-refactoring/list-of-changes.md` (C19).
