Skip to content

Commit 799aab5

Browse files
Fix: ruleIDs mapping for PMD (#201)
* Fix: ruleIDs mapping for PMD * create test
1 parent df55ffa commit 799aab5

File tree

8 files changed

+41
-7
lines changed

8 files changed

+41
-7
lines changed

.codacy/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ tools:
88
- lizard@1.17.31
99
- opengrep@1.16.4
1010
- pmd@6.55.0
11-
- pylint@3.3.9
11+
- pylint@4.0.5
1212
- revive@1.12.0
1313
- trivy@0.69.3

cmd/upload.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,16 @@ func getPatternByID(patterns []domain.PatternConfiguration, patternID string) *d
293293
})
294294
}
295295
for _, p := range sarifPatterns {
296-
if strings.EqualFold(p.ID, patternID) {
296+
//Only for PMD v6 or PMD v7 because the patternID is only part
297+
//of the original ruleset name and the prefix shouldn't be part of it
298+
//because the comparison will be always negative
299+
//So we need to clean that prefix first.
300+
cleanPMDPrefix := strings.TrimPrefix(patternID, "PMD_")
301+
cleanPatternID := strings.TrimPrefix(cleanPMDPrefix, "PMD7_")
302+
303+
lowerID := strings.ToLower(p.ID)
304+
lowerPattern := strings.ToLower(cleanPatternID)
305+
if lowerID == lowerPattern || strings.Contains(lowerID, lowerPattern) {
297306
return &p
298307
}
299308
}

cmd/upload_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"path/filepath"
55
"testing"
6+
"codacy/cli-v2/domain"
67

78
"github.com/stretchr/testify/assert"
89
)
@@ -127,3 +128,28 @@ func TestGetToolShortName(t *testing.T) {
127128
})
128129
}
129130
}
131+
132+
func TestGetPatternByID(t *testing.T) {
133+
patterns := []domain.PatternConfiguration{
134+
{
135+
PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"},
136+
},
137+
}
138+
139+
t.Run("exact match returns pattern", func(t *testing.T) {
140+
result := getPatternByID(patterns, "PMD7_category_java_design_NPathComplexity")
141+
assert.NotNil(t, result)
142+
assert.Equal(t, "PMD7_category_java_design_NPathComplexity", result.ID)
143+
})
144+
145+
t.Run("pmd7 prefix match returns pattern", func(t *testing.T) {
146+
result := getPatternByID(patterns, "PMD7_NPathComplexity")
147+
assert.NotNil(t, result)
148+
assert.Equal(t, "PMD7_category_java_design_NPathComplexity", result.ID)
149+
})
150+
151+
t.Run("no matching pattern returns nil", func(t *testing.T) {
152+
result := getPatternByID(patterns, "UNKNOWN_PATTERN")
153+
assert.Nil(t, result)
154+
})
155+
}

integration-tests/config-discover/expected/tools-configs/pylint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ load-plugins=
55

66
[MESSAGES CONTROL]
77
disable=all
8-
enable=C0123,C0200,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0116,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307
8+
enable=C0123,C0200,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307
99

integration-tests/init-with-token/expected/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ tools:
77
- lizard@1.17.31
88
- opengrep@1.17.0
99
- pmd@6.55.0
10-
- pylint@3.3.9
10+
- pylint@4.0.5
1111
- trivy@0.69.3

integration-tests/init-without-token/expected/tools-configs/pylint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[MASTER]
44
[MESSAGES CONTROL]
55
disable=all
6-
enable=C0123,C0200,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0116,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307
6+
enable=C0123,C0200,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307
77
ignore=CVS
88
load-plugins=
99
persistent=yes

plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ load-plugins=
55

66
[MESSAGES CONTROL]
77
disable=all
8-
enable=C0123,C0200,C0303,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0116,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307
8+
enable=C0123,C0200,C0303,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307
99

tools/pylint/pylintDefaultPatterns.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var DefaultPatterns = []string{
1818
"E0113",
1919
"E0114",
2020
"E0115",
21-
"E0116",
2221
"E0117",
2322
"E0202",
2423
"E0203",

0 commit comments

Comments
 (0)