From 5b32ff1931f96fa13750730f1f1b3f18e9ed8bd3 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 11:54:11 +0100 Subject: [PATCH 1/7] Fix: ruleIDs mapping for PMD --- cmd/upload.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/upload.go b/cmd/upload.go index 1aa612be..0b265c86 100644 --- a/cmd/upload.go +++ b/cmd/upload.go @@ -293,7 +293,16 @@ func getPatternByID(patterns []domain.PatternConfiguration, patternID string) *d }) } for _, p := range sarifPatterns { - if strings.EqualFold(p.ID, patternID) { + //Only for PMD v6 or PMD v7 because the patternID is only part + //of the original ruleset name and the prefix shouldn't be part of it + //because the comparison will be always negative + //So we need to clean that prefix first. + cleanPMDPrefix := strings.TrimPrefix(patternID, "PMD_") + cleanPatternID := strings.TrimPrefix(cleanPMDPrefix, "PMD7_") + + lowerID := strings.ToLower(p.ID) + lowerPattern := strings.ToLower(cleanPatternID) + if lowerID == lowerPattern || strings.Contains(lowerID, lowerPattern) { return &p } } From 04ae908ca7dff742db0aa5c190c11aa151b1b356 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 12:16:29 +0100 Subject: [PATCH 2/7] create test --- cmd/upload_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmd/upload_test.go b/cmd/upload_test.go index 5785bf0e..79d645bd 100644 --- a/cmd/upload_test.go +++ b/cmd/upload_test.go @@ -127,3 +127,28 @@ func TestGetToolShortName(t *testing.T) { }) } } + +func TestGetPatternByID(t *testing.T) { + patterns := []domain.PatternConfiguration{ + { + PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"}, + } + } + + t.Run("exact match returns pattern", func(t *testing.T) { + result := getPatternByID(patterns, "PMD7_category_java_design_NPathComplexity") + assert.NotNil(t, result) + assert.Equal(t, "PMD7_category_java_design_NPathComplexity", result.ID) + }) + + t.Run("pmd7 prefix match returns pattern", func(t *testing.T) { + result := getPatternByID(patterns, "PMD7_NPathComplexity") + assert.NotNil(t, result) + assert.Equal(t, "PMD7_NPathComplexity", result.ID) + }) + + t.Run("no matching pattern returns nil", func(t *testing.T) { + result := getPatternByID(patterns, "UNKNOWN_PATTERN") + assert.Nil(t, result) + }) +} From c58021efd9f0f14cfb6d61cb9874f41e5b4d0f0f Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 12:21:53 +0100 Subject: [PATCH 3/7] fix extra pylint pattern in tests --- .../config-discover/expected/tools-configs/pylint.rc | 2 +- .../init-without-token/expected/tools-configs/pylint.rc | 2 +- plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc | 2 +- tools/pylint/pylintDefaultPatterns.go | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/integration-tests/config-discover/expected/tools-configs/pylint.rc b/integration-tests/config-discover/expected/tools-configs/pylint.rc index 648a520c..d7694e5c 100644 --- a/integration-tests/config-discover/expected/tools-configs/pylint.rc +++ b/integration-tests/config-discover/expected/tools-configs/pylint.rc @@ -5,5 +5,5 @@ load-plugins= [MESSAGES CONTROL] disable=all -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 +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 diff --git a/integration-tests/init-without-token/expected/tools-configs/pylint.rc b/integration-tests/init-without-token/expected/tools-configs/pylint.rc index 3b981a8a..97185cff 100644 --- a/integration-tests/init-without-token/expected/tools-configs/pylint.rc +++ b/integration-tests/init-without-token/expected/tools-configs/pylint.rc @@ -3,7 +3,7 @@ [MASTER] [MESSAGES CONTROL] disable=all -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 +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 ignore=CVS load-plugins= persistent=yes diff --git a/plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc b/plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc index 92f4aea4..441f156d 100644 --- a/plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc +++ b/plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc @@ -5,5 +5,5 @@ load-plugins= [MESSAGES CONTROL] disable=all -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 +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 diff --git a/tools/pylint/pylintDefaultPatterns.go b/tools/pylint/pylintDefaultPatterns.go index 6db735ec..39d7c02e 100644 --- a/tools/pylint/pylintDefaultPatterns.go +++ b/tools/pylint/pylintDefaultPatterns.go @@ -18,7 +18,6 @@ var DefaultPatterns = []string{ "E0113", "E0114", "E0115", - "E0116", "E0117", "E0202", "E0203", From 5f362c08e8981583ed63092e6db7c78523c97b82 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 12:25:40 +0100 Subject: [PATCH 4/7] fix tests --- .codacy/codacy.yaml | 2 +- cmd/upload_test.go | 2 +- integration-tests/init-with-token/expected/codacy.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.codacy/codacy.yaml b/.codacy/codacy.yaml index 34b0fb76..926f972b 100644 --- a/.codacy/codacy.yaml +++ b/.codacy/codacy.yaml @@ -8,6 +8,6 @@ tools: - lizard@1.17.31 - opengrep@1.16.4 - pmd@6.55.0 - - pylint@3.3.9 + - pylint@4.0.5 - revive@1.12.0 - trivy@0.69.3 diff --git a/cmd/upload_test.go b/cmd/upload_test.go index 79d645bd..4a45212f 100644 --- a/cmd/upload_test.go +++ b/cmd/upload_test.go @@ -131,7 +131,7 @@ func TestGetToolShortName(t *testing.T) { func TestGetPatternByID(t *testing.T) { patterns := []domain.PatternConfiguration{ { - PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"}, + PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"} } } diff --git a/integration-tests/init-with-token/expected/codacy.yaml b/integration-tests/init-with-token/expected/codacy.yaml index d5754b6a..4f16bcff 100644 --- a/integration-tests/init-with-token/expected/codacy.yaml +++ b/integration-tests/init-with-token/expected/codacy.yaml @@ -7,5 +7,5 @@ tools: - lizard@1.17.31 - opengrep@1.17.0 - pmd@6.55.0 - - pylint@3.3.9 + - pylint@4.0.5 - trivy@0.69.3 From 4193344cf3140c6671e7563cb5784df891698f56 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 12:39:16 +0100 Subject: [PATCH 5/7] fix tests --- cmd/upload_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/upload_test.go b/cmd/upload_test.go index 4a45212f..03f13fbc 100644 --- a/cmd/upload_test.go +++ b/cmd/upload_test.go @@ -132,7 +132,7 @@ func TestGetPatternByID(t *testing.T) { patterns := []domain.PatternConfiguration{ { PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"} - } + }, } t.Run("exact match returns pattern", func(t *testing.T) { From 22d764e077954f3a2a3cc110d27ed83c722a9cbc Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 12:40:28 +0100 Subject: [PATCH 6/7] fix tests --- cmd/upload_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/upload_test.go b/cmd/upload_test.go index 03f13fbc..0259196c 100644 --- a/cmd/upload_test.go +++ b/cmd/upload_test.go @@ -131,7 +131,7 @@ func TestGetToolShortName(t *testing.T) { func TestGetPatternByID(t *testing.T) { patterns := []domain.PatternConfiguration{ { - PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"} + PatternDefinition: domain.PatternDefinition{Id: "PMD7_category_java_design_NPathComplexity", Category: "BestPractice", Level: "Warning", Description: "Exact match"}, }, } From b97122ba83e31856c4e566aeea2bd4219f773ac2 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 14 Apr 2026 12:44:20 +0100 Subject: [PATCH 7/7] fix testGetPatternByID --- cmd/upload_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/upload_test.go b/cmd/upload_test.go index 0259196c..2d4a6391 100644 --- a/cmd/upload_test.go +++ b/cmd/upload_test.go @@ -3,6 +3,7 @@ package cmd import ( "path/filepath" "testing" + "codacy/cli-v2/domain" "github.com/stretchr/testify/assert" ) @@ -144,7 +145,7 @@ func TestGetPatternByID(t *testing.T) { t.Run("pmd7 prefix match returns pattern", func(t *testing.T) { result := getPatternByID(patterns, "PMD7_NPathComplexity") assert.NotNil(t, result) - assert.Equal(t, "PMD7_NPathComplexity", result.ID) + assert.Equal(t, "PMD7_category_java_design_NPathComplexity", result.ID) }) t.Run("no matching pattern returns nil", func(t *testing.T) {