Skip to content

Commit bd27b4f

Browse files
prioritize existing config file over generated
1 parent 1d5d76c commit bd27b4f

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

tools/lizard/lizardRunner.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"codacy/cli-v2/domain"
88
"codacy/cli-v2/tools"
99
"codacy/cli-v2/utils/logger"
10-
"github.com/sirupsen/logrus"
1110
"encoding/json"
1211
"fmt"
1312
"os"
1413
"os/exec"
14+
15+
"github.com/sirupsen/logrus"
1516
)
1617

1718
// RunLizard runs the Lizard tool and returns any issues found
@@ -20,8 +21,6 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s
2021
configFile, exists := tools.ConfigFileExists(config.Config, "lizard.yaml")
2122
var patterns []domain.PatternDefinition
2223
var errConfigs error
23-
24-
2524
if exists {
2625
// Configuration exists, read from file
2726
patterns, errConfigs = ReadConfig(configFile)
@@ -38,8 +37,6 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s
3837
if len(patterns) == 0 {
3938
return fmt.Errorf("no valid patterns found in configuration")
4039
}
41-
42-
4340
// Construct base command with lizard module
4441
args := []string{"-m", "lizard", "-V"}
4542

@@ -50,23 +47,20 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s
5047
args = append(args, ".")
5148
}
5249

53-
5450
// For non-SARIF output, let Lizard handle file output directly
5551
if outputFormat != "sarif" && outputFile != "" {
5652
args = append(args, "-o", outputFile)
5753
}
5854

59-
6055
// Run the command
6156
cmd := exec.Command(binary, args...)
6257
cmd.Dir = workDirectory
6358

64-
6559
var err error
6660
var stderr bytes.Buffer
67-
61+
6862
cmd.Stderr = &stderr
69-
63+
7064
// For SARIF output, we need to capture and parse the output
7165
if outputFormat == "sarif" {
7266
var stdout bytes.Buffer

tools/runnerUtils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ func ConfigFileExists(conf config.ConfigType, fileNames ...string) (string, bool
2121
generatedConfigFile := filepath.Join(conf.ToolsConfigDirectory(), fileName)
2222
existingConfigFile := filepath.Join(conf.RepositoryDirectory(), fileName)
2323

24-
if _, err := os.Stat(generatedConfigFile); err == nil {
25-
return generatedConfigFile, true
26-
} else if _, err := os.Stat(existingConfigFile); err == nil {
24+
if _, err := os.Stat(existingConfigFile); err == nil {
2725
return existingConfigFile, true
26+
} else if _, err := os.Stat(generatedConfigFile); err == nil {
27+
return generatedConfigFile, true
2828
}
2929
}
3030

0 commit comments

Comments
 (0)