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

Using the --fix option with --stdin appends file content to the json result #8673

Closed
jgiovaresco opened this issue Sep 9, 2020 · 2 comments · Fixed by #8694
Closed

Using the --fix option with --stdin appends file content to the json result #8673

jgiovaresco opened this issue Sep 9, 2020 · 2 comments · Fixed by #8694

Comments

@jgiovaresco
Copy link

When I run rubocop using --fix and --stdin flags, I can see that the content of the file is appended to the JSON result.
This prevent tools (like RubyMine) to parse the response (https://youtrack.jetbrains.com/issue/RUBY-27006)

Expected behavior

I would expect to have only the JSON result.

Actual behavior

Example:

❯ rubocop --format json --force-exclusion --fix --stdin application_controller.rb < app/controllers/application_controller.rb 
{"metadata":{"rubocop_version":"0.90.0","ruby_engine":"ruby","ruby_version":"2.7.0","ruby_patchlevel":"0","ruby_platform":"x86_64-darwin19"},"files":[{"path":"application_controller.rb","offenses":[]}],"summary":{"offense_count":0,"target_file_count":1,"inspected_file_count":1}}====================
class ApplicationController < ActionController::API
end

Steps to reproduce the problem

Just run the following in a Rails project:

rubocop --format json --force-exclusion --fix --stdin application_controller.rb < app/controllers/application_controller.rb

RuboCop version

❯ bundle exec rubocop -V              
0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.7.0 x86_64-darwin19)
koic added a commit to koic/rubocop that referenced this issue Sep 14, 2020
…=json` and `--stdin`

Fixes rubocop#8673.

This PR returns only JSON result when specifying `--format=json` and `--stdin`
to fix the JSON parse error. Similar HTML and JUnit formatters are targeted as well.
bbatsov pushed a commit that referenced this issue Sep 14, 2020
…and `--stdin`

Fixes #8673.

This PR returns only JSON result when specifying `--format=json` and `--stdin`
to fix the JSON parse error. Similar HTML and JUnit formatters are targeted as well.
@ngouy
Copy link

ngouy commented Oct 2, 2020

nice fix but breaking change for other tools that were somehow dealing with the "bugged" output (ruby-rubocop vs-code extension as an example)

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 2, 2020

That's unfortunate, but I guess it won't be a hard to adjust the VS Code extension.

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

Successfully merging a pull request may close this issue.

3 participants