Skip to content

Add StyleCop analyzers and enforce code style via Directory.Build.props #30

Description

@david-acm

Problem

There are no static analysis packages or enforced style rules across the solution. The .editorconfig has a max_line_length of 6279 (clearly unintentional), and code style is inconsistent across files.

Fix

1. Add analyzers to Directory.Build.props

<ItemGroup>
  <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
  <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.*" PrivateAssets="all" />
</ItemGroup>

2. Add a .editorconfig at the repo root

root = true

[*.cs]
indent_style = space
indent_size = 4
max_line_length = 120
dotnet_sort_system_directives_first = true
dotnet_style_qualification_for_field = false
csharp_prefer_simple_using_statement = true

3. Add a stylecop.json (optional suppressions)

Configure per-project as needed, e.g. suppress file headers if not wanted.

4. Treat warnings as errors in CI only

In Directory.Build.props:

<PropertyGroup Condition="'$(CI)' == 'true'">
  <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

This avoids blocking local builds while enforcing clean CI runs.

Notes

  • Fix the max_line_length = 6279 typo in the existing .editorconfig — should be 120.
  • Run dotnet format to auto-fix trivially correctable style violations before enabling the analyzers.

Acceptance Criteria

  • StyleCop.Analyzers added to Directory.Build.props
  • .editorconfig at repo root with max_line_length = 120
  • dotnet build produces 0 new warnings after fixes
  • CI pipeline treats analyzer warnings as errors

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions