aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2018-12-25 18:23:01 +0200
committerDmitry Gutov2018-12-25 18:23:01 +0200
commit9916410fa8bc765677e2d09384599aa85945967d (patch)
tree8e7fcc5c38ec6d50e7eec4935bc747783e25373b
parente533848dd35426f8328f3d6e290ee5c08a776553 (diff)
downloademacs-9916410fa8bc765677e2d09384599aa85945967d.tar.gz
emacs-9916410fa8bc765677e2d09384599aa85945967d.zip
Prepend 'rubocop' with 'bundle exec' when appropriate
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/progmodes/ruby-mode.el15
2 files changed, 16 insertions, 1 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 34151d8caad..e427e84780d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -511,6 +511,8 @@ This enables more efficient backends. See the docstring of
511*** The Rubocop Flymake diagnostic function will only run Lint cops if 511*** The Rubocop Flymake diagnostic function will only run Lint cops if
512it can't find the config file. 512it can't find the config file.
513 513
514*** Rubocop is called with 'bundle exec' if Gemfile mentions it.
515
514** Package 516** Package
515 517
516*** New function 'package-get-version' lets packages query their own version. 518*** New function 'package-get-version' lets packages query their own version.
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
2323 (let ((command (list "rubocop" "--stdin" buffer-file-name "--format" "emacs" 2323 (let ((command (list "rubocop" "--stdin" buffer-file-name "--format" "emacs"
2324 "--cache" "false" ; Work around a bug in old version. 2324 "--cache" "false" ; Work around a bug in old version.
2325 "--display-cop-names")) 2325 "--display-cop-names"))
2326 (default-directory default-directory)
2326 config-dir) 2327 config-dir)
2327 (when buffer-file-name 2328 (when buffer-file-name
2328 (setq config-dir (locate-dominating-file buffer-file-name 2329 (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
2331 (setq command (append command '("--lint"))) 2332 (setq command (append command '("--lint")))
2332 (setq command (append command (list "--config" 2333 (setq command (append command (list "--config"
2333 (expand-file-name ruby-rubocop-config 2334 (expand-file-name ruby-rubocop-config
2334 config-dir))))) 2335 config-dir))))
2336 (when (ruby-flymake-rubocop--use-bundler-p config-dir)
2337 (setq command (append '("bundle" "exec") command))
2338 ;; In case of a project with multiple nested subprojects,
2339 ;; each one with a Gemfile.
2340 (setq default-directory config-dir)))
2335 2341
2336 (ruby-flymake--helper 2342 (ruby-flymake--helper
2337 "rubocop-flymake" 2343 "rubocop-flymake"
@@ -2369,6 +2375,13 @@ If there is no Rubocop config file, Rubocop will be passed a flag
2369 into diags 2375 into diags
2370 finally (funcall report-fn diags))))))) 2376 finally (funcall report-fn diags)))))))
2371 2377
2378(defun ruby-flymake-rubocop--use-bundler-p (dir)
2379 (let ((file (expand-file-name "Gemfile" dir)))
2380 (and (file-exists-p file)
2381 (with-temp-buffer
2382 (insert-file-contents file)
2383 (re-search-forward "^ *gem ['\"]rubocop['\"]" nil t)))))
2384
2372(defun ruby-flymake-auto (report-fn &rest args) 2385(defun ruby-flymake-auto (report-fn &rest args)
2373 (apply 2386 (apply
2374 (if (and ruby-flymake-use-rubocop-if-available 2387 (if (and ruby-flymake-use-rubocop-if-available