@@ -366,6 +366,21 @@ func runTool(workDirectory string, toolName string, pathsToCheck []string, outpu
366366 runtime = config .Config .Runtimes ()[tool .Runtime ]
367367 }
368368 }
369+
370+ if tool .ConfigFileName != "" {
371+ configFile , exists := HasConfigFile (config .Config , tool .ConfigFileName )
372+ if ! exists {
373+ fmt .Printf ("Config file %s not found, creating...\n " , tool .ConfigFileName )
374+ // TODO: Implement CreateConfigFile function in utils
375+ // err := utils.CreateConfigFile(config.Config, tool.ConfigFileName)
376+ // if err != nil {
377+ // return fmt.Errorf("failed to create config file %s: %w", tool.ConfigFileName, err)
378+ // }
379+ } else {
380+ fmt .Printf ("Using existing config file: %s\n " , configFile )
381+ }
382+ }
383+
369384 return runToolByName (toolName , workDirectory , pathsToCheck , autoFix , outputFile , outputFormat , tool , runtime )
370385}
371386
@@ -456,3 +471,56 @@ var analyzeCmd = &cobra.Command{
456471 }
457472 },
458473}
474+
475+ // HasConfigFile checks if a tool's config file exists in the .codacy/tools-configs directory
476+ // or in the repository root directory.
477+ //
478+ // Parameters:
479+ // - config: The configuration object containing directory paths
480+ // - configFileName: The name of the config file to check for
481+ //
482+ // Returns:
483+ // - string: The full path to the config file if it exists
484+ // - bool: True if the config file exists, false otherwise
485+ func HasConfigFile (config interface {}, configFileName string ) (string , bool ) {
486+ fmt .Println ("Checking for config file:" , configFileName )
487+ // If no config file name is specified, return false
488+ if configFileName == "" {
489+ return "" , false
490+ }
491+
492+ // We need to get the workspace directory from the config
493+ // For now, we'll check in the current directory and .codacy/tools-config
494+ workDir , err := os .Getwd ()
495+ if err != nil {
496+ return "" , false
497+ }
498+
499+ fmt .Println ("Work directory:" , workDir )
500+ fmt .Println ("Checking in .codacy/tools-configs directory first" )
501+ // Check in .codacy/tools-configs directory first
502+ toolsConfigDir := filepath .Join (workDir , ".codacy" , "tools-configs" )
503+ fmt .Println ("Tools config directory:" , toolsConfigDir )
504+ configPath := filepath .Join (toolsConfigDir , configFileName )
505+ fmt .Println ("Config path:" , configPath )
506+ if _ , err := os .Stat (configPath ); err == nil {
507+ fmt .Println ("Found config file in tools-configs directory!" )
508+ return configPath , true
509+ } else {
510+ fmt .Println ("Config file NOT found in tools-configs directory. Error:" , err )
511+ }
512+
513+ // Check in repository root directory as fallback
514+ rootConfigPath := filepath .Join (workDir , configFileName )
515+ fmt .Println ("Checking root config path:" , rootConfigPath )
516+ if _ , err := os .Stat (rootConfigPath ); err == nil {
517+ fmt .Println ("Found config file in repository root directory!" )
518+ return rootConfigPath , true
519+ } else {
520+ fmt .Println ("Config file NOT found in repository root. Error:" , err )
521+ }
522+
523+ // Config file not found
524+ fmt .Println ("Config file not found anywhere" )
525+ return "" , false
526+ }
0 commit comments