This report provides a comprehensive analysis of all Roslyn analyzers in the Philips CodeAnalysis repository and identifies which analyzers lack code fixers, along with implementation viability recommendations.
- Total Analyzers: 90
- Analyzers with Code Fixers: 70 (77.8% coverage)
- Analyzers without Code Fixers: 20 (22.2% missing)
- Implementation Viability: 18 high-viability, 2 medium-viability, 0 low-viability
| Project | Total Analyzers | With Code Fixers | Coverage |
|---|---|---|---|
| MaintainabilityAnalyzers | 85 | 65 | 76.5% |
| MoqAnalyzers | 2 | 2 | 100% |
| SecurityAnalyzers | 2 | 2 | 100% |
| DuplicateCodeAnalyzer | 1 | 1 | 100% |
These analyzers have simple logic and would benefit significantly from code fixers:
- Lines: 37
- Complexity: Very Low
- Recommendation: STRONGLY RECOMMENDED - Simple field visibility change
- Implementation: Replace
protectedwithprivatemodifier
- Lines: 33
- Complexity: Very Low
- Recommendation: STRONGLY RECOMMENDED - Direct statement removal
- Implementation: Remove goto statements and restructure control flow
- Lines: 44
- Complexity: Very Low
- Recommendation: STRONGLY RECOMMENDED - Simple region removal
- Implementation: Remove
#regionand#endregiondirectives within methods
- Lines: 85
- Complexity: Low
- Recommendation: RECOMMENDED - Replace hardcoded paths with configurable alternatives
- Implementation: Extract path literals to configuration or constants
- Lines: 59
- Complexity: Low
- Recommendation: RECOMMENDED - Namespace renaming
- Implementation: Update namespace declaration to match assembly name
- Lines: 68
- Complexity: Low
- Recommendation: RECOMMENDED - File renaming suggestion
- Implementation: Suggest filename without spaces (cosmetic fix)
- Lines: 70
- Complexity: Low
- Recommendation: RECOMMENDED - Path shortening suggestions
- Implementation: Suggest shorter alternative paths
- Lines: 61
- Complexity: Low
- Recommendation: STRONGLY RECOMMENDED - Reorder get/set accessors
- Implementation: Move getter before setter in property declarations
- Lines: 101
- Complexity: Low
- Recommendation: RECOMMENDED - Add copyright header
- Implementation: Insert standard copyright text at file beginning
- Lines: 96
- Complexity: Low
- Recommendation: RECOMMENDED - Namespace alignment
- Implementation: Update namespace to match file path structure
- Lines: 103
- Complexity: Low
- Recommendation: MEDIUM PRIORITY - Complex condition refactoring
- Implementation: Extract complex conditions into separate boolean variables
- Lines: 46
- Complexity: Low
- Recommendation: RECOMMENDED - Cast optimization
- Implementation: Replace partial property casts with complete object casts
- Lines: 40
- Complexity: Low
- Recommendation: STRONGLY RECOMMENDED - Add readonly modifier
- Implementation: Add
readonlymodifier to lock objects
- Lines: 114
- Complexity: Medium
- Recommendation: RECOMMENDED - InitializeComponent call management
- Implementation: Add or reorganize InitializeComponent calls
- Lines: 72
- Complexity: Medium
- Recommendation: RECOMMENDED - Exception wrapping improvement
- Implementation: Pass inner exception to new exception constructors
- Lines: 64
- Complexity: Low
- Recommendation: RECOMMENDED - Namespace prefix correction
- Implementation: Add required namespace prefix
- Lines: 141
- Complexity: Medium
- Recommendation: RECOMMENDED - Variable renaming
- Implementation: Rename variables to follow camelCase/PascalCase conventions
- Lines: 72
- Complexity: Low
- Recommendation: RECOMMENDED - Add using statements or disposal
- Implementation: Wrap unmanaged objects in using statements
- Lines: 126
- Complexity: Medium-High
- Recommendation: CONDITIONAL - Requires semantic analysis
- Challenges: Multiple diagnostic scenarios, semantic model dependency
- Implementation: Add logging statements for caught exceptions
- Lines: 301
- Complexity: Medium-High
- Recommendation: CONDITIONAL - Complex string manipulation
- Challenges: Nested format detection, symbol analysis required
- Implementation: Flatten nested string.Format calls
- Start with Simple Cases: Begin with analyzers having <50 lines and no semantic analysis
- Focus on Modifiers:
NoProtectedFieldsAnalyzer,LockObjectsMustBeReadonlyAnalyzer,OrderPropertyAccessorsAnalyzer - Address Naming:
VariableNamingConventionAnalyzer,NamespaceMatchAssemblyNameAnalyzer
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(SampleCodeFixProvider))]
public sealed class SampleCodeFixProvider : SingleDiagnosticCodeFixProvider<MemberDeclarationSyntax>
{
protected override string Title => "Fix description";
protected override DiagnosticId DiagnosticId => DiagnosticId.SampleRule;
protected override SyntaxNode ApplyFix(MemberDeclarationSyntax node, ITypeSymbol typeSymbol)
{
// Simple syntax transformation
return node.WithModifiers(/* new modifiers */);
}
}- Modifier Changes: Add/remove/replace keywords (
readonly,private, etc.) - Node Reordering: Rearrange declaration order (property accessors)
- Text Insertion: Add copyright headers, using statements
- Simple Replacements: Replace hardcoded values with constants
Each code fixer should include:
- Positive test cases: Verify fix applies correctly
- Negative test cases: Ensure no false positives
- Edge cases: Handle partial classes, nested structures
- Regression tests: Ensure no side effects
- Reduced Manual Work: 20 analyzers × average 5 issues per project = 100 manual fixes saved
- Consistency: Automated fixes ensure uniform code style
- Learning: Developers see correct patterns immediately
- Faster Adoption: Teams more likely to enable analyzers with automatic fixes
- Reduced Friction: Less resistance to new coding standards
- Time Savings: Estimated 2-4 hours saved per developer per week
The Philips Roslyn Analyzers repository has excellent code fixer coverage at 77.8%. The remaining 20 analyzers without code fixers are predominantly in the MaintainabilityAnalyzers project and have high implementation viability.
Recommendation: Prioritize implementing code fixers for the 18 high-viability analyzers, starting with the simplest cases (modifier changes and reordering) before moving to more complex scenarios involving semantic analysis.
The investment in these code fixers will significantly improve developer experience and accelerate adoption of the analyzers across development teams.