Repository navigation
[code-simplifier] Simplify RedundantTestMethodAttributeAnalyzer named-argument lookups - #11304
Conversation
Consolidate three duplicated foreach loops over AttributeData.NamedArguments (searching for a single named argument by key) into a shared TryGetNamedArgument helper, reused by HasNonEmptyConditionIgnoreMessage, GetNamedIntArgument, and TryGetIgnoreMessage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Summary
This PR is a small, self-contained internal refactor of RedundantTestMethodAttributeAnalyzer.cs. It consolidates three duplicated "find named argument by key" loops (HasNonEmptyConditionIgnoreMessage, GetNamedIntArgument, TryGetIgnoreMessage) into a single shared TryGetNamedArgument helper, and converts two methods to expression-bodied members. No public API surface, resources, or behavior-affecting logic paths are touched.
Semantic equivalence verified: Attribute named-argument keys are unique per attribute usage, so TryGetNamedArgument's "return on first key match" is equivalent to each original loop's per-key scan. The fallback behavior when a matched value's runtime type doesn't match the expected type (int in GetNamedIntArgument, string in the IgnoreMessage cases) is preserved identically (falls through to the default/prior value), matching the original implementations exactly.
Verdict by Dimension
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | Clean — refactor is behavior-preserving; traced all 3 call sites against original loops |
| 2 | Threading & Concurrency | N/A — no shared mutable state introduced |
| 3 | Public API Surface | N/A — all changed members are private static |
| 4 | Backward Compatibility | N/A — internal analyzer implementation detail only |
| 5 | Performance | Clean — marginal improvement (single shared helper, same O(n) scan) |
| 6 | Cross-TFM Correctness | Clean — no TFM-specific constructs used |
| 7 | IPC Contract Stability | N/A |
| 8 | Localization | N/A — no resource/string changes |
| 9 | Test Coverage | Clean — pure refactor of existing, already-tested logic; no new branches introduced that would require new tests |
| 10 | Security | N/A |
| 11 | Explicit vs. Implicit | Clean — TryGetNamedArgument is a clear, idiomatic Try* pattern |
| 12 | Simplicity | Improvement — reduces duplication, more concise expression-bodied members |
| 13–22 | (Analyzers/design/style/etc.) | N/A / clean — no findings |
Findings
None. No inline comments were necessary — the change is a straightforward, verified-equivalent internal refactor with no functional, API, or style concerns.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The helper currently returns the first matching IgnoreMessage, changing existing behavior for duplicate entries.
Get a fresh assessment by requesting another Copilot review.
Review tier: Lite (auto)
Findings: 1
Note
Copilot is running an experiment and ran this review at Lite.
Open (1)
What changed in this PR
This pull request centralizes named-argument lookups in RedundantTestMethodAttributeAnalyzer.
Changes:
- Adds shared
TryGetNamedArgumentlogic. - Reuses it across condition, retry, and ignore-message handling.
- Requires preserving the previous last-match behavior for duplicate
IgnoreMessageentries.
| File | Summary |
|---|---|
src/Analyzers/MSTest.Analyzers/RedundantTestMethodAttributeAnalyzer.cs |
Consolidates duplicated named-argument lookup logic. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Preserve the previous typed lookup behavior in GetNamedIntArgument.
Get a fresh assessment by requesting another Copilot review.
Review tier: Lite (auto)
Findings: 1
Note
Copilot is running an experiment and ran this review at Lite.
Open (1)
Resolved since last review (1)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
…ute-analyzer-49b5906d3e2a4a9c
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No blocking issues were identified; remaining feedback is a minor validation-count clarification.
Review effort: Lite (auto)
Findings: None
Note
Copilot is running an experiment and ran this review at Lite.
This comment has been minimized.
This comment has been minimized.
|
Final test-triage resolution — Azure Pipelines build 1599689 Analysis is final (completed build, Signature: The same test passed on the Linux Release and MacOS Release legs in this same build, so the failure is isolated to Windows file-handle contention around the cancellation-signal temp file rather than a cross-platform product regression. Confidence: Moderate. The stack trace shows the failure originates from opening the signal file ( History: Checked up to 12 prior completed builds (main branch, 30-day window; Decision: Per the persistent-failure threshold, this does not warrant a new issue (only one occurrence, no cross-build recurrence, no existing matching issue found in a search of open/closed issues for this test/class/signal-file name). Recommend a maintainer re-run the Windows leg to confirm this was a transient file-locking race; if it recurs on an unrelated commit/build, it should be escalated then. No corresponding issue created; other build legs for this PR are unaffected (candidateCount 94, only 1 failure/retry signal, 0 diagnostics).
|


Consolidate three duplicated foreach loops over AttributeData.NamedArguments (searching for a single named argument by key) into a shared TryGetNamedArgument helper, reused by HasNonEmptyConditionIgnoreMessage, GetNamedIntArgument, and TryGetIgnoreMessage.
Fixes #11303