Skip to content

Commit 5ddc3ab

Browse files
chore: update Codacy configuration and enhance tool runtime handling
- Remove Flutter runtime from Codacy configuration - Upgrade ESLint version to 8.57.0 - Introduce a new function to retrieve tool runtime dependencies - Refactor runtime dependency handling in init.go to improve tool configuration management
1 parent cc5d1e7 commit 5ddc3ab

3 files changed

Lines changed: 58 additions & 14 deletions

File tree

.codacy/codacy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
runtimes:
22
- dart@3.7.2
3-
- flutter@3.7.2
43
- java@17.0.10
54
- node@22.2.0
65
- python@3.11.11
76
tools:
7+
- codacy-enigma-cli@0.0.1-main.8.49310c3
88
- dartanalyzer@3.7.2
9-
- eslint@9.3.0
9+
- eslint@8.57.0
1010
- lizard@1.17.19
1111
- pmd@6.55.0
1212
- pylint@3.3.6

cmd/init.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func configFileTemplate(tools []tools.Tool) string {
165165
// Get runtime versions all at once
166166
runtimeVersions := plugins.GetRuntimeVersions()
167167

168+
// Get tool runtime dependencies
169+
runtimeDependencies := plugins.GetToolRuntimeDependencies()
170+
168171
// Build map of enabled tools with their versions
169172
for _, tool := range tools {
170173
toolsMap[tool.Uuid] = true
@@ -176,17 +179,20 @@ func configFileTemplate(tools []tools.Tool) string {
176179
toolVersions[tool.Uuid] = defaultVersion
177180
}
178181
}
179-
}
180182

181-
// Process tools to get their configurations
182-
runtimeInfos := make(map[string]*plugins.RuntimeInfo)
183-
for runtime, version := range runtimeVersions {
184-
runtimeInfo, err := processRuntime(runtime, version)
185-
if err != nil {
186-
log.Printf("Warning: Failed to process runtime %s: %v", runtime, err)
187-
continue
183+
// Get the tool's runtime dependency
184+
toolName := toolNameMap[tool.Uuid]
185+
if toolName != "" {
186+
if runtime, ok := runtimeDependencies[toolName]; ok {
187+
// Handle special case for dartanalyzer which can use either dart or flutter
188+
if toolName == "dartanalyzer" {
189+
// For now, default to dart runtime
190+
neededRuntimes["dart"] = true
191+
} else {
192+
neededRuntimes[runtime] = true
193+
}
194+
}
188195
}
189-
runtimeInfos[runtime] = runtimeInfo
190196
}
191197

192198
// Start building the YAML content

plugins/tool-utils.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"gopkg.in/yaml.v3"
1515
)
1616

17+
const toolPluginYamlPathTemplate = "tools/%s/plugin.yaml"
18+
1719
//go:embed tools/*/plugin.yaml
1820
var toolsFS embed.FS
1921

@@ -120,7 +122,7 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
120122

121123
for _, config := range configs {
122124
// Load the tool plugin - always use forward slashes for embedded filesystem paths (for windows support)
123-
pluginPath := fmt.Sprintf("tools/%s/plugin.yaml", config.Name)
125+
pluginPath := fmt.Sprintf(toolPluginYamlPathTemplate, config.Name)
124126

125127
// Read from embedded filesystem
126128
data, err := toolsFS.ReadFile(pluginPath)
@@ -367,7 +369,7 @@ func GetSupportedTools() (map[string]struct{}, error) {
367369

368370
toolName := entry.Name()
369371
// Always use forward slashes for embedded filesystem paths
370-
pluginPath := fmt.Sprintf("tools/%s/plugin.yaml", toolName)
372+
pluginPath := fmt.Sprintf(toolPluginYamlPathTemplate, toolName)
371373

372374
// Check if plugin.yaml exists
373375
_, err := toolsFS.ReadFile(pluginPath)
@@ -398,7 +400,7 @@ func GetToolVersions() map[string]string {
398400
}
399401

400402
tool := entry.Name()
401-
pluginPath := fmt.Sprintf("tools/%s/plugin.yaml", tool)
403+
pluginPath := fmt.Sprintf(toolPluginYamlPathTemplate, tool)
402404
data, err := toolsFS.ReadFile(pluginPath)
403405
if err != nil {
404406
continue
@@ -416,3 +418,39 @@ func GetToolVersions() map[string]string {
416418

417419
return versions
418420
}
421+
422+
// GetToolRuntimeDependencies returns a map of tool names to their runtime dependencies
423+
func GetToolRuntimeDependencies() map[string]string {
424+
dependencies := make(map[string]string)
425+
426+
// Read the tools directory from embedded filesystem
427+
entries, err := toolsFS.ReadDir("tools")
428+
if err != nil {
429+
return dependencies
430+
}
431+
432+
// Process each tool directory
433+
for _, entry := range entries {
434+
if !entry.IsDir() {
435+
continue
436+
}
437+
438+
tool := entry.Name()
439+
pluginPath := fmt.Sprintf(toolPluginYamlPathTemplate, tool)
440+
data, err := toolsFS.ReadFile(pluginPath)
441+
if err != nil {
442+
continue
443+
}
444+
445+
var config ToolPluginConfig
446+
if err := yaml.Unmarshal(data, &config); err != nil {
447+
continue
448+
}
449+
450+
if config.Runtime != "" {
451+
dependencies[tool] = config.Runtime
452+
}
453+
}
454+
455+
return dependencies
456+
}

0 commit comments

Comments
 (0)