Skip to content

Commit aa75670

Browse files
authored
Merge pull request #56 from codacy/feature/add-dartanalyzer
add dart analyzer
2 parents 054c857 + 30efdfd commit aa75670

File tree

19 files changed

+515
-22
lines changed

19 files changed

+515
-22
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
- node@22.2.0
33
- python@3.11.11
4+
- dart@3.7.2
45
tools:
56
- eslint@9.3.0
67
- trivy@0.59.1
78
- pylint@3.3.6
89
- pmd@6.55.0
10+
- dartanalyzer@3.7.2

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ go.work.sum
2727
# Codacy CLI
2828
cli-v2
2929
codacy-cli
30+
31+
32+
#Ignore cursor AI rules
33+
.cursor/rules/codacy.mdc

cmd/analyze.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ func runPylintAnalysis(workDirectory string, pathsToCheck []string, outputFile s
217217
return tools.RunPylint(workDirectory, pylint, pathsToCheck, outputFile, outputFormat)
218218
}
219219

220+
func runDartAnalyzer(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error {
221+
dartanalyzer := config.Config.Tools()["dartanalyzer"]
222+
return tools.RunDartAnalyzer(workDirectory, dartanalyzer.InstallDir, dartanalyzer.Binaries["dart"], pathsToCheck, outputFile, outputFormat)
223+
}
224+
220225
var analyzeCmd = &cobra.Command{
221226
Use: "analyze",
222227
Short: "Runs all configured linters.",
@@ -307,6 +312,8 @@ func runTool(workDirectory string, toolName string, args []string, outputFile st
307312
return runPmdAnalysis(workDirectory, args, outputFile, outputFormat)
308313
case "pylint":
309314
return runPylintAnalysis(workDirectory, args, outputFile, outputFormat)
315+
case "dartanalyzer":
316+
return runDartAnalyzer(workDirectory, args, outputFile, outputFormat)
310317
default:
311318
return fmt.Errorf("unsupported tool: %s", toolName)
312319
}

cmd/init.go

Lines changed: 36 additions & 13 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(" - python@3.11.11\n")
178181
}
182+
if needsDart {
183+
sb.WriteString(" - dart@3.7.2\n")
184+
}
179185
} else {
180186
// In local mode with no tools specified, include all runtimes
181187
sb.WriteString(" - node@22.2.0\n")
182188
sb.WriteString(" - python@3.11.11\n")
189+
sb.WriteString(" - dart@3.7.2\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()
@@ -380,6 +389,13 @@ func createToolFileConfigurations(tool tools.Tool, patternConfiguration []domain
380389
}
381390
}
382391
fmt.Println("Pylint configuration created based on Codacy settings")
392+
case DartAnalyzer:
393+
if len(patternConfiguration) > 0 {
394+
err := createDartAnalyzerConfigFile(patternConfiguration, toolsConfigDir)
395+
if err != nil {
396+
return fmt.Errorf("failed to create Dart Analyzer config: %v", err)
397+
}
398+
}
383399
}
384400
return nil
385401
}
@@ -414,6 +430,12 @@ func createTrivyConfigFile(config []domain.PatternConfiguration, toolsConfigDir
414430
return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(trivyConfigurationString), utils.DefaultFilePerms)
415431
}
416432

433+
func createDartAnalyzerConfigFile(config []domain.PatternConfiguration, toolsConfigDir string) error {
434+
435+
dartAnalyzerConfigurationString := tools.CreateDartAnalyzerConfig(config)
436+
return os.WriteFile(filepath.Join(toolsConfigDir, "analysis_options.yaml"), []byte(dartAnalyzerConfigurationString), utils.DefaultFilePerms)
437+
}
438+
417439
// createDefaultTrivyConfigFile creates a default trivy.yaml configuration file
418440
func createDefaultTrivyConfigFile(toolsConfigDir string) error {
419441
// Use empty tool configuration to get default settings
@@ -462,8 +484,9 @@ func cleanConfigDirectory(toolsConfigDir string) error {
462484
}
463485

464486
const (
465-
ESLint string = "f8b29663-2cb2-498d-b923-a10c6a8c05cd"
466-
Trivy string = "2fd7fbe0-33f9-4ab3-ab73-e9b62404e2cb"
467-
PMD string = "9ed24812-b6ee-4a58-9004-0ed183c45b8f"
468-
PyLint string = "31677b6d-4ae0-4f56-8041-606a8d7a8e61"
487+
ESLint string = "f8b29663-2cb2-498d-b923-a10c6a8c05cd"
488+
Trivy string = "2fd7fbe0-33f9-4ab3-ab73-e9b62404e2cb"
489+
PMD string = "9ed24812-b6ee-4a58-9004-0ed183c45b8f"
490+
PyLint string = "31677b6d-4ae0-4f56-8041-606a8d7a8e61"
491+
DartAnalyzer string = "d203d615-6cf1-41f9-be5f-e2f660f7850f"
469492
)

config-file/configFile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package config_file
33
import (
44
"codacy/cli-v2/config"
55
"codacy/cli-v2/plugins"
6-
"gopkg.in/yaml.v3"
76
"os"
7+
8+
"gopkg.in/yaml.v3"
89
)
910

1011
type configFile struct {

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *ConfigType) Tools() map[string]*plugins.ToolInfo {
8282

8383
func (c *ConfigType) AddTools(configs []plugins.ToolConfig) error {
8484
// Process the tool configurations using the plugins.ProcessTools function
85-
toolInfoMap, err := plugins.ProcessTools(configs, c.toolsDirectory)
85+
toolInfoMap, err := plugins.ProcessTools(configs, c.toolsDirectory, c.runtimes)
8686
if err != nil {
8787
return err
8888
}

config/tools-installer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
3535
}
3636

3737
// Make sure the installation directory exists
38+
3839
err := os.MkdirAll(toolInfo.InstallDir, 0755)
3940
if err != nil {
4041
return fmt.Errorf("failed to create installation directory: %w", err)

domain/patternConfiguration.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ type ParameterConfiguration struct {
66
}
77

88
type PatternDefinition struct {
9-
Id string `json:"id"`
9+
Id string `json:"id"`
10+
Category string `json:"category"`
11+
Level string `json:"level"`
1012
}
1113

1214
type PatternConfiguration struct {

plugins/runtimes/dart/plugin.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: dart
2+
description: Dart runtime
3+
download:
4+
url_template: "https://storage.googleapis.com/dart-archive/channels/stable/release/{{.Version}}/sdk/dartsdk-{{.OS}}-{{.Arch}}-release.{{.Extension}}"
5+
file_name_template: "dart-sdk"
6+
extension:
7+
default: "zip"
8+
arch_mapping:
9+
"386": "ia32"
10+
"amd64": "x64"
11+
"arm": "arm"
12+
"arm64": "arm64"
13+
os_mapping:
14+
"darwin": "macos"
15+
"linux": "linux"
16+
"windows": "windows"
17+
binaries:
18+
- name: dart
19+
path: "bin/dart"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: flutter
2+
description: Dart Flutterruntime
3+
download:
4+
url_template: "https://storage.googleapis.com/flutter_infra_release/releases/stable/{{.OS}}/flutter_{{.OS}}_{{.Arch}}_{{.Version}}-stable.zip"
5+
file_name_template: "flutter"
6+
extension:
7+
default: "zip"
8+
arch_mapping:
9+
"386": "ia32"
10+
"amd64": "x64"
11+
"arm": "arm"
12+
"arm64": "arm64"
13+
os_mapping:
14+
"darwin": "macos"
15+
"linux": "linux"
16+
"windows": "windows"
17+
binaries:
18+
- name: dart
19+
path: "bin/dart"

0 commit comments

Comments
 (0)