From a5543e34fd1d8d33e5d6c3283e13c27e09b2da03 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 22 Jun 2026 10:45:49 -0700 Subject: [PATCH 1/2] Replace test #pragma suppressions with SuppressMessage and null-forgiving CODESTYLE.md now bans `#pragma warning disable` in favor of [SuppressMessage] / .editorconfig. Conform the two test cases: - CA1508 (analyzer): annotate OperatorEquals_BothNull_ReturnsTrue with [SuppressMessage] + Justification - the test intentionally compares two null tags to exercise operator== with both operands null. - CS8602 (compiler nullable; [SuppressMessage] cannot suppress it): use the null-forgiving operator on the Equals(object?) receiver instead. Build: 0 warnings / 0 errors. Tests: 257/257 pass. --- LanguageTagsTests/LanguageTagTests.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/LanguageTagsTests/LanguageTagTests.cs b/LanguageTagsTests/LanguageTagTests.cs index 63b9914..33bbe08 100644 --- a/LanguageTagsTests/LanguageTagTests.cs +++ b/LanguageTagsTests/LanguageTagTests.cs @@ -249,9 +249,7 @@ public void Equals_NullTag_ReturnsFalse() { LanguageTag tag = LanguageTag.Parse("en-US")!; _ = tag.Equals(null).Should().BeFalse(); -#pragma warning disable CS8602 - _ = tag.Equals((object?)null).Should().BeFalse(); -#pragma warning restore CS8602 + _ = tag!.Equals((object?)null).Should().BeFalse(); } [Fact] @@ -282,14 +280,17 @@ public void OperatorEquals_DifferentTags_ReturnsFalse() } [Fact] + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Maintainability", + "CA1508:Avoid dead conditional code", + Justification = "Test intentionally compares two null tags to exercise operator== with both operands null." + )] public void OperatorEquals_BothNull_ReturnsTrue() { LanguageTag? tag1 = null; LanguageTag? tag2 = null; -#pragma warning disable CA1508 // Avoid dead conditional code _ = (tag1 == tag2).Should().BeTrue(); -#pragma warning restore CA1508 } [Fact] From 3cb1785c19f5722d24927d65526d641548578932 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Mon, 22 Jun 2026 10:51:15 -0700 Subject: [PATCH 2/2] Document why null-forgiving is needed on the Equals(object?) receiver Copilot read tag! as redundant. It is load-bearing: removing it reintroduces CS8602 (verified by a clean build), because the compiler flags the Equals(object?) overload's receiver as possibly-null here - a false-positive that [SuppressMessage] cannot suppress (CS#### are compiler, not analyzer, diagnostics). Add a one-line comment so the suppression reads intentionally rather than as a real null concern. --- LanguageTagsTests/LanguageTagTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LanguageTagsTests/LanguageTagTests.cs b/LanguageTagsTests/LanguageTagTests.cs index 33bbe08..e589483 100644 --- a/LanguageTagsTests/LanguageTagTests.cs +++ b/LanguageTagsTests/LanguageTagTests.cs @@ -249,6 +249,7 @@ public void Equals_NullTag_ReturnsFalse() { LanguageTag tag = LanguageTag.Parse("en-US")!; _ = tag.Equals(null).Should().BeFalse(); + // tag is non-null; ! avoids a CS8602 false-positive on the Equals(object?) receiver. _ = tag!.Equals((object?)null).Should().BeFalse(); }