From 6e2d376f84ddf9af593072954c97e9c82ab85331 Mon Sep 17 00:00:00 2001 From: Dan Orzechowski Date: Fri, 29 Nov 2019 10:58:28 -0500 Subject: [PATCH] add flymake-eslint-project-root --- README.md | 5 +++++ flymake-eslint.el | 51 ++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 318833a..52eaca8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,11 @@ useful variables are members of the `flymake-eslint` group and can be viewed and Useful when the value of variable `exec-path' is set dynamically and the location of eslint might not be known ahead of time." :type 'boolean :group 'flymake-eslint) + +(defcustom flymake-eslint-project-root nil + "Buffer-local. Set to a filesystem path to use that path as the current working directory of the linting process." + :type 'string + :group 'flymake-eslint) ``` ## Bugs diff --git a/flymake-eslint.el b/flymake-eslint.el index 628c014..10a288a 100644 --- a/flymake-eslint.el +++ b/flymake-eslint.el @@ -1,6 +1,6 @@ ;;; flymake-eslint.el --- A Flymake backend for Javascript using eslint -*- lexical-binding: t; -*- -;;; Version: 1.4.0 +;;; Version: 1.5.0 ;;; Author: Dan Orzechowski ;;; Contributor: Terje Larsen @@ -53,11 +53,20 @@ (defcustom flymake-eslint-defer-binary-check nil "Set to t to bypass the initial check which ensures eslint is present. -Useful when the value of `exec-path' is set dynamically and the location of eslint might not be known ahead of time." +Useful when the value of variable `exec-path' is set dynamically and the location of eslint might not be known ahead of time." :type 'boolean :group 'flymake-eslint) +;; useful buffer-local variables + + +(defcustom flymake-eslint-project-root nil + "Buffer-local. Set to a filesystem path to use that path as the current working directory of the linting process." + :type 'string + :group 'flymake-eslint) + + ;; internal variables @@ -121,24 +130,25 @@ Create Flymake diag messages from contents of ESLINT-STDOUT-BUFFER, to be report Create linter process for SOURCE-BUFFER which invokes CALLBACK once linter is finished. CALLBACK is passed one argument, which is a buffer containing stdout from linter." (when (process-live-p flymake-eslint--process) (kill-process flymake-eslint--process)) - (setq flymake-eslint--process - (make-process - :name "flymake-eslint" - :connection-type 'pipe - :noquery t - :buffer (generate-new-buffer " *flymake-eslint*") - :command (list flymake-eslint-executable-name "--no-color" "--no-ignore" "--stdin" "--stdin-filename" (buffer-file-name source-buffer) (or flymake-eslint-executable-args "")) - :sentinel (lambda (proc &rest ignored) - ;; do stuff upon child process termination - (when (and (eq 'exit (process-status proc)) - ;; make sure we're not using a deleted buffer - (buffer-live-p source-buffer) - ;; make sure we're using the latest lint process - (with-current-buffer source-buffer (eq proc flymake-eslint--process))) - ;; read from eslint output then destroy temp buffer when done - (let ((proc-buffer (process-buffer proc))) - (funcall callback proc-buffer) - (kill-buffer proc-buffer))))))) + (let ((default-directory (or flymake-eslint-project-root default-directory))) + (setq flymake-eslint--process + (make-process + :name "flymake-eslint" + :connection-type 'pipe + :noquery t + :buffer (generate-new-buffer " *flymake-eslint*") + :command (list flymake-eslint-executable-name "--no-color" "--no-ignore" "--stdin" "--stdin-filename" (buffer-file-name source-buffer) (or flymake-eslint-executable-args "")) + :sentinel (lambda (proc &rest ignored) + ;; do stuff upon child process termination + (when (and (eq 'exit (process-status proc)) + ;; make sure we're not using a deleted buffer + (buffer-live-p source-buffer) + ;; make sure we're using the latest lint process + (with-current-buffer source-buffer (eq proc flymake-eslint--process))) + ;; read from eslint output then destroy temp buffer when done + (let ((proc-buffer (process-buffer proc))) + (funcall callback proc-buffer) + (kill-buffer proc-buffer)))))))) (defun flymake-eslint--check-and-report (source-buffer flymake-report-fn) "Internal function. @@ -168,6 +178,7 @@ Run eslint on the current buffer, and report results using FLYMAKE-REPORT-FN. A (interactive) (if (not flymake-eslint-defer-binary-check) (flymake-eslint--ensure-binary-exists)) + (make-local-variable 'flymake-eslint-project-root) (flymake-mode t) (add-hook 'flymake-diagnostic-functions 'flymake-eslint--checker nil t))