Skip to content

Commit 5d06a3a

Browse files
fixed test
1 parent eb240f7 commit 5d06a3a

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

tools/pylint/src/pylintConfigParser.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"codacy/cli-v2/tools/types"
55
"encoding/json"
66
"fmt"
7+
"log"
78
"strings"
89
)
910

@@ -109,11 +110,20 @@ func GeneratePylintRC(patterns []types.PylintPatternConfiguration) string {
109110
rcContent.WriteString("[MESSAGES CONTROL]\n")
110111
rcContent.WriteString("disable=all\n")
111112

112-
// Collect all enabled pattern IDs
113+
// Collect all enabled pattern IDs and their parameters
113114
var enabledPatterns []string
115+
patternParams := make(map[string]map[string]string)
114116
for _, pattern := range patterns {
115117
if pattern.Enabled {
116-
enabledPatterns = append(enabledPatterns, ExtractPatternID(pattern.Id))
118+
patternID := ExtractPatternID(pattern.Id)
119+
enabledPatterns = append(enabledPatterns, patternID)
120+
121+
// Store parameters for this pattern
122+
params := make(map[string]string)
123+
for _, param := range pattern.Parameters {
124+
params[param.Name] = param.Value
125+
}
126+
patternParams[patternID] = params
117127
}
118128
}
119129

@@ -164,6 +174,7 @@ func GroupParametersBySection(patterns []types.PylintPatternConfiguration) map[s
164174
for _, param := range pattern.Parameters {
165175
// Skip parameters without a section name
166176
if param.SectionName == nil {
177+
log.Printf("Parameter %s has no section name", param.Name)
167178
continue
168179
}
169180

tools/pylint/test/pylintConfigParser_test.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,6 @@ func TestFilterEnabledPatterns(t *testing.T) {
395395
assert.Equal(t, "max-line-length", enabledPatterns[0].Parameters[0].Name)
396396
assert.Equal(t, "145", enabledPatterns[0].Parameters[0].Value)
397397

398-
groupedParams := pylint.GroupParametersBySection(enabledPatterns)
399-
400-
// Get and log the keys
401-
keys := make([]string, 0, len(groupedParams))
402-
for k := range groupedParams {
403-
keys = append(keys, k)
404-
}
405-
t.Logf("Grouped Parameters Keys: %v", keys)
406-
t.Logf("Grouped Parameters: %+v", groupedParams)
407398
}
408399

409400
func TestGeneratePylintRC(t *testing.T) {
@@ -419,7 +410,6 @@ func TestGeneratePylintRC(t *testing.T) {
419410

420411
// Finally generate the pylintrc content
421412
rcContentNonEmptyParameters := pylint.GeneratePylintRC(enabledPatterns)
422-
t.Logf("Generated pylintrc content:\n%s", rcContentNonEmptyParameters)
423413

424414
// Verify the pylintrc content matches the expected format
425415
expectedContent := `[MASTER]
@@ -445,6 +435,7 @@ inlinevar-rgx=[A-Za-z0-9_]*$
445435
method-rgx=[a-z_][a-z0-9_]{2,30}$
446436
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
447437
variable-rgx=[a-z_][a-z0-9_]{2,30}$
438+
448439
`
449440
assert.Equal(t, expectedContent, rcContentNonEmptyParameters)
450441

@@ -457,7 +448,6 @@ variable-rgx=[a-z_][a-z0-9_]{2,30}$
457448
},
458449
}
459450
rcContentEmptyParameters := pylint.GeneratePylintRC(emptyPatterns)
460-
t.Logf("Generated pylintrc content:\n%s", rcContentEmptyParameters)
461451
assert.Contains(t, rcContentEmptyParameters, "enable=C0209") // Single line with all enabled patterns
462452
assert.NotContains(t, rcContentEmptyParameters, "max-line-length") // Should not include any parameters
463453
}
@@ -475,24 +465,23 @@ func TestComplexPatternSet(t *testing.T) {
475465
// Generate pylintrc content
476466
rcContent := pylint.GeneratePylintRC(enabledPatterns)
477467

478-
// Print the generated content
479468
t.Logf("Generated pylintrc content:\n%s", rcContent)
480469

481470
// Verify all enabled patterns are present in a single line
482471
expectedEnableLine := "enable=C0301,C0209,R0903,C0111,R0904,R0912,R0916,C0103,C0114,C0117,C0302,C0303,C0304,C0305,C0306"
483472
assert.Contains(t, rcContent, expectedEnableLine)
484473

485474
// Verify parameters for patterns with user-defined values
486-
assert.Contains(t, rcContent, "max-line-length=145") // C0301
487-
assert.Contains(t, rcContent, "max-doc-length=80") // C0111
488-
assert.Contains(t, rcContent, "max-branches=15") // R0912
489-
assert.Contains(t, rcContent, "method-naming-style=snake_case") // C0103
490-
assert.Contains(t, rcContent, "docstring-min-length=20") // C0114
491-
assert.Contains(t, rcContent, "max-module-lines=2000") // C0302
475+
assert.Contains(t, rcContent, "max-line-length=145") // C0301
476+
assert.NotContains(t, rcContent, "max-doc-length=80") //C0111- should not be there since it's not mapped to any section
477+
assert.Contains(t, rcContent, "max-branches=15") // R0912
478+
assert.NotContains(t, rcContent, "method-naming-style=snake_case") // C0103- should not be there since it's not mapped to any section
479+
assert.Contains(t, rcContent, "docstring-min-length=20") // C0114
480+
assert.Contains(t, rcContent, "max-module-lines=2000") // C0302
492481

493482
// Verify parameters for patterns with only default values
494-
assert.Contains(t, rcContent, "max-args=5") // R0903
495-
assert.Contains(t, rcContent, "trailing-whitespace=0") // C0303
483+
assert.Contains(t, rcContent, "max-args=5") // R0903
484+
assert.NotContains(t, rcContent, "trailing-whitespace=0") // C0303- should not be there since it's not mapped to any section
496485

497486
// Verify patterns without parameters don't have any parameter settings
498487
assert.NotContains(t, rcContent, "C0209=")

0 commit comments

Comments
 (0)