Skip to content

Use NetAnalyzers from SDK instead of FxCopAnalyzers - #30138

Merged
pranavkm merged 26 commits into
dotnet:mainfrom
Youssef1313:migrate-analyzers
Feb 19, 2021
Merged

pranavkm merged 26 commits into
dotnet:mainfrom
Youssef1313:migrate-analyzers

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Feb 12, 2021 •

Copy link
Copy Markdown
Member

Fixes #30099

  • Replaces FxCopAnalyzers package references with NetAnalyzers. (Used from .NET SDK instead of package)
  • Deletes rulset files
  • Migrate rulesets to editorconfigs

@sharwell Can you review?

@Youssef1313
Youssef1313 requested a review from a team as a code owner February 12, 2021 11:34
@ghost ghost added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Feb 12, 2021
Comment thread eng/targets/CSharp.Common.props Resolved
@Youssef1313 Youssef1313 changed the title Use NetAnalyzers WIP: Use NetAnalyzers Feb 12, 2021
@Youssef1313
Youssef1313 requested a review from dougbu as a code owner February 12, 2021 11:50
@Youssef1313 Youssef1313 changed the title WIP: Use NetAnalyzers WIP: Use NetAnalyzers from SDK instead of FxCopAnalyzers Feb 12, 2021
@Youssef1313

Youssef1313 commented Feb 12, 2021 •

Copy link
Copy Markdown
Member Author

There CA1310 violations like:

Do you want me to pass a StringComparison.Ordinal, or StringComparison.Invariant, or disable the rule?

I'm not sure why the main branch doesn't fail with this error. It's already enabled without my changes 😄

@Pilchie Pilchie added the community-contribution Indicates that the PR has been added by a community member label Feb 12, 2021
@Pilchie Pilchie self-assigned this Feb 12, 2021

@Pilchie Pilchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pranavkm or @NTaylorMullen any ideas on why it doesn't already fail?

I definitely prefer Ordinal comparisons whenever possible, especially for language keyword comparisons.

return false;
}

return left.Equals(right);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note - safe because SourceSpan is a struct, so can't be null, and will never be ReferenceEquals.

@Pilchie

Pilchie commented Feb 12, 2021

Copy link
Copy Markdown
Member

Looks good so far - let me know when you're done.

Comment thread .editorconfig Resolved
Comment thread .editorconfig Outdated
dotnet_diagnostic.CA1305.severity = error
dotnet_diagnostic.CA1310.severity = error
# Temporarily disabling, waiting on PR feedback to re-enable
dotnet_diagnostic.CA1310.severity = none

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.

💡 Setting diagnostic severity is more efficient if it's done in a globalconfig instead of editorconfig. See dotnet/razor#3087 for an example of how I converted aspnetcore-tooling from rulesets to globalconfig.

Comment thread src/Mvc/Directory.Build.props Resolved
@Youssef1313

Youssef1313 commented Feb 14, 2021 •

Copy link
Copy Markdown
Member Author

There are some violations of CA1305 from https://github.com/aspnet/MessagePack-CSharp.git which is imported through gitmodules. I'll move this specific rule to .editorconfig instead of .globalconfig as a workaround.

@Youssef1313 Youssef1313 changed the title WIP: Use NetAnalyzers from SDK instead of FxCopAnalyzers Use NetAnalyzers from SDK instead of FxCopAnalyzers Feb 15, 2021
@Youssef1313

Copy link
Copy Markdown
Member Author

This should be ready for another look.

@Pilchie Pilchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me, but I'd like @pranavkm or @NTaylorMullen to make sure they agree with me about the Ordinal comparisons in the Razor compiler before we merge.

Comment thread .editorconfig Resolved

@pranavkm pranavkm left a comment

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.

Thanks, this is absolutely great!

var targetQueue = GetTargetHelixQueue().ToLowerInvariant();

if (Queues.Contains("All.OSX") && targetQueue.StartsWith("osx"))
if (Queues.Contains("All.OSX") && targetQueue.StartsWith("osx", StringComparison.OrdinalIgnoreCase))

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.

Suggested change
if (Queues.Contains("All.OSX") && targetQueue.StartsWith("osx", StringComparison.OrdinalIgnoreCase))
if (Queues.Contains("All.OSX") && targetQueue.StartsWith("osx", StringComparison.Ordinal))

That would be the equivalent to the previous check

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.

I'll let this be. This is test-only code so it doesn't make a difference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@HaoK actually asked to change this to OrdinalIgnoreCase as part of this review.

@pranavkm
pranavkm merged commit 350ea5b into dotnet:main Feb 19, 2021
@Youssef1313
Youssef1313 deleted the migrate-analyzers branch February 19, 2021 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from FxCopAnalyzers to NetAnalyzers

7 participants