build: enable CA2007 enforcement via nested src/.editorconfig - #5230
Conversation
Move ConfigureAwait(false) enforcement (CA2007) from the legacy CodeAnalysis.ruleset to a nested src/.editorconfig. The .ruleset file no longer reliably enables CA2007 with current .NET SDKs (CA2007 is disabled by default), so the rule only fired in CI Release builds and was silently ignored locally in Rider and `dotnet build`. Using the modern dotnet_diagnostic.<id>.severity in a nested editorconfig under /src has two benefits: - it correctly activates rules that are disabled by default; - it naturally scopes the rule to library code only — tests, samples and benchmarks are unaffected, where awaiting without ConfigureAwait is fine and often more readable. Closes #2308 #skip-changelog Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5230 +/- ##
==========================================
+ Coverage 74.12% 74.13% +0.01%
==========================================
Files 508 508
Lines 18282 18282
Branches 3574 3574
==========================================
+ Hits 13551 13553 +2
+ Misses 3861 3860 -1
+ Partials 870 869 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| # Settings that apply only to library code under /src | ||
| # (so tests, samples, benchmarks, and integration-tests are not affected). |
There was a problem hiding this comment.
question: .editorconfig vs .globalconfig
I'm wondering, which file is better here:
.editorconfig.globalconfig
To me, .editorconfig is more for style choices,
and .globalconfig is more for code quality rules.
The difference on a "content level" is that (unlike .editorconfig), .globalconfig does not have a language section (e.g. [*.cs]).
But ... to be fair ... this might be just total bikeshedding from my end, and is more of a "stylistic" choice rather than a "functional" choice.
I just wanted to raise awareness that there is also a .globalconfig option we could use.
There was a problem hiding this comment.
Let's change if it ever causes us issues further down the road. For the time being, I think this does what we want and we can move on to other stuff.
Relocate the [test/**/*.cs] section from the root .editorconfig into a dedicated test/.editorconfig, matching the src/.editorconfig convention from #5230 so diagnostic suppressions are consistently discoverable. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: James Crosswell <james.crosswell@gmail.com>
Summary
Move
ConfigureAwait(false)enforcement (CA2007) from the legacysrc/CodeAnalysis.rulesetto a nestedsrc/.editorconfig.The ruleset file no longer reliably enables CA2007 with current .NET SDKs (CA2007 is disabled by default in modern .NET analyzers, and
<CodeAnalysisRuleSet>only overrides severity for rules that are already active). As a result, the rule only fired in CI Release builds and was silently ignored locally — both in Rider and withdotnet build— the regression reported in #2308.Using
dotnet_diagnostic.CA2007.severity = errorinside a nested editorconfig under/srchas two advantages over the previous setup:ConfigureAwait(false)is unnecessary noise.Verification
Tested locally on macOS:
src/Sentry/Sentry.csprojin Debug → 0 errors.await sentryTask.ConfigureAwait(false);withawait sentryTask;inSpotlightHttpTransport.cs→ build fails with:net8.0,net9.0,net10.0). Reverted before commit.test/Sentry.Tests/Sentry.Tests.csprojwith its existingawait client.GetAsync(...);calls (noConfigureAwait) → 0 CA2007 errors, confirming the rule is correctly scoped to/srconly.Closes #2308
#skip-changelog