@@ -2,8 +2,10 @@ package cmd
22
33import (
44 "codacy/cli-v2/config"
5+ "codacy/cli-v2/domain"
56 "codacy/cli-v2/plugins"
67 "codacy/cli-v2/tools"
8+ "codacy/cli-v2/tools/lizard"
79 "encoding/json"
810 "fmt"
911 "io"
@@ -329,26 +331,39 @@ func runEslintAnalysis(workDirectory string, pathsToCheck []string, autoFix bool
329331
330332func runTrivyAnalysis (workDirectory string , pathsToCheck []string , outputFile string , outputFormat string ) error {
331333 trivy := config .Config .Tools ()["trivy" ]
334+ if trivy == nil {
335+ log .Fatal ("Trivy tool configuration not found" )
336+ }
332337 trivyBinary := trivy .Binaries ["trivy" ]
333338
334339 return tools .RunTrivy (workDirectory , trivyBinary , pathsToCheck , outputFile , outputFormat )
335340}
336341
337342func runPmdAnalysis (workDirectory string , pathsToCheck []string , outputFile string , outputFormat string ) error {
338343 pmd := config .Config .Tools ()["pmd" ]
344+ if pmd == nil {
345+ log .Fatal ("Pmd tool configuration not found" )
346+ }
339347 pmdBinary := pmd .Binaries ["pmd" ]
340348
341349 return tools .RunPmd (workDirectory , pmdBinary , pathsToCheck , outputFile , outputFormat , config .Config )
342350}
343351
344352func runPylintAnalysis (workDirectory string , pathsToCheck []string , outputFile string , outputFormat string ) error {
345353 pylint := config .Config .Tools ()["pylint" ]
354+ if pylint == nil {
355+ log .Fatal ("Pylint tool configuration not found" )
356+ }
357+ pylintBinary := pylint .Binaries ["python" ]
346358
347- return tools .RunPylint (workDirectory , pylint , pathsToCheck , outputFile , outputFormat )
359+ return tools .RunPylint (workDirectory , pylintBinary , pathsToCheck , outputFile , outputFormat )
348360}
349361
350362func runDartAnalyzer (workDirectory string , pathsToCheck []string , outputFile string , outputFormat string ) error {
351363 dartanalyzer := config .Config .Tools ()["dartanalyzer" ]
364+ if dartanalyzer == nil {
365+ log .Fatal ("Dart analyzer tool configuration not found" )
366+ }
352367 return tools .RunDartAnalyzer (workDirectory , dartanalyzer .InstallDir , dartanalyzer .Binaries ["dart" ], pathsToCheck , outputFile , outputFormat )
353368}
354369
@@ -357,8 +372,43 @@ func runSemgrepAnalysis(workDirectory string, pathsToCheck []string, outputFile
357372 if semgrep == nil {
358373 log .Fatal ("Semgrep tool configuration not found" )
359374 }
375+ semgrepBinary := semgrep .Binaries ["python" ]
376+
377+ return tools .RunSemgrep (workDirectory , semgrepBinary , pathsToCheck , outputFile , outputFormat )
378+ }
379+
380+ func runLizardAnalysis (workDirectory string , pathsToCheck []string , outputFile string , outputFormat string ) error {
381+ lizardTool := config .Config .Tools ()["lizard" ]
382+
383+ if lizardTool == nil {
384+ log .Fatal ("Lizard plugin configuration not found" )
385+ }
386+
387+ lizardBinary := lizardTool .Binaries ["python" ]
388+
389+ configFile , exists := tools .ConfigFileExists (config .Config , "lizard.yaml" )
390+ var patterns []domain.PatternDefinition
391+ var err error
392+
393+ //this logic is here because I want to pass the config to the runner which is good for:
394+ //Separation of concerns, runner will simply run the tool now
395+ //Easier testing, since config is now passed
396+ //Avoiding fetching the default patterns in tests (unless we want to maintain codacy directory with the configs)
397+ if exists {
398+ // Configuration exists, read from file
399+ patterns , err = lizard .ReadConfig (configFile )
400+ if err != nil {
401+ return fmt .Errorf ("error reading config file: %v" , err )
402+ }
403+ } else {
404+ fmt .Println ("No configuration file found for Lizard, using default patterns, run init with repository token to get a custom configuration" )
405+ patterns , err = tools .FetchDefaultEnabledPatterns (Lizard )
406+ if err != nil {
407+ return fmt .Errorf ("failed to fetch default patterns: %v" , err )
408+ }
409+ }
360410
361- return tools . RunSemgrep (workDirectory , semgrep , pathsToCheck , outputFile , outputFormat )
411+ return lizard . RunLizard (workDirectory , lizardBinary , pathsToCheck , outputFile , outputFormat , patterns )
362412}
363413
364414var analyzeCmd = & cobra.Command {
@@ -380,6 +430,7 @@ var analyzeCmd = &cobra.Command{
380430 } else {
381431 // Run all configured tools
382432 toolsToRun = config .Config .Tools ()
433+ log .Println ("Running all configured tools..." )
383434 }
384435
385436 if len (toolsToRun ) == 0 {
@@ -463,6 +514,8 @@ func runTool(workDirectory string, toolName string, args []string, outputFile st
463514 return runSemgrepAnalysis (workDirectory , args , outputFile , outputFormat )
464515 case "dartanalyzer" :
465516 return runDartAnalyzer (workDirectory , args , outputFile , outputFormat )
517+ case "lizard" :
518+ return runLizardAnalysis (workDirectory , args , outputFile , outputFormat )
466519 default :
467520 return fmt .Errorf ("unsupported tool: %s" , toolName )
468521 }
0 commit comments