Skip to content

Commit 4e2f5cb

Browse files
committed
some clean up
1 parent c0b8f3d commit 4e2f5cb

File tree

6 files changed

+30
-134
lines changed

6 files changed

+30
-134
lines changed

.codacy/codacy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
runtimes:
22
33
4+
45
tools:
56
67
78
89
10+

cmd/init.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ func configFileTemplate(tools []tools.Tool) string {
138138
// Track needed runtimes
139139
needsNode := false
140140
needsPython := false
141-
141+
needsDart := false
142142
// Default versions
143143
defaultVersions := map[string]string{
144-
ESLint: "9.3.0",
145-
Trivy: "0.59.1",
146-
PyLint: "3.3.6",
147-
PMD: "6.55.0",
144+
ESLint: "9.3.0",
145+
Trivy: "0.59.1",
146+
PyLint: "3.3.6",
147+
PMD: "6.55.0",
148+
DartAnalyzer: "3.7.2",
148149
}
149150

150151
// Build map of enabled tools with their versions
@@ -161,6 +162,8 @@ func configFileTemplate(tools []tools.Tool) string {
161162
needsNode = true
162163
} else if tool.Uuid == PyLint {
163164
needsPython = true
165+
} else if tool.Uuid == DartAnalyzer {
166+
needsDart = true
164167
}
165168
}
166169

@@ -176,10 +179,14 @@ func configFileTemplate(tools []tools.Tool) string {
176179
if needsPython {
177180
sb.WriteString(" - [email protected]\n")
178181
}
182+
if needsDart {
183+
sb.WriteString(" - [email protected]\n")
184+
}
179185
} else {
180186
// In local mode with no tools specified, include all runtimes
181187
sb.WriteString(" - [email protected]\n")
182188
sb.WriteString(" - [email protected]\n")
189+
sb.WriteString(" - [email protected]\n")
183190
}
184191

185192
sb.WriteString("tools:\n")
@@ -188,10 +195,11 @@ func configFileTemplate(tools []tools.Tool) string {
188195
if len(tools) > 0 {
189196
// Add only the tools that are in the API response (enabled tools)
190197
uuidToName := map[string]string{
191-
ESLint: "eslint",
192-
Trivy: "trivy",
193-
PyLint: "pylint",
194-
PMD: "pmd",
198+
ESLint: "eslint",
199+
Trivy: "trivy",
200+
PyLint: "pylint",
201+
PMD: "pmd",
202+
DartAnalyzer: "dartanalyzer",
195203
}
196204

197205
for uuid, name := range uuidToName {
@@ -205,6 +213,7 @@ func configFileTemplate(tools []tools.Tool) string {
205213
sb.WriteString(fmt.Sprintf(" - trivy@%s\n", defaultVersions[Trivy]))
206214
sb.WriteString(fmt.Sprintf(" - pylint@%s\n", defaultVersions[PyLint]))
207215
sb.WriteString(fmt.Sprintf(" - pmd@%s\n", defaultVersions[PMD]))
216+
sb.WriteString(fmt.Sprintf(" - dartanalyzer@%s\n", defaultVersions[DartAnalyzer]))
208217
}
209218

210219
return sb.String()

domain/patternConfiguration.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ type PatternDefinition struct {
1313

1414
type PatternConfiguration struct {
1515
PatternDefinition PatternDefinition `json:"patternDefinition"`
16-
Enabled bool `json:"enabled"`
1716
Parameters []ParameterConfiguration
1817
}

tools/dartanalyzerConfigCreator.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package tools
22

33
import (
44
"codacy/cli-v2/domain"
5-
"fmt"
65
"slices"
7-
"strconv"
86
"strings"
97

108
"gopkg.in/yaml.v3"
@@ -27,16 +25,10 @@ func CreateDartAnalyzerConfig(configuration []domain.PatternConfiguration) strin
2725
errorsMap := config["analyzer"].(map[string]interface{})["errors"].(map[string]string)
2826
lintsMap := config["linter"].(map[string]interface{})["rules"].(map[string]string)
2927
for _, pattern := range configuration {
30-
fmt.Println(pattern.PatternDefinition.Id, pattern.Enabled, pattern.PatternDefinition.Category)
3128
if slices.Contains(errorPatterns, pattern.PatternDefinition.Category) {
32-
if pattern.Enabled {
33-
errorsMap[strings.TrimPrefix(pattern.PatternDefinition.Id, patternPrefix)] = strings.ToLower(pattern.PatternDefinition.Level)
34-
} else {
35-
errorsMap[strings.TrimPrefix(pattern.PatternDefinition.Id, patternPrefix)] = "ignore"
36-
}
37-
29+
errorsMap[strings.TrimPrefix(pattern.PatternDefinition.Id, patternPrefix)] = strings.ToLower(pattern.PatternDefinition.Level)
3830
} else {
39-
lintsMap[strings.TrimPrefix(pattern.PatternDefinition.Id, patternPrefix)] = strconv.FormatBool(pattern.Enabled)
31+
lintsMap[strings.TrimPrefix(pattern.PatternDefinition.Id, patternPrefix)] = "true"
4032
}
4133
}
4234

tools/dartanalyzerRunner.go

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import (
66
"codacy/cli-v2/plugins"
77
"encoding/json"
88
"fmt"
9-
"net/http"
109
"os"
1110
"os/exec"
1211
"path/filepath"
1312
"strconv"
1413
"strings"
15-
"time"
1614
)
1715

18-
const CodacyApiBase = "https://app.codacy.com"
1916
const codacyToolName = "dartanalyzer"
2017
const patternPrefix = "dartanalyzer_"
2118

@@ -138,114 +135,3 @@ func RunDartAnalyzer(workDirectory string, toolInfo *plugins.ToolInfo, files []s
138135
}
139136

140137
}
141-
142-
func convertDartAnalyzerOutputToSarif(output string) (string, error) {
143-
// Create base SARIF structure
144-
sarif := map[string]interface{}{
145-
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
146-
"runs": []map[string]interface{}{
147-
{
148-
"results": []map[string]interface{}{},
149-
},
150-
},
151-
}
152-
153-
// Split output into lines
154-
lines := strings.Split(output, "\n")
155-
156-
// Process each line
157-
for _, line := range lines {
158-
if line == "" {
159-
continue
160-
}
161-
162-
// Split line into fields
163-
fields := strings.Split(line, "|")
164-
if len(fields) < 8 {
165-
continue
166-
}
167-
168-
// Extract fields
169-
file := fields[3]
170-
lineNum, _ := strconv.Atoi(fields[4])
171-
message := fields[7]
172-
173-
// Create result object
174-
result := map[string]interface{}{
175-
"message": map[string]string{
176-
"text": message,
177-
},
178-
"locations": []map[string]interface{}{
179-
{
180-
"physicalLocation": map[string]interface{}{
181-
"artifactLocation": map[string]interface{}{
182-
"uri": file,
183-
},
184-
"region": map[string]interface{}{
185-
"startLine": lineNum,
186-
},
187-
},
188-
},
189-
},
190-
}
191-
192-
// Add result to SARIF output
193-
sarif["runs"].([]map[string]interface{})[0]["results"] = append(
194-
sarif["runs"].([]map[string]interface{})[0]["results"].([]map[string]interface{}),
195-
result,
196-
)
197-
}
198-
199-
// Convert to JSON
200-
sarifJson, err := json.MarshalIndent(sarif, "", " ")
201-
if err != nil {
202-
return "", fmt.Errorf("error marshaling SARIF: %v", err)
203-
}
204-
205-
return string(sarifJson), nil
206-
}
207-
208-
func getToolFromCodacy(apiToken string, provider string, owner string, repository string) (*Tool, error) {
209-
url := fmt.Sprintf("%s/api/v3/analysis/organizations/%s/%s/repositories/%s/tools",
210-
CodacyApiBase,
211-
provider,
212-
owner,
213-
repository)
214-
215-
client := &http.Client{
216-
Timeout: 10 * time.Second,
217-
}
218-
219-
req, err := http.NewRequest("GET", url, nil)
220-
if err != nil {
221-
return nil, fmt.Errorf("error creating request: %v", err)
222-
}
223-
224-
req.Header.Set("Accept", "application/json")
225-
req.Header.Set("api-token", apiToken)
226-
227-
resp, err := client.Do(req)
228-
if err != nil {
229-
return nil, fmt.Errorf("error making request: %v", err)
230-
}
231-
defer resp.Body.Close()
232-
233-
if resp.StatusCode >= 400 {
234-
return nil, fmt.Errorf("failed to get tools from Codacy API: %v", resp.Status)
235-
}
236-
237-
var response struct {
238-
Data []Tool `json:"data"`
239-
}
240-
241-
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
242-
return nil, fmt.Errorf("error decoding response: %v", err)
243-
}
244-
245-
for _, tool := range response.Data {
246-
if tool.Name == codacyToolName {
247-
return &tool, nil
248-
}
249-
}
250-
return nil, fmt.Errorf("tool %s not found", codacyToolName)
251-
}

tools/dartanalyzerRunner_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package tools
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestRunDartAnalyzerToFile(t *testing.T) {
8+
}

0 commit comments

Comments
 (0)