-
Notifications
You must be signed in to change notification settings - Fork 470
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
Use AnalyzerConfigFiles instead of AnalyzerConfigDocument #5065
Conversation
63dce50
to
f66b73c
Compare
@sharwell @mavasani With this test-only change, the product code no longer gets the correct value for It looks like Edit: The above isn't accurate. // Local functions.
ICategorizedAnalyzerConfigOptions ComputeCategorizedAnalyzerConfigOptions()
{
var categorizedOptionsFromAdditionalFiles = ComputeCategorizedAnalyzerConfigOptionsFromAdditionalFiles(); /* This is the parsing done manually and don't adhere to the compiler rules */
#if CODEANALYSIS_V3_OR_BETTER
return AggregateCategorizedAnalyzerConfigOptions.Create(options.AnalyzerConfigOptionsProvider, compilation, categorizedOptionsFromAdditionalFiles); /* This combines both options.AnalyzerConfigOptionsProvider (from the compiler) with the parsing done from additional files */
#else
return categorizedOptionsFromAdditionalFiles;
#endif
} If the tests are run with additional files (which I'm not doing in this PR), they won't require Edit2: The above might still not be 100% accurate 😕 One thing that isn't clear to me is about MSBuild properties, they seem to be configurable by both csproj and editorconfig ( |
fb2ffc3
to
9c48a08
Compare
if (AnalyzerConfigDocument is not null) | ||
{ | ||
solution = solution.AddAnalyzerConfigDocument( | ||
DocumentId.CreateNewId(projectId, debugName: ".editorconfig"), | ||
".editorconfig", | ||
SourceText.From($"is_global = true" + Environment.NewLine + AnalyzerConfigDocument), | ||
filePath: @"/.editorconfig"); | ||
} | ||
|
||
return solution; | ||
}); |
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.
AnalyzerConfigDocument doesn't work with named sections despite it looks like it should parse from the compiler?
This is a point of confusion to me.
While I'm deleting AnalyzerConfigDocument
altogether, the behavior of it not working when its value is like "[*]\r\nprop=value"
but works when it's "prop=value"
is very very strange to me.
I'm either missing something or this may indicate a bug from roslyn 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.
Global config files don't use [*]
. They just have is_global=true
as the first line followed by the properties themselves.
Codecov Report
@@ Coverage Diff @@
## main #5065 +/- ##
========================================
Coverage 95.52% 95.52%
========================================
Files 1199 1200 +1
Lines 274508 274871 +363
Branches 16602 16616 +14
========================================
+ Hits 262219 262574 +355
- Misses 10110 10111 +1
- Partials 2179 2186 +7 |
I need to look and see how this relates to #4921 |
@@ -926,14 +924,14 @@ public class C | |||
{{ | |||
}} | |||
}}" | |||
} | |||
}, | |||
AnalyzerConfigFiles = { ("/.editorconfig", $"[*]{Environment.NewLine}{editorConfigText}") } |
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.
IMO, this deserves a static helper method to return AnalyzerConfigFiles
given string editorConfigText
as the input.
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.
@mavasani For this specific test file, I used it only twice (in the same test). Did you mean to introduce it in a new helper class and use it from all tests?
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 form used here is the form I generally expect to see.
😕 I thought I already implemented this as part of another change |
...zers/UnitTests/Microsoft.NetCore.Analyzers/Publish/AvoidAssemblyLocationInSingleFileTests.cs
Outdated
Show resolved
Hide resolved
…/AvoidAssemblyLocationInSingleFileTests.cs Co-authored-by: Sam Harwell <[email protected]>
...ers/UnitTests/Microsoft.CodeQuality.Analyzers/Maintainability/ReviewUnusedParametersTests.cs
Outdated
Show resolved
Hide resolved
…ntainability/ReviewUnusedParametersTests.cs Co-authored-by: Sam Harwell <[email protected]>
This was recently added in the testing library in dotnet/roslyn-sdk#734.
The main goal of this is to (later) remove the logic of parsing editorconfig files and leave that up to the compiler (dotnet/roslyn-sdk#734 (comment))This comment is aboutAdditionalFiles
, notAnalyzerConfigDocument
.