1+ # ===============================================
2+ # CRITICAL RULES - BLOCK DEVELOPMENT (Real bugs/security)
3+ # ===============================================
4+
5+ # Security - These are actual vulnerabilities
6+ dotnet_diagnostic.CA3001.severity = error # SQL injection
7+ dotnet_diagnostic.CA3003.severity = error # File path injection
8+ dotnet_diagnostic.CA3006.severity = error # Process command injection
9+ dotnet_diagnostic.CA3075.severity = error # XML DTD processing
10+ dotnet_diagnostic.CA5362.severity = error # Certificate validation bypass
11+ dotnet_diagnostic.CA5394.severity = error # Insecure randomness
12+ dotnet_diagnostic.SCS0002.severity = error # SQL injection
13+ dotnet_diagnostic.SCS0007.severity = error # XSS
14+ dotnet_diagnostic.SCS0028.severity = error # Unsafe deserialization
15+ dotnet_diagnostic.SCS0029.severity = error # Hardcoded passwords
16+
17+ # Memory Leaks - These cause production issues
18+ dotnet_diagnostic.CA1001.severity = error # Types owning disposables must be disposable
19+ dotnet_diagnostic.CA2000.severity = warning # Dispose objects before scope loss
20+ dotnet_diagnostic.CA2213.severity = error # Disposable fields must be disposed
21+ dotnet_diagnostic.IDISP001.severity = warning # Dispose created
22+ dotnet_diagnostic.IDISP003.severity = error # Dispose previous before reassigning
23+ dotnet_diagnostic.IDISP004.severity = error # Don't ignore IDisposable returns
24+ dotnet_diagnostic.IDISP005.severity = error # Return value disposal tracking
25+ dotnet_diagnostic.IDISP007.severity = error # Don't dispose injected
26+
27+ # Async/Threading - These cause deadlocks/crashes
28+ dotnet_diagnostic.VSTHRD100.severity = error # Async void methods
29+ dotnet_diagnostic.VSTHRD110.severity = error # Observe async results
30+ dotnet_diagnostic.VSTHRD002.severity = error # Avoid .Result and .Wait()
31+ dotnet_diagnostic.AsyncFixer03.severity = error # Fire-and-forget async
32+
33+ # Reliability - These cause runtime failures
34+ dotnet_diagnostic.CA2201.severity = error # Don't raise reserved exceptions
35+ dotnet_diagnostic.CA2219.severity = error # Don't raise exceptions in finally
36+ dotnet_diagnostic.CA2241.severity = error # String format mismatches
37+
38+ # ===============================================
39+ # PERFORMANCE RULES - AUTO-FIXABLE (Won't block dev)
40+ # ===============================================
41+
42+ # All these have automatic fixes and improve performance
43+ dotnet_diagnostic.CA1510.severity = warning # Remove redundant null checks
44+ dotnet_diagnostic.CA1822.severity = warning # Mark members as static
45+ dotnet_diagnostic.CA1865.severity = warning # Use char overloads instead of string
46+ dotnet_diagnostic.CA1805.severity = warning # Remove explicit initialization to default
47+ dotnet_diagnostic.CA1859.severity = warning # Use concrete return types
48+ dotnet_diagnostic.CA1720.severity = warning # Rename identifier that conflicts with type
49+ dotnet_diagnostic.CA1827.severity = suggestion # Use Any() instead of Count() > 0
50+ dotnet_diagnostic.CA1829.severity = suggestion # Use Length/Count property
51+ dotnet_diagnostic.CA1834.severity = suggestion # Use StringBuilder.Append(char)
52+ dotnet_diagnostic.CA1835.severity = suggestion # Use Memory/Span overloads
53+ dotnet_diagnostic.CA1841.severity = suggestion # Prefer Dictionary.Contains
54+ dotnet_diagnostic.CA1845.severity = suggestion # Use span-based string.Concat
55+ dotnet_diagnostic.CA1846.severity = suggestion # Prefer AsSpan over Substring
56+ dotnet_diagnostic.CA1847.severity = suggestion # Use char literal for single char
57+ dotnet_diagnostic.CA2016.severity = warning # Forward CancellationToken
58+
59+ # Meziantou Performance - All auto-fixable
60+ dotnet_diagnostic.MA0029.severity = suggestion # Combine LINQ methods
61+ dotnet_diagnostic.MA0063.severity = suggestion # Optimize Enumerable.Count() usage
62+ dotnet_diagnostic.MA0066.severity = suggestion # Use Equals over CompareTo == 0
63+ dotnet_diagnostic.MA0067.severity = suggestion # Use Guid.Empty
64+ dotnet_diagnostic.MA0089.severity = suggestion # Use Memory optimizations
65+ dotnet_diagnostic.MA0110.severity = suggestion # Use regex source generator
66+ dotnet_diagnostic.MA0098.severity = suggestion # Use IEnumerable.Any() instead of Count()
67+
68+ # AsyncFixer - Auto-fixable performance
69+ dotnet_diagnostic.AsyncFixer01.severity = suggestion # Unnecessary async/await
70+ dotnet_diagnostic.AsyncFixer04.severity = suggestion # ConfigureAwait(false)
71+ dotnet_diagnostic.AsyncFixer05.severity = suggestion # Downcasting Task<T> to Task
72+
73+ # ===============================================
74+ # FORMATTING - ONLY IN CI/CD (Never block local dev)
75+ # ===============================================
76+
77+ # StyleCop - All auto-fixable formatting
78+ dotnet_diagnostic.SA1000.severity = none # Keywords should be spaced correctly
79+ dotnet_diagnostic.SA1005.severity = none # Single line comment spacing
80+ dotnet_diagnostic.SA1010.severity = none # Opening square brackets should not be preceded by a space
81+ dotnet_diagnostic.SA1025.severity = none # Multiple whitespace
82+ dotnet_diagnostic.SA1027.severity = none # Tabs and spaces should be used correctly
83+ dotnet_diagnostic.SA1028.severity = none # No trailing whitespace
84+ dotnet_diagnostic.SA1121.severity = none # Use built-in type alias
85+ dotnet_diagnostic.SA1122.severity = none # Use string.Empty
86+ dotnet_diagnostic.SA1137.severity = none # Same indentation
87+ dotnet_diagnostic.SA1204.severity = none # Static members should appear before non-static members
88+ dotnet_diagnostic.SA1210.severity = none # Using directives ordering
89+ dotnet_diagnostic.SA1214.severity = none # Readonly fields should appear before non-readonly fields
90+ dotnet_diagnostic.SA1413.severity = none # Trailing comma
91+ dotnet_diagnostic.SA1503.severity = none # Braces should not be omitted
92+ dotnet_diagnostic.SA1508.severity = none # Closing brace should not be preceded by a blank line
93+ dotnet_diagnostic.SA1516.severity = none # Elements separated by blank line
94+
95+ # ===============================================
96+ # PERMANENTLY DISABLED (Noise/False positives)
97+ # ===============================================
98+
99+ # Too pedantic or situational
100+ dotnet_diagnostic.CA1062.severity = none # Validate arguments (null checks everywhere)
101+ dotnet_diagnostic.CA1303.severity = none # Localization
102+ dotnet_diagnostic.CA1031.severity = none # Catch specific exceptions
103+ dotnet_diagnostic.CA1014.severity = none # CLSCompliant
104+ dotnet_diagnostic.CA2007.severity = none # ConfigureAwait (covered by AsyncFixer)
105+
106+ # Naming - Only enforce on public API surface
107+ dotnet_code_quality.CA1707.api_surface = public # Allow underscores in private members (_camelCase convention)
108+ dotnet_diagnostic.SA1600.severity = none # Documentation
109+ dotnet_diagnostic.SA1633.severity = none # File headers
110+ dotnet_diagnostic.SA1402.severity = none # Single type per file
111+ dotnet_diagnostic.SA1101.severity = none # Prefix this
112+ dotnet_diagnostic.SA1309.severity = none # Field underscore
113+ dotnet_diagnostic.SA1200.severity = none # Using directives placement
114+ dotnet_diagnostic.MA0002.severity = warning # Use IEqualityComparer or IComparer (perf issue)
115+ dotnet_diagnostic.MA0004.severity = none # Use AsyncFixer04 instead
116+ dotnet_diagnostic.MA0006.severity = suggestion # Use string.Equals (correctness)
117+ dotnet_diagnostic.MA0009.severity = warning # Regex DoS (real security issue)
118+ dotnet_diagnostic.MA0016.severity = suggestion # Prefer abstraction over implementation
119+ dotnet_diagnostic.MA0048.severity = none # File name must match type name - replaced by FDW005 (supports generic arity variants)
120+ dotnet_diagnostic.FDW005.severity = warning # File name must match type name (FDW custom - allows generic arity variants in same file)
121+ dotnet_diagnostic.FDW006.severity = warning # Method too long (replaces MA0051)
122+ dotnet_diagnostic.FDW007.severity = warning # Method too complex
123+ dotnet_diagnostic.FDW008.severity = warning # Method name contains underscore
124+ dotnet_diagnostic.MA0051.severity = none # Replaced by FDW006+FDW007
125+ dotnet_diagnostic.VSTHRD200.severity = none # Async suffix - confusing API
126+
127+ # ===============================================
128+ # MODERN ANALYZER RECOMMENDATIONS
129+ # ===============================================
130+
131+ # Consider adding these modern analyzers:
132+ # - Microsoft.CodeAnalysis.NetAnalyzers (included in .NET SDK)
133+ # - Roslynator.Analyzers (excellent refactoring, not pedantic)
134+ # - Microsoft.VisualStudio.Threading.Analyzers (you have this)
135+ # - NetFabric.Hyperlinq.Analyzer (LINQ performance)
136+ # - SmartAnalyzers.CSharpExtensions.Annotations (null safety)
137+
138+ # ===============================================
139+ # CI/CD ESCALATION (add to your pipeline)
140+ # ===============================================
141+ # In your azure-pipelines.yml:
142+ # - script: |
143+ # dotnet format --verify-no-changes --severity info
144+ # displayName: 'Verify formatting'
145+ # condition: eq(variables['Build.Reason'], 'PullRequest')
146+ #
147+ # - script: |
148+ # dotnet build -p:EnforceCodeStyleInBuild=true -p:TreatWarningsAsErrors=true
149+ # displayName: 'Build with strict analysis'
150+ # condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
151+
152+ # ===============================================
153+ # IDE EXPERIENCE SETTINGS
154+ # ===============================================
155+
156+ # Modern C# preferences (all have fixes)
157+ csharp_style_prefer_switch_expression = true :suggestion
158+ csharp_style_prefer_pattern_matching = true :suggestion
159+ csharp_style_prefer_null_check_over_type_check = true :suggestion
160+ csharp_prefer_simple_using_statement = true :suggestion
161+ csharp_style_prefer_index_operator = true :suggestion
162+ csharp_style_prefer_range_operator = true :suggestion
163+ csharp_style_implicit_object_creation_when_type_is_apparent = true :suggestion
164+ csharp_style_prefer_tuple_swap = true :suggestion
165+ csharp_style_prefer_utf8_string_literals = true :suggestion
166+
167+ # Init-only preferences
168+ csharp_style_prefer_readonly_struct = true :suggestion
169+ csharp_style_prefer_readonly_struct_member = true :suggestion
170+
171+ # File scoped namespaces (modern C#)
172+ csharp_style_namespace_declarations = file_scoped:suggestion
173+
174+ # Primary constructors (C# 12)
175+ csharp_style_prefer_primary_constructors = true :suggestion
176+
177+ # ===============================================
178+ # NAMING CONVENTIONS (non-blocking)
179+ # ===============================================
180+
181+ # Define naming rules but keep them as suggestions
182+ dotnet_naming_rule.async_methods_should_have_suffix.severity = suggestion
183+ dotnet_naming_rule.async_methods_should_have_suffix.symbols = async_methods
184+ dotnet_naming_rule.async_methods_should_have_suffix.style = async_suffix
185+
186+ dotnet_naming_symbols.async_methods.applicable_kinds = method
187+ dotnet_naming_symbols.async_methods.applicable_accessibilities = *
188+ dotnet_naming_symbols.async_methods.required_modifiers = async
189+
190+ dotnet_naming_style.async_suffix.required_suffix = Async
191+ dotnet_naming_style.async_suffix.capitalization = pascal_case
0 commit comments