-
Notifications
You must be signed in to change notification settings - Fork 660
Add Microsoft static code analyzers #2761
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
Conversation
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.
Besides the failing dotnet format
test and the remaining _
in the codebase, this is quite wonderful. Thank you!
The only thing I can think of to add, perhaps in a followup pull request, is null
guards in all constructors.
src/GitVersion.Core.Tests/Configuration/DefaultConfigFileLocatorTests.cs
Outdated
Show resolved
Hide resolved
services.AddSingleton<IVersionStrategy>(new V2Strategy(dateTimeOffset)); | ||
}); | ||
}); | ||
var versionCalculator = GetBaseVersionCalculator(contextBuilder => contextBuilder.OverrideServices(services => |
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 prefer to keep the curly braces here as it's more readable and aligned
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.
Sorry I missed this formatting issue. Just to be sure what's your preference between
var versionCalculator = GetBaseVersionCalculator(contextBuilder =>
contextBuilder.OverrideServices(services =>
{
services.RemoveAll<IVersionStrategy>();
services.AddSingleton<IVersionStrategy>(new V1Strategy(DateTimeOffset.Now));
services.AddSingleton<IVersionStrategy>(new V2Strategy(dateTimeOffset));
}));
var versionCalculator = GetBaseVersionCalculator(contextBuilder =>
{
contextBuilder.OverrideServices(services =>
{
services.RemoveAll<IVersionStrategy>();
services.AddSingleton<IVersionStrategy>(new V1Strategy(DateTimeOffset.Now));
services.AddSingleton<IVersionStrategy>(new V2Strategy(dateTimeOffset));
}
}));
In case you go with choice 2, we will probably have to either reduce the severity, prevent preference of expression body for lambdas or use pragam disable for such places.
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.
option 1 seems fine if the second expression is on new line and aligned as in the sample
src/GitVersion.Core.Tests/VersionCalculation/BaseVersionCalculatorTests.cs
Outdated
Show resolved
Hide resolved
src/GitVersion.Core.Tests/VersionCalculation/BaseVersionCalculatorTests.cs
Outdated
Show resolved
Hide resolved
I do agree with removing _. There are 2 more things to add.
And as I suggested, please add the nuget packages to Directory.build.props instead of the csprojs |
{ | ||
CreateLocalRepository(); | ||
} | ||
: base(builder) => CreateLocalRepository(); |
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.
There is no analyzer to help with this kind of formatting. I will make the changes manually, just let me know your preference between:
- Always break after
=>
- Always break before
=>
(that's the one I usually go for but that's purely personal) - Break only on long line.
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.
3
The test seems to be working fine on my machine (VS + command line). Could you make a test on yours and let me know if that works or fails? |
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.
All tests green. LGTM!
@asbjornu Merge done. |
@Evangelink If you don't mind I'll check it tomorrow, having day off today |
Hey sure! Enjoy your day off and speak to you soon. |
@Evangelink can you rebase on top of main and solve all conflicts, then we can merge it |
@arturcic Sure! Will work on it now. Any preference between rebase + force push and merge main? |
I usually rebase as it's cleaner in terms of history. As long as the branch is not merged into the |
Fix error Fix 2 Add resharper config foo
@Evangelink can you fix formatting? https://github.com/GitTools/GitVersion/runs/3135376706?check_suite_focus=true |
@arturcic My bad! I will fix that today. |
@arturcic, all green! Do you approve? :) |
Thank you @Evangelink for your contribution! |
Fixes #2760
I have used the "default" sets of rules tweaked a bit based on some of the inputs from your resharper PR. This PR may already be a little too big so feel free to let me know if you prefer to split it.
Some split idea:
EDIT:
There are a couple of diagnostics being raised as info as they are awaiting for a decision:
CA1816: Dispose. In a couple of places in the code the
Dispose
pattern is not implemented correctly. I could implement it but there are some open questions: can some classes be marked assealed
(in this case there is no need for the pattern). There is one case whereDispose
isvirtual
, I don't know if I can make the change (causing a potential API break, if that's part of what you consider to be the API of your library).CA2219: Do not raise from finally. Is it fine for you to make a change (flags) and throw outside?
CA1016: Mark assemblies with assembly version.
CA2211: Non constant fields should not be visible
CA1018: Specify attribute usage
CA1806: unused HResult. There is a call to
SetError
in aDispose
and the result is ignored. Ignoring HResult can lead to weird behaviors but in the case of aDispose
we may consider that to be ok. I don't know enough the code to be able to make such call.