@@ -299,86 +299,51 @@ func createToolFileConfigurations(tool domain.Tool, patternConfiguration []domai
299299 toolsConfigDir := config .Config .ToolsConfigDirectory ()
300300 switch tool .Uuid {
301301 case ESLint :
302- if len (patternConfiguration ) > 0 {
303- eslintConfigurationString := tools .CreateEslintConfig (patternConfiguration )
304-
305- eslintConfigFile , err := os .Create (filepath .Join (toolsConfigDir , "eslint.config.mjs" ))
306- if err != nil {
307- return fmt .Errorf ("failed to create eslint config file: %v" , err )
308- }
309- defer eslintConfigFile .Close ()
310-
311- _ , err = eslintConfigFile .WriteString (eslintConfigurationString )
312- if err != nil {
313- return fmt .Errorf ("failed to write eslint config: %v" , err )
314- }
315- fmt .Println ("ESLint configuration created based on Codacy settings. Ignoring plugin rules. ESLint plugins are not supported yet." )
316- } else {
317- err := createDefaultEslintConfigFile (toolsConfigDir )
318- if err != nil {
319- return fmt .Errorf ("failed to create default ESLint config: %v" , err )
320- }
321- fmt .Println ("Default ESLint configuration created" )
302+ err := tools .CreateEslintConfig (toolsConfigDir , patternConfiguration )
303+ if err != nil {
304+ return fmt .Errorf ("failed to write eslint config: %v" , err )
322305 }
306+ fmt .Println ("ESLint configuration created based on Codacy settings. Ignoring plugin rules. ESLint plugins are not supported yet." )
323307 case Trivy :
324- if len (patternConfiguration ) > 0 {
325- err := createTrivyConfigFile (patternConfiguration , toolsConfigDir )
326- if err != nil {
327- return fmt .Errorf ("failed to create Trivy config: %v" , err )
328- }
329- fmt .Println ("Trivy configuration created based on Codacy settings" )
330- } else {
331- err := createDefaultTrivyConfigFile (toolsConfigDir )
332- if err != nil {
333- return fmt .Errorf ("failed to create default Trivy config: %v" , err )
334- }
308+ err := createTrivyConfigFile (patternConfiguration , toolsConfigDir )
309+ if err != nil {
310+ return fmt .Errorf ("failed to create Trivy config: %v" , err )
335311 }
336- case PMD :
337- if len (patternConfiguration ) > 0 {
338- err := createPMDConfigFile (patternConfiguration , toolsConfigDir )
339- if err != nil {
340- return fmt .Errorf ("failed to create PMD config: %v" , err )
341- }
312+ fmt .Println ("Trivy configuration created based on Codacy settings" )
342313
343- fmt .Println ("PMD configuration created based on Codacy settings" )
344- } else {
345- err := createDefaultPMDConfigFile (toolsConfigDir )
346- if err != nil {
347- return fmt .Errorf ("failed to create default PMD config: %v" , err )
348- }
314+ case PMD :
315+ err := createPMDConfigFile (patternConfiguration , toolsConfigDir )
316+ if err != nil {
317+ return fmt .Errorf ("failed to create PMD config: %v" , err )
349318 }
350-
319+ fmt . Println ( "PMD configuration created based on Codacy settings" )
351320 case PyLint :
352- if len (patternConfiguration ) > 0 {
353- err := createPylintConfigFile (patternConfiguration , toolsConfigDir )
354- if err != nil {
355- return fmt .Errorf ("failed to create Pylint config: %v" , err )
356- }
357- fmt .Println ("Pylint configuration created based on Codacy settings" )
358- } else {
359- err := createDefaultPylintConfigFile (toolsConfigDir )
360- if err != nil {
361- return fmt .Errorf ("failed to create default Pylint config: %v" , err )
362- }
321+ err := createPylintConfigFile (patternConfiguration , toolsConfigDir )
322+ if err != nil {
323+ return fmt .Errorf ("failed to create Pylint config: %v" , err )
363324 }
325+ fmt .Println ("Pylint configuration created based on Codacy settings" )
364326 case DartAnalyzer :
365- if len (patternConfiguration ) > 0 {
366- err := createDartAnalyzerConfigFile (patternConfiguration , toolsConfigDir )
367- if err != nil {
368- return fmt .Errorf ("failed to create Dart Analyzer config: %v" , err )
369- }
370- fmt .Println ("Dart configuration created based on Codacy settings" )
327+
328+ err := createDartAnalyzerConfigFile (patternConfiguration , toolsConfigDir )
329+ if err != nil {
330+ return fmt .Errorf ("failed to create Dart Analyzer config: %v" , err )
371331 }
332+ fmt .Println ("Dart configuration created based on Codacy settings" )
333+
372334 case Semgrep :
373- if len (patternConfiguration ) > 0 {
374- err := createSemgrepConfigFile (patternConfiguration , toolsConfigDir )
375- if err != nil {
376- return fmt .Errorf ("failed to create Semgrep config: %v" , err )
377- }
378- fmt .Println ("Semgrep configuration created based on Codacy settings" )
335+ err := createSemgrepConfigFile (patternConfiguration , toolsConfigDir )
336+ if err != nil {
337+ return fmt .Errorf ("failed to create Semgrep config: %v" , err )
379338 }
339+ fmt .Println ("Semgrep configuration created based on Codacy settings" )
340+
380341 case Lizard :
381- createLizardConfigFile (toolsConfigDir , patternConfiguration )
342+ err := createLizardConfigFile (toolsConfigDir , patternConfiguration )
343+ if err != nil {
344+ return fmt .Errorf ("failed to create Lizard config: %v" , err )
345+ }
346+ fmt .Println ("Lizard configuration created based on Codacy settings" )
382347 }
383348 return nil
384349}
@@ -388,21 +353,11 @@ func createPMDConfigFile(config []domain.PatternConfiguration, toolsConfigDir st
388353 return os .WriteFile (filepath .Join (toolsConfigDir , "ruleset.xml" ), []byte (pmdConfigurationString ), utils .DefaultFilePerms )
389354}
390355
391- func createDefaultPMDConfigFile (toolsConfigDir string ) error {
392- content := tools .CreatePmdConfig ([]domain.PatternConfiguration {})
393- return os .WriteFile (filepath .Join (toolsConfigDir , "ruleset.xml" ), []byte (content ), utils .DefaultFilePerms )
394- }
395-
396356func createPylintConfigFile (config []domain.PatternConfiguration , toolsConfigDir string ) error {
397357 pylintConfigurationString := pylint .GeneratePylintRC (config )
398358 return os .WriteFile (filepath .Join (toolsConfigDir , "pylint.rc" ), []byte (pylintConfigurationString ), utils .DefaultFilePerms )
399359}
400360
401- func createDefaultPylintConfigFile (toolsConfigDir string ) error {
402- pylintConfigurationString := pylint .GeneratePylintRCDefault ()
403- return os .WriteFile (filepath .Join (toolsConfigDir , "pylint.rc" ), []byte (pylintConfigurationString ), utils .DefaultFilePerms )
404- }
405-
406361// createTrivyConfigFile creates a trivy.yaml configuration file based on the API configuration
407362func createTrivyConfigFile (config []domain.PatternConfiguration , toolsConfigDir string ) error {
408363
@@ -418,27 +373,6 @@ func createDartAnalyzerConfigFile(config []domain.PatternConfiguration, toolsCon
418373 return os .WriteFile (filepath .Join (toolsConfigDir , "analysis_options.yaml" ), []byte (dartAnalyzerConfigurationString ), utils .DefaultFilePerms )
419374}
420375
421- // createDefaultTrivyConfigFile creates a default trivy.yaml configuration file
422- func createDefaultTrivyConfigFile (toolsConfigDir string ) error {
423- // Use empty tool configuration to get default settings
424- emptyConfig := []domain.PatternConfiguration {}
425- content := tools .CreateTrivyConfig (emptyConfig )
426-
427- // Write to file
428- return os .WriteFile (filepath .Join (toolsConfigDir , "trivy.yaml" ), []byte (content ), utils .DefaultFilePerms )
429- }
430-
431- // createDefaultEslintConfigFile creates a default eslint.config.mjs configuration file
432- func createDefaultEslintConfigFile (toolsConfigDir string ) error {
433- // Use empty tool configuration to get default settings
434- //
435- emptyConfig := []domain.PatternConfiguration {}
436- content := tools .CreateEslintConfig (emptyConfig )
437-
438- // Write to file
439- return os .WriteFile (filepath .Join (toolsConfigDir , "eslint.config.mjs" ), []byte (content ), utils .DefaultFilePerms )
440- }
441-
442376// SemgrepRulesFile represents the structure of the rules.yaml file
443377type SemgrepRulesFile struct {
444378 Rules []map [string ]interface {} `yaml:"rules"`
@@ -485,30 +419,16 @@ func cleanConfigDirectory(toolsConfigDir string) error {
485419}
486420
487421func createLizardConfigFile (toolsConfigDir string , patternConfiguration []domain.PatternConfiguration ) error {
488- var patterns []domain.PatternDefinition
422+ patterns := make ([]domain.PatternDefinition , len (patternConfiguration ))
423+ for i , pattern := range patternConfiguration {
424+ patterns [i ] = pattern .PatternDefinition
489425
490- if len (patternConfiguration ) == 0 {
491- patternsConfig , err := codacyclient .GetDefaultToolPatternsConfig (initFlags , Lizard )
492- if err != nil {
493- return err
494- }
495- patterns = make ([]domain.PatternDefinition , len (patternsConfig ))
496- for i , pattern := range patternsConfig {
497- patterns [i ] = pattern .PatternDefinition
498- }
499- } else {
500- patterns = make ([]domain.PatternDefinition , len (patternConfiguration ))
501- for i , pattern := range patternConfiguration {
502- patterns [i ] = pattern .PatternDefinition
503- }
504426 }
505-
506- content , err := lizard .CreateLizardConfig (patterns )
427+ err := lizard .CreateLizardConfig (toolsConfigDir , patterns )
507428 if err != nil {
508429 return fmt .Errorf ("failed to create Lizard configuration: %w" , err )
509430 }
510-
511- return os .WriteFile (filepath .Join (toolsConfigDir , "lizard.yaml" ), []byte (content ), utils .DefaultFilePerms )
431+ return nil
512432}
513433
514434// buildDefaultConfigurationFiles creates default configuration files for all tools
@@ -521,18 +441,9 @@ func buildDefaultConfigurationFiles(toolsConfigDir string) error {
521441 }
522442 switch tool {
523443 case ESLint :
524- eslintConfigurationString := tools .CreateEslintConfig (patternsConfig )
525-
526- eslintConfigFile , err := os .Create (filepath .Join (toolsConfigDir , "eslint.config.mjs" ))
527- if err != nil {
444+ if err := tools .CreateEslintConfig (toolsConfigDir , patternsConfig ); err != nil {
528445 return fmt .Errorf ("failed to create eslint config file: %v" , err )
529446 }
530- defer eslintConfigFile .Close ()
531-
532- _ , err = eslintConfigFile .WriteString (eslintConfigurationString )
533- if err != nil {
534- return fmt .Errorf ("failed to write eslint config: %v" , err )
535- }
536447 case Trivy :
537448 if err := createTrivyConfigFile (patternsConfig , toolsConfigDir ); err != nil {
538449 return fmt .Errorf ("failed to create default Trivy configuration: %w" , err )
@@ -559,7 +470,6 @@ func buildDefaultConfigurationFiles(toolsConfigDir string) error {
559470 }
560471 }
561472 }
562-
563473 return nil
564474}
565475
0 commit comments