summaryrefslogtreecommitdiff
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2018-12-25 18:23:01 +0200
committerDmitry Gutov <dgutov@yandex.ru>2018-12-25 18:23:01 +0200
commit9916410fa8bc765677e2d09384599aa85945967d (patch)
tree8e7fcc5c38ec6d50e7eec4935bc747783e25373b /lisp/progmodes/ruby-mode.el
parente533848dd35426f8328f3d6e290ee5c08a776553 (diff)
downloademacs-9916410fa8bc765677e2d09384599aa85945967d.tar.gz
Prepend 'rubocop' with 'bundle exec' when appropriate
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el15
1 files changed, 14 insertions, 1 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 351dac2f852..d0ae9b4644f 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -2323,6 +2323,7 @@ If there is no Rubocop config file, Rubocop will be passed a flag
(let ((command (list "rubocop" "--stdin" buffer-file-name "--format" "emacs"
"--cache" "false" ; Work around a bug in old version.
"--display-cop-names"))
+ (default-directory default-directory)
config-dir)
(when buffer-file-name
(setq config-dir (locate-dominating-file buffer-file-name
@@ -2331,7 +2332,12 @@ If there is no Rubocop config file, Rubocop will be passed a flag
(setq command (append command '("--lint")))
(setq command (append command (list "--config"
(expand-file-name ruby-rubocop-config
- config-dir)))))
+ config-dir))))
+ (when (ruby-flymake-rubocop--use-bundler-p config-dir)
+ (setq command (append '("bundle" "exec") command))
+ ;; In case of a project with multiple nested subprojects,
+ ;; each one with a Gemfile.
+ (setq default-directory config-dir)))
(ruby-flymake--helper
"rubocop-flymake"
@@ -2369,6 +2375,13 @@ If there is no Rubocop config file, Rubocop will be passed a flag
into diags
finally (funcall report-fn diags)))))))
+(defun ruby-flymake-rubocop--use-bundler-p (dir)
+ (let ((file (expand-file-name "Gemfile" dir)))
+ (and (file-exists-p file)
+ (with-temp-buffer
+ (insert-file-contents file)
+ (re-search-forward "^ *gem ['\"]rubocop['\"]" nil t)))))
+
(defun ruby-flymake-auto (report-fn &rest args)
(apply
(if (and ruby-flymake-use-rubocop-if-available