Skip to content

Commit ad422c5

Browse files
fix issue with analysis using tool configuration file
1 parent 06bb49b commit ad422c5

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

.codacy/codacy.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ go.work.sum
2727
# Codacy CLI
2828
cli-v2
2929
codacy-cli
30-
**/.codacy/logs/
3130
.codacy/
31+
.github/instructions/
3232

3333

3434
#Ignore cursor AI rules

cmd/analyze.go

Lines changed: 23 additions & 7 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.ShortName == toolName {
248+
if t.Name == toolName {
249249
tool = t
250250
break
251251
}
@@ -264,19 +264,19 @@ func getToolName(toolName string, version string) string {
264264
if toolName == "eslint" {
265265
switch majorVersion {
266266
case 7:
267-
return "eslint"
267+
return "ESLint (deprecated)"
268268
case 8:
269-
return "eslint-8"
269+
return "ESLint"
270270
case 9:
271-
return "eslint-9"
271+
return "ESLint9"
272272
}
273273
} else {
274274
if toolName == "pmd" {
275275
switch majorVersion {
276276
case 6:
277-
return "pmd"
277+
return "PMD"
278278
case 7:
279-
return "pmd-7"
279+
return "PMD7"
280280
}
281281
}
282282
}
@@ -351,10 +351,26 @@ func runToolByName(toolName string, workDirectory string, pathsToCheck []string,
351351
if err != nil {
352352
return err
353353
}
354+
355+
// Get the tool name with the right version e.g. ESLint9, PMD7, etc.
356+
toolRightVersion := getToolName(toolName, tool.Version)
357+
358+
// Get the repository tools to access tool settings
359+
repositoryTools, _ := codacyclient.GetRepositoryTools(initFlags)
360+
361+
// Find the matching tool in repositoryTools
362+
var t *domain.Tool
363+
for i, tool := range repositoryTools {
364+
if tool.Name == toolRightVersion {
365+
t = &repositoryTools[i]
366+
break
367+
}
368+
}
369+
354370
switch toolName {
355371
case "eslint":
356372
binaryPath := runtime.Binaries[tool.Runtime]
357-
return tools.RunEslint(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, autoFix, outputFile, outputFormat)
373+
return tools.RunEslint(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, autoFix, outputFile, outputFormat, t.Settings.UsesConfigurationFile)
358374
case "trivy":
359375
binaryPath := tool.Binaries[toolName]
360376
return tools.RunTrivy(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)

tools/eslintRunner.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ import (
1111
// * Run from the root of the repo we want to analyse
1212
// * NODE_PATH="<the installed eslint path>/node_modules"
1313
// * The local installed ESLint should have the @microsoft/eslint-formatter-sarif installed
14-
func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) error {
14+
func RunEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string, userUsesConfigurationFile bool) error {
1515
eslintInstallationNodeModules := filepath.Join(eslintInstallationDirectory, "node_modules")
1616
eslintJsPath := filepath.Join(eslintInstallationNodeModules, ".bin", "eslint")
1717

1818
cmd := exec.Command(nodeBinary, eslintJsPath)
1919

2020
// Add config file from tools-configs directory if it exists
21-
if configFile, exists := ConfigFileExists(config.Config, "eslint.config.mjs"); exists {
22-
// For Eslint compatibility with version 8.
23-
// https://eslint.org/docs/v8.x/use/configure/configuration-files-new
24-
cmd.Env = append(cmd.Env, "ESLINT_USE_FLAT_CONFIG=true")
21+
if !userUsesConfigurationFile {
22+
if configFile, exists := ConfigFileExists(config.Config, "eslint.config.mjs"); exists {
23+
// For Eslint compatibility with version 8.
24+
// https://eslint.org/docs/v8.x/use/configure/configuration-files-new
25+
cmd.Env = append(cmd.Env, "ESLINT_USE_FLAT_CONFIG=true")
2526

26-
cmd.Args = append(cmd.Args, "-c", configFile)
27+
cmd.Args = append(cmd.Args, "-c", configFile)
28+
}
2729
}
2830

2931
if autoFix {

0 commit comments

Comments
 (0)