Fix bare #pragma warning disable in AvoidUsingRedundantElseAnalyzer - #1339
Merged
Conversation
…1338) The `#pragma warning disable` in `FindLocalIdentifiersIn` lost its warning ID in f807685, so it disabled every warning from that point to the end of the file, while the matching `#pragma warning restore IDE0010` only lifted IDE0010. Restore the ID so the suppression is scoped to the switch again. Add a `check_pragmas` CI job that rejects any `#pragma warning disable` with an empty warning list, so the ID cannot be silently dropped again.
This was referenced Aug 26, 2026
Closed
Bump Meziantou.Analyzer from 3.0.103 to 3.0.182
Analogy-LogViewer/Analogy.LogViewer.OpenTelemetry#98
Closed
Closed
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.189
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#556
Closed
This was referenced Aug 31, 2026
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.195
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#544
Open
Open
Open
Open
Open
Open
Open
Open
Open
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.
Fixes #1338
What changed
src/Meziantou.Analyzer/Rules/AvoidUsingRedundantElseAnalyzer.cs— the#pragma warning disableinFindLocalIdentifiersInhad no warning ID, so it disabled every warning from line 96 to the end of the file. The matching#pragma warning restore IDE0010only lifted IDE0010, so the blanket disable was never actually restored. The ID was lost in f807685 ("Update .NET SDK 9.0", Nov 2024). Restored it to#pragma warning disable IDE0010 // Add missing casesso the suppression is scoped to theswitchagain (and dropped the trailing whitespace the bare pragma carried)..github/workflows/ci.yml— newcheck_pragmasjob that fails on any#pragma warning disablewith an empty warning list, annotating the offending file and line. Added todeploy'sneedsso it blocks publishing. This is the cheap recurrence guard suggested in the issue; nothing in the repo linted for bare pragmas before.Why it matters
This is analyzer source that runs inside every consumer's compiler. Nullable warnings, CA rules and the project's own dogfooded MA rules were all off for
FindLocalIdentifiersIn— the helper deciding which identifiers MA0160 treats as captured. A regression there would have been flagged by neither the build nor CI.Verification
roslyn4.8→roslyn5.9) build with 0 warnings — nothing was actually being hidden by the blanket disable, so no follow-up suppressions were needed.AvoidUsingRedundantElseAnalyzerTests: 27/27 passed on bothroslyn5.9androslyn4.8.pwshin both directions: clean on this branch (exit 0), and it correctly flagsAvoidUsingRedundantElseAnalyzer.cs:96when the bare pragma is reintroduced (exit 1).dotnet run --project src/DocumentationGeneratorexits 0 — no markdown changes.Note for the reviewer
The CI check is limited to bare
disable, as the issue specified. A bare#pragma warning restoreis also legal and can silently re-enable warnings suppressed by an enclosing region, but there are none in the repo today — happy to widen the check if you'd like it to cover those too.