question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage of _ in methods arguments raises SA1313

See original GitHub issue

Usage of _ in method arguments raises SA1313.

Example:

public override void Foo( int arg, int _ )
{
...
}

Can you please make an exception to SA1313, to support ‘_’ in method arguments?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
sharwellcommented, Nov 17, 2020

Closing this one as won’t fix. The recommended solution for method signatures when a parameter is intentionally not used is:

  1. Give the parameter a meaningful name. This should match the original definition when applicable (see #1949).
  2. Assign the parameter to a discard at the start of the method to clearly indicate to the reader that the parameter is intentionally unused.

For example:

public void Method(T value)
{
  _ = value;
}
4reactions
palenshuscommented, Nov 15, 2022

Currently IDE0060 suggests that we do in fact rename unused parameters to _:

IDE0060 Remove unused parameter ‘sender’ if it is not part of a shipped public Avoid unused parameters in your code. If the parameter cannot be removed, then change its name so it starts with an underscore and is optionally followed by an integer, such as ‘_’, ‘_1’, ‘_2’, etc. These are treated as special discard symbol names.

However, if we follow that advice, given by the IDE, then we run into this issue. That doesn’t seem like a good thing to Won’t Fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

StyleCopAnalyzers/documentation/SA1313.md at master
This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic. Cause. The name of a parameter in C# does...
Read more >
https://raw.githubusercontent.com/dotnet/runtime/8...
Interface methods should be callable by child types --> <Rule Id="CA1034" ... Use Integral Or String Argument For Indexers --> <Rule Id="CA1044" ...
Read more >
stylecop - StyleCopAnalyzers/SA1313 in a positional record
So, the elements FirstName and LastName act both as a property and an argument for the constructor. As properties, these elements should be ......
Read more >
CA2208: Instantiate argument exceptions correctly
When a method has a parameter, and it throws an exception type that is, or derives from, ArgumentException, it is expected to call...
Read more >
Identification of Novel Thermosensors in Gram-Positive ...
Through in vivo experiments, we demonstrate that SA1313 from Staphylococcus aureus and BA5598 from Bacillus anthracis, which likely control ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found