Skip to content

Latest commit

 

History

History
209 lines (164 loc) · 8.36 KB

File metadata and controls

209 lines (164 loc) · 8.36 KB

Analyzer Code Fixer Coverage Report

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.

Executive Summary

  • 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

Coverage by Project

Project Total Analyzers With Code Fixers Coverage
MaintainabilityAnalyzers 85 65 76.5%
MoqAnalyzers 2 2 100%
SecurityAnalyzers 2 2 100%
DuplicateCodeAnalyzer 1 1 100%

Missing Code Fixers - Detailed Analysis

High Viability (Easy Implementation) - 18 Analyzers

These analyzers have simple logic and would benefit significantly from code fixers:

1. NoProtectedFieldsAnalyzer (PH2070)

  • Lines: 37
  • Complexity: Very Low
  • Recommendation: STRONGLY RECOMMENDED - Simple field visibility change
  • Implementation: Replace protected with private modifier

2. PreventUseOfGotoAnalyzer (PH2068)

  • Lines: 33
  • Complexity: Very Low
  • Recommendation: STRONGLY RECOMMENDED - Direct statement removal
  • Implementation: Remove goto statements and restructure control flow

3. NoRegionsInMethodAnalyzer (PH2081)

  • Lines: 44
  • Complexity: Very Low
  • Recommendation: STRONGLY RECOMMENDED - Simple region removal
  • Implementation: Remove #region and #endregion directives within methods

4. NoHardCodedPathsAnalyzer (PH2080)

  • Lines: 85
  • Complexity: Low
  • Recommendation: RECOMMENDED - Replace hardcoded paths with configurable alternatives
  • Implementation: Extract path literals to configuration or constants

5. NamespaceMatchAssemblyNameAnalyzer (PH2135)

  • Lines: 59
  • Complexity: Low
  • Recommendation: RECOMMENDED - Namespace renaming
  • Implementation: Update namespace declaration to match assembly name

6. NoSpaceInFilenameAnalyzer (PH2087)

  • Lines: 68
  • Complexity: Low
  • Recommendation: RECOMMENDED - File renaming suggestion
  • Implementation: Suggest filename without spaces (cosmetic fix)

7. LimitPathLengthAnalyzer (PH2088)

  • Lines: 70
  • Complexity: Low
  • Recommendation: RECOMMENDED - Path shortening suggestions
  • Implementation: Suggest shorter alternative paths

8. OrderPropertyAccessorsAnalyzer (PH2085)

  • Lines: 61
  • Complexity: Low
  • Recommendation: STRONGLY RECOMMENDED - Reorder get/set accessors
  • Implementation: Move getter before setter in property declarations

9. CopyrightPresentAnalyzer (PH2028)

  • Lines: 101
  • Complexity: Low
  • Recommendation: RECOMMENDED - Add copyright header
  • Implementation: Insert standard copyright text at file beginning

10. NamespaceMatchFilePathAnalyzer (PH2006)

  • Lines: 96
  • Complexity: Low
  • Recommendation: RECOMMENDED - Namespace alignment
  • Implementation: Update namespace to match file path structure

11. LimitConditionComplexityAnalyzer (PH2092)

  • Lines: 103
  • Complexity: Low
  • Recommendation: MEDIUM PRIORITY - Complex condition refactoring
  • Implementation: Extract complex conditions into separate boolean variables

12. CastCompleteObjectAnalyzer (PH2119)

  • Lines: 46
  • Complexity: Low
  • Recommendation: RECOMMENDED - Cast optimization
  • Implementation: Replace partial property casts with complete object casts

13. LockObjectsMustBeReadonlyAnalyzer (PH2066)

  • Lines: 40
  • Complexity: Low
  • Recommendation: STRONGLY RECOMMENDED - Add readonly modifier
  • Implementation: Add readonly modifier to lock objects

14. WinFormsInitializeComponentMustBeCalledOnceAnalyzer (PH2042)

  • Lines: 114
  • Complexity: Medium
  • Recommendation: RECOMMENDED - InitializeComponent call management
  • Implementation: Add or reorganize InitializeComponent calls

15. ThrowInnerExceptionAnalyzer (PH2091)

  • Lines: 72
  • Complexity: Medium
  • Recommendation: RECOMMENDED - Exception wrapping improvement
  • Implementation: Pass inner exception to new exception constructors

16. NamespacePrefixAnalyzer (PH2079)

  • Lines: 64
  • Complexity: Low
  • Recommendation: RECOMMENDED - Namespace prefix correction
  • Implementation: Add required namespace prefix

17. VariableNamingConventionAnalyzer (PH2030)

  • Lines: 141
  • Complexity: Medium
  • Recommendation: RECOMMENDED - Variable renaming
  • Implementation: Rename variables to follow camelCase/PascalCase conventions

18. UnmanagedObjectsNeedDisposingAnalyzer (PH2133)

  • Lines: 72
  • Complexity: Low
  • Recommendation: RECOMMENDED - Add using statements or disposal
  • Implementation: Wrap unmanaged objects in using statements

Medium Viability (Moderate Implementation) - 2 Analyzers

1. LogExceptionAnalyzer (PH2090)

  • Lines: 126
  • Complexity: Medium-High
  • Recommendation: CONDITIONAL - Requires semantic analysis
  • Challenges: Multiple diagnostic scenarios, semantic model dependency
  • Implementation: Add logging statements for caught exceptions

2. NoNestedStringFormatsAnalyzer (PH2067)

  • Lines: 301
  • Complexity: Medium-High
  • Recommendation: CONDITIONAL - Complex string manipulation
  • Challenges: Nested format detection, symbol analysis required
  • Implementation: Flatten nested string.Format calls

Implementation Recommendations

Immediate Action Items (High ROI)

  1. Start with Simple Cases: Begin with analyzers having <50 lines and no semantic analysis
  2. Focus on Modifiers: NoProtectedFieldsAnalyzer, LockObjectsMustBeReadonlyAnalyzer, OrderPropertyAccessorsAnalyzer
  3. Address Naming: VariableNamingConventionAnalyzer, NamespaceMatchAssemblyNameAnalyzer

Implementation Guidelines

For High-Viability Analyzers:

[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 */);
    }
}

Common Patterns:

  1. Modifier Changes: Add/remove/replace keywords (readonly, private, etc.)
  2. Node Reordering: Rearrange declaration order (property accessors)
  3. Text Insertion: Add copyright headers, using statements
  4. Simple Replacements: Replace hardcoded values with constants

Testing Strategy

Each code fixer should include:

  1. Positive test cases: Verify fix applies correctly
  2. Negative test cases: Ensure no false positives
  3. Edge cases: Handle partial classes, nested structures
  4. Regression tests: Ensure no side effects

Benefits of Implementation

User Experience

  • 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

Development Efficiency

  • 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

Conclusion

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.