Skip to content

Move IDE0078 codefix to Analyzers#60378

Merged
mavasani merged 1 commit intodotnet:mainfrom
Youssef1313:move-fixer
Mar 28, 2022
Merged

Move IDE0078 codefix to Analyzers#60378
mavasani merged 1 commit intodotnet:mainfrom
Youssef1313:move-fixer

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

Closes #45569

@Youssef1313 Youssef1313 requested a review from a team as a code owner March 25, 2022 10:31
@ghost ghost added Community The pull request was submitted by a contributor who is not a Microsoft employee. Area-IDE labels Mar 25, 2022
<Compile Include="$(MSBuildThisFileDirectory)ConvertTypeOfToNameOf\CSharpConvertTypeOfToNameOfCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConvertSwitchStatementToExpression\ConvertSwitchStatementToExpressionCodeFixProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConvertSwitchStatementToExpression\ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CSharpUsePatternCombinatorsCodeFixProvider.cs" />
Copy link
Copy Markdown
Contributor

@mavasani mavasani Mar 25, 2022

Choose a reason for hiding this comment

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

I am wondering if we should add ExportCodeFixProviderAttribute and DiagnosticAnalyzerAttribute to Banned APIs in Features layer, with a recommendation message in the diagnostic to move the analyzer/fixer down to the shared layer, when possible. For cases where this is not possible due to analyzer/fixer using a public API not available in a shipped Roslyn version, one would be expected to add a source suppression, with a reference to a tracking issue to perform the move later when the public API does become available (similar to the issue closed by this PR).

What do you thing @Youssef1313?

Copy link
Copy Markdown
Contributor

@mavasani mavasani Mar 25, 2022

Choose a reason for hiding this comment

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

Btw, I don't recall whether or not the BannedApiAnalyzer flags banned attribute constructors :-)

Copy link
Copy Markdown
Member Author

@Youssef1313 Youssef1313 Mar 25, 2022

Choose a reason for hiding this comment

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

@mavasani There are too many codefixes there (in Features) anyway. Banning the attribute (if possible) and suppressing all of the warnings is going to be noisy. I may look into moving more codefixes later. Then fix BannedApiAnalyzer if needed and use it.

{
var semanticModel = p.Target.SemanticModel;
Debug.Assert(semanticModel != null);
RoslynDebug.Assert(semanticModel != null);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Debug.Assert isn't annotated for netstandard2.0. Used RoslynDebug instead of null-suppression with !.


#if !CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer.
internal override CodeActionPriority Priority => CodeActionPriority.Low;
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how does this work in vs @mavasani ? do we pick up the CodeStyle fixer? Or do we pick up the one from Features?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We prefer the fixer and analyzer from NuGet package over the one from VSIX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Btw is there a specific reason for marking this as low priority?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mavasani From related discussion in #43596, it seems this was a copy from another feature

image

I think if overriding Priority is something important the API may be considered to be exposed publicly

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

cc @alrz

@mavasani mavasani enabled auto-merge March 28, 2022 06:40
@mavasani mavasani merged commit 634c37a into dotnet:main Mar 28, 2022
@ghost ghost added this to the Next milestone Mar 28, 2022
@Youssef1313 Youssef1313 deleted the move-fixer branch March 28, 2022 08:31
@allisonchou allisonchou modified the milestones: Next, 17.2.P3 Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE0078 diagnostic shows up without the code fix in CSharp CodeStyle NuGet package

5 participants