-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Set up-to-date .NET code quality analyzers #30921
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8f6e5c4
Convert legacy ruleset to globalconfig
huoyaoyuan c57ace0
Enable recommended rules for documentation
huoyaoyuan cd9b592
Enable recommended rules for globalization
huoyaoyuan 13d7c6a
Enable recommended rules for maintainability
huoyaoyuan f5a7716
Apply minor performance rules
huoyaoyuan 5b63d72
Mark CA1826/CA1860 as suggestion
huoyaoyuan 0a8ec4d
Enable recommended rules for reliability
huoyaoyuan fced254
Enable selected rules for usage
huoyaoyuan fa3c95c
Merge branch 'master'
huoyaoyuan 68f2170
Fix CA1865
huoyaoyuan 68f4fa5
Turn off CA1507
huoyaoyuan 7ece8ec
Update for suggestions
huoyaoyuan d92ea91
Merge branch 'master' into netcore-analyzer
huoyaoyuan 68e400d
Put globalconfig into seperated folder and reference explicitly
huoyaoyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# .NET Code Style | ||
# IDE styles reference: https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ | ||
is_global = true | ||
|
||
# IDE0001: Simplify names | ||
dotnet_diagnostic.IDE0001.severity = warning | ||
|
||
# IDE0002: Simplify member access | ||
dotnet_diagnostic.IDE0002.severity = warning | ||
|
||
# IDE0003: Remove qualification | ||
dotnet_diagnostic.IDE0003.severity = warning | ||
|
||
# IDE0004: Remove unnecessary cast | ||
dotnet_diagnostic.IDE0004.severity = warning | ||
|
||
# IDE0005: Remove unnecessary imports | ||
dotnet_diagnostic.IDE0005.severity = warning | ||
|
||
# IDE0034: Simplify default literal | ||
dotnet_diagnostic.IDE0034.severity = warning | ||
|
||
# IDE0036: Sort modifiers | ||
dotnet_diagnostic.IDE0036.severity = warning | ||
|
||
# IDE0040: Add accessibility modifier | ||
dotnet_diagnostic.IDE0040.severity = warning | ||
|
||
# IDE0049: Use keyword for type name | ||
dotnet_diagnostic.IDE0040.severity = warning | ||
|
||
# IDE0055: Fix formatting | ||
dotnet_diagnostic.IDE0055.severity = warning | ||
|
||
# IDE0051: Private method is unused | ||
dotnet_diagnostic.IDE0051.severity = silent | ||
|
||
# IDE0052: Private member is unused | ||
dotnet_diagnostic.IDE0052.severity = silent | ||
|
||
# IDE0073: File header | ||
dotnet_diagnostic.IDE0073.severity = warning | ||
|
||
# IDE0130: Namespace mismatch with folder | ||
dotnet_diagnostic.IDE0130.severity = warning | ||
|
||
# IDE1006: Naming style | ||
dotnet_diagnostic.IDE1006.severity = warning | ||
|
||
# CA1305: Specify IFormatProvider | ||
# Too many noisy warnings for parsing/formatting numbers | ||
dotnet_diagnostic.CA1305.severity = none | ||
|
||
# CA1507: Use nameof to express symbol names | ||
# Flaggs serialization name attributes | ||
dotnet_diagnostic.CA1507.severity = suggestion | ||
|
||
# CA1806: Do not ignore method results | ||
# The usages for numeric parsing are explicitly optional | ||
dotnet_diagnostic.CA1806.severity = suggestion | ||
|
||
# CA1822: Mark members as static | ||
# Potential false positive around reflection/too much noise | ||
dotnet_diagnostic.CA1822.severity = none | ||
|
||
# CA1826: Do not use Enumerable method on indexable collections | ||
dotnet_diagnostic.CA1826.severity = suggestion | ||
|
||
# CA1859: Use concrete types when possible for improved performance | ||
# Involves design considerations | ||
dotnet_diagnostic.CA1859.severity = suggestion | ||
|
||
# CA1860: Avoid using 'Enumerable.Any()' extension method | ||
dotnet_diagnostic.CA1860.severity = suggestion | ||
|
||
# CA1861: Avoid constant arrays as arguments | ||
# Outdated with collection expressions | ||
dotnet_diagnostic.CA1861.severity = suggestion | ||
|
||
# CA2007: Consider calling ConfigureAwait on the awaited task | ||
dotnet_diagnostic.CA2007.severity = warning | ||
|
||
# CA2016: Forward the 'CancellationToken' parameter to methods | ||
# Some overloads are having special handling for debugger | ||
dotnet_diagnostic.CA2016.severity = suggestion | ||
|
||
# CA2021: Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types | ||
# Causing a lot of false positives with generics | ||
dotnet_diagnostic.CA2021.severity = none | ||
|
||
# CA2101: Specify marshaling for P/Invoke string arguments | ||
# Reports warning for all non-UTF16 usages on DllImport; consider migrating to LibraryImport | ||
dotnet_diagnostic.CA2101.severity = none | ||
|
||
# CA2201: Do not raise reserved exception types | ||
dotnet_diagnostic.CA2201.severity = warning | ||
|
||
# CA2208: Instantiate argument exceptions correctly | ||
dotnet_diagnostic.CA2208.severity = suggestion | ||
|
||
# CA2242: Test for NaN correctly | ||
dotnet_diagnostic.CA2242.severity = warning | ||
|
||
# Banned APIs | ||
dotnet_diagnostic.RS0030.severity = error | ||
|
||
# Temporarily disable analysing CanBeNull = true in NRT contexts due to mobile issues. | ||
# See: https://github.com/ppy/osu/pull/19677 | ||
dotnet_diagnostic.OSUF001.severity = none |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Higher global_level has higher priority, the default global_level | ||
# is 100 for root .globalconfig and 0 for others | ||
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files#precedence | ||
is_global = true | ||
global_level = 101 | ||
|
||
dotnet_diagnostic.CA2007.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this debatable. This is test code, so performance isn't a matter, and
.Count() > 0
is way clearer than.Any()
in my book. To the point that rider has begun flagging.Any()
usages and suggesting to replace them with count checks at hint level.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The story about
Any
vsCount
is beyond this. CA1860 is about using.Count > 0
instead of predicate-less.Any()
, and has a lot of violations in both game and test code. When using a predicate, the performance characteristic reverses.Do you mean predicate-less
Any
? This is the same as CA1860.To be straight, performance-wise,
.Count
is better than.Any()
, butAny()
is better than.Count()
, and.Any(predicate)
is better than.Count(predicate)
. This leads to inconsistent style for maximizing performance.I'm very sure that the performance is not important here. The question is whether to prefer
.Count > 0
overAny()
for every cases - it has about 30 violations in game code base.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's situational, at least for test code. At the end of the day it's up to the reviewers to be able to understand the code and feel whether it's maintainable or not.
For operational code, I think we can do manual review to keep things simple.
Personally, whenever I see
!x.Any(y)
, I always have to go and check the documentation for the empty case especially as it relates tox.All(!y)
. With this context,Count()
is easier to mentally parse for me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meets my expectation to keep things as-is and review in future.