SublimeLinter / SublimeLinter-rubocop

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

Change deprecated executable_path call #52

Closed martinbohman closed 6 years ago

martinbohman commented 6 years ago

Fixes https://github.com/SublimeLinter/SublimeLinter-rubocop/issues/51

However if I understand correctly the changes referred in above issue, maybe it would be better to stop using self.executable as well and just define command = ['ruby', '-S'] (as well as removing executable = 'ruby' on line 32 https://github.com/SublimeLinter/SublimeLinter-rubocop/blob/master/linter.py#L32 ) Let me know if you want me to make this change.

kaste commented 6 years ago

Hi!

You're correct. 'executable' is also deprecated. Just use the name of the binary, here 'ruby'.

martinbohman commented 6 years ago

@kaste I have pushed this change

kaste commented 6 years ago

Okay, I'm back.

So this an no-brainer change. We generally lack ruby people in the org, so may I ask? We have two paths here. Either we run ruby -s rubocop or ruby -s bundle exec robocop. Why is that? Why do we not run bundle exec rubocop directly?

kaste commented 6 years ago

To compare that to the other linter platforms (python, node). Usually their cmd looks like ['eslint', '-arg1', ...] or ['flake8', '-'] etc. cmd[0] always refers to the so-called executable, which can be globally or locally available.

Now in SublimeLinter land we exchange this executable at cmd[0]. So for example instead of eslint we actually execute nvm 8.6 exec eslint, or in python land we could exec python -m flake8 or py -3.6 -m flake8. (But of course, if eslint or flake8 are globally available we can just stick with it.)

For ruby, we should be able to transform rubocop -arg -otherarg into bundle exec rubocop or ruby -S rubocop or chef exec rubocop etc.

Is this something you think ruby people or you would be interested in?

kaste commented 6 years ago

A minimal new implementation of this plugin can be found at https://github.com/SublimeLinter/SublimeLinter-rubocop/pull/55

Would be nice if you could check it!

printercu commented 5 years ago

Hi! Seems like executable_path was the only way to make plugin work with rvm. As I understood there is ~/.rvm/bin/rvm-auto-ruby which selects appropriate ruby depending on cwd. Now it's not possible to make linter use this (in easy way, without creating alias) because executable name is hardcoded.

WDYT about adding config option, to make it possible to use rvm-auto-ruby instead of ruby?

kaste commented 5 years ago

It's a bit more complicated @printercu Which binary SublimeLinter will use is computed here https://github.com/SublimeLinter/SublimeLinter/blob/5091073469c4258f9c73aa81f680b0f5f2a4c316/lint/base_linter/ruby_linter.py#L29-L102

What I still don't know is why we use ['ruby', '-s', 'rubocop', ...] as the command. I think it should be just ['rubocop', ...].

printercu commented 5 years ago

Thanks for the link! I had to create link to ~/.rvm/bin/rvm-auto-ruby named ruby. But now I see that adding ~/.rvm/bin/ to sublimelinter's paths do the trick and makes it use rvm-auto-ruby.

Will ['rubocop', ...] support multiple ruby versions?

kaste commented 5 years ago

If I look at the code I linked above it should still work with different Ruby versions. You could try for yourself. Just open your packages folder and git clone this repo into it. After that you can patch it in place. There is no risk, if you rm the clone Sublime will use the official, latest version again.

printercu commented 5 years ago

If I change from command = ['ruby', '-S'] to command = [] I get SublimeLinter: #366 ruby_linter.py:97: WARNING: rubocop deactivated, cannot locate the gem 'bundle'. Without "use_bundle_exec": true I get SublimeLinter: #365 ruby_linter.py:97: WARNING: rubocop deactivated, cannot locate the gem 'rubocop'

kaste commented 5 years ago

Thanks for testing. That basically means (for your setup) the installed gems e.g. rubocop or bundle are not in your PATH. (I assumed/hoped they would.)

printercu commented 5 years ago

I think this is because calling bundle exec (same for rubocop) without ruby -S tries to execute it with system ruby, where I don't have bundler and rubocop installed. While both of them are installed in different rvm rubies.