-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Editorconfig vs Global analyzerconfig #47707
Comments
Tagging @chsienki @jasonmalinowski |
Awesome writeup, thanks! |
Global AnalyzerConfig is a new configuration file format for providing project level analyzer options. It works orthogonally with EditorConfig, which provides file/directory based options. See dotnet/roslyn#47707 for more detailed description. This PR primarily adds documentation from the same issue. Additionally, it also adds documentation for precedence between options (severity options and non-severity options) coming from different configuration sources. This addresses dotnet/roslyn#47154.
Global AnalyzerConfig is a new configuration file format for providing project level analyzer options. It works orthogonally with EditorConfig, which provides file/directory based options. See dotnet/roslyn#47707 for more detailed description. This PR primarily adds documentation from the same issue. Additionally, it also adds documentation for precedence between options (severity options and non-severity options) coming from different configuration sources. This addresses dotnet/roslyn#47154.
@chsienki The only pending item here is |
I am going to close this issue now. |
How do I resolve |
@paulomorgado This requires @chsienki to implement #48634. Chris, this is now the third customer request for the same feature. The global configs that ship with the SDK are conflicting with end user's global config and we need precedence feature to allow end users to override the settings from the SDK. |
Hello I've still some "confusion points":
|
This is a compiler feature, not tied to any specific .NET SDK. It should work on any target framework as long as you have the required VS/compiler that supports this feature (VS2019 16.8 should have the required compiler).
Depends on which compiler version you are using, it needs compiler version 3.7 or later.
Yes, this analyzer package is not tied to a specific target platform or .NET SDK.
No, by definition .editorconfig files are dependent on the folder location so shipping them inside a NuGet package does not make sense. This was one of the primary use cases for introducing folder agnostic global config files. |
@mavasani is it possible to ship a |
Tagging @jmarolf. I don't think we have logic in the SDK targets to automatically append globalconfig files in NuGet package's |
correct @mavasani, unless you have explicitly set
So in your nuget package you just need to include a props or targets file that looks like this <Project>
<ItemGroup>
<GlobalAnalyzerConfigFiles Include="Relative/path/.globalconfig" />
</ItemGroup>
</Project> |
I wonder why when enabling a rule like IDE0017, nothing comes up. Then, I open a file which I now the rule will be fired and that file starts getting itself tracked. I have StyleCop enabled but IDE entries don't have much to do with StyleCop, correct? Wonder what am I missing |
Editorconfig
Starting VS2019 16.3, Roslyn compiler and IDE supports analyzer and source generator configuration via regular .editorconfig files for configuration that applies to specific source files and/or folders within a project, applicable files and/or folders are selected by section headers.
Designed to work well will existing .editorconfig files used to configure editor style settings for different IDEs.
.editorconfig
File/directory based discovery and configuration:
Core scenarios: Support end user analyzer and source generator configuration via below entries:
key = value
for analyzer config options passed to analyzers and source generatorsConflict resolution:
/nowarn
,/warnaserror
) and entries coming from ruleset or global analyzerconfig files.Example:
Global analyzerconfig
Starting VS2019 16.7, Roslyn compiler and IDE supports special global, compilation level analyzer/source generator configuration files for specifying configuration that applies to all the source files in the compilation/project, regardless of the actual file names or file paths of these source files.
Unlike editorconfig files, these are not designed to configure editor style settings for different IDEs.
key = value
is_global = true
File/directory agnostic configuration:
[*.cs]
or[*]
, or section headers that use relative file paths are ignored.Core scenarios: Support identical analyzer configuration entries as editorconfig files, but for different core scenarios:
Conflict resolution:
/nowarn
,/warnaserror
) always override the entries from global analyzerconfig files.Example:
Confusion points
The core points of confusion are:
<EditorConfgFiles Include="path_to_global_analyzer_config"/>
. This was done to reduce the engineering cost on project system side, especially legacy project system. However, this makes the user feel the file name and format must match regular .editorconfig files, including use of globbing based section headers. For example, classic user mistake highlighted in the issue here..editorconfig
and things work just fine as long as entries abide by the global analyzerconfig's required format.Action items for future work
There are few action items that we plan to take up to reduce the above confusion:
Added with Add documentation for Global AnalyzerConfig docs#20824. See https://docs.microsoft.com/dotnet/fundamentals/code-analysis/configuration-files
Added with Issue a warning when a global analyzer config contains an invalid section name. #47728.
<EditorConfgFiles Include="<%path_to_global_analyzer_config%>" />
, we should consider introducing a new item name, say<GlobalAnalyzerConfgFiles Include="<%path_to_global_analyzer_config%>" />
. Under the covers, compiler MSBuild targets will just append both editorconfig files and global analyzerconfig files to a single list of config files passed to the compiler. However, this will likely reduce the chances of user getting confused into thinking these are regular editorconfig files.Added with Enable automatic discovery of global editor configs #47803
Tracked with We should update the GeneratedCodeUtilities heuristic to consider source files without a file path as generated files, currently they are considered as non-generated files #48480
The text was updated successfully, but these errors were encountered: