Skip to content

Commit 117cdab

Browse files
fixing tests and adding logs
1 parent d7d206f commit 117cdab

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

cmd/analyze.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ func validateToolName(toolName string) error {
283283
return nil
284284
}
285285

286+
// checkIfConfigExistsAndIsNeeded validates if a tool has config file and creates one if needed
286287
func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
287288
configFileName := constants.ToolConfigFileNames[toolName]
288289
if configFileName == "" {
@@ -296,19 +297,33 @@ func checkIfConfigExistsAndIsNeeded(toolName string, cliLocalMode bool) error {
296297

297298
// Check if the config file exists
298299
if _, err := os.Stat(toolConfigPath); os.IsNotExist(err) {
299-
// Only show error if we're in remote mode and need the config file
300+
// Config file does not exist - create it if we have the means to do so
300301
if (!cliLocalMode && initFlags.ApiToken != "") || cliLocalMode {
301302
fmt.Printf("Creating new config file for tool %s\n", toolName)
302303
if err := configsetup.CreateToolConfigurationFile(toolName, initFlags); err != nil {
303304
return fmt.Errorf("failed to create config file for tool %s: %w", toolName, err)
304305
}
306+
307+
// Ensure .gitignore exists FIRST to prevent config files from being analyzed
308+
if err := configsetup.CreateGitIgnoreFile(); err != nil {
309+
logger.Warn("Failed to create .gitignore file", logrus.Fields{
310+
"error": err,
311+
})
312+
}
305313
} else {
306-
fmt.Printf("Config file not found for tool %s: %s and no API token provided\n", toolName, toolConfigPath)
314+
logger.Debug("Config file not found for tool, using tool defaults", logrus.Fields{
315+
"tool": toolName,
316+
"toolConfigPath": toolConfigPath,
317+
"message": "No API token provided",
318+
})
307319
}
308320
} else if err != nil {
309321
return fmt.Errorf("error checking config file for tool %s: %w", toolName, err)
310322
} else {
311-
fmt.Printf("Config file found for %s: %s\n", toolName, toolConfigPath)
323+
logger.Info("Config file found for tool", logrus.Fields{
324+
"tool": toolName,
325+
"toolConfigPath": toolConfigPath,
326+
})
312327
}
313328
return nil
314329
}

cmd/configsetup/setup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ func createToolFileConfiguration(tool domain.Tool, patternConfiguration []domain
511511
}
512512

513513
toolsConfigDir := config.Config.ToolsConfigDirectory()
514+
515+
// Ensure the tools-configs directory exists
516+
if err := os.MkdirAll(toolsConfigDir, constants.DefaultDirPerms); err != nil {
517+
return fmt.Errorf("failed to create tools-configs directory: %w", err)
518+
}
519+
514520
return creator.CreateConfig(toolsConfigDir, patternConfiguration)
515521
}
516522

tools/eslintRunner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory
3838
//When writing to file, use the output file option
3939
cmd.Args = append(cmd.Args, "-o", outputFile)
4040
}
41+
4142
if len(pathsToCheck) > 0 {
4243
cmd.Args = append(cmd.Args, pathsToCheck...)
4344
} else {

0 commit comments

Comments
 (0)