') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Replace test #pragma suppressions with SuppressMessage and null-forgiving by ptr727 · Pull Request #184 · ptr727/LanguageTags · GitHub
Skip to content

Replace test #pragma suppressions with SuppressMessage and null-forgiving - #184

Merged
ptr727 merged 2 commits into
developfrom
fix-test-pragma-suppressmessage
Jun 22, 2026
Merged

Replace test #pragma suppressions with SuppressMessage and null-forgiving#184
ptr727 merged 2 commits into
developfrom
fix-test-pragma-suppressmessage

Conversation

@ptr727

Copy link
Copy Markdown
Owner

Follow-up to the template re-sync (#182): CODESTYLE.md now bans #pragma warning disable in favor of [SuppressMessage] / .editorconfig. Two test cases in LanguageTagTests.cs used #pragma; this conforms them to the rule. Surfaced by Copilot on #183.

Changes

  • CA1508 (analyzer - "'tag1 == tag2' is always true"): annotate OperatorEquals_BothNull_ReturnsTrue with [SuppressMessage] + Justification. The test deliberately compares two null tags to exercise operator== with both operands null.
  • CS8602 (compiler nullable warning): [SuppressMessage] cannot suppress compiler CS#### diagnostics, only #pragma/NoWarn or code can. Replaced the #pragma with the null-forgiving operator on the Equals(object?) receiver - idiomatic and rule-compliant (CODESTYLE bans #pragma, not !).

No #pragma warning directives remain in the codebase.

Verification

  • dotnet build (no-incremental): 0 warnings / 0 errors
  • dotnet format style --verify-no-changes: clean
  • dotnet test: 257/257 pass

…ving
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.
CopilotAI review requested due to automatic review settings June 22, 2026 17:46

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the test suite with the newly consolidated CODESTYLE.md rule (post template re-sync) that bans #pragma warning disable by replacing pragma-based suppressions with [SuppressMessage] (for analyzer warnings) and code-based nullability handling (for compiler warnings).

Changes:

  • Replace #pragma warning disable CS8602 in Equals_NullTag_ReturnsFalse by using the null-forgiving operator on the call site.
  • Replace #pragma warning disable CA1508 in OperatorEquals_BothNull_ReturnsTrue with a method-level [SuppressMessage] including a justification.

Comment threadLanguageTagsTests/LanguageTagTests.cs
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.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@ptr727
ptr727 merged commit 0061702 into developJun 22, 2026
8 checks passed
@ptr727
ptr727 deleted the fix-test-pragma-suppressmessage branch June 22, 2026 17:53
ptr727 added a commit that referenced this pull request Jun 22, 2026
Maintenance promotion: template re-sync (#182) + test #pragma cleanup (#184). No functional change, no version.json bump.
Sign up for freeto 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.

2 participants

@ptr727