diff --git a/.gitignore b/.gitignore index 4e318b0..1ebd21a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ go.work go.work.sum .idea/ + +cli-v2 \ No newline at end of file diff --git a/cmd/analyze.go b/cmd/analyze.go index f741f39..30a17de 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -1,18 +1,19 @@ package cmd import ( - "codacy/cli-v2/tools" "codacy/cli-v2/config" + "codacy/cli-v2/tools" "fmt" + "github.com/spf13/cobra" "log" "os" - "github.com/spf13/cobra" + "path" ) var outputFolder string func init() { - analyzeCmd.Flags().StringVarP(&outputFolder, "output", "o", ".codacy/out/eslint.sarif", "where to output the results") + analyzeCmd.Flags().StringVarP(&outputFolder, "output", "o", path.Join(".codacy", "out"), "where to output the results") rootCmd.AddCommand(analyzeCmd) } @@ -41,8 +42,7 @@ var analyzeCmd = &cobra.Command{ log.Fatal("You need to specify the tool you want to run for now! ;D") } - msg := fmt.Sprintf("Running the tool %s. Output will be available at %s", args[0], outputFolder) - fmt.Println(msg) + fmt.Printf("Running the tool %s. Output will be available at %s\n", args[0], outputFolder) err = tools.RunEslintToFile(workDirectory, eslintInstallationDirectory, nodeBinary, outputFolder) if err != nil { log.Fatal(err) diff --git a/tools/eslintRunner.go b/tools/eslintRunner.go index 293fb58..fafdcdd 100644 --- a/tools/eslintRunner.go +++ b/tools/eslintRunner.go @@ -20,7 +20,7 @@ func RunEslintToString(repositoryToAnalyseDirectory string, eslintInstallationDi // * The local installed ESLint should have the @microsoft/eslint-formatter-sarif installed func runEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory string, nodeBinary string, outputFolder string) (string, error) { eslintInstallationNodeModules := filepath.Join(eslintInstallationDirectory, "node_modules") - eslintJsPath := filepath.Join(eslintInstallationNodeModules, ".bin/eslint") + eslintJsPath := filepath.Join(eslintInstallationNodeModules, ".bin", "eslint") cmd := exec.Command(nodeBinary, eslintJsPath, "-f", "@microsoft/eslint-formatter-sarif") @@ -35,10 +35,8 @@ func runEslint(repositoryToAnalyseDirectory string, eslintInstallationDirectory nodePathEnv := "NODE_PATH=" + eslintInstallationNodeModules cmd.Env = append(cmd.Env, nodePathEnv) - out, err := cmd.Output() - if err != nil { - return "", err - } + // TODO eslint returns 1 when it finds errors, so we're not propagating it + out, _ := cmd.Output() return string(out), nil }