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.

2 Answers 2


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)))))

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.