Skip to content

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Dec 17, 2020

Fixes #50011

@Youssef1313 Youssef1313 changed the title Ban DiagnosticAnalyzer ctor in CodeStyle layer Ban DiagnosticDescriptor ctor in CodeStyle layer Dec 17, 2020
@Youssef1313
Copy link
Member Author

@mavasani I can't figure out why the build is passing here. Can you assist please?

@mavasani
Copy link
Contributor

Sure, let me investigate.

@mavasani
Copy link
Contributor

Hopefully, you should see build failure with RS0030 diagnostics now.

@Youssef1313
Copy link
Member Author

@mavasani The analyzers that cause RS0030 are run against generated code, while AbstractBuiltInCodeStyleDiagnosticAnalyzer doesn't. e.g:

context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);

@mavasani
Copy link
Contributor

mavasani commented Jan 5, 2021

@Youssef1313 I wouldn't worry about violation in AbstractValidateFormatStringDiagnosticAnalyzer.cs - just add a source suppression as @Evangelink's PR dotnet/roslyn-analyzers#4226 will soon help us remove that analyzer completely.

I think we do want to run AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer.cs on generated code, so a source suppression with a good comment should be good for it as well.

T:Microsoft.CodeAnalysis.CodeStyle.NotificationOption; Use 'Microsoft.CodeAnalysis.CodeStyle.NotificationOption2' instead
T:Microsoft.CodeAnalysis.CodeStyle.NotificationOption; Use 'Microsoft.CodeAnalysis.CodeStyle.NotificationOption2' instead
M:Microsoft.CodeAnalysis.DiagnosticDescriptor.#ctor(System.String,System.String,System.String,System.String,Microsoft.CodeAnalysis.DiagnosticSeverity,System.Boolean,System.String,System.String,System.String[]); Analyzers should extend 'AbstractBuiltInCodeStyleDiagnosticAnalyzer' or 'AbstractCodeQualityDiagnosticAnalyzer' instead
M:Microsoft.CodeAnalysis.DiagnosticDescriptor.#ctor(System.String,Microsoft.CodeAnalysis.LocalizableString,Microsoft.CodeAnalysis.LocalizableString,System.String,Microsoft.CodeAnalysis.DiagnosticSeverity,System.Boolean,Microsoft.CodeAnalysis.LocalizableString,System.String,System.String[]); Analyzers should extend 'AbstractBuiltInCodeStyleDiagnosticAnalyzer' or 'AbstractCodeQualityDiagnosticAnalyzer' instead
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to ban all overloads of the constructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Youssef1313 That would be a feature request for the Banned API analyzer. Feel free to file one on the roslyn-analyzers repo.

Copy link
Contributor

@mavasani mavasani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

If you can also update the help links for IDE0005 descriptors, that will be nice. Thanks!

@mavasani
Copy link
Contributor

mavasani commented Jan 5, 2021

@Youssef1313 You also have some merge conflicts.

@Youssef1313
Copy link
Member Author

protected DiagnosticDescriptor CreateDescriptorWithId(
LocalizableString title, LocalizableString message)
{
return new DiagnosticDescriptor(
_descriptorId, title, message,
DiagnosticCategory.Style,
DiagnosticSeverity.Hidden,
isEnabledByDefault: true);
}

The above method is used by IDE0053

We should check whether it currently has the correct link. If it doesn't and the current build didn't fail, we need think of an alternative/enhancement. Probably add a new test to [IDEDiagnosticIDConfigurationTests] (https://github.com/dotnet/roslyn/blob/5eae4001901cb03a71c668f2aaa42783ea50570b/src/EditorFeatures/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs) for validating the help links.

@mavasani
Copy link
Contributor

mavasani commented Jan 5, 2021

We should check whether it currently has the correct link. If it doesn't and the current build didn't fail, we need think of an alternative/enhancement

@Youssef1313 I think we are fine here - we don't expect many analyzers to be IDE-only analyzers (not present in CodeStyle layer). The guidance for future is absolutely to add analyzers to the shared layer, which implicitly adds them to CodeStyle layer. If absolutely required, we can also add the banned symbols added in this PR to https://github.com/dotnet/roslyn/blob/master/src/Features/BannedSymbols.txt

@mavasani
Copy link
Contributor

mavasani commented Jan 6, 2021

@Youssef1313 Tests are still failing.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approval

@Youssef1313 Youssef1313 marked this pull request as ready for review January 6, 2021 18:53
@Youssef1313 Youssef1313 requested a review from a team as a code owner January 6, 2021 18:53
@jinujoseph jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jan 6, 2021
@mavasani mavasani merged commit 0f8d5c9 into dotnet:master Jan 6, 2021
@ghost ghost added this to the Next milestone Jan 6, 2021
@Cosifne Cosifne modified the milestones: Next, 16.9 Jan 27, 2021
@JoeRobich JoeRobich modified the milestones: 16.9, 16.9.P4 Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE auto-merge Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

6 participants