Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reviewdog reports issues in old lines instead of new ones #1725

Open
ptzianos opened this issue Apr 30, 2024 · 0 comments
Open

Reviewdog reports issues in old lines instead of new ones #1725

ptzianos opened this issue Apr 30, 2024 · 0 comments

Comments

@ptzianos
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant