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.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 } } diff --git a/cmd/upload_test.go b/cmd/upload_test.go index 5785bf0e..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" ) @@ -127,3 +128,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_category_java_design_NPathComplexity", result.ID) + }) + + t.Run("no matching pattern returns nil", func(t *testing.T) { + result := getPatternByID(patterns, "UNKNOWN_PATTERN") + assert.Nil(t, result) + }) +} 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-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 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",