add eslint checker for flymake
This commit is contained in:
6 files changed
+85
-3
No files matched your search
@@ -118,3 +118,9 @@
|
|||||||
[submodule "site-lisp/emmet-mode"]
|
[submodule "site-lisp/emmet-mode"]
|
||||||
path = site-lisp/emmet-mode
|
path = site-lisp/emmet-mode
|
||||||
url = https://github.com/smihica/emmet-mode.git
|
url = https://github.com/smihica/emmet-mode.git
|
||||||
|
[submodule "site-lisp/flymake-eslint"]
|
||||||
|
path = site-lisp/flymake-eslint
|
||||||
|
url = https://github.com/orzechowskid/flymake-eslint.git
|
||||||
|
[submodule "site-lisp/eslint-disable-rule"]
|
||||||
|
path = site-lisp/eslint-disable-rule
|
||||||
|
url = https://github.com/DamienCassou/eslint-disable-rule.git
|
||||||
@@ -121,6 +121,7 @@ If freezing sometimes, decrease it. If stuttering, increase it.")
|
|||||||
(require 'init-eglot)
|
(require 'init-eglot)
|
||||||
(require 'init-prettier)
|
(require 'init-prettier)
|
||||||
(require 'init-emmet)
|
(require 'init-emmet)
|
||||||
|
(require 'init-flymake)
|
||||||
|
|
||||||
|
|
||||||
(setq custom-file (expand-file-name "custom.el" creature/cache-dir))
|
(setq custom-file (expand-file-name "custom.el" creature/cache-dir))
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
;; -*- coding: utf-8; lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defun creature/flymake-show-diagnostics-buffer-and-jump ()
|
||||||
|
(interactive)
|
||||||
|
(flymake-show-diagnostics-buffer)
|
||||||
|
(select-window
|
||||||
|
(get-buffer-window (flymake--diagnostics-buffer-name))))
|
||||||
|
|
||||||
|
(with-eval-after-load 'flymake
|
||||||
|
(add-hook 'flymake-mode-hook #'creature/flymake-add-eslint-backend)
|
||||||
|
|
||||||
|
(lazy-load-set-keys
|
||||||
|
'(("C-c C-n" . flymake-goto-next-error)
|
||||||
|
("C-c C-p" . flymake-goto-prev-error))
|
||||||
|
flymake-mode-map)
|
||||||
|
|
||||||
|
(lazy-load-set-keys
|
||||||
|
'(("ex" . flymake-show-diagnostic)
|
||||||
|
("el" . creature/flymake-show-diagnostics-buffer-and-jump))
|
||||||
|
flymake-mode-map creature/prefix-key)
|
||||||
|
|
||||||
|
(with-eval-after-load 'which-key
|
||||||
|
(which-key-add-keymap-based-replacements
|
||||||
|
flymake-mode-map
|
||||||
|
"e" "errors"
|
||||||
|
"el" "lines"
|
||||||
|
"ex" "error message"
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
|
(autoload 'eslint-disable-rule-disable-next-line "eslint-disable-rule" "" t)
|
||||||
|
(autoload 'eslint-disable-rule-flymake "eslint-disable-rule-flymake")
|
||||||
|
(autoload 'eslint-disable-rule-flycheck "eslint-disable-rule-flycheck")
|
||||||
|
|
||||||
|
|
||||||
|
(defvar creature/eslint-inited nil)
|
||||||
|
|
||||||
|
(autoload 'flymake-eslint-enable "flymake-eslint" "" t)
|
||||||
|
(defun creature/flymake-add-eslint-backend ()
|
||||||
|
(make-local-variable 'creature/eslint-inited)
|
||||||
|
|
||||||
|
(when (and flymake-mode
|
||||||
|
(not creature/eslint-inited)
|
||||||
|
(derived-mode-p 'js-mode 'typescript-mode 'web-mode))
|
||||||
|
|
||||||
|
;; flymake-eslint-enable 内部会再次调用 (flymake-mode 1) ,为防止无限
|
||||||
|
;; 循环调用,用 ‘creature/eslint-inited’ 记录该函数调用状态避免多次调用
|
||||||
|
(setq creature/eslint-inited t)
|
||||||
|
|
||||||
|
(flymake-eslint-enable)
|
||||||
|
(setq flymake-eslint-project-root
|
||||||
|
(creature/flymake-eslint-find-work-dir))))
|
||||||
|
|
||||||
|
(defun creature/flymake-eslint-find-work-dir ()
|
||||||
|
(let ((max-len 0)
|
||||||
|
(curr-len 0)
|
||||||
|
(temp-dir nil)
|
||||||
|
(work-dir nil))
|
||||||
|
(dolist (filename '(".eslintrc"
|
||||||
|
".eslintrc.js"
|
||||||
|
".eslintrc.cjs"
|
||||||
|
".eslintrc.yaml"
|
||||||
|
".eslintrc.yml"
|
||||||
|
".eslintrc.json"
|
||||||
|
"package.json"))
|
||||||
|
(setq temp-dir (locate-dominating-file buffer-file-name filename))
|
||||||
|
(when (stringp temp-dir)
|
||||||
|
(setq curr-len (string-bytes (file-truename temp-dir)))
|
||||||
|
|
||||||
|
(when (> curr-len max-len)
|
||||||
|
(setq max-len curr-len
|
||||||
|
work-dir temp-dir))))
|
||||||
|
work-dir))
|
||||||
|
|
||||||
|
|
||||||
|
(provide 'init-flymake)
|
||||||
@@ -10,9 +10,6 @@
|
|||||||
creature/map
|
creature/map
|
||||||
"b" "buffer"
|
"b" "buffer"
|
||||||
"c" "comments"
|
"c" "comments"
|
||||||
"e" "errors"
|
|
||||||
"el" "lines"
|
|
||||||
"ex" "error message"
|
|
||||||
"f" "files"
|
"f" "files"
|
||||||
"g" "magit"
|
"g" "magit"
|
||||||
"gf" "magit files"
|
"gf" "magit files"
|
||||||
|
|||||||
Submodule
+1
Submodule site-lisp/eslint-disable-rule added at 642ead1241.
Submodule
+1
Submodule site-lisp/flymake-eslint added at efbf9e1fcc.
Reference in new issue
Block a user