Skip to content

Commit 92b4e2e

Browse files
refactor getToolName method
1 parent f1ea25d commit 92b4e2e

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

cmd/analyze.go

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -259,28 +259,41 @@ func loadsToolAndPatterns(toolName string, onlyEnabledPatterns bool) (domain.Too
259259
return tool, patterns
260260
}
261261

262+
var versionedToolNames = map[string]map[int]string{
263+
"eslint": {
264+
7: "ESLint (deprecated)",
265+
8: "ESLint",
266+
9: "ESLint9",
267+
},
268+
"pmd": {
269+
6: "PMD",
270+
7: "PMD7",
271+
},
272+
}
273+
274+
var simpleToolAliases = map[string]string{
275+
"lizard": "Lizard",
276+
"semgrep": "Semgrep",
277+
"pylint": "pylintpython3",
278+
"trivy": "Trivy",
279+
}
280+
262281
func getToolName(toolName string, version string) string {
263282
majorVersion := getMajorVersion(version)
264-
if toolName == "eslint" {
265-
switch majorVersion {
266-
case 7:
267-
return "ESLint (deprecated)"
268-
case 8:
269-
return "ESLint"
270-
case 9:
271-
return "ESLint9"
272-
}
273-
} else {
274-
if toolName == "pmd" {
275-
switch majorVersion {
276-
case 6:
277-
return "PMD"
278-
case 7:
279-
return "PMD7"
280-
}
283+
284+
// Check for version-specific tool name: for eslint and pmd
285+
if versions, ok := versionedToolNames[toolName]; ok {
286+
if name, ok := versions[majorVersion]; ok {
287+
return name
281288
}
282289
}
283290

291+
// Check for non-versioned tool name alias
292+
if codacyToolName, ok := simpleToolAliases[toolName]; ok {
293+
return codacyToolName
294+
}
295+
296+
// 3. Default: Return the original tool name if no map or version matches
284297
return toolName
285298
}
286299

cmd/upload.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ func processSarif(sarif Sarif, tools map[string]*plugins.ToolInfo) [][]map[strin
136136
}
137137

138138
for _, run := range sarif.Runs {
139+
//getToolName will take care of mapping sarif tool names to codacy tool names
140+
//especially for eslint and pmd that have multiple versions
139141
var toolName = getToolName(strings.ToLower(run.Tool.Driver.Name), run.Tool.Driver.Version)
140142
tool, patterns := loadsToolAndPatterns(toolName, false)
141143

0 commit comments

Comments
 (0)