SublimeLinter / SublimeLinter-rubocop

SublimeLinter 3 plugin for Ruby, using rubocop.
MIT License
159 stars 40 forks source link

Can't get SublimeLinter-rubocop 3.0.0 running with rvm #66

Closed themilkman closed 5 years ago

themilkman commented 5 years ago

Hi,

after searching for the reason SL-R doesn't work anymore for me I noticed the version bump. It also took me some more time to find the notes in the "Release"-section (a package-control notice would have been really nice).

So, since that I try to get it working again and ... keep on failling.

I added the following in my ~/.config/sublime-text-3/Packages/User/SublimeLinter.sublime-settings

    "linters": {
      "rubocop": {
        "executable": ["~/.rvm/rubies/default/bin/ruby", "-S", "rubocop"]
      }
    },

Manually running

cat path/to/my.rb | /home/me/.rvm/rubies/default/bin/ruby -S rubocop --format emacs --force-exclusion --stdin /full/path/to/my.rb

on terminal works fine. But the SublimeText console debug output is:

SublimeLinter: sublime_linter.py:266  Delay linting 'my.rb' for 0.0s
SublimeLinter: linter.py:985          rubocop: checking lint mode 'background' vs lint reason 'on_user_request'
SublimeLinter: #11 linter.py:1003     rubocop: linting 'my.rb'
SublimeLinter: #11 linter.py:786      rubocop: wanted executable is '['/home/me/.rvm/rubies/default/bin/ruby', '-S', 'rubocop']'
SublimeLinter: #11 linter.py:1478     Running ...

  /home/me/<path_to>/backend  (working dir)
  $ cat path/to/my.rb | /home/me/.rvm/rubies/default/bin/ruby -S rubocop --format emacs --force-exclusion --stdin  /full/path/to/my.rb

SublimeLinter: #11 linter.py:684      WARNING: rubocop output:
/home/me/.rvm/rubies/default/bin/ruby: No such file or directory -- rubocop (LoadError)

SublimeLinter: #11 linter.py:686      Note: above warning will become an error in the future. Implement `on_stderr` if you think this is wrong.
SublimeLinter: #11 linter.py:1076     rubocop: no output
SublimeLinter: sublime_linter.py:529  Linting 'my.rb' took 0.10s

And my statusbar says "rubocop(erred)".

What am I missing, what am I doing wrong?

Thanks for any help!

Working on:

Edit: I have serveral projects on my machines with different rubies, so I am forced to get a "generic" rvm ruby detection running.

kaste commented 5 years ago

@jeffbyrnes for comments and visibility

Now, that the same command works on the cli but not within Sublime is a bummer. The command also looks okay. 😠

Can you clone this repo into Sublime's package folder, checkout the previous version, and post which command we used before?

themilkman commented 5 years ago

Hi @kaste, thanks for your fast reply and helpful debug suggestion - with this, I got it running :

    "linters": {
      "rubocop": {
        "executable": ["~/.rvm/bin/rvm-auto-ruby", "-S", "rubocop"]
      }
    },

From my perspective this issue is resolved. But maybe a example on the Readme wouldn't be a bad idea :)

Edit: Removed note about version detection in ST - package list shows it...

DixonGarcia commented 5 years ago

Thanks @themilkman I had that issue and this works for me! :+1: :rocket:

jeffbyrnes commented 5 years ago

@kaste ugh that is super unpleasant that it keels over with RVM, yet works fine with rbenv & a system install of Ruby.

My expectation was that, with RVM hooked into your shell, that Sublime would work well, the same way it does with rbenv, but clearly that is not the case.

I’m surprised that running the binary directly doesn’t work correctly, but then again, RVM does quite a lot under-the-covers…

kaste commented 5 years ago

I also hoped that here/is/my/ruby -S rubocop would be fine bc it is fine on the CLI. I also hoped we would find a more efficient way of using rvm bc running rvm-auto-ruby to prepare the ENV basically after every keystroke (but debounced) seems like a waste. Is there a marker file (say .rvmrc) we can search for which tells us that this project is managed by rvm?

Last resort is of course: just ask which rvm-auto-ruby and if it returns something just use rvm-auto-ruby -S rubocop.

LeEnno commented 5 years ago

Stumbled upon the same problem. Will gladly try to help track this one down.

Is there a marker file (say .rvmrc) we can search for which tells us that this project is managed by rvm?

Not for me, no.

I also hoped that here/is/my/ruby -S rubocop would be fine bc it is fine on the CLI.

I only have a rudimentary understanding of what is happening with rvm and Sublime. But in the past the problem has often been that there is a difference between

That would explain why a command works on CLI but not in Sublime. Just as an idea.

themilkman commented 5 years ago

I only have a rudimentary understanding of what is happening with rvm and Sublime. But in the past the problem has often been that there is a difference between

* "I as a user open a shell in `~` and rvm loads a lot of stuff" and

* "Sublime opens a shell outside of `~` and the rvm-stuff does not get loaded".

That would explain why a command works on CLI but not in Sublime. Just as an idea.

That sounds like a missing login shell for me. Just a guess.

kaste commented 5 years ago

Is it enough to ask for which rvm-auto-ruby and then use it if it's present? Or are there edge-cases where you have that script but a specific project/folder still shouldn't use it? (Asking because @LeEnno said there are no marker files. How does rvm know which project uses which ruby then?)

LeEnno commented 5 years ago

How does rvm know which project uses which ruby then?

AFAIK rvm uses a default ruby which you can set via CLI globally. You can specify the ruby version for a project/directory via a .ruby-version file though. But you don't have to. So there are marker files, but they are optional.

Regarding rvm-auto-ruby: from my understanding it will still resolve to the wrong version when being called from the wrong directory. E.g. calling rvm-auto-ruby -v from ~ will bring up ruby 2.2.4p230 (default). In my project folder it will result in ruby 2.3.1p112 (specified in a .ruby-version file).

Dunno what this means for SublimeLinter though. Maybe @themilkman is onto something with a missing login shell?

In the past I fixed versions of SublimeLinter manually by wrapping linter commands in a cd /path/to/project command. That always worked as expected.

If I can help with anything else, let me know.

kaste commented 5 years ago

@themilkman Does rvm need just a login shell (-l) or an interactive login shell (-il)?

@LeEnno Could you test the following scenarios. Load Sublime via clicking on an desktop icon. (This usually provides the dumbest ENV if you haven't patched your icons.) Then open the Sublime console and execute the following commands

import subprocess
subprocess.check_output(['rvm-auto-ruby', '-v'], cwd=...)

Fill in cwd with None and some project folders.

Now do the same starting Sublime using subl . from a fully interactive shell, e.g. from the root of a project. (Usually now the ENV has everything you ever wanted and Sublime will inherit that ENV.)

(Be sure you don't have path/env fixers/plugins installed into Sublime 😁 )

themilkman commented 5 years ago

@kaste I never really understood the complete difference between a login and a normal shell, I just accepted that it takes other things on its load path.. xD BUT since I didn't know until now of the interactive login shell with -il I personally would say that a normal login shell is what we are looking for.

LeEnno commented 5 years ago

@LeEnno Could you test the following scenarios.

I tested 2 scenarios: opening sublime from the applications folder and via subl . from my project folder. In both cases the output was the same:

Dunno what this means though.

kaste commented 5 years ago

Well, I want to make sure rvm actually resolves different ruby versions based basically on the cwd not on the ENV. (Or that it works in our scenario and not just as a shell tool.)

kaste commented 5 years ago

Then a PR is at #67