Skip to content

Add analyzer rules for ConceptAs conventions (CRARCH0027, CRARCH0028)#10

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/add-static-code-analysis-rules
Draft

Add analyzer rules for ConceptAs conventions (CRARCH0027, CRARCH0028)#10
Copilot wants to merge 3 commits into
mainfrom
copilot/add-static-code-analysis-rules

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Adds two Roslyn analyzers enforcing ConceptAs domain value conventions with actionable diagnostic messages.

Rules

CRARCH0027: ConceptAs must have NotSet sentinel

  • Detects records inheriting ConceptAs<T> without a static readonly sentinel field
  • Accepts NotSet, Empty, Null, or None as valid names
  • Diagnostic message includes type-specific examples (Guid.Empty, string.Empty, 0)

CRARCH0028: Guid-backed concepts must have New() factory

  • Detects ConceptAs<Guid> records without a static New() method
  • Only triggers for Guid-backed concepts, ignores string/int/etc
  • Diagnostic message includes factory implementation example

CRARCH0029: Reserved

  • Rule ID allocated, infrastructure in place but deferred
  • Primitive type detection requires additional semantic analysis refinement

Example

Before:

public record AuthorId(Guid Value) : ConceptAs<Guid>(Value)
{
}
// ⚠️ CRARCH0027: Record 'AuthorId' must have NotSet sentinel
// ⚠️ CRARCH0028: Record 'AuthorId' must have New() factory

After:

public record AuthorId(Guid Value) : ConceptAs<Guid>(Value)
{
    public static readonly AuthorId NotSet = new(Guid.Empty);
    public static AuthorId New() => new(Guid.NewGuid());
}

Implementation

  • ConceptAsMustHaveNotSetSentinelRule.cs - checks for sentinel field by name
  • GuidConceptMustHaveNewFactoryRule.cs - checks Guid concepts for New() method
  • Wired into NamedTypeAnalyzer symbol analysis pipeline
  • 7 new BDD-style specs, all existing tests pass (108/108)

Copilot AI added 2 commits June 16, 2026 12:56
…RCH0029)

- CRARCH0027: ConceptAs must have a static readonly NotSet sentinel
- CRARCH0028: Guid-backed identity concept must have a static New() factory
- CRARCH0029: Avoid using primitive types - wrap in ConceptAs<> (initial implementation)
- CRARCH0027 and CRARCH0028 fully implemented with passing tests
- CRARCH0029 infrastructure in place but commented out pending refinement
- All 108 analyzer tests passing
Copilot AI changed the title [WIP] Add static code analysis rules for ConceptAs Add analyzer rules for ConceptAs conventions (CRARCH0027, CRARCH0028) Jun 16, 2026
Copilot AI requested a review from einari June 16, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants