Skip to content

Make PragmaScope a no-op for empty warning lists to prevent global warning suppression leakage - #98

Merged
matt-edmondson merged 2 commits into
mainfrom
copilot/fix-empty-warning-list-issue
Sep 13, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
copilot/fix-empty-warning-list-issue

Conversation

Copilot AI commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

PragmaScope previously emitted bare #pragma warning disable/restore when given an empty warning list, which in C# applies to all warnings. In nested scopes, this could both over-suppress diagnostics inside the inner scope and prematurely restore warnings in an enclosing scope.

  • Behavioral change: empty warnings are now no-op

    • PragmaScope now skips emitting directives when warnings is null/empty/whitespace.
    • This preserves enclosing suppression state and avoids accidental global suppression.
  • API contract documentation

    • Updated PragmaScope XML docs on the warnings parameter to explicitly define empty/whitespace input as no-op behavior.
  • Regression coverage

    • Added tests for:
      • empty string input (new PragmaScope(cb, ""))
      • empty sequence input (new PragmaScope(cb, [])) nested inside an outer pragma scope
    • The nested case verifies the outer CS1591 suppression remains active until its own scope closes.
using (new PragmaScope(cb, "CS1591"))
{
    using (new PragmaScope(cb, [])) // now no-op
    {
        cb.WriteLine("public int X;");
    }

    cb.WriteLine("public int Y;"); // still under CS1591 suppression
}

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix PragmaScope handling of empty warning lists Make PragmaScope a no-op for empty warning lists to prevent global warning suppression leakage Sep 13, 2026
@matt-edmondson
matt-edmondson marked this pull request as ready for review September 13, 2026 13:04
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 4c823eb into main Sep 13, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the copilot/fix-empty-warning-list-issue branch September 13, 2026 13:14
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.

PragmaScope with an empty warning list emits a bare disable/restore, silently suppressing all warnings and clobbering an enclosing scope

2 participants