Genese complexity report

<- options.model.ts
Methods : 8
Complexity index : 94.6
Cyclomatic complexity : 19
Cognitive complexity
62.5 % Correct 5/8
25 % Warning 2/8 (threshold : 10)
12.5 % Error 1/8 (threshold : 20)
Cyclomatic complexity
87.5 % Correct 7/8
12.5 % Warning 1/8 (threshold : 5)
0 % Error 0/8 (threshold : 10)
Methods of options.model.ts
setOptions Complexity Index 6.9 Cyclomatic complexity 2
                            
                                
                
            
            
                /**
                 * Sets the options of genese-complexity module
                 * @param pathCommand               // The path of the folder where the command-line was entered (can't be overriden)
                 * @param pathFolderToAnalyze       // The path of the folder to analyse (can be overriden)
                 * @param pathGeneseNodeJs          // The path of the node_module Genese in the nodejs user environment (can't be overriden)
                 */
                static setOptions( // ------------------------------------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    pathCommand: string, // ------------------------------------------------------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                    pathFolderToAnalyze: string, // ---------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    pathGeneseNodeJs: string // -------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                ): void { // --------------------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    WINDOWS = process.platform === 'win32'; // ----------------------------------------------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    const geneseConfigPath = `${pathCommand}/geneseconfig.json`; // -------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    if (fs.existsSync(geneseConfigPath)) { // ------------------------------------------------------------------------------------------ +2.4 Complexity index (+0.4 atomic, +2 structural)
                        Options.setOptionsFromConfig(geneseConfigPath); // ----------------------------------------------------------------------------- +1.3 Complexity index (+0.3 atomic, +1 structural)
                    }
                    Options.setOptionsFromCommandLine( // ---------------------------------------------------------------------------------------------- +1.2 Complexity index (+0.2 atomic, +1 structural)
                        pathCommand, // ---------------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        pathFolderToAnalyze, // -------------------------------------------------------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                        pathGeneseNodeJs // ------------------------------------------------------------------------------------------------------------ +0.1 Complexity index (+0.1 atomic)
                    );
                }
            
                            
                        
setOptionsFromCommandLine Complexity Index 3.5 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Sets the options of genese-complexity module with command-line options (lower priority than geneseconfig.json options)
                 * @param pathCommand               // The path of the folder where the command-line was entered (can't be overriden)
                 * @param pathFolderToAnalyze       // The path of the folder to analyse (can be overriden)
                 * @param pathGeneseNodeJs          // The path of the node_module Genese in the nodejs user environment (can't be overriden)
                 */
                static setOptionsFromCommandLine(pathCommand: string, pathFolderToAnalyze: string, pathGeneseNodeJs: string): void { // ---------------- +0.8 Complexity index (+0.8 atomic)
                    Options.pathCommand = pathCommand; // ---------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    Options.pathFolderToAnalyze = getPathWithSlash(pathFolderToAnalyze); // ------------------------------------------------------------ +1.5 Complexity index (+0.5 atomic, +1 structural)
                    Options.pathGeneseNodeJs = pathGeneseNodeJs; // ------------------------------------------------------------------------------------ +0.4 Complexity index (+0.4 atomic)
                    Options.pathOutDir = `${pathCommand}/genese/complexity/reports`; // ---------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                }
            
                            
                        
setOptionsFromConfig Complexity Index 17.3 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Sets the options of genese-complexity module with geneseconfig.json options (higher priority than geneseconfig.json options)
                 * @param geneseConfigPath  // The path of the geneseconfig.json file
                 */
                static setOptionsFromConfig(geneseConfigPath: string): void { // ---------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                    const config = require(geneseConfigPath); // -------------------------------------------------------------------------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
            
                    Options.ignore = this.filterIgnorePathsForDotSlash(config.complexity.ignore) ?? Options.ignore; // -------------------------------------------- +2.1 Complexity index (+1.1 atomic, +1 structural)
                    Options.ignore.forEach((path, i) => { // ------------------------------------------------------------------------------------------------------ +2.6 Complexity index (+0.6 atomic, +2 structural)
                        Options.ignoreRegex += i !== Options.ignore.length - 1 ? `${this.pathTransformator(path)}|` : `${this.pathTransformator(path)}`; // ------- +5.7 Complexity index (+1.7 atomic, +1 nesting, +3 structural)
                    });
            
                    Options.pathFolderToAnalyze = // -------------------------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        config.complexity?.pathFolderToAnalyze ?? // ---------------------------------------------------------------------------------------------- +0.4 Complexity index (+0.4 atomic)
                        Options.pathFolderToAnalyze; // ----------------------------------------------------------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    Options.pathOutDir = // ----------------------------------------------------------------------------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                        config.complexity?.pathReports ?? Options.pathOutDir; // ---------------------------------------------------------------------------------- +0.6 Complexity index (+0.6 atomic)
                    Options.ignore.push(Options.pathOutDir); // --------------------------------------------------------------------------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    Options.cognitiveCpx = config.complexity.cognitiveCpx ?? Options.cognitiveCpx; // ------------------------------------------------------------- +0.9 Complexity index (+0.9 atomic)
                    Options.cyclomaticCpx = config.complexity.cyclomaticCpx ?? Options.cyclomaticCpx; // ---------------------------------------------------------- +0.9 Complexity index (+0.9 atomic)
                }
            
                            
                        
filterIgnorePathsForDotSlash Complexity Index 10.9 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Separate paths which needs to start by "./" and others
                 * @param ignorePaths
                 * @returns {String[]}
                 */
                static filterIgnorePathsForDotSlash(ignorePaths: string[]): string[] { // ------------- +0.6 Complexity index (+0.6 atomic)
                    const ignorePathsToFormat = ignorePaths.filter( // -------------------------------- +1.4 Complexity index (+0.4 atomic, +1 structural)
                        (x) => !x.startsWith('*.') // ------------------------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                    );
                    const ignorePathsToKeep = ignorePaths.filter((x) => x.startsWith('*.')); // ------- +3.9 Complexity index (+0.9 atomic, +3 structural)
                    return getArrayOfPathsWithDotSlash(ignorePathsToFormat).concat( // ---------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        ignorePathsToKeep // ---------------------------------------------------------- +0.1 Complexity index (+0.1 atomic)
                    );
                }
            
                            
                        
isIgnored Complexity Index 5 Cyclomatic complexity 3
                            
                                
                
            
            
                /**
                 * Checks if a file or a folder is ignored in geneseconfig.json
                 * @param path
                 */
                static isIgnored(path: string): boolean { // ----------------------------- +0.3 Complexity index (+0.3 atomic)
                    if (Options.ignoreRegex.length > 0) { // ----------------------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        return path.match(Options.ignoreRegex)?.length > 0; // ----------- +1.8 Complexity index (+0.8 atomic, +1 structural)
                    } else { // ---------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                        return false; // ------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    }
                }
            
                            
                        
pathTransformator Complexity Index 40.7 Cyclomatic complexity 6
                            
                                
                
            
                static pathTransformator(path: string) { // ------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    const SEPARATED_PATH = path.split('/'); // ---------------------------------- +1.5 Complexity index (+0.5 atomic, +1 structural)
                    let pathTester = ''; // ----------------------------------------------------- +0.3 Complexity index (+0.3 atomic)
                    SEPARATED_PATH.forEach((subPath, i) => { // --------------------------------- +2.5 Complexity index (+0.5 atomic, +2 structural)
                        if (subPath.startsWith('*.')) { // -------------------------------------- +3.4 Complexity index (+0.4 atomic, +1 nesting, +2 structural)
                            subPath = subPath.split('.').join('\\.'); // ------------------------ +2.7 Complexity index (+0.7 atomic, +2 structural)
                            pathTester = subPath.replace('*\\.', '[a-z]*\\.'); // --------------- +1.6 Complexity index (+0.6 atomic, +1 structural)
                        } else { // ------------------------------------------------------------- +1.1 Complexity index (+0.1 atomic, +1 structural)
                            if (subPath.match('([a-z].*)')) { // -------------------------------- +3.9 Complexity index (+0.4 atomic, +1.5 nesting, +2 structural)
                                i !== SEPARATED_PATH.length - 1 // ------------------------------ +3.7 Complexity index (+0.7 atomic, +2 nesting, +1 structural)
                                    ? (pathTester += `${subPath}\\/`) // ------------------------ +0.3 Complexity index (+0.3 atomic)
                                    : (pathTester += `${subPath}`); // -------------------------- +0.3 Complexity index (+0.3 atomic)
                            }
            
                            if (subPath.match('(\\*\\*)') || subPath.match('(\\*)')) { // ------- +6.4 Complexity index (+0.9 atomic, +1.5 nesting, +4 structural)
                                i !== SEPARATED_PATH.length - 1 // ------------------------------ +3.7 Complexity index (+0.7 atomic, +2 nesting, +1 structural)
                                    ? (pathTester += '([a-z].*)\\/') // ------------------------- +0.3 Complexity index (+0.3 atomic)
                                    : (pathTester += '([a-z].*)'); // --------------------------- +0.3 Complexity index (+0.3 atomic)
                            }
            
                            if (subPath.match('(\\.$)')) { // ----------------------------------- +3.9 Complexity index (+0.4 atomic, +1.5 nesting, +2 structural)
                                i !== SEPARATED_PATH.length - 1 // ------------------------------ +3.7 Complexity index (+0.7 atomic, +2 nesting, +1 structural)
                                    ? (pathTester += `${subPath}\\/`) // ------------------------ +0.3 Complexity index (+0.3 atomic)
                                    : (pathTester += subPath); // ------------------------------- +0.3 Complexity index (+0.3 atomic)
                            }
                        }
                    });
                    return pathTester; // ------------------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
handleStarPath Complexity Index 6.7 Cyclomatic complexity 2
                            
                                
                
            
            
                static handleStarPath(ignorePath: string, path: string) { // ------- +0.5 Complexity index (+0.5 atomic)
                    if (ignorePath.startsWith('*.')) { // -------------------------- +2.4 Complexity index (+0.4 atomic, +2 structural)
                        return path.includes(ignorePath.slice(1)); // -------------- +3.6 Complexity index (+0.6 atomic, +2 structural, +1 use)
                    }
                    return false; // ----------------------------------------------- +0.2 Complexity index (+0.2 atomic)
                }
            
                            
                        
getThresholds Complexity Index 3.6 Cyclomatic complexity 1
                            
                                
                
            
            
                /**
                 * Gets the different thresholds defined in Options class
                 * @returns {ComplexitiesByStatus}
                 */
                static getThresholds(): ComplexitiesByStatus { // ------------------------------------- +0.2 Complexity index (+0.2 atomic)
                    const cpxByStatus = new ComplexitiesByStatus(); // -------------------------------- +0.4 Complexity index (+0.4 atomic)
                    cpxByStatus.cognitive.warning = Options.cognitiveCpx.warningThreshold; // --------- +0.7 Complexity index (+0.7 atomic)
                    cpxByStatus.cognitive.error = Options.cognitiveCpx.errorThreshold; // ------------- +0.7 Complexity index (+0.7 atomic)
                    cpxByStatus.cyclomatic.warning = Options.cyclomaticCpx.warningThreshold; // ------- +0.7 Complexity index (+0.7 atomic)
                    cpxByStatus.cyclomatic.error = Options.cyclomaticCpx.errorThreshold; // ----------- +0.7 Complexity index (+0.7 atomic)
                    return cpxByStatus; // ------------------------------------------------------------ +0.2 Complexity index (+0.2 atomic)
                }