« Code analysis » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications |
|||
Ligne 17 : | Ligne 17 : | ||
== Core options == | == Core options == | ||
<filebox fn='.editorconfig' lang='ini'> | <filebox fn='.editorconfig' lang='ini'> | ||
root = true | root = true | ||
Ligne 47 : | Ligne 44 : | ||
== Analyzer configuration == | == Analyzer configuration == | ||
<filebox fn='.editorconfig' lang='ini'> | <filebox fn='.editorconfig' lang='ini'> | ||
# set the rules severity to warning | # set the rules severity to warning | ||
dotnet_analyzer_diagnostic.severity = warning | dotnet_analyzer_diagnostic.severity = warning | ||
Ligne 56 : | Ligne 50 : | ||
== Miscellaneous configuration == | == Miscellaneous configuration == | ||
<filebox fn='.editorconfig' lang='ini'> | <filebox fn='.editorconfig' lang='ini'> | ||
# Sort using and Import directives with System.* appearing first | # Sort using and Import directives with System.* appearing first | ||
dotnet_sort_system_directives_first = true | dotnet_sort_system_directives_first = true | ||
Ligne 65 : | Ligne 56 : | ||
== Style configuration == | == Style configuration == | ||
<filebox fn='.editorconfig' lang='ini'> | <filebox fn='.editorconfig' lang='ini'> | ||
# IDE0160 / IDE0161: Namespace declaration preferences | # IDE0160 / IDE0161: Namespace declaration preferences | ||
csharp_style_namespace_declarations = file_scoped : error | csharp_style_namespace_declarations = file_scoped : error | ||
Ligne 79 : | Ligne 67 : | ||
== Disable rules == | == Disable rules == | ||
<filebox fn='.editorconfig' lang='ini'> | <filebox fn='.editorconfig' lang='ini'> | ||
# lower speller rule severity to suggestion | # lower speller rule severity to suggestion | ||
dotnet_diagnostic.VSSpell001.severity = suggestion | dotnet_diagnostic.VSSpell001.severity = suggestion | ||
Ligne 95 : | Ligne 80 : | ||
* [https://rules.sonarsource.com/csharp/ C# rules] | * [https://rules.sonarsource.com/csharp/ C# rules] | ||
<filebox fn='.editorconfig' lang='ini'> | <filebox fn='.editorconfig' lang='ini'> | ||
# S1135: Track uses of "TODO" tags | # S1135: Track uses of "TODO" tags | ||
dotnet_diagnostic.S1135.severity = none | dotnet_diagnostic.S1135.severity = none |
Version du 24 avril 2024 à 11:08
Links
Enable additional rules
Those rules are enabled by default.
Edit the project file to enable additional rules:
MyProject.csproj |
<PropertyGroup> <!-- ... --> <AnalysisLevel>latest-recommended</AnalysisLevel> </PropertyGroup> |
Editorconfig
Core options
.editorconfig |
root = true # All files [*] indent_style = space insert_final_newline = true charset = utf-8 # XML project files [*.csproj] indent_size = 2 # JSON config files [*.json] indent_size = 2 # C# code files [*.cs] indent_size = 4 trim_trailing_whitespace = true # set the rules severity to warning dotnet_analyzer_diagnostic.severity = warning |
Analyzer configuration
.editorconfig |
# set the rules severity to warning dotnet_analyzer_diagnostic.severity = warning |
Miscellaneous configuration
.editorconfig |
# Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true |
Style configuration
.editorconfig |
# IDE0160 / IDE0161: Namespace declaration preferences csharp_style_namespace_declarations = file_scoped : error # IDE0007 / IDE0008: 'var' preferences csharp_style_var_for_built_in_types = true csharp_style_var_when_type_is_apparent = true csharp_style_var_elsewhere = false : suggestion |
Disable rules
.editorconfig |
# lower speller rule severity to suggestion dotnet_diagnostic.VSSpell001.severity = suggestion dotnet_diagnostic.VSSpell002.severity = suggestion # Specify CultureInfo dotnet_diagnostic.CA1304.severity = suggestion # Specify a culture dotnet_diagnostic.CA1311.severity = suggestion |
Sonar Lint
.editorconfig |
# S1135: Track uses of "TODO" tags dotnet_diagnostic.S1135.severity = none |
Installation
- Installation the extension for Visual Studio or VS Code
Visual Studio
Set the scope of live code analysis
- Tools → Options
- Text Editor → C# → Advanced
- Run background code analysis for: Current document
- Show compiler errors and warnings for: Open documents