Skip to content

Commit ee1b0e6

Browse files
fix toolname comparison during the analysis (#172)
* in analyse.go we now compare the tool name with the shortName (i.e. pmd 7.16.0 should be pmd-7 instead of pmd, which is version 6) * we now translate the name of pmd according to the tool, the same as eslint: pmd 7.16.0 should be called as pmd-7 and pmd 6.55.0 should be called pmd
1 parent 100b5f7 commit ee1b0e6

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

cmd/analyze.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func loadsToolAndPatterns(toolName string, onlyEnabledPatterns bool) (domain.Too
245245
}
246246
var tool domain.Tool
247247
for _, t := range toolsResponse {
248-
if t.Name == toolName {
248+
if t.ShortName == toolName {
249249
tool = t
250250
break
251251
}
@@ -260,9 +260,8 @@ func loadsToolAndPatterns(toolName string, onlyEnabledPatterns bool) (domain.Too
260260
}
261261

262262
func getToolName(toolName string, version string) string {
263-
263+
majorVersion := getMajorVersion(version)
264264
if toolName == "eslint" {
265-
majorVersion := getMajorVersion(version)
266265
switch majorVersion {
267266
case 7:
268267
return "eslint"
@@ -271,7 +270,15 @@ func getToolName(toolName string, version string) string {
271270
case 9:
272271
return "eslint-9"
273272
}
274-
273+
} else {
274+
if toolName == "pmd" {
275+
switch majorVersion {
276+
case 6:
277+
return "pmd"
278+
case 7:
279+
return "pmd-7"
280+
}
281+
}
275282
}
276283

277284
return toolName

cmd/analyze_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,39 @@ func TestGetFileExtension(t *testing.T) {
5656
}
5757
}
5858

59+
func TestGetToolName(t *testing.T) {
60+
tests := []struct {
61+
name string
62+
tool string
63+
version string
64+
expected string
65+
}{
66+
// ESLint cases
67+
{"eslint v7", "eslint", "7.32.0", "eslint"},
68+
{"eslint v8", "eslint", "8.15.0", "eslint-8"},
69+
{"eslint v9", "eslint", "9.1.0", "eslint-9"},
70+
{"eslint unknown version", "eslint", "10.0.0", "eslint"},
71+
72+
// PMD cases
73+
{"pmd v6", "pmd", "6.55.0", "pmd"},
74+
{"pmd v7", "pmd", "7.0.0", "pmd-7"},
75+
{"pmd unknown version", "pmd", "8.0.0", "pmd"},
76+
77+
// Other tools should remain unchanged
78+
{"unknown tool", "bandit", "1.7.4", "bandit"},
79+
}
80+
81+
for _, tt := range tests {
82+
t.Run(tt.name, func(t *testing.T) {
83+
got := getToolName(tt.tool, tt.version)
84+
if got != tt.expected {
85+
t.Errorf("getToolName(%q, %q) = %q; want %q",
86+
tt.tool, tt.version, got, tt.expected)
87+
}
88+
})
89+
}
90+
}
91+
5992
func TestIsToolSupportedForFile(t *testing.T) {
6093
langConfig := &LanguagesConfig{
6194
Tools: []struct {

0 commit comments

Comments
 (0)