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

syntax-checker configuration for bundler #3726

Closed
howdoicomputer opened this issue Nov 8, 2015 · 10 comments
Closed

syntax-checker configuration for bundler #3726

howdoicomputer opened this issue Nov 8, 2015 · 10 comments
Labels
Question Ruby stale marked as a stale issue/pr (usually by a bot) Syntax-checking updated This issue has been updated since becoming stale

Comments

@howdoicomputer
Copy link

I'm just starting out with Spacemacs and the Flycheck plugin seems to be unable to correctly guess my path to RuboCop. I'm pretty sure Flycheck allows wrapping a command through its API but I'm just starting out with Emacs Lisp and am a little confused about how to configure Flycheck to use bundle exec for RuboCop. Do I need to define an entirely new checker? Can I just specify the check name and the command I want to wrap the check call with?

http://www.flycheck.org/manual/latest/Flycheck-hooks.html
flycheck/flycheck#752 (comment)

@rashkov
Copy link

rashkov commented Jan 13, 2016

You can provide the path to rubocop by using SPC-e-S or flycheck-set-checker-executable. Then you select which checker you want to configure (rubocop), then you provide the full path to rubocop's executable.

@asymmetric
Copy link
Contributor

@rashkov is there a way to configure it to use rbenv's shims? Even if I point flycheck-set-checker-executable to ~/.rbenv/shims/rubocop I still get rbenv: rubocop command not found - although it's present in that ruby version.

@rashkov
Copy link

rashkov commented Apr 29, 2016

@asymmetric Not sure what the problem could be as I'm also using rbenv, and also pointing it to ~/.rbenv/shims/rubocop. Maybe you can try running rbenv rehash and then try again with spacemacs. Also make sure that you can invoke rubocop from the command-line against a ruby file and see that it works properly.

@asymmetric
Copy link
Contributor

asymmetric commented Apr 29, 2016

@rashkov how are you making spacemacs aware of rbenv? I have eval $(rbenv init -) inside my ~/.zshenv file (which seems the right choice as that's what loaded by non-interactive shells), but still I get the error.

One more question: where have you installed your gems? I have them local to the project (i.e. I passed the --path option to bundler).

And yes, rubocop is available straight from the shell.

Thanks!

@rashkov
Copy link

rashkov commented Apr 29, 2016

@asymmetric: I actually never made spacemacs aware of rbenv, it has always worked out of the box. In fact, I just turned off rbenv and tested out spacemacs, and rubocop still works when I point spacemacs to ~/.rbenv/shims/rubocop

I turned off rbenv by exporting my PATH without the rbenv directories. Running which ruby now pointed to my system ruby instead or rbenv's ruby. Then I launched spacemacs from that shell, pointed flycheck's rubocop to the wrong executable to "break it", then pointed it back to ~/.rbenv/shims/rubocop, and after editing the file a little and saving it rubocop woke up and started working again.

My gems are all installed to ~/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems
I just do bundle install to take care of my project-specific gems, and I'm pretty sure they all install to that directory that I just listed. However I never installed rubocop through bundler. It is not even in my gemfile. I installed it via "gem install rubocop".

Also this comes to mind: recently my rbenv broke on another computer, and I had to delete (or move) the ~/.gems directory. The gems in that folder were interfering with rbenv. That might be something to try as well

@asymmetric
Copy link
Contributor

I see. The difference between my setup and yours is that my rubocop is installed via bundler, so flycheck would need to run bundle exec. If I install rubocop wih gem install, it works from Emacs.

I suspect the solution involves implementing a function to pass to flycheck-command-wrapper-function, but I haven't been able to come up with one yet, as I've never written any Lisp :)

@rashkov
Copy link

rashkov commented Apr 29, 2016

Just realized that this entire github issue is about bundle exec, my bad. I've totally ignored that aspect.

Yes, flycheck-command-wrapper-function definitely appears to be the right place to fix this. Wish I could help with that but I would also need to pick up some elisp before that happens.

@bryan-ash
Copy link

👍 I've recently switched over to Spacemacs and would love to see this one fixed.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
@yourpalal
Copy link

yourpalal commented May 20, 2020

After trying a bunch of things with flycheck-command-wrapper, I realised that there's a much simpler solution!

  1. mkdir ~/bin/
  2. ensure that ~/bin/ is in your PATH. (run spacemacs/edit-env for instance)
  3. echo '#!/bin/bash\n\nbundle exec rubocop "$@"' > ~/bin/rubocop
  4. chmod +x ~/bin/rubocop
  5. restart emacs

Emacs will now use your wrapper script in ~/bin/rubocop, thereby running rubocop with bundle exec

@JAremko JAremko added the updated This issue has been updated since becoming stale label May 26, 2020
@JAremko JAremko closed this as completed May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ruby stale marked as a stale issue/pr (usually by a bot) Syntax-checking updated This issue has been updated since becoming stale
Projects
None yet
Development

No branches or pull requests

7 participants