@@ -299,86 +299,47 @@ 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 }
312+ fmt .Println ("Trivy configuration created based on Codacy settings" )
336313 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- }
342-
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+ err := createPMDConfigFile (patternConfiguration , toolsConfigDir )
315+ if err != nil {
316+ return fmt .Errorf ("failed to create PMD config: %v" , err )
349317 }
350-
318+ fmt . Println ( "PMD configuration created based on Codacy settings" )
351319 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- }
320+ err := createPylintConfigFile (patternConfiguration , toolsConfigDir )
321+ if err != nil {
322+ return fmt .Errorf ("failed to create Pylint config: %v" , err )
363323 }
324+ fmt .Println ("Pylint configuration created based on Codacy settings" )
364325 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" )
326+ err := createDartAnalyzerConfigFile (patternConfiguration , toolsConfigDir )
327+ if err != nil {
328+ return fmt .Errorf ("failed to create Dart Analyzer config: %v" , err )
371329 }
330+ fmt .Println ("Dart configuration created based on Codacy settings" )
372331 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" )
332+ err := createSemgrepConfigFile (patternConfiguration , toolsConfigDir )
333+ if err != nil {
334+ return fmt .Errorf ("failed to create Semgrep config: %v" , err )
379335 }
336+ fmt .Println ("Semgrep configuration created based on Codacy settings" )
380337 case Lizard :
381- createLizardConfigFile (toolsConfigDir , patternConfiguration )
338+ err := createLizardConfigFile (toolsConfigDir , patternConfiguration )
339+ if err != nil {
340+ return fmt .Errorf ("failed to create Lizard config: %v" , err )
341+ }
342+ fmt .Println ("Lizard configuration created based on Codacy settings" )
382343 }
383344 return nil
384345}
@@ -388,21 +349,11 @@ func createPMDConfigFile(config []domain.PatternConfiguration, toolsConfigDir st
388349 return os .WriteFile (filepath .Join (toolsConfigDir , "ruleset.xml" ), []byte (pmdConfigurationString ), utils .DefaultFilePerms )
389350}
390351
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-
396352func createPylintConfigFile (config []domain.PatternConfiguration , toolsConfigDir string ) error {
397353 pylintConfigurationString := pylint .GeneratePylintRC (config )
398354 return os .WriteFile (filepath .Join (toolsConfigDir , "pylint.rc" ), []byte (pylintConfigurationString ), utils .DefaultFilePerms )
399355}
400356
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-
406357// createTrivyConfigFile creates a trivy.yaml configuration file based on the API configuration
407358func createTrivyConfigFile (config []domain.PatternConfiguration , toolsConfigDir string ) error {
408359
@@ -418,27 +369,6 @@ func createDartAnalyzerConfigFile(config []domain.PatternConfiguration, toolsCon
418369 return os .WriteFile (filepath .Join (toolsConfigDir , "analysis_options.yaml" ), []byte (dartAnalyzerConfigurationString ), utils .DefaultFilePerms )
419370}
420371
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-
442372// SemgrepRulesFile represents the structure of the rules.yaml file
443373type SemgrepRulesFile struct {
444374 Rules []map [string ]interface {} `yaml:"rules"`
@@ -485,54 +415,30 @@ func cleanConfigDirectory(toolsConfigDir string) error {
485415}
486416
487417func createLizardConfigFile (toolsConfigDir string , patternConfiguration []domain.PatternConfiguration ) error {
488- var patterns []domain.PatternDefinition
418+ patterns := make ([]domain.PatternDefinition , len (patternConfiguration ))
419+ for i , pattern := range patternConfiguration {
420+ patterns [i ] = pattern .PatternDefinition
489421
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- }
504422 }
505-
506- content , err := lizard .CreateLizardConfig (patterns )
423+ err := lizard .CreateLizardConfig (toolsConfigDir , patterns )
507424 if err != nil {
508425 return fmt .Errorf ("failed to create Lizard configuration: %w" , err )
509426 }
510-
511- return os .WriteFile (filepath .Join (toolsConfigDir , "lizard.yaml" ), []byte (content ), utils .DefaultFilePerms )
427+ return nil
512428}
513429
514430// buildDefaultConfigurationFiles creates default configuration files for all tools
515431func buildDefaultConfigurationFiles (toolsConfigDir string ) error {
516-
517432 for _ , tool := range AvailableTools {
518433 patternsConfig , err := codacyclient .GetDefaultToolPatternsConfig (initFlags , tool )
519434 if err != nil {
520435 return fmt .Errorf ("failed to get default tool patterns config: %w" , err )
521436 }
522437 switch tool {
523438 case ESLint :
524- eslintConfigurationString := tools .CreateEslintConfig (patternsConfig )
525-
526- eslintConfigFile , err := os .Create (filepath .Join (toolsConfigDir , "eslint.config.mjs" ))
527- if err != nil {
439+ if err := tools .CreateEslintConfig (toolsConfigDir , patternsConfig ); err != nil {
528440 return fmt .Errorf ("failed to create eslint config file: %v" , err )
529441 }
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- }
536442 case Trivy :
537443 if err := createTrivyConfigFile (patternsConfig , toolsConfigDir ); err != nil {
538444 return fmt .Errorf ("failed to create default Trivy configuration: %w" , err )
@@ -559,7 +465,6 @@ func buildDefaultConfigurationFiles(toolsConfigDir string) error {
559465 }
560466 }
561467 }
562-
563468 return nil
564469}
565470
0 commit comments