Summary
Simplify and unify code style configuration by removing redundant settings that match Roslyn defaults, adding modern C# 12/13 style rules, resolving formatting tool conflicts, and trimming .DotSettings overlap.
Background
The current .editorconfig has ~50 settings that match Roslyn defaults exactly and can be removed. Several modern C# 12/13 style rules are missing. The .DotSettings file duplicates some settings already in .editorconfig and Directory.Build.props. Additionally, dotnet format and jb cleanupcode produce different output for the same config, causing formatting churn.
Plan
Phase 1: Remove redundant settings (~50 lines)
Remove all settings where both value and severity match Roslyn defaults:
Formatting rules (all match defaults, ~30 settings):
- All 7
csharp_new_line_* settings
- All 6
csharp_indent_* settings
- All 18
csharp_space_* settings
csharp_preserve_single_line_blocks
Code style settings matching defaults:
dotnet_separate_import_directive_groups
- All 4
dotnet_style_parentheses_* settings
csharp_style_expression_bodied_lambdas
csharp_style_unused_value_expression_statement_preference
Severity consolidation: Replace ~35 rules that share the pattern "default value, elevated to :suggestion" with a single bulk severity line:
dotnet_analyzer_diagnostic.category-Style.severity = suggestion
Then only override specific rules that need warning, silent, or none.
Phase 2: Add modern C# 12/13 rules
| Rule |
Setting |
Suggested |
| Primary constructors (C# 12) |
csharp_style_prefer_primary_constructors |
true:suggestion |
| Collection expressions (C# 12) |
dotnet_style_prefer_collection_expression |
when_types_loosely_match:suggestion |
| Extended property pattern (C# 10) |
csharp_style_prefer_extended_property_pattern |
true:suggestion |
| Readonly struct |
csharp_style_prefer_readonly_struct |
true:suggestion |
| Readonly struct member |
csharp_style_prefer_readonly_struct_member |
true:suggestion |
| Method group conversion |
csharp_style_prefer_method_group_conversion |
true:suggestion |
| Null check over type check |
csharp_style_prefer_null_check_over_type_check |
true:suggestion |
| Top-level statements |
csharp_style_prefer_top_level_statements |
true:silent |
Phase 3: Resolve formatting tool conflicts
- Add targeted
resharper_* settings to .editorconfig to make JB match dotnet format output for:
- Attribute placement on enum members
- Object/array initializer wrapping
- Use
--no-builtin-settings with cleanupcode in CI
- Verify idempotency:
dotnet format → jb cleanupcode → dotnet format --verify-no-changes → jb cleanupcode → git diff --exit-code
Phase 4: Trim .DotSettings
- Remove mandatory imports that duplicate
Directory.Build.props <Using> items (JetBrains.Annotations, System.Diagnostics.CodeAnalysis, GraphZen.Infrastructure)
- Remove/comment ReSharper inspection severities that have
.editorconfig equivalents (e.g., ConvertToCollectionExpression → IDE0300, ConvertToUsingDeclaration → IDE0063)
- Document what remains in
.DotSettings and why (cleanup profile, file templates, inspection excludes)
Settings that must stay (non-default values)
| Setting |
Project Value |
Roslyn Default |
dotnet_sort_system_directives_first |
true |
false |
csharp_style_var_* (all 3) |
true |
false |
csharp_style_expression_bodied_methods |
true |
false |
csharp_style_expression_bodied_constructors |
true |
false |
csharp_style_expression_bodied_operators |
true |
false |
csharp_style_expression_bodied_local_functions |
true |
false |
csharp_style_namespace_declarations |
file_scoped |
block_scoped |
csharp_preserve_single_line_statements |
false |
true |
Verification
References
Summary
Simplify and unify code style configuration by removing redundant settings that match Roslyn defaults, adding modern C# 12/13 style rules, resolving formatting tool conflicts, and trimming
.DotSettingsoverlap.Background
The current
.editorconfighas ~50 settings that match Roslyn defaults exactly and can be removed. Several modern C# 12/13 style rules are missing. The.DotSettingsfile duplicates some settings already in.editorconfigandDirectory.Build.props. Additionally,dotnet formatandjb cleanupcodeproduce different output for the same config, causing formatting churn.Plan
Phase 1: Remove redundant settings (~50 lines)
Remove all settings where both value and severity match Roslyn defaults:
Formatting rules (all match defaults, ~30 settings):
csharp_new_line_*settingscsharp_indent_*settingscsharp_space_*settingscsharp_preserve_single_line_blocksCode style settings matching defaults:
dotnet_separate_import_directive_groupsdotnet_style_parentheses_*settingscsharp_style_expression_bodied_lambdascsharp_style_unused_value_expression_statement_preferenceSeverity consolidation: Replace ~35 rules that share the pattern "default value, elevated to
:suggestion" with a single bulk severity line:dotnet_analyzer_diagnostic.category-Style.severity = suggestionThen only override specific rules that need
warning,silent, ornone.Phase 2: Add modern C# 12/13 rules
csharp_style_prefer_primary_constructorstrue:suggestiondotnet_style_prefer_collection_expressionwhen_types_loosely_match:suggestioncsharp_style_prefer_extended_property_patterntrue:suggestioncsharp_style_prefer_readonly_structtrue:suggestioncsharp_style_prefer_readonly_struct_membertrue:suggestioncsharp_style_prefer_method_group_conversiontrue:suggestioncsharp_style_prefer_null_check_over_type_checktrue:suggestioncsharp_style_prefer_top_level_statementstrue:silentPhase 3: Resolve formatting tool conflicts
resharper_*settings to.editorconfigto make JB matchdotnet formatoutput for:--no-builtin-settingswithcleanupcodein CIdotnet format→jb cleanupcode→dotnet format --verify-no-changes→jb cleanupcode→git diff --exit-codePhase 4: Trim .DotSettings
Directory.Build.props<Using>items (JetBrains.Annotations,System.Diagnostics.CodeAnalysis,GraphZen.Infrastructure).editorconfigequivalents (e.g.,ConvertToCollectionExpression→ IDE0300,ConvertToUsingDeclaration→ IDE0063).DotSettingsand why (cleanup profile, file templates, inspection excludes)Settings that must stay (non-default values)
dotnet_sort_system_directives_firsttruefalsecsharp_style_var_*(all 3)truefalsecsharp_style_expression_bodied_methodstruefalsecsharp_style_expression_bodied_constructorstruefalsecsharp_style_expression_bodied_operatorstruefalsecsharp_style_expression_bodied_local_functionstruefalsecsharp_style_namespace_declarationsfile_scopedblock_scopedcsharp_preserve_single_line_statementsfalsetrueVerification
dotnet format --verify-no-changespassesdotnet jb cleanupcode ... && git diff --exit-codepassesdotnet buildwithEnforceCodeStyleInBuild=trueshows no new warnings.editorconfigis significantly shorter with no loss of enforcementReferences