Skip to content

Add SonarAnalyzer.CSharp and tighten Roslyn analyzer rules#18

Merged
tillig merged 14 commits into
developfrom
feature/tighten-analyzers
May 29, 2026
Merged

Add SonarAnalyzer.CSharp and tighten Roslyn analyzer rules#18
tillig merged 14 commits into
developfrom
feature/tighten-analyzers

Conversation

@tillig

@tillig tillig commented May 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds SonarAnalyzer.CSharp (10.27.0.140913) to all projects
  • Introduces unified build/Source.ruleset and build/Test.ruleset with consistent analyzer configuration
  • Fixes all actionable analyzer warnings (code changes per-rule in individual commits)
  • Disables rules that are false positives or inapplicable for this project's patterns

Changes

  • New analyzer: SonarAnalyzer.CSharp added via PackageReference with PrivateAssets=all
  • Rulesets: Unified Source.ruleset and Test.ruleset covering Microsoft, Sonar, StyleCop, and xUnit analyzers
  • Code fixes: Various warning fixes committed individually by rule ID for easy review
  • Zero warnings: Build completes with no analyzer warnings

Test plan

  • CI build passes (zero errors, zero warnings)
  • All existing tests pass
  • No public API changes (verify with dotnet format --verify-no-changes)

tillig added 14 commits May 28, 2026 12:37
Adds SonarAnalyzer.CSharp 10.27.0.140913 to all projects. Replaces
existing Source.ruleset and Test.ruleset with unified versions shared
across the Autofac organization. Ensures all projects have
AnalysisMode=AllEnabledByDefault and EnforceCodeStyleInBuild=true.
… classes.

Replaces the [SuppressMessage] for CA1018 with an actual [AttributeUsage]
declaration on source types, and adds explicit [AttributeUsage] to test
attribute classes. This resolves both CA1018 and the Sonar S3993 warning.
Autofac intentionally maintains deprecated APIs for backward compatibility.
Tests exercise deprecated APIs to verify they still work. Warnings about
using deprecated code are not actionable in this context.
- CA1063 (Implement IDisposable correctly): enabled as Warning in both
  Source and Test rulesets for explicit enforcement.
- S3881 (IDisposable pattern): disabled because Autofac uses non-standard
  dispose patterns for container lifecycle management.
- Fixed comment/rule ordering where S1133 insertion displaced comments.
- CA1711: test classes commonly use suffixes like Impl, Handler, etc.
- CA1721: test interfaces intentionally have properties matching methods.
- S125: commented-out code in tests is acceptable for examples/notes.
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.27%. Comparing base (37afb4c) to head (6b671af).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop      #18   +/-   ##
========================================
  Coverage    71.27%   71.27%           
========================================
  Files            7        7           
  Lines           94       94           
  Branches        28       28           
========================================
  Hits            67       67           
  Misses          12       12           
  Partials        15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tillig tillig merged commit bf66e1b into develop May 29, 2026
10 checks passed
@tillig tillig deleted the feature/tighten-analyzers branch May 29, 2026 21:22
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.

1 participant