SublimeLinter / SublimeLinter-rubocop

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

Cannot use `executable` with `use_bundle_exec`? #74

Closed joshuapinter closed 3 years ago

joshuapinter commented 3 years ago

I'm using rbenv and I'm trying to use the rubocop that we have in our bundle.

I have my executable set to ~/me/.rbenv/shims/rubocop and use_bundle_exec to true.

Based on the console log it's not finding the right executable.

If I look at the code, it appears that if executable is set, it ignores use_bundle_exec. Am I wrong?

For reference, if I run bundle exec rubocop in my project directory, everything works great. Running just rubocop it does not.

FYI, I'm a contributor to rubocop so we use various github branches in our Gemfile to pull and test the master branch of the gem.

Thanks!

kaste commented 3 years ago

You're correct, setting executable disables all other settings. Two things can go wrong, at least. 1. Maybe we don't set the correct working dir. We Print that in debug mode. 2. The process environment of Sublime itself is different from your Terminal. You could check that by closing Sublime completely, and starting it again using subl . from the Terminal. It should then inherit the ENV from the Terminal.

joshmfrankel commented 3 years ago

@joshuapinter Have you tried overriding the env for the rubocop linter in your settings file? For example here is mine with asdf. I'm guessing rbenv is similiar in that you can use ~/.rbenv/shims as the environment override. With this config you should be able to remove your executable config above

"rubocop": {
      "use_bundle_exec": true,
      "env": {
        "PATH": "~/.asdf/shims:$PATH"
      }
    }

Reference: http://www.sublimelinter.com/en/stable/troubleshooting.html#debugging-path-problems

Mac OSX alternative Alternatively, if you're on OS X and launching Sublime Text via the Finder menu you can try the following (though I'd suggest trying the previous fix first)

Set the path used by launchctl (which launches apps via Finder) to include the path to your Rubocop shim

sudo launchctl config user path /Users/<username>/.asdf/shims:/Users/<username>/.asdf/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Something like the above but for rbenv should work.

Reference: https://apple.stackexchange.com/questions/51677/how-to-set-path-for-finder-launched-applications

joshuapinter commented 3 years ago

@joshmfrankel Hey Josh. Not sure why I didn't reply to this originally but just wanted to follow-up and say that the configuration change you suggested worked perfectly. It now finds and uses the rubocop binary in my ~/.rbenv/shims directory. My final config looks like this:

{
  "linters": {
    "rubocop": {
      "use_bundle_exec": true,
      "env": {
        "PATH": "~/.rbenv/shims:$PATH"
      }
    }
  }
}

Belated thank you! 🙏

williantenfen commented 2 years ago

I think this should be in the README:

"rubocop": {
      "use_bundle_exec": true,
      "env": {
        "PATH": "~/.asdf/shims:$PATH"
      }
    }