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

"Tip: Based on detected gems..." is appended to file when --stdin option is used e.g. in editor integration #9617

Closed
henrahmagix opened this issue Mar 18, 2021 · 2 comments · Fixed by #9618
Assignees
Labels

Comments

@henrahmagix
Copy link
Contributor

This makes the -s|--stdin option unviable for editor integration.

I'm using VS Code with the Ruby extension, and it uses the output to replace the file contents when format-on-save is turned on. Here's the extension that produces the rubocop ... line.

My VS Code settings for this:

"ruby.useLanguageServer": true,
"editor.formatOnSave": true,
"ruby.format": "rubocop",

Expected behavior

Rubocop detects when it's outputting to stdout and skips SuggestExtensions. Or it prints it before the output delimiter so scripts ignore it.

Actual behavior

The suggested extensions copy gets appended to the file that was formatted by rubocop in my code editor.

Steps to reproduce the problem

Given some gems that produce suggested extensions, e.g. minitest, and a file /path/to/file.rb that contains some ruby code:

module RubocopBugEmptyFile; end

This is ok as it's human-usage, not scripted:

$: rubocop /path/to/file.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Tip: Based on detected gems, the following RuboCop extension libraries might be helpful:
  * rubocop-minitest (http://github.com/rubocop-hq/rubocop-minitest)

You can opt out of this message by adding the following to your config (see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions for more options):
  AllCops:
    SuggestExtensions: false

This is incorrect as it's meant to be used by scripts for editor integration:

$: rubocop -s '/path/to/file.rb' -a < /path/to/file.rb
Inspecting 1 file
.

1 file inspected, no offenses detected
====================
module Empty; end

Tip: Based on detected gems, the following RuboCop extension libraries might be helpful:
  * rubocop-minitest (http://github.com/rubocop-hq/rubocop-minitest)

You can opt out of this message by adding the following to your config (see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions for more options):
  AllCops:
    SuggestExtensions: false

As far as I can tell, based on VS Code's Ruby extension known "output delimiter", I think it should be this:

$: rubocop -s '/path/to/file.rb' -a < /path/to/file.rb
Inspecting 1 file
.

1 file inspected, no offenses detected
====================
module Empty; end

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.11.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.6.6 x86_64-darwin19)
  - rubocop-rails 2.9.1
  - rubocop-rspec 2.1.0
@dvandersluis dvandersluis self-assigned this Mar 18, 2021
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Mar 18, 2021
dvandersluis added a commit that referenced this issue Mar 18, 2021
[Fix #9617] Disable suggested extensions when using the `--stdin` option
@henrahmagix
Copy link
Contributor Author

Aw wow, that was super quick, thanks so much @dvandersluis!

Could you kindly comment here when it's released, so I get a notification please? Or if you know roughly when it might get released so I can set a reminder? Thanks a bunch!

@dvandersluis
Copy link
Member

dvandersluis commented Mar 18, 2021

Thanks for the issue @henrahmagix!

I'm not sure when the next release is planned for but you can have github notify you about releases specifically in the Watch menu for the repo (under Custom). This will be released in the next release, whenever that ends up being (usually releases happen every 2-4 weeks or so but we don't have a specific schedule).

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

Successfully merging a pull request may close this issue.

2 participants