UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

85 lines (82 loc) 4.13 kB
/** * @file Orchestrate null safety detection across multiple analyzers * @description Single responsibility: Coordinate comprehensive null safety analysis * * This orchestrator module coordinates multiple specialized null safety detectors * to provide comprehensive analysis of potential runtime errors. It ensures consistent * application of all null safety checks while maintaining separation of concerns * between different types of null-related bugs. * * Design rationale: * - Orchestrator pattern enables adding new detectors without modifying existing code * - Separate detectors maintain focused responsibilities for different bug patterns * - Spread operator aggregation preserves individual detector results * - Consistent interface simplifies integration with main analysis pipeline */ const detectNullAccess = require('./detect/detectNullAccess'); const detectUseBeforeInit = require('./detect/detectUseBeforeInit'); const detectTypeCoercion = require('./detect/detectTypeCoercion'); /** * Execute comprehensive null safety analysis using multiple specialized detectors * * Technical function: Coordinates execution of all null safety detectors and aggregates results * * Implementation rationale: * - Spread operator efficiently merges arrays from multiple detectors * - Sequential execution ensures all detectors run regardless of individual failures * - Common interface (ast, filePath) enables consistent detector implementation * - Array flattening provides unified result set for downstream processing * * Detector coordination strategy: * - Each detector focuses on specific null safety patterns for maintainability * - Independent execution prevents detector failures from affecting others * - Results aggregation preserves all findings for comprehensive reporting * - Consistent parameter passing enables shared utility function usage * * Null safety coverage areas: * - detectNullAccess: Direct null/undefined property access and method calls * - detectUseBeforeInit: Variables used before declaration or initialization * - detectTypeCoercion: Implicit type conversions that may hide null issues * * Performance considerations: * - Single AST traversal per detector optimizes parsing overhead * - Independent detectors can be parallelized in future optimizations * - Result aggregation is O(n) where n is total number of issues found * - Memory usage scales linearly with number of detected issues * * Error handling strategy: * - Detector failures contained within individual functions * - Orchestrator continues execution if individual detectors throw exceptions * - Empty arrays returned from failed detectors don't break aggregation * - Consistent error propagation enables upstream error handling * * Extensibility design: * - Adding new detectors requires only one line addition to aggregation * - Detector interface standardization enables consistent implementation * - Result format consistency maintained across all detectors * - Module structure supports dependency injection for testing * * Alternative approaches considered: * - Single monolithic detector: Rejected for maintainability and testing complexity * - Event-based aggregation: Rejected as overkill for synchronous analysis * - Configurable detector selection: Rejected to maintain consistent analysis coverage * * @param {Object} ast - Parsed AST tree for comprehensive static analysis * @param {string} filePath - File path for issue location reporting and context * @returns {Array<Object>} Aggregated array of all null safety issues found by all detectors * @example * // Returns combined results from all detectors: * [ * { type: 'null_access', location: 'file.js:10', ... }, * { type: 'use_before_init', location: 'file.js:5', ... }, * { type: 'type_coercion', location: 'file.js:20', ... } * ] */ function detectNullSafetyPatterns(ast, filePath) { return [ ...detectNullAccess(ast, filePath), ...detectUseBeforeInit(ast, filePath), ...detectTypeCoercion(ast, filePath) ]; } module.exports = detectNullSafetyPatterns;