Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SA1313: Adding features and tests. #3892

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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 _) { ++_; }

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     

Remove unused method
Kielek added a commit to Kielek/opentelemetry-dotnet-contrib that referenced this pull request Oct 30, 2024
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