-
Notifications
You must be signed in to change notification settings - Fork 462
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
Port FxCop Code Metrics rules #1740
Conversation
1. [CA1501](https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1501-avoid-excessive-inheritance): Avoid excessive inheritance 2. [CA1502](https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1502-avoid-excessive-complexity): Avoid excessive complexity 3. [CA1505](https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1505-avoid-unmaintainable-code): Avoid unmaintainable code 4. [CA1506](https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1506-avoid-excessive-class-coupling): Avoid excessive class coupling Fixes dotnet#433 Fixes dotnet#434 Fixes dotnet#436 Fixes dotnet#437 Future work items (I will file issues for these soon): 1. Refactor the core code metrics computation into a separate library. 2 A command line tool, such as Metrics.exe, that uses the above library and dumps out the metrics tree onto console or a log file (Metrics.exe shipped prior to VS2017). 3. Share code with VS implementation of Code Metrics - currently we have a clone of the code that computes the metrics. Once we start inserting packages from this repo to VS repo, we can delete the clone and reference that package (which will need to happen when we move CodeStyle rules to NuGet packages).
Tagging @heejaechang as the core code metrics computation code/tests are a clone from the VS side pull request. #1741 tracks refactoring/packaging this further. |
is analyzer only new code and all others are just fork from vs side? |
Yes, analyzer and analyzer tests are the only new piece of code. |
/// CA1501: 10 | ||
/// See CA1508 unit tests for more examples. | ||
/// </summary> | ||
private const string CodeMetricsConfigurationFile = "CodeMetricsConfig.txt"; |
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.
is this existing format? or new? if it is new, can we use new editorconfig support?
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.
Talked offline, the editorconfig options passed down to the compiler/analyzers is still not checked in, and will not work against 2.6.1 (which the current branch targets)
{ | ||
compilationContext.ReportDiagnostic(diagnostic); | ||
} | ||
} |
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.
is it intentionally keep going? or forgot to return?>
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.
Good idea, let me change analyzer to bail out on configuration errors.
} | ||
|
||
// Compute code metrics. | ||
var computeTask = Task.Run(() => CodeAnalysisMetricData.ComputeAsync(compilationContext.Compilation, compilationContext.CancellationToken)); |
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.
is there a reason who run it on Task.Run and then wait on that? rather than directly wait on task returned by ComputAsync?
private static bool TryParseCodeMetricsConfigurationFile( | ||
AdditionalText additionalText, | ||
CancellationToken cancellationToken, | ||
out ImmutableDictionary<string, List<(SymbolKind?, uint)>> ruleIdToThresholdMap, |
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.
reason it is List rather than dictionary? I guess it is expected to be small most of time?
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.
IReadOnlyList?
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.
Yes, only one rule realistically needs separate values for Types and Methods. I can change it to IReadOnlyList.
@dotnet-bot retest prtest/Windows/NT/Debug please |
1 similar comment
@dotnet-bot retest prtest/Windows/NT/Debug please |
|
||
"; | ||
|
||
var expectedMetricsText = @" |
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.
are these new test or ported from VS side?
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.
Ported from VS side. Hopefully we will delete from VS side soon.
@@ -0,0 +1,103 @@ | |||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
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.
is this right copyright header?
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 used the same header as other files in the repo, for example https://github.com/dotnet/roslyn-analyzers/blob/master/src/Utilities/DiagnosticHelpers.cs#L1
Fixes #433
Fixes #434
Fixes #436
Fixes #437
Customer requests:
Future work items (
I will file issues for these soon#1741):