Summary
Several critical functions in the codebase exceed 100 lines and handle multiple responsibilities, making them difficult to test, understand, and maintain. These need to be decomposed into smaller, focused functions.
Functions Requiring Decomposition
Critical Priority
-
dependency_index.go:ResolveModulesToProducts (294 lines)
- Current: Handles direct resolution, transitive resolution, and builtin modules in one function
- Suggested: Break into
resolveToDirectProducts, resolveToTransitiveProducts, resolveToBuiltinModules
-
package_info.go:NewPackageInfo (149 lines)
- Current: Handles multiple responsibilities (parsing, validation, dependency resolution)
- Suggested: Extract validation, dependency parsing, and data merging into separate functions
-
generate.go:genRulesFromSrcFiles (82 lines)
- Current: Handles proto rules, source collection, and rule generation
- Suggested: Extract proto rule generation and source file processing
Proposed Refactoring Approach
Example for ResolveModulesToProducts:
func (di *DependencyIndex) ResolveModulesToProducts(modules []string, pkgIdentities []string) ResolutionResult {
result := NewResolutionResult()
result = di.resolveToDirectProducts(modules, pkgIdentities, result)
result = di.resolveToTransitiveProducts(result)
result = di.resolveToBuiltinModules(result)
return result
}
func (di *DependencyIndex) resolveToDirectProducts(modules []string, pkgIdentities []string, result ResolutionResult) ResolutionResult {
// Focused logic for direct product resolution
}
func (di *DependencyIndex) resolveToTransitiveProducts(result ResolutionResult) ResolutionResult {
// Focused logic for transitive product resolution
}
Acceptance Criteria
Benefits
- Testability: Smaller functions are easier to unit test
- Readability: Clearer intent and easier to understand
- Maintainability: Easier to modify individual pieces of logic
- Reusability: Extracted functions may be useful elsewhere
- Debugging: Easier to isolate and fix issues
Implementation Notes
- Preserve existing behavior - this is a refactoring, not a feature change
- Add tests for new functions before and after extraction
- Use descriptive function names that clearly indicate purpose
- Consider performance implications of function call overhead
- Update documentation to reflect new structure
Summary
Several critical functions in the codebase exceed 100 lines and handle multiple responsibilities, making them difficult to test, understand, and maintain. These need to be decomposed into smaller, focused functions.
Functions Requiring Decomposition
Critical Priority
dependency_index.go:ResolveModulesToProducts(294 lines)resolveToDirectProducts,resolveToTransitiveProducts,resolveToBuiltinModulespackage_info.go:NewPackageInfo(149 lines)generate.go:genRulesFromSrcFiles(82 lines)Proposed Refactoring Approach
Example for
ResolveModulesToProducts:Acceptance Criteria
Benefits
Implementation Notes