Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codacy/codacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
26 changes: 26 additions & 0 deletions cmd/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"path/filepath"
"testing"
"codacy/cli-v2/domain"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -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)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion integration-tests/init-with-token/expected/codacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 0 additions & 1 deletion tools/pylint/pylintDefaultPatterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var DefaultPatterns = []string{
"E0113",
"E0114",
"E0115",
"E0116",
"E0117",
"E0202",
"E0203",
Expand Down
Loading