reviewdog / reviewdog

🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

Home Page:https://medium.com/@haya14busa/reviewdog-a-code-review-dog-who-keeps-your-codebase-healthy-d957c471938b#.8xctbaw5u

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reviewdog reports issues in old lines instead of new ones

ptzianos opened this issue · comments

Hi, I'm running reviewdog with the following flags:

lint:
	@reviewdog -fail-on-error $$([ "${CI}" = "true" ] && echo "-reporter=github-pr-review") -diff="git diff origin/main" -filter-mode=added -tee

The issue that I'm seeing is that I'm getting errors for lines that have been replaced. One example is this:
Screenshot_20240430_151626

As far as I understand by looking at the code, the github library will fetch the latest diff using a REST call to the Github API. Doing the same call myself I get this output:

$ curl https://api.github.com/repos/ocurity/dracon/pulls/156 -H 'Accept: application/vnd.github.v3.diff'
diff --git a/cmd/draconctl/migrations/inspect.go b/cmd/draconctl/migrations/inspect.go
index a20b6fa4..3ccce794 100644
--- a/cmd/draconctl/migrations/inspect.go
+++ b/cmd/draconctl/migrations/inspect.go
@@ -56,18 +56,20 @@ func inspectMigrations(cmd *cobra.Command, args []string) error {
                        Dirty   bool
                }{latestMigration, isDirty}
 
-               marshaledBytes, err := json.Marshal(jsonOutput)
+               var marshaledBytes []byte
+               marshaledBytes, err = json.Marshal(jsonOutput)
                if err != nil {
                        return fmt.Errorf("could not marshal JSON output: %w", err)
                }
-               fmt.Fprintln(cmd.OutOrStderr(), string(marshaledBytes))
+
+               _, err = fmt.Fprintln(cmd.OutOrStdout(), string(marshaledBytes))
        } else {
-               table := tablewriter.NewWriter(os.Stdout) //cmd.OutOrStdout())
+               table := tablewriter.NewWriter(cmd.OutOrStdout())
                table.SetHeader([]string{"", ""})
                table.Append([]string{"Latest Migration Version", fmt.Sprintf("%d", latestMigration)})
                table.Append([]string{"Has Failed Migrations", fmt.Sprintf("%v", isDirty)})
                table.Render()
        }
 
-       return nil
+       return err
 }

As you can see here:

-               table := tablewriter.NewWriter(os.Stdout) //cmd.OutOrStdout())
+               table := tablewriter.NewWriter(cmd.OutOrStdout())

the line triggering the error has been modified to no longer have the error.

Is there some flag that I'm missing, or am I using a wrong flag and getting this result?