From 889a40cdc3ca204cf7c7da90d60976f1daea94fb Mon Sep 17 00:00:00 2001 From: Seong Yong-ju Date: Mon, 11 Nov 2019 17:17:31 +0900 Subject: [PATCH] Add eslint_d support for JavaScript, React, TypeScript modes --- CHANGELOG.develop | 3 +++ layers/+frameworks/react/packages.el | 3 ++- layers/+lang/javascript/funcs.el | 4 ++++ layers/+lang/javascript/packages.el | 3 ++- layers/+lang/typescript/funcs.el | 4 ++++ layers/+lang/typescript/packages.el | 15 +++++++++++---- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index d23dbd239..afbe93145 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -177,6 +177,7 @@ the [[file:CHANGELOG.org][CHANGELOG.org]] file. - CoffeeScript support has been extracted from the =javascript= layer into the new =coffeescript= layer. - Added missing prefix for =js2-mode= +- Added =eslint_d= support (thanks to Seong Yong-ju) ***** Markdown - Key bindings: - Removed ~SPC m i I~ for =markdown-insert-reference-image= @@ -2532,6 +2533,7 @@ Other: - Open =.jsx= files with =rjsx-mode= (thanks to Thomas de BeauchĂȘne) - Made =react= layer respect =javascript= layers variable =javascript-fmt-on-save= (thanks to Tommy Groshong) + - Added =eslint_d= support (thanks to Seong Yong-ju) - Key bindings: - Added =import-js= support with key bindings: - ~SPC m i i~ to mport the module for the variable under the cursor @@ -2878,6 +2880,7 @@ Other: - Added a =typescript-lsp-linter= variable to allow for disabling =lsp= as a linter, when =lsp= is set as the backend (thanks to Thanh Vuong) - Fix =tide= with =tsx= files (thanks to Aaron Jensen) +- Added =eslint_d= support (thanks to Seong Yong-ju) **** Vagrant - Key bindings: - move key bindings prefix to ~SPC a V~ (thanks to Thomas de BeauchĂȘne) diff --git a/layers/+frameworks/react/packages.el b/layers/+frameworks/react/packages.el index e2b596c8a..acad2e270 100644 --- a/layers/+frameworks/react/packages.el +++ b/layers/+frameworks/react/packages.el @@ -42,7 +42,8 @@ (with-eval-after-load 'flycheck (dolist (checker '(javascript-eslint javascript-standard)) (flycheck-add-mode checker 'rjsx-mode))) - (spacemacs/enable-flycheck 'rjsx-mode)) + (spacemacs/enable-flycheck 'rjsx-mode) + (add-hook 'rjsx-mode-hook #'spacemacs//javascript-setup-checkers 'append)) (defun react/pre-init-import-js () (when (eq javascript-import-tool 'import-js) diff --git a/layers/+lang/javascript/funcs.el b/layers/+lang/javascript/funcs.el index 6ba73d6ed..bd96b08d1 100644 --- a/layers/+lang/javascript/funcs.el +++ b/layers/+lang/javascript/funcs.el @@ -153,6 +153,10 @@ ;; Others +(defun spacemacs//javascript-setup-checkers () + (when-let* ((found (executable-find "eslint_d"))) + (set (make-local-variable 'flycheck-javascript-eslint-executable) found))) + (defun spacemacs/javascript-format () "Call formatting tool specified in `javascript-fmt-tool'." (interactive) diff --git a/layers/+lang/javascript/packages.el b/layers/+lang/javascript/packages.el index d604c96da..d32a5621b 100644 --- a/layers/+lang/javascript/packages.el +++ b/layers/+lang/javascript/packages.el @@ -52,7 +52,8 @@ (add-hook `js2-mode-hook `turn-on-evil-matchit-mode)) (defun javascript/post-init-flycheck () - (spacemacs/enable-flycheck 'js2-mode)) + (spacemacs/enable-flycheck 'js2-mode) + (add-hook 'js2-mode-hook #'spacemacs//javascript-setup-checkers 'append)) (defun javascript/post-init-ggtags () (add-hook 'js2-mode-local-vars-hook #'spacemacs/ggtags-mode-enable)) diff --git a/layers/+lang/typescript/funcs.el b/layers/+lang/typescript/funcs.el index 65484f3d5..a41b6bd6f 100644 --- a/layers/+lang/typescript/funcs.el +++ b/layers/+lang/typescript/funcs.el @@ -175,3 +175,7 @@ (dolist (value values) (add-to-list 'safe-local-variable-values (cons 'typescript-backend value)))) + +(defun spacemacs//typescript-setup-checkers () + (when-let* ((found (executable-find "eslint_d"))) + (set (make-local-variable 'flycheck-javascript-eslint-executable) found))) diff --git a/layers/+lang/typescript/packages.el b/layers/+lang/typescript/packages.el index 008ba19aa..eff98540b 100644 --- a/layers/+lang/typescript/packages.el +++ b/layers/+lang/typescript/packages.el @@ -59,16 +59,23 @@ (message "Invalid typescript-layer configuration, no such linter: %s" typescript-linter)))))) +(defun typescript/set-lsp-linter () + (with-eval-after-load 'lsp-ui + (with-eval-after-load 'flycheck + (flycheck-add-mode 'javascript-eslint 'typescript-tsx-mode) + (flycheck-add-mode 'javascript-eslint 'typescript-mode)))) + (defun typescript/post-init-flycheck () (spacemacs/enable-flycheck 'typescript-mode) (spacemacs/enable-flycheck 'typescript-tsx-mode) (cond ((eq (spacemacs//typescript-backend) `tide) (typescript/set-tide-linter)) ((eq (spacemacs//typescript-backend) `lsp) - (with-eval-after-load 'lsp-ui - (with-eval-after-load 'flycheck - (flycheck-add-mode 'javascript-eslint 'typescript-tsx-mode) - (flycheck-add-mode 'javascript-eslint 'typescript-mode)))))) + (typescript/set-lsp-linter))) + + (spacemacs/add-to-hooks #'spacemacs//typescript-setup-checkers + '(typescript-mode-hook typescript-tsx-mode-hook) + t)) (defun typescript/post-init-smartparens () (if dotspacemacs-smartparens-strict-mode