-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Change CodeAnalysis rules from 'Info' to 'Warning' after fixing all instances of the violations #7174
Comments
CA1837: https://docs.microsoft.com/en-au/dotnet/fundamentals/code-analysis/quality-rules/ca1837 We can't use this one because it isn't available in older versions of .NET. When the team decides to no longer support versions below .NET 5 then this can be enabled. |
CA2241: https://docs.microsoft.com/en-au/dotnet/fundamentals/code-analysis/quality-rules/CA2241 Example:
I don't know if this is on purpose. This would just result in an empty string afaik. |
ca2249: https://docs.microsoft.com/en-au/dotnet/fundamentals/code-analysis/quality-rules/ca2249 This one also has issues because of the missing overloads on |
@Forgind I can't manage to get StyleCop Analyzers to run anymore. Are they working for you? |
The cases I saw looked like they should resolve to an empty string, so I think it's fine to replace those with string.Empty and skip the format part. |
Does this also complain about cases like: string s = "foobar";
int i = s.IndexOf("b");
if (i > 0) {
// Uses i
} ? Also, what do you mean by missing overloads? Like string.Contains requires a string, and we sometimes use a char? If that's the case, I'd leave the ones where we use a char; it's more efficient memory-wise to not allocate a string for no reason—though I guess it's probably short enough that the runtime wouldn't actually have to allocate anyway. |
Do you mean locally or in PRs? I just tested a local build, and the analyzer seemed to work fine. If PR builds aren't catching it anymore, it might be throttled, but I don't know how to change that. |
Locally, I am probably doing it wrong somehow. It has been a long while since I worked on this. Do I use visual studio 2019 release , 2022 release, or 2022 preview? |
I don't think it matters. What are you doing to run them? I went to my msbuild repo and ran |
yes, there is a char overload and there are functions which take different comparators than |
Awesome. I will submit a PR with the fixes. |
@rainersigwald some of these PRs are about to increase churn pretty heavily. How would you like me to handle larger change sets like those? For now I will avoid any analyzers with over 1-2k warnings. |
@Forgind I just want to summarise where I am up to on this. Basically we ran into an issue where some of the analysers fail the build because of code pulled in from nuget packages e.g :
This is because of how analyzers work with This was all explained in dotnet/roslyn#55992. Where many people gave input on the system. This culminated in this pull request to demonstrate a solution: There is a catch in that solution, in that the added The other solution is that we move back to using the There may be another method around this but it wasn't suggested from the other people. Could you please discuss with the team and then get back to me? I will then make the required changes. |
@sharwell do you have any thoughts of the configuration of analyzers based on the above issues? |
I'd like to wait to see what sharwell suggests. Personally, both solutions sound problematic in their own ways, and although I'd personally be fine with wasting a couple gbs, I suspect at least one person on my team will be strongly opposed. On the other hand, it would be frustrating to have a massive .editorconfig. One other option I think we should at least consider is only promoting analysis messages to warnings if we can do some without a warning coming from anything we depend on. That's a stupid requirement, but it may be the most pragmatic. We have a lot of issues we want to tackle for 17.2 with major customer impact, and you've probably noticed we're pretty far behind even with just reviewing and merging what's already open. |
Relates to #7174 https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1838 There is extensive discussion in this PR (#7186) on GitHub.
We need to address this as it is the same issue we ran into for #7571, but its worse because code style can be different between the nuget package code and msbuild. @sharwell are you able to look at #7174 (comment) and let us know your thoughts? |
You should add file scoped namespaces to the list, is there a code for it? |
Style rules in .globalconfig will not apply to a correctly authored NuGet package. If you are running into problems with the global NuGet cache, there is a bug in one or more NuGet packages which needs to be corrected (or have a workaround). It's not clear which package(s) or rule(s) are involved in the problem you saw. |
@sharwell the package in question is |
There are a few ways to resolve:
|
My understanding is that this isn't possible because we don't know an absolute path for the NuGet packages folder. Is that not the case? |
I'm not completely sure here. For central builds (with determinism enabled), the paths should be normalized to a |
#7571) Relates to #7174 https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1518.md The two remaining warnings/suggestions are from RoslynImmutableInterlocked pulled in from Microsoft.CodeAnalysis.Collections in Microsoft.Build.Framework. Solution for the warnings from the nuget package is outlined in dotnet/roslyn#55992
Code-style rules (IDE) are also useful. |
Additional checks to enable once fixed:
|
Regarding some of the rules, per @rainersigwald's comment in https://github.com/dotnet/msbuild/pull/7953/files/c517eaada858f113d7bbf6c06cdf6044b5accb15#r1051020281, it does make sense to leave them as warning for the inner-loop agility, while turn warnings to errors at CI builds. |
As a follow up to #5656 each code analysis rule that is marked as
Action="Info"
should be evaluated and migrated toAction="Warning"
once all instances of the violations are fixed or marked with ignore.To make the process as painless as possible. Each rule should be implemented in its own PR.
Before the merges:
List of rules to enable after resolving occurrences:
Environment.ProcessId
because it isn't available in older versions of .NET. When the team decides to no longer support versions below .NET 5 then this can be enabled.The text was updated successfully, but these errors were encountered: