Skip to content

Commit 36886e5

Browse files
review improvements
1 parent a191751 commit 36886e5

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

.codacy/codacy.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
runtimes:
22
3-
43
tools:
54
65
7-
86
97

tools/runnerUtils.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@ import (
66
"path/filepath"
77
)
88

9-
// ConfigFileExists checks if a specific configuration file exists in the .codacy/tools-configs/
9+
// ConfigFileExists checks if any of the specified configuration files exist in the .codacy/tools-configs/
1010
// or on the root of the repository directory.
1111
//
1212
// Parameters:
1313
// - conf: The configuration object containing the tools config directory
14-
// - fileName: The configuration file name to check for
14+
// - fileNames: A list of configuration file names to check for
1515
//
1616
// Returns:
17-
// - string: The relative path to the configuration file (for cmd args)
18-
// - bool: True if the file exists, false otherwise
19-
func ConfigFileExists(conf config.ConfigType, fileName string) (string, bool) {
20-
generatedConfigFile := filepath.Join(conf.ToolsConfigDirectory(), fileName)
21-
existingConfigFile := filepath.Join(conf.RepositoryDirectory(), fileName)
17+
// - string: The relative path to the first configuration file found (for cmd args)
18+
// - bool: True if any file exists, false otherwise
19+
func ConfigFileExists(conf config.ConfigType, fileNames ...string) (string, bool) {
20+
for _, fileName := range fileNames {
21+
generatedConfigFile := filepath.Join(conf.ToolsConfigDirectory(), fileName)
22+
existingConfigFile := filepath.Join(conf.RepositoryDirectory(), fileName)
2223

23-
if _, err := os.Stat(generatedConfigFile); err == nil {
24-
return generatedConfigFile, true
25-
} else if _, err := os.Stat(existingConfigFile); err == nil {
26-
return existingConfigFile, true
24+
if _, err := os.Stat(generatedConfigFile); err == nil {
25+
return generatedConfigFile, true
26+
} else if _, err := os.Stat(existingConfigFile); err == nil {
27+
return existingConfigFile, true
28+
}
2729
}
2830

2931
return "", false

tools/semgrepRunner.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ func RunSemgrep(workDirectory string, toolInfo *plugins.ToolInfo, files []string
1919
cmdArgs = append(cmdArgs, "--sarif")
2020
}
2121

22+
// Define possible Semgrep config file names
23+
semgrepConfigFiles := []string{".semgrep.yml", ".semgrep.yaml", ".semgrep/semgrep.yml"}
24+
2225
// Check if a config file exists in the expected location and use it if present
23-
if configFile, exists := ConfigFileExists(config.Config, ".semgrep.yml"); exists {
26+
if configFile, exists := ConfigFileExists(config.Config, semgrepConfigFiles...); exists {
2427
cmdArgs = append(cmdArgs, "--config", configFile)
2528
} else {
2629
// add --config auto only if no config file exists

0 commit comments

Comments
 (0)