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

RS2000 ignores target-typed new expressions and creation outside of immediate field-initialization #5957

Open
ErikWe opened this issue Apr 8, 2022 · 1 comment

Comments

@ErikWe
Copy link

ErikWe commented Apr 8, 2022

Analyzer

Diagnostic ID: RS2000: Add analyzer diagnostic IDs to analyzer release

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 6.0.201

NuGet Package: Microsoft.CodeAnalysis.Analyzers

Version: 3.3.3 (Latest)

Describe the bug

RS2000 is not displayed in two separate circumstances, despite the diagnostic ID not being listed in the analyzer release:

  1. A DiagnosticDescriptor is created using a 'target-typed new expression', i.e
class Foo
{
    DiagnosticDescriptor Rule = new(...);
}
  1. A DiagnosticDescriptor is created outside of immediate field-initialization, e.g
class Foo
{
    DiagnosticDescriptor Rule { get; } = new DiagnosticDescriptor(...);
}

However, creating a DiagnosticDescriptor in the following way results in RS2000:

class Foo
{
    DiagnosticDescriptor Rule = new DiagnosticDescriptor(...);
}

Expected behavior

If the diagnostic ID is not already listed in the analyzer release, RS2000 should be displayed - as is the case in the final example above.

Actual behavior

RS2000 is not displayed.

Additional information

Related diagnostics are affected in similar ways, such as RS1017.

@Youssef1313
Copy link
Member

Youssef1313 commented Apr 9, 2022

Also #5890

Regarding the property initializer case, I don't know if the behavior was intended or not. @mavasani Do you know if property initializers should be supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants