Skip to content

Commit 6b70dcf

Browse files
committed
fx local mode/eslint version
1 parent 630a087 commit 6b70dcf

File tree

3 files changed

+85
-10
lines changed

3 files changed

+85
-10
lines changed

cmd/init.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ func configFileTemplate(tools []domain.Tool) string {
224224
sb.WriteString(fmt.Sprintf(" - %s@%s\n", runtime, runtimeVersions[runtime]))
225225
}
226226
} else {
227-
// In local mode with no tools specified, use the default tool list from plugins.GetToolVersions()
228-
227+
// If no tools were specified (local mode), include all tools in sorted order
229228
for toolName := range defaultVersions {
230229
if runtime, ok := runtimeDependencies[toolName]; ok {
231230
if toolName == "dartanalyzer" {
@@ -269,19 +268,32 @@ func configFileTemplate(tools []domain.Tool) string {
269268
}
270269
}
271270
} else {
272-
// Write tools only once in local mode
271+
// If no tools were specified (local mode), include all tools in sorted order
273272
var sortedTools []string
274-
seen := make(map[string]bool)
275-
for toolName := range defaultVersions {
276-
if defaultVersions[toolName] != "" && !seen[toolName] {
277-
sortedTools = append(sortedTools, toolName)
278-
seen[toolName] = true
273+
274+
// Get supported tools from plugin system
275+
supportedTools, err := plugins.GetSupportedTools()
276+
if err != nil {
277+
log.Printf("Warning: failed to get supported tools: %v", err)
278+
return sb.String()
279+
}
280+
281+
// Convert map keys to slice and sort them
282+
for toolName := range supportedTools {
283+
if version, ok := defaultVersions[toolName]; ok {
284+
// Skip tools without a version
285+
if version != "" {
286+
sortedTools = append(sortedTools, toolName)
287+
}
279288
}
280289
}
281290
sort.Strings(sortedTools)
291+
292+
// Write sorted tools
282293
for _, toolName := range sortedTools {
283-
version := defaultVersions[toolName]
284-
sb.WriteString(fmt.Sprintf(" - %s@%s\n", toolName, version))
294+
if version, ok := defaultVersions[toolName]; ok {
295+
sb.WriteString(fmt.Sprintf(" - %s@%s\n", toolName, version))
296+
}
285297
}
286298
}
287299

plugins/tool-utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
250250
return result, nil
251251
}
252252

253+
// GetSupportedTools returns a map of supported tool names
254+
func GetSupportedTools() (map[string]struct{}, error) {
255+
entries, err := toolsFS.ReadDir("tools")
256+
if err != nil {
257+
return nil, fmt.Errorf("error reading tools directory: %w", err)
258+
}
259+
260+
tools := make(map[string]struct{})
261+
for _, entry := range entries {
262+
if entry.IsDir() {
263+
tools[entry.Name()] = struct{}{}
264+
}
265+
}
266+
267+
return tools, nil
268+
}
269+
253270
// GetToolVersions returns a map of tool names to their default versions
254271
func GetToolVersions() map[string]string {
255272
return GetPluginManager().GetToolVersions()

plugins/tool-utils_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,49 @@ func TestProcessToolsWithDownload(t *testing.T) {
152152
}
153153
assert.Contains(t, trivyInfo.DownloadURL, expectedArch)
154154
}
155+
156+
func TestGetSupportedTools(t *testing.T) {
157+
tests := []struct {
158+
name string
159+
expectedTools []string
160+
expectedError bool
161+
}{
162+
{
163+
name: "should return supported tools",
164+
expectedTools: []string{
165+
"eslint",
166+
"pmd",
167+
"pylint",
168+
"trivy",
169+
"dartanalyzer",
170+
"semgrep",
171+
"lizard",
172+
"codacy-enigma-cli",
173+
},
174+
expectedError: false,
175+
},
176+
}
177+
178+
for _, tt := range tests {
179+
t.Run(tt.name, func(t *testing.T) {
180+
supportedTools, err := GetSupportedTools()
181+
182+
if tt.expectedError {
183+
assert.Error(t, err)
184+
return
185+
}
186+
187+
assert.NoError(t, err)
188+
assert.NotNil(t, supportedTools)
189+
190+
// Check that all expected tools are supported
191+
for _, expectedTool := range tt.expectedTools {
192+
_, exists := supportedTools[expectedTool]
193+
assert.True(t, exists, "tool %s should be supported", expectedTool)
194+
}
195+
196+
// Check that we have exactly the expected number of tools
197+
assert.Equal(t, len(tt.expectedTools), len(supportedTools), "number of supported tools should match")
198+
})
199+
}
200+
}

0 commit comments

Comments
 (0)