Skip to content

Conversation

@azarasi3
Copy link

#2974 SA1313: Parameter '__' must begin with lower-case letter.

Support for parameter names containing only '_'

The issue with lambda expression parameter names can be resolved by apply the following three options:

  • Allow
    1. All _
    System.Action<int, int, int> action = (_, _, _) => { };
    
    1. Increasing from _ by one character
    System.Action<int, int, int> action = (_, __, ___) => { };
    
  • Not allow
    1. Single __ is not allowed
    System.Action<int> action = __ => { };
    

A compromise between IDE0060 and SA1313

Although it was decided not to fix it in #2599, since there is an exception rule for _ in SA1313, we think that it can be resolved by allowing parameters starting with _ as an exception when they are unused, in response to IDE0060 in SA1313.

  • Exception rule:
    • Since _ in method parameter names can be used as variables, the naming convention prioritizes unused intent and allows unused parameter names starting with _.
      However, to prioritize simple code, explicit discarding is not allowed.
    • In the case where parameter names start with _ and increase by one character at a time.
  • Examples
    • Allowed
      void Handler(object sender, EventArgs e) { _ = sender; _ = e; } // Explicit discards
    • Allow
      void Handler(object _, EventArg __) { }
      void MethodName(int _, int a, int __) { }
    • Not allow
      void Handler(object _1, EventArg _2) { _ = _1; _ = _2; } // Explicit discards
      void MethodName(ref int _) { ++_; }

@codecov
Copy link

codecov bot commented Sep 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.45%. Comparing base (f5843ae) to head (8bd213f).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #3892    +/-   ##
========================================
  Coverage   97.44%   97.45%            
========================================
  Files         926      932     +6     
  Lines      110283   110571   +288     
  Branches     3319     3328     +9     
========================================
+ Hits       107467   107758   +291     
+ Misses       1847     1845     -2     
+ Partials      969      968     -1     

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.

1 participant