Skip to content

Commit d75b76a

Browse files
more improvements using the tool config file
1 parent 9af545d commit d75b76a

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

.codacy/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ tools:
1313
1414
1515
16-
16+

cmd/analyze.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
312312
// Use the configuration system to get the tools config directory
313313
toolsConfigDir := config.Config.ToolsConfigDirectory()
314314
toolConfigPath := filepath.Join(toolsConfigDir, configFileName)
315-
316315
// Check if the config file exists
317316
if _, err := os.Stat(toolConfigPath); os.IsNotExist(err) {
318317
// Config file does not exist - create it if we have the means to do so
@@ -347,14 +346,10 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
347346
}
348347

349348
func runToolByName(toolName string, workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string, tool *plugins.ToolInfo, runtime *plugins.RuntimeInfo, cliLocalMode bool) error {
350-
err := checkIfConfigExistsAndIsNeeded(toolName, cliLocalMode)
351-
if err != nil {
352-
return err
353-
}
354-
355349
var t *domain.Tool
356350
var usesConfigurationFile = false
357351

352+
//Check if the user is using the repository configuration file
358353
// If the user doesn't provide init flags, we skip fetching repository tools
359354
if initFlags != (domain.InitFlags{}) {
360355
// Get the tool name with the right version e.g. ESLint9, PMD7, etc.
@@ -364,7 +359,6 @@ func runToolByName(toolName string, workDirectory string, pathsToCheck []string,
364359
repositoryTools, _ := codacyclient.GetRepositoryTools(initFlags)
365360

366361
// Find the matching tool in repositoryTools
367-
368362
for i, tool := range repositoryTools {
369363
if tool.Name == toolRightVersion {
370364
t = &repositoryTools[i]
@@ -374,6 +368,14 @@ func runToolByName(toolName string, workDirectory string, pathsToCheck []string,
374368
}
375369
}
376370

371+
// If the user is not using configuration file from repository, we check if there's a local one
372+
if !usesConfigurationFile {
373+
err := checkIfConfigExistsAndIsNeeded(toolName, cliLocalMode)
374+
if err != nil {
375+
return err
376+
}
377+
}
378+
377379
switch toolName {
378380
case "eslint":
379381
binaryPath := runtime.Binaries[tool.Runtime]

cmd/configsetup/repository_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func createToolConfigurationFiles(tools []domain.Tool, flags domain.InitFlags) e
9191
}
9292

9393
// CreateToolConfigurationFile creates a configuration file for a single tool
94-
// CreateToolConfigurationFile generates a configuration file for a single tool.
9594
func CreateToolConfigurationFile(toolName string, flags domain.InitFlags) error {
9695
// Find the tool UUID by tool name
96+
fmt.Printf("Creating configuration file for tool %s\n", toolName)
9797
toolUUID := getToolUUIDByName(toolName)
9898
if toolUUID == "" {
9999
return fmt.Errorf("tool '%s' not found in supported tools", toolName)

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

0 commit comments

Comments
 (0)