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

IDE1006 fires on discard parameters #47569

Closed
Forge36 opened this issue Sep 9, 2020 · 3 comments · Fixed by #48306
Closed

IDE1006 fires on discard parameters #47569

Forge36 opened this issue Sep 9, 2020 · 3 comments · Fixed by #48306
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Analyzers Question
Milestone

Comments

@Forge36
Copy link

Forge36 commented Sep 9, 2020

Version Used:
Microsoft Visual Studio Professional 2019
Version 16.6.3

Steps to Reproduce:

  1. Create a function with an unused parameter (I used _ and _1 to handle multiple discarded parameters)
    public object DiscardParameter(string _1)
  2. Define .editorconfig rule
    dotnet_naming_rule.parameter_should_be_camelcase.severity = suggestion
    dotnet_naming_rule.parameter_should_be_camelcase.symbols = parameter
    dotnet_naming_rule.parameter_should_be_camelcase.style = camelcase

Expected Behavior:
No warning

Actual Behavior:

Severity Code Description Project File Line Suppression State Priority
Message IDE1006 Naming rule violation: Prefix '_' is not expected *** *** 903 Active Normal

Reference:
https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1801?view=vs-2019

This rule does not flag parameters that are named with the discard symbol, for example, _, _1, and _2

Incompatible rules are confusing

@Youssef1313
Copy link
Member

Youssef1313 commented Sep 10, 2020

The doc link you're referring to is for CA1801 which is unrelated to IDE1006.

The behavior I'm seeing for IDE1006 seems correct (camel case shouldn't start with _).

@Forge36
Copy link
Author

Forge36 commented Sep 10, 2020

The doc link you're referring to is for CA1801 which is unrelated to IDE1006.

The behavior I'm seeing for IDE1006 seems correct (camel case shouldn't start with _).

CA1801 defines discard parameters as _ or _1 ... .
IDE1006 defines _ as an exception to the naming rules.

This conflict causes fixes to CA1801 to raise IDE1006.

It appears to be a bug that the two rules don't share the same exceptions. Currently the only way to resolve this (when the parameters can't be removed, and are not used) is to add a suppression for one of the errors.

@jinujoseph jinujoseph added this to the 16.9 milestone Oct 4, 2020
@jinujoseph jinujoseph added the 4 - In Review A fix for the issue is submitted for review. label Oct 4, 2020
@sharwell sharwell added the Need Design Review The end user experience design needs to be reviewed and approved. label Oct 11, 2020
@kendrahavens
Copy link
Contributor

Design Meeting Notes

  • We should recognize this syntax and update the naming style analyzers to ignore "_<#>"
  • We have concerns that "_1" can be used as a parameter and is not actually recognized as a "true" discard. It can be used like a regular parameter name and not get a warning. This makes us want the language itself to recognize these as discards. (Will bring forward at LDM)
    • For this case, we should add an analyzer to recommend using a true discard if a "fake" discard is used. Especially as when multiple discards are allowed in C#9.

@ghost ghost closed this as completed in #48306 Oct 15, 2020
@jinujoseph jinujoseph removed the Need Design Review The end user experience design needs to be reviewed and approved. label Oct 16, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Analyzers Question
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants