build: make the IDE code-style analyzers reach the build, and gate IDE0017 - #132
Merged
Merged
Conversation
…E0017
SonarQube kept reporting roslyn:IDE0017 ("Simplify object initialization") on
code the build had just declared clean. Raising the severity in .editorconfig
does not fix that on its own: Roslyn's command-line driver skips analyzers whose
diagnostics are all info/hidden by default, and it makes that call before the
.editorconfig severity is consulted, so the whole IDE* family was dropped from
the build regardless of the severity given to it. Pinning IDE0017 to `error`
still produced a green build.
Asking for a SARIF error log lifts that filter. It is the same switch
SonarScanner sets in order to import roslyn:* issues, which is exactly why Sonar
saw a diagnostic set the build never computed. With it on, an IDE rule raised to
`warning` becomes a build error through TreatWarningsAsErrors.
The property lives in Directory.Build.targets rather than Directory.Build.props
because IntermediateOutputPath is only defined once
Microsoft.Common.CurrentVersion.targets has run; from .props it expands to empty
and drops the .sarif in each project directory instead of obj/. The condition
leaves SonarScanner's own ErrorLog alone when it runs.
Enabling this surfaced two real IDE0017 violations in CameraControllerSeamTests,
rewritten to the object-initializer form already used elsewhere in that file.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are small, consistent with the repo’s strict build configuration, and the updated test code and build-time SARIF logging approach are coherent and self-contained.
Pull request overview
This PR closes the gap between Sonar-reported roslyn:IDE* code-style diagnostics (notably IDE0017) and what a clean dotnet build currently enforces, by ensuring the compiler actually computes and reports IDE analyzer diagnostics during command-line builds.
Changes:
- Add a repo-wide
Directory.Build.targetsthat setsErrorLogto a per-project SARIF file underobj/(only when$(ErrorLog)is not already set), which causes Roslyn to include IDE analyzer diagnostics in the build. - Configure
IDE0017as a warning in.editorconfig, relying onTreatWarningsAsErrors=trueto gate it as a build error. - Update
CameraControllerSeamTeststo use object initializers, resolving IDE0017 hits surfaced by the new build behavior.
File summaries
| File | Description |
|---|---|
| tests/RustPlusApi.Camera.UnitTests/CameraControllerSeamTests.cs | Refactors two test constructions to object initializers to satisfy IDE0017. |
| Directory.Build.targets | Enables SARIF error logging in builds (when not already set) so IDE analyzers are not silently skipped. |
| .editorconfig | Sets IDE0017 severity to warning so it becomes a build-breaking warning under TreatWarningsAsErrors. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
SonarQube keeps reporting
roslyn:IDE0017("Simplify object initialization") on code a greendotnet buildhas just declared clean. This closes that gap for the wholeIDE*family.The part that isn't obvious
EnforceCodeStyleInBuildandTreatWarningsAsErrorswere already on, so setting the severity looked like it should be enough. It isn't — I setdotnet_diagnostic.IDE0017.severity = errorand a deliberate probe violation still built clean, while a deliberate SonarS3400in the same build failed it as expected. Analyzers were running; noIDE*diagnostic was ever reported.Roslyn's command-line driver skips analyzers whose diagnostics are all info/hidden by default, and that decision happens before your
.editorconfigseverity is consulted. So theIDE*family was being dropped from the build no matter what severity it was given.The differentiator is
/errorlog. Confirmed by elimination:dotnet_diagnostic.IDE0017.severity = errorin.editorconfig.globalconfig(verified it reachedcsc)-p:EnableCodeStyleSeverity=true-p:ErrorLog=…error IDE0017That also explains the original symptom: SonarScanner sets
ErrorLogitself to importroslyn:*issues, so Sonar has been seeing a diagnostic set the build never computed.Changes
Directory.Build.targets(new) — setsErrorLogtoobj/…/<Project>.sarif. In.targetsrather than.propsbecauseIntermediateOutputPathisn't defined that early; from.propsit expands to empty and litters a.sarifinto every project directory (I hit exactly that). Guarded byCondition="'$(ErrorLog)' == ''"so SonarScanner's own value wins when it runs..editorconfig—dotnet_diagnostic.IDE0017.severity = warning, promoted to an error byTreatWarningsAsErrors.CameraControllerSeamTests.cs— the two real violations this surfaced, rewritten to the object-initializer form already used elsewhere in the file.Verification
dotnet build RustPlusApi.sln --no-incremental→ exit 0. The onlyIDE0017hits solution-wide were those two; no flood of newly-unmasked analyzers.dotnet buildfails witherror IDE0017, exit 1.dotnet test RustPlusApi.sln→ 1239 passed, 18 projects, both TFM hosts.jb cleanupcodeon the edited file is idempotent, so the pre-push hook won't reject it..sariffiles land inobj/, already covered by.gitignore:31.The pre-existing
MSB3073warning (git config core.hooksPathexiting 255) is a local sandbox git-lock artifact, present before these changes and unrelated.Follow-ups (not in this PR)
IDE*family, so any otherroslyn:IDE*smell Sonar reports can now be gated by adding a severity line next toIDE0017— no further plumbing.CLAUDE.md's "Commands" section describes the strict build as "TreatWarningsAsErrors + latest-all analyzers"; that's now slightly incomplete. The mechanism is documented in theDirectory.Build.targetscomment for the moment.🤖 Generated with Claude Code