Skip to content

Commit 1366f9a

Browse files
committed
add dart analyzer
1 parent 8bc9720 commit 1366f9a

File tree

11 files changed

+484
-9
lines changed

11 files changed

+484
-9
lines changed

cli-v2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func main() {
1616
configErr := cfg.ReadConfigFile(config.Config.ProjectConfigFile())
1717
// whenever there is no configuration file, the only command allowed to run is the 'init'
1818
if configErr != nil && len(os.Args) > 1 && os.Args[1] != "init" {
19+
fmt.Println(configErr)
1920
fmt.Println("No configuration file was found, execute init command first.")
2021
return
2122
}

cmd/analyze.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func init() {
9797
analyzeCmd.Flags().StringVar(&outputFormat, "format", "", "Output format (use 'sarif' for SARIF format)")
9898
analyzeCmd.Flags().BoolVar(&autoFix, "fix", false, "Apply auto fix to your issues when available")
9999
analyzeCmd.Flags().StringVar(&pmdRulesetFile, "rulesets", "", "Path to PMD ruleset file")
100+
analyzeCmd.Flags().StringVarP(&apiToken, "api-token", "a", "", "API token for Codacy API")
101+
analyzeCmd.Flags().StringVarP(&provider, "provider", "p", "", "Provider (gh, gl, bb)")
102+
analyzeCmd.Flags().StringVar(&owner, "owner", "", "Owner/Organization")
103+
analyzeCmd.Flags().StringVarP(&repository, "repository", "r", "", "Repository")
100104
rootCmd.AddCommand(analyzeCmd)
101105
}
102106

@@ -224,6 +228,11 @@ func runPylintAnalysis(workDirectory string, pathsToCheck []string, outputFile s
224228
}
225229
}
226230

231+
func runDartAnalyzer(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) {
232+
dartanalyzer := config.Config.Tools()["dartanalyzer"]
233+
tools.RunDartAnalyzer(workDirectory, dartanalyzer, pathsToCheck, outputFile, outputFormat, apiToken, provider, owner, repository)
234+
}
235+
227236
var analyzeCmd = &cobra.Command{
228237
Use: "analyze",
229238
Short: "Runs all linters.",
@@ -251,6 +260,8 @@ var analyzeCmd = &cobra.Command{
251260
runPmdAnalysis(workDirectory, args, outputFile, outputFormat)
252261
case "pylint":
253262
runPylintAnalysis(workDirectory, args, outputFile, outputFormat)
263+
case "dartanalyzer":
264+
runDartAnalyzer(workDirectory, args, outputFile, outputFormat)
254265
case "":
255266
log.Fatal("You need to specify a tool to run analysis with, e.g., '--tool eslint'")
256267
default:

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
@@ -69,7 +69,7 @@ func (c *ConfigType) Tools() map[string]*plugins.ToolInfo {
6969

7070
func (c *ConfigType) AddTools(configs []plugins.ToolConfig) error {
7171
// Process the tool configurations using the plugins.ProcessTools function
72-
toolInfoMap, err := plugins.ProcessTools(configs, c.toolsDirectory)
72+
toolInfoMap, err := plugins.ProcessTools(configs, c.toolsDirectory, c.runtimes)
7373
if err != nil {
7474
return err
7575
}

config/tools-installer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ func InstallTools() error {
2626

2727
// InstallTool installs a specific tool
2828
func InstallTool(name string, toolInfo *plugins.ToolInfo) error {
29+
fmt.Println("Installing tool", name, "in", toolInfo.InstallDir)
2930
// Check if the tool is already installed
3031
if isToolInstalled(toolInfo) {
3132
fmt.Printf("Tool %s v%s is already installed\n", name, toolInfo.Version)
3233
return nil
3334
}
3435

3536
// Make sure the installation directory exists
37+
3638
err := os.MkdirAll(toolInfo.InstallDir, 0755)
3739
if err != nil {
3840
return fmt.Errorf("failed to create installation directory: %w", err)

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"

plugins/tool-utils.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ type ToolInfo struct {
110110
}
111111

112112
// ProcessTools processes a list of tool configurations and returns a map of tool information
113-
func ProcessTools(configs []ToolConfig, toolDir string) (map[string]*ToolInfo, error) {
113+
func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*RuntimeInfo) (map[string]*ToolInfo, error) {
114114
result := make(map[string]*ToolInfo)
115115

116116
for _, config := range configs {
@@ -122,21 +122,32 @@ func ProcessTools(configs []ToolConfig, toolDir string) (map[string]*ToolInfo, e
122122
if err != nil {
123123
return nil, fmt.Errorf("error reading plugin.yaml for %s: %w", config.Name, err)
124124
}
125-
125+
fmt.Println("Plugin path", pluginPath)
126126
var pluginConfig ToolPluginConfig
127127
err = yaml.Unmarshal(data, &pluginConfig)
128128
if err != nil {
129129
return nil, fmt.Errorf("error parsing plugin.yaml for %s: %w", config.Name, err)
130130
}
131-
131+
fmt.Println("EOD")
132132
// Create the install directory path
133133
installDir := path.Join(toolDir, fmt.Sprintf("%s@%s", config.Name, config.Version))
134134

135+
// Handle special case for dartanalyzer since it can be used with either dart or flutter
136+
toolRuntime := pluginConfig.Runtime
137+
if config.Name == "dartanalyzer" {
138+
if runtimes["flutter"] != nil {
139+
installDir = runtimes["flutter"].InstallDir
140+
toolRuntime = "flutter"
141+
} else {
142+
installDir = runtimes["dart"].InstallDir
143+
toolRuntime = "dart"
144+
}
145+
}
135146
// Create ToolInfo with basic information
136147
info := &ToolInfo{
137148
Name: config.Name,
138149
Version: config.Version,
139-
Runtime: pluginConfig.Runtime,
150+
Runtime: toolRuntime,
140151
InstallDir: installDir,
141152
Binaries: make(map[string]string),
142153
Formatters: make(map[string]string),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: dartanalyzer
2+
description: Dart Analyzer
3+
runtime: "{{.Runtime}}"
4+
runtime_binaries:
5+
package_manager: dart
6+
execution: dart
7+
installation:
8+
command: "pub add --dev flutter_lints"
9+

0 commit comments

Comments
 (0)