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

Rubocop TIP output is going to files on auto save #138

Open
RichardsonWTR opened this issue Dec 3, 2020 · 7 comments
Open

Rubocop TIP output is going to files on auto save #138

RichardsonWTR opened this issue Dec 3, 2020 · 7 comments

Comments

@RichardsonWTR
Copy link

RichardsonWTR commented Dec 3, 2020

After upgrading to 1.5.1, Rubocop by default prints the following message in the console when you run the command:

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

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 exact message appears at the end of every file when I save using the auto formatting in the VSCode Extension.

Versions

  • Ruby 2.5.1p57 (2018-03-29 revision 63029)
  • gem Rubocop: ~> 1.5.1
  • VSCode
Version: 1.51.1
Commit: e5a624b788d92b8d34d1392e4c4d9789406efe8f
Date: 2020-11-10T23:31:29.624Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 4.15.0-118-generic
  • ruby-rubocop: 0.8.5

Relevant VSCode preferences

{
    "ruby.format": "rubocop",
    "editor.formatOnSave": true,
    "editor.formatOnSaveTimeout": 5000,
    "[ruby]": {
        "editor.defaultFormatter": "misogi.ruby-rubocop"
    },
    "ruby.rubocop.useBundler": true,
}

Setting the option SuggestExtensions: false as showed by Rubocop fixes the issue; for now.

@cspotcode
Copy link

I'm unable to set SuggestExtensions: false, because when I do that, it complains:

The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.

It seems like this is triggered by the presence of a .rubocop.yml file.

We want default rubocop behavior because we can't justify writing a config file for this project (ruby is not our main language) so I'm looking for a way to workaround this bug without having a .rubocop.yml file.

@dvandersluis
Copy link

dvandersluis commented Dec 21, 2020

@cspotcode the message you're getting is due to RuboCop marking new cops as pending between major releases. You can choose to automatically enable or disable them by default in your .rubocop.yml along with SuggestExtensions: false, which will continue to use the default rubocop configuration but remove the warning messages you're experiencing):

AllCops:
  NewCops: [enable|disable] # choose one
  SuggestExtensions: false

See https://docs.rubocop.org/rubocop/1.6/versioning.html for more details.

@cspotcode
Copy link

cspotcode commented Dec 21, 2020 via email

@alakotko
Copy link

I had the same problem.

@uaru
Copy link

uaru commented Apr 16, 2021

I have the same problem. The time I am saving thanks to rubocop I am wasting because of the garbage it writes to .rb files.

@dvandersluis
Copy link

This is not a RuboCop bug, but rather a bug of how this library is calling RuboCop. The suggested extensions text only is added when using a formatter that is intended for human consumption. If this library used a RuboCop formatter meant for parsing (-f j for json for instance), the text would not be output by RuboCop and then added to your code.

@erikdstock
Copy link
Contributor

So it seems like this is a bug that breaks the extension. Is there a fix? From this code which sets the args and the --help output below it seems the answer may be to set an additional --stderr flag:

    --stderr                     Write all output to stderr except for the
                                     autocorrected source. This is especially useful
                                     when combined with --auto-correct and --stdin.
...
    -s, --stdin FILE                 Pipe source from STDIN, using FILE in offense
                                     reports. This is useful for editor integration.

I can't work on this right now so am just going to disable the suggested extensions.

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

6 participants