11package pylint
22
33import (
4- "codacy/cli-v2/tools/types "
4+ "codacy/cli-v2/domain "
55 "fmt"
66 "log"
77 "strings"
88)
99
1010// getDefaultParametersForPatterns returns a map of pattern IDs to their default parameters
11- func getDefaultParametersForPatterns (patternIDs []string ) map [string ][]types .ParameterConfiguration {
12- defaultParams := make (map [string ][]types .ParameterConfiguration )
11+ func getDefaultParametersForPatterns (patternIDs []string ) map [string ][]domain .ParameterConfiguration {
12+ defaultParams := make (map [string ][]domain .ParameterConfiguration )
1313
1414 for _ , patternID := range patternIDs {
1515 if params , exists := PatternDefaultParameters [patternID ]; exists {
@@ -39,7 +39,7 @@ func writeEnabledPatterns(rcContent *strings.Builder, patternIDs []string) {
3939}
4040
4141// writeParametersBySection writes the parameters grouped by section to the RC content
42- func writeParametersBySection (rcContent * strings.Builder , groupedParams map [string ][]types. PylintPatternParameterConfiguration ) {
42+ func writeParametersBySection (rcContent * strings.Builder , groupedParams map [string ][]domain. ParameterConfiguration ) {
4343 for sectionName , params := range groupedParams {
4444 rcContent .WriteString (fmt .Sprintf ("[%s]\n " , sectionName ))
4545 for _ , param := range params {
@@ -50,30 +50,41 @@ func writeParametersBySection(rcContent *strings.Builder, groupedParams map[stri
5050}
5151
5252// groupParametersByPatterns groups parameters from patterns into sections
53- func groupParametersByPatterns (patterns []types .PatternConfiguration ) map [string ][]types. PylintPatternParameterConfiguration {
54- groupedParams := make (map [string ][]types. PylintPatternParameterConfiguration )
53+ func groupParametersByPatterns (patterns []domain .PatternConfiguration ) map [string ][]domain. ParameterConfiguration {
54+ groupedParams := make (map [string ][]domain. ParameterConfiguration )
5555
5656 for _ , pattern := range patterns {
57- patternID := extractPatternId (pattern .InternalId )
57+ patternID := extractPatternId (pattern .PatternDefinition . Id )
5858 params := pattern .Parameters
5959
6060 // If no parameters, check defaults
6161 if len (params ) == 0 {
62- params = PatternDefaultParameters [patternID ]
62+ if defaultParams , exists := PatternDefaultParameters [patternID ]; exists {
63+ params = defaultParams
64+ }
6365 }
6466
67+ // Add parameters to their respective sections
6568 for _ , param := range params {
6669 sectionName := GetParameterSection (param .Name )
6770 if sectionName == nil {
6871 log .Printf ("Parameter %s has no section name" , param .Name )
6972 continue
7073 }
7174
72- groupedParams [* sectionName ] = append (groupedParams [* sectionName ], types.PylintPatternParameterConfiguration {
73- Name : param .Name ,
74- Value : param .Value ,
75- SectionName : sectionName ,
76- })
75+ // Check if parameter already exists in section
76+ exists := false
77+ for _ , existingParam := range groupedParams [* sectionName ] {
78+ if existingParam .Name == param .Name {
79+ exists = true
80+ break
81+ }
82+ }
83+
84+ // Only add if not already present
85+ if ! exists {
86+ groupedParams [* sectionName ] = append (groupedParams [* sectionName ], param )
87+ }
7788 }
7889 }
7990
@@ -90,10 +101,12 @@ func GeneratePylintRCDefault() string {
90101 defaultParams := getDefaultParametersForPatterns (DefaultPatterns )
91102
92103 // Convert default parameters to pattern configurations
93- var patterns []types .PatternConfiguration
104+ var patterns []domain .PatternConfiguration
94105 for patternID , params := range defaultParams {
95- patterns = append (patterns , types.PatternConfiguration {
96- InternalId : "PyLintPython3_" + patternID ,
106+ patterns = append (patterns , domain.PatternConfiguration {
107+ PatternDefinition : domain.PatternDefinition {
108+ Id : "PyLintPython3_" + patternID ,
109+ },
97110 Parameters : params ,
98111 })
99112 }
@@ -106,24 +119,23 @@ func GeneratePylintRCDefault() string {
106119}
107120
108121// GeneratePylintRC generates a pylintrc file content with the specified patterns enabled
109- func GeneratePylintRC (config types. ToolConfiguration ) string {
122+ func GeneratePylintRC (config []domain. PatternConfiguration ) string {
110123 var rcContent strings.Builder
111124
112125 writePylintRCHeader (& rcContent )
113126
114127 // Collect enabled pattern IDs
115128 var enabledPatternsIds []string
116- if config .IsEnabled {
117- for _ , pattern := range config .Patterns {
118- patternID := extractPatternId (pattern .InternalId )
119- enabledPatternsIds = append (enabledPatternsIds , patternID )
120- }
129+
130+ for _ , pattern := range config {
131+ patternID := extractPatternId (pattern .PatternDefinition .Id )
132+ enabledPatternsIds = append (enabledPatternsIds , patternID )
121133 }
122134
123135 writeEnabledPatterns (& rcContent , enabledPatternsIds )
124136
125137 // Group and write parameters
126- groupedParams := groupParametersByPatterns (config . Patterns )
138+ groupedParams := groupParametersByPatterns (config )
127139 writeParametersBySection (& rcContent , groupedParams )
128140
129141 return rcContent .String ()
0 commit comments