Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions cmd/test-linter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package main

import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/DevSymphony/sym-cli/internal/adapter"
"github.com/DevSymphony/sym-cli/internal/adapter/eslint"
)

func main() {
fmt.Println("=== Testing ESLint Adapter ===")
fmt.Println()

// 1. Create ESLint adapter
homeDir, _ := os.UserHomeDir()
toolsDir := filepath.Join(homeDir, ".sym", "tools")
workDir, _ := os.Getwd()

adp := eslint.NewAdapter(toolsDir)
fmt.Printf("✓ Created ESLint adapter\n")
fmt.Printf(" Tools directory: %s\n", adp.ToolsDir)

// 2. Check availability
ctx := context.Background()
fmt.Println("Checking ESLint availability...")
err := adp.CheckAvailability(ctx)
if err != nil {
fmt.Printf("⚠️ ESLint not available: %v\n", err)
fmt.Println("\nInstalling ESLint...")
// Try to install
installConfig := adapter.InstallConfig{
ToolsDir: toolsDir,
}
installErr := adp.Install(ctx, installConfig)
if installErr != nil {
fmt.Printf("❌ Failed to install: %v\n", installErr)
os.Exit(1)
}
fmt.Println("✓ ESLint installed successfully")
fmt.Println()
} else {
fmt.Println("✓ ESLint is available")
fmt.Println()
}

// 3. Create a simple ESLint config
config := []byte(`{
"env": {
"node": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"],
"no-unused-vars": "error",
"no-console": "warn"
}
}`)

// 4. Find test file
testFile := filepath.Join(workDir, "test_file.js")
if _, err := os.Stat(testFile); os.IsNotExist(err) {
fmt.Printf("❌ Test file not found: %s\n", testFile)
os.Exit(1)
}
fmt.Printf("Test file: %s\n\n", testFile)

// 5. Execute ESLint
fmt.Println("Running ESLint...")
output, err := adp.Execute(ctx, config, []string{testFile})
if err != nil {
fmt.Printf("⚠️ ESLint execution error: %v\n", err)
// Continue to parse output even if there's an error (violations cause non-zero exit)
}

// 6. Show raw output
fmt.Println("\n--- Raw ESLint Output ---")
if output.Stdout != "" {
fmt.Printf("STDOUT:\n%s\n", output.Stdout)
}
if output.Stderr != "" {
fmt.Printf("STDERR:\n%s\n", output.Stderr)
}
fmt.Printf("Exit Code: %d\n", output.ExitCode)
fmt.Printf("Duration: %s\n", output.Duration)

// 7. Parse violations
fmt.Println("\n--- Parsed Violations ---")
violations, parseErr := adp.ParseOutput(output)
if parseErr != nil {
fmt.Printf("❌ Failed to parse output: %v\n", parseErr)
os.Exit(1)
}

if len(violations) == 0 {
fmt.Println("✅ No violations found!")
} else {
fmt.Printf("Found %d violation(s):\n\n", len(violations))
for i, v := range violations {
fmt.Printf("%d. [%s] %s\n", i+1, v.Severity, v.RuleID)
fmt.Printf(" File: %s:%d:%d\n", v.File, v.Line, v.Column)
fmt.Printf(" Message: %s\n", v.Message)

// Show that we have the raw output stored
if len(output.Stdout) > 0 {
fmt.Printf(" ✓ Raw output captured: %d bytes\n", len(output.Stdout))
}
if len(output.Stderr) > 0 {
fmt.Printf(" ✓ Raw error captured: %d bytes\n", len(output.Stderr))
}
fmt.Printf(" ✓ Execution time: %s\n\n", output.Duration)
}
}

fmt.Println("=== Test Complete ===")
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/DevSymphony/sym-cli
go 1.25.1

require (
github.com/bmatcuk/doublestar/v4 v4.9.1
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // symphonyclient integration: browser automation for OAuth
github.com/spf13/cobra v1.10.1
)
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/bmatcuk/doublestar/v4 v4.9.1 h1:X8jg9rRZmJd4yRy7ZeNDRnM+T3ZfHv15JiBJ/avrEXE=
github.com/bmatcuk/doublestar/v4 v4.9.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
Expand All @@ -15,10 +13,10 @@ github.com/google/jsonschema-go v0.3.0 h1:6AH2TxVNtk3IlvkkhjrtbUc4S8AvO0Xii0DxIy
github.com/google/jsonschema-go v0.3.0/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/modelcontextprotocol/go-sdk v1.1.0 h1:Qjayg53dnKC4UZ+792W21e4BpwEZBzwgRW6LrjLWSwA=
github.com/modelcontextprotocol/go-sdk v1.1.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/modelcontextprotocol/go-sdk v1.1.0 h1:Qjayg53dnKC4UZ+792W21e4BpwEZBzwgRW6LrjLWSwA=
github.com/modelcontextprotocol/go-sdk v1.1.0/go.mod h1:6fM3LCm3yV7pAs8isnKLn07oKtB0MP9LHd3DfAcKw10=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -35,13 +33,12 @@ github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zI
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
205 changes: 202 additions & 3 deletions internal/adapter/checkstyle/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ Output:

userPrompt := fmt.Sprintf("Convert this Java rule to Checkstyle module:\n\n%s", rule.Say)

response, err := llmClient.Complete(ctx, systemPrompt, userPrompt)
// Call LLM with power model + low reasoning
response, err := llmClient.Request(systemPrompt, userPrompt).WithPower(llm.ReasoningMinimal).Execute(ctx)
if err != nil {
return nil, fmt.Errorf("LLM call failed: %w", err)
}
Expand Down Expand Up @@ -285,6 +286,9 @@ Output:
return nil, nil
}

// Filter properties to only include valid ones for this module
filteredProps := filterValidProperties(result.ModuleName, result.Properties)

// Build module
module := &checkstyleModule{
Name: result.ModuleName,
Expand All @@ -297,8 +301,11 @@ Output:
Value: mapCheckstyleSeverity(result.Severity),
})

// Add other properties
for key, value := range result.Properties {
// Add filtered properties
for key, value := range filteredProps {
if key == "severity" {
continue // Already added above
}
module.Properties = append(module.Properties, checkstyleProperty{
Name: key,
Value: value,
Expand All @@ -321,3 +328,195 @@ func mapCheckstyleSeverity(severity string) string {
return "error"
}
}

// validCheckstyleProperties defines valid properties for each Checkstyle module
// This prevents LLM from generating invalid properties that cause runtime errors
var validCheckstyleProperties = map[string]map[string]bool{
"TypeName": {
"severity": true,
"format": true,
"tokens": true,
},
"MethodName": {
"severity": true,
"format": true,
"allowClassName": true,
"applyToPublic": true,
"applyToProtected": true,
"applyToPackage": true,
"applyToPrivate": true,
"tokens": true,
},
"ParameterName": {
"severity": true,
"format": true,
"ignoreOverridden": true,
"accessModifiers": true,
},
"LocalVariableName": {
"severity": true,
"format": true,
"allowOneCharVarInForLoop": true,
},
"ConstantName": {
"severity": true,
"format": true,
"applyToPublic": true,
"applyToProtected": true,
"applyToPackage": true,
"applyToPrivate": true,
},
"LineLength": {
"severity": true,
"max": true,
"ignorePattern": true,
"fileExtensions": true,
},
"MethodLength": {
"severity": true,
"max": true,
"countEmpty": true,
"tokens": true,
},
"ParameterNumber": {
"severity": true,
"max": true,
"ignoreOverriddenMethods": true,
"tokens": true,
},
"FileLength": {
"severity": true,
"max": true,
"fileExtensions": true,
},
"Indentation": {
"severity": true,
"basicOffset": true,
"braceAdjustment": true,
"caseIndent": true,
"throwsIndent": true,
"arrayInitIndent": true,
"lineWrappingIndentation": true,
"forceStrictCondition": true,
},
"WhitespaceAround": {
"severity": true,
"allowEmptyConstructors": true,
"allowEmptyMethods": true,
"allowEmptyTypes": true,
"allowEmptyLoops": true,
"allowEmptyLambdas": true,
"allowEmptyCatches": true,
"ignoreEnhancedForColon": true,
"tokens": true,
},
"NeedBraces": {
"severity": true,
"allowSingleLineStatement": true,
"allowEmptyLoopBody": true,
"tokens": true,
},
"LeftCurly": {
"severity": true,
"option": true,
"ignoreEnums": true,
"tokens": true,
},
"RightCurly": {
"severity": true,
"option": true,
"tokens": true,
},
"AvoidStarImport": {
"severity": true,
"excludes": true,
"allowClassImports": true,
"allowStaticMemberImports": true,
},
"IllegalImport": {
"severity": true,
"illegalPkgs": true,
"illegalClasses": true,
"regexp": true,
},
"UnusedImports": {
"severity": true,
"processJavadoc": true,
},
"CyclomaticComplexity": {
"severity": true,
"max": true,
"switchBlockAsSingleDecisionPoint": true,
"tokens": true,
},
"NPathComplexity": {
"severity": true,
"max": true,
},
"JavadocMethod": {
"severity": true,
"accessModifiers": true,
"allowMissingParamTags": true,
"allowMissingReturnTag": true,
"allowedAnnotations": true,
"validateThrows": true,
"tokens": true,
},
"JavadocType": {
"severity": true,
"scope": true,
"excludeScope": true,
"authorFormat": true,
"versionFormat": true,
"allowMissingParamTags": true,
"allowUnknownTags": true,
"allowedAnnotations": true,
"tokens": true,
},
"MissingJavadocMethod": {
"severity": true,
"minLineCount": true,
"allowedAnnotations": true,
"scope": true,
"excludeScope": true,
"allowMissingPropertyJavadoc": true,
"ignoreMethodNamesRegex": true,
"tokens": true,
},
"EmptyBlock": {
"severity": true,
"option": true,
"tokens": true,
},
"MagicNumber": {
"severity": true,
"ignoreNumbers": true,
"ignoreHashCodeMethod": true,
"ignoreAnnotation": true,
"ignoreFieldDeclaration": true,
"ignoreAnnotationElementDefaults": true,
"constantWaiverParentToken": true,
"tokens": true,
},
}

// filterValidProperties filters out invalid properties for a given module
func filterValidProperties(moduleName string, properties map[string]string) map[string]string {
validProps, hasDefinedProps := validCheckstyleProperties[moduleName]
if !hasDefinedProps {
// If module is not in our whitelist, only allow severity
result := make(map[string]string)
if sev, ok := properties["severity"]; ok {
result["severity"] = sev
}
return result
}

result := make(map[string]string)
for key, value := range properties {
if validProps[key] {
result[key] = value
}
}
return result
}
Loading