Skip to content

Commit

Permalink
Fix exit status 1 on analyze and extra directory
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoCostaCodacy committed May 22, 2024
1 parent 7c03bd8 commit 610d50e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ go.work
go.work.sum

.idea/

cli-v2
10 changes: 5 additions & 5 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
@@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions tools/eslintRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
}

0 comments on commit 610d50e

Please sign in to comment.