Skip to content

Commit 1d28c09

Browse files
fix issue with initFlags when is nil
1 parent 8a885ca commit 1d28c09

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

cmd/analyze.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,26 +352,32 @@ func runToolByName(toolName string, workDirectory string, pathsToCheck []string,
352352
return err
353353
}
354354

355-
// Get the tool name with the right version e.g. ESLint9, PMD7, etc.
356-
toolRightVersion := getToolName(toolName, tool.Version)
357-
fmt.Printf(toolName)
355+
var t *domain.Tool
356+
var usesConfigurationFile = false
358357

359-
// Get the repository tools to access tool settings
360-
repositoryTools, _ := codacyclient.GetRepositoryTools(initFlags)
358+
// If the user doesn't provide init flags, we skip fetching repository tools
359+
if initFlags != (domain.InitFlags{}) {
360+
// Get the tool name with the right version e.g. ESLint9, PMD7, etc.
361+
toolRightVersion := getToolName(toolName, tool.Version)
361362

362-
// Find the matching tool in repositoryTools
363-
var t *domain.Tool
364-
for i, tool := range repositoryTools {
365-
if tool.Name == toolRightVersion {
366-
t = &repositoryTools[i]
367-
break
363+
// Get the repository tools to access tool settings
364+
repositoryTools, _ := codacyclient.GetRepositoryTools(initFlags)
365+
366+
// Find the matching tool in repositoryTools
367+
368+
for i, tool := range repositoryTools {
369+
if tool.Name == toolRightVersion {
370+
t = &repositoryTools[i]
371+
usesConfigurationFile = t.Settings.UsesConfigurationFile
372+
break
373+
}
368374
}
369375
}
370376

371377
switch toolName {
372378
case "eslint":
373379
binaryPath := runtime.Binaries[tool.Runtime]
374-
return tools.RunEslint(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, autoFix, outputFile, outputFormat, t.Settings.UsesConfigurationFile)
380+
return tools.RunEslint(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, autoFix, outputFile, outputFormat, usesConfigurationFile)
375381
case "trivy":
376382
binaryPath := tool.Binaries[toolName]
377383
return tools.RunTrivy(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)

tools/eslintRunner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
// * Run from the root of the repo we want to analyse
1212
// * NODE_PATH="<the installed eslint path>/node_modules"
1313
// * The local installed ESLint should have the @microsoft/eslint-formatter-sarif installed
14-
func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string, UsesConfigurationFile bool) error {
14+
func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string, usesConfigurationFile bool) error {
1515
eslintInstallationNodeModules := filepath.Join(eslintInstallationDirectory, "node_modules")
1616
eslintJsPath := filepath.Join(eslintInstallationNodeModules, ".bin", "eslint")
1717

1818
cmd := exec.Command(nodeBinary, eslintJsPath)
1919

2020
// Add config file from tools-configs directory if it exists
21-
if !UsesConfigurationFile {
21+
if !usesConfigurationFile {
2222
if configFile, exists := ConfigFileExists(config.Config, "eslint.config.mjs"); exists {
2323
// For Eslint compatibility with version 8.
2424
// https://eslint.org/docs/v8.x/use/configure/configuration-files-new

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)