@@ -2,7 +2,6 @@ package cmd
22
33import (
44 "codacy/cli-v2/config"
5- "codacy/cli-v2/domain"
65 "codacy/cli-v2/plugins"
76 "codacy/cli-v2/tools"
87 "codacy/cli-v2/tools/lizard"
@@ -331,7 +330,7 @@ func runToolByTooName(toolName string, workDirectory string, pathsToCheck []stri
331330 case "semgrep" :
332331 return tools .RunSemgrep (workDirectory , tool .Binaries [tool .Runtime ], pathsToCheck , outputFile , outputFormat )
333332 case "lizard" :
334- return runLizardAnalysis (workDirectory , pathsToCheck , outputFile , outputFormat )
333+ return lizard . RunLizard (workDirectory , tool . Binaries [ tool . Runtime ] , pathsToCheck , outputFile , outputFormat )
335334 case "enigma" :
336335 return tools .RunEnigma (workDirectory , tool .InstallDir , tool .Binaries [tool .Runtime ], pathsToCheck , outputFile , outputFormat )
337336 }
@@ -351,8 +350,6 @@ func genericRunTool(toolName string, workDirectory string, pathsToCheck []string
351350 return fmt .Errorf ("failed to install %s: %w" , toolName , err )
352351 }
353352 tool = config .Config .Tools ()[toolName ]
354- isToolInstalled = config .Config .IsToolInstalled (toolName , tool )
355-
356353 runtime = config .Config .Runtimes ()[tool .Runtime ]
357354 isRuntimeInstalled = runtime == nil || config .Config .IsRuntimeInstalled (tool .Runtime , runtime )
358355 if ! isRuntimeInstalled {
@@ -362,7 +359,6 @@ func genericRunTool(toolName string, workDirectory string, pathsToCheck []string
362359 return fmt .Errorf ("failed to install %s runtime: %w" , tool .Runtime , err )
363360 }
364361 runtime = config .Config .Runtimes ()[tool .Runtime ]
365- isRuntimeInstalled = config .Config .IsRuntimeInstalled (tool .Runtime , runtime )
366362 }
367363
368364 } else {
@@ -375,83 +371,11 @@ func genericRunTool(toolName string, workDirectory string, pathsToCheck []string
375371 return fmt .Errorf ("failed to install %s runtime: %w" , tool .Runtime , err )
376372 }
377373 runtime = config .Config .Runtimes ()[tool .Runtime ]
378- isRuntimeInstalled = config .Config .IsRuntimeInstalled (tool .Runtime , runtime )
379374 }
380-
381375 }
382-
383376 return runToolByTooName (toolName , workDirectory , pathsToCheck , autoFix , outputFile , outputFormat , tool , runtime )
384377}
385378
386- func runLizardAnalysis (workDirectory string , pathsToCheck []string , outputFile string , outputFormat string ) error {
387- // Ensure Lizard tool is configured and installed
388- lizardTool := config .Config .Tools ()["lizard" ]
389- isToolInstalled := config .Config .IsToolInstalled ("lizard" , lizardTool )
390-
391- // Also check if the runtime is installed
392- var isRuntimeInstalled bool
393- if lizardTool != nil {
394- pythonRuntime := config .Config .Runtimes ()["python" ]
395- isRuntimeInstalled = pythonRuntime != nil && config .Config .IsRuntimeInstalled ("python" , pythonRuntime )
396- }
397-
398- if lizardTool == nil || ! isToolInstalled || ! isRuntimeInstalled {
399- if lizardTool == nil {
400- fmt .Println ("Lizard tool configuration not found, adding and installing..." )
401- } else if ! isToolInstalled {
402- fmt .Println ("Lizard tool is not installed, installing..." )
403- } else if ! isRuntimeInstalled {
404- fmt .Println ("Python runtime is not installed, installing Lizard (which will install the runtime)..." )
405- }
406-
407- err := config .InstallTool ("lizard" , lizardTool , "" )
408- if err != nil {
409- return fmt .Errorf ("failed to install lizard: %w" , err )
410- }
411-
412- // Get the updated tool info after installation
413- lizardTool = config .Config .Tools ()["lizard" ]
414- if lizardTool == nil {
415- return fmt .Errorf ("lizard tool configuration still not found after installation" )
416- }
417- fmt .Println ("Lizard tool installed successfully" )
418- }
419-
420- // Ensure Python runtime is available
421- pythonRuntime := config .Config .Runtimes ()["python" ]
422- if pythonRuntime == nil {
423- return fmt .Errorf ("python runtime not found - this should not happen after lizard installation" )
424- }
425-
426- // Ensure python binary is available
427- lizardBinary := lizardTool .Binaries ["python" ]
428- if lizardBinary == "" {
429- return fmt .Errorf ("python binary not found in lizard tool configuration" )
430- }
431-
432- // Get configuration patterns
433- configFile , exists := tools .ConfigFileExists (config .Config , "lizard.yaml" )
434- var patterns []domain.PatternDefinition
435- var err error
436-
437- if exists {
438- // Configuration exists, read from file
439- patterns , err = lizard .ReadConfig (configFile )
440- if err != nil {
441- return fmt .Errorf ("error reading config file: %v" , err )
442- }
443- } else {
444- fmt .Println ("No configuration file found for Lizard, using default patterns, run init with repository token to get a custom configuration" )
445- patterns , err = tools .FetchDefaultEnabledPatterns (domain .Lizard )
446- if err != nil {
447- return fmt .Errorf ("failed to fetch default patterns: %v" , err )
448- }
449- }
450-
451- // Run Lizard
452- return lizard .RunLizard (workDirectory , lizardBinary , pathsToCheck , outputFile , outputFormat , patterns )
453- }
454-
455379var analyzeCmd = & cobra.Command {
456380 Use : "analyze" ,
457381 Short : "Runs all configured linters." ,
0 commit comments