Skip to content

Don't report CA1704 for parameters named _ - #86288

Merged
jasonmalinowski merged 1 commit into
dotnet:mainfrom
komsa:Feature/ca1704-discard-parameters
Nov 3, 2026
Merged

jasonmalinowski merged 1 commit into
dotnet:mainfrom
komsa:Feature/ca1704-discard-parameters

Conversation

@FreeAndNil

@FreeAndNil FreeAndNil commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Related to dotnet/roslyn-analyzers#5183, follow-up to #85161

@jasonmalinowski @CyrusNajmabadi you mentioned being open to a few more special cases if they present themselves; this is the next one.

Problem

CA1704 reports _ as an unmeaningful parameter name:

[ClassInitialize]
public static void ClassInitialize(TestContext _) { }
//                                             ^ CA1704

_ is the established way to mark a parameter that a signature requires but the method does not use. IDE0060 (remove unused parameter) explicitly skips parameters named _, _1, … for that reason (IsSymbolWithSpecialDiscardName). So the two analyzers contradict each other:

  • keep _ → CA1704
  • rename to e.g. context → IDE0060

On one mid-size codebase, after #85161, 20 of the remaining 103 CA1704 findings were parameters named _.

Change

A parameter named _ is no longer reported by CA1704.

  • _1, __ etc. were never reported (longer than one character, no words to spell check)
  • fields named _ are unaffected (the _ prefix is stripped, nothing remains)
  • every other single-letter parameter is still reported

Notes for review

  • Only removes diagnostics, so it cannot break existing builds.
  • No new rule, option or descriptor change, so no AnalyzerReleases entry is needed.
  • No new public API.

Tests

In IdentifiersShouldBeSpelledCorrectlyTests:

  • _ as method, constructor and delegate parameter → no diagnostic
Microsoft Reviewers: Open in CodeFlow

@FreeAndNil
FreeAndNil requested a review from a team as a code owner November 3, 2026 09:27
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Nov 3, 2026
@jasonmalinowski

Copy link
Copy Markdown
Member

Yes, that's quite reasonable. 😄

@jasonmalinowski
jasonmalinowski merged commit ff3971a into dotnet:main Nov 3, 2026
25 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Nov 3, 2026
@akhera99 akhera99 modified the milestones: Next, 18.14 Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Analyzers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants