5

I want ruby-rubocop Flycheck syntax checker to execute bundle exec rubocop instead of just rubocop.

What I've tried:

  1. (setq flycheck-ruby-rubocop-executable "bundle exec rubocop")

    Results in following error:

    Error while checking syntax automatically: (error "Output file descriptor of flycheck-ruby-rubocop is closed")
    
  2. (flycheck-set-checker-executable 'ruby-rubocop "bundle exec rubocop")

    I get error:

    user-error: bundle exec rubocop is no executable
    
  3. This answer:

    (setq flycheck-command-wrapper-function
      (lambda (command)
        (append '("bundle" "exec") command)))
    

    It broke all checkers, because now it appends "bundle exec" to all checkers, not only ruby-rubocop, and it didn't work in ruby buffer (it still used rubocop without bundle exec). I don't know how to make this variable buffer-local.

kolen
  • 221
  • 2
  • 6

2 Answers2

4

Use setq-local to make a variable buffer-local. It works well in a hook like this:

(add-hook 'ruby-mode-hook
  (lambda ()
    (setq-local flycheck-command-wrapper-function
                (lambda (command) (append '("bundle" "exec") command)))))
llvtt
  • 41
  • 2
3

I'll let someone else clear that issue up for Flycheck.

But for completeness' sake: if you install Emacs 27 (or newer) and enable flymake-mode in Ruby buffers, Rubocop integration is there, and it appends "bundle exec" when appropriate.

Dmitry
  • 3,508
  • 15
  • 20