From 6aacfacb67e3416e8fdb84a24423e25f3d4f7cd2 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Wed, 10 Jan 2024 07:55:04 +0800 Subject: [PATCH] use "emacs-flymake-eslint" replace "flymake-eslint" --- .gitmodules | 6 ++--- lisp/init-flymake.el | 49 +++++++++++----------------------- site-lisp/emacs-flymake-eslint | 1 + site-lisp/flymake-eslint | 1 - 4 files changed, 20 insertions(+), 37 deletions(-) create mode 160000 site-lisp/emacs-flymake-eslint delete mode 160000 site-lisp/flymake-eslint diff --git a/.gitmodules b/.gitmodules index 14f5c4d..f434518 100644 --- a/.gitmodules +++ b/.gitmodules @@ -118,9 +118,6 @@ [submodule "site-lisp/emmet-mode"] path = site-lisp/emmet-mode 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 @@ -187,3 +184,6 @@ [submodule "site-lisp/emacs-corfu-doc-terminal"] path = site-lisp/emacs-corfu-doc-terminal url = https://codeberg.org/akib/emacs-corfu-doc-terminal.git +[submodule "site-lisp/emacs-flymake-eslint"] + path = site-lisp/emacs-flymake-eslint + url = https://github.com/zedhugh/emacs-flymake-eslint.git diff --git a/lisp/init-flymake.el b/lisp/init-flymake.el index de3183f..19663c2 100644 --- a/lisp/init-flymake.el +++ b/lisp/init-flymake.el @@ -44,48 +44,31 @@ (autoload 'eslint-disable-rule-flymake "eslint-disable-rule-flymake") (autoload 'eslint-disable-rule-flycheck "eslint-disable-rule-flycheck") +(autoload 'emacs-flymake-eslint-enable "emacs-flymake-eslint" "" t) +(autoload 'emacs-flymake-eslint--checker "emacs-flymake-eslint" "" t) -(defvar-local creature/eslint-inited nil - "Eslint inited for buffer.") +(defun eslint-disable-rule--emacs-flymake-eslint-active-p () + "Return non nil if `flymake-eslint' is enabled in the current buffer." + (and + (featurep 'flymake) + (or (featurep 'flymake-eslint) + (featurep 'emacs-flymake-eslint)) + flymake-mode + (member eslint-disable-rule-flymake--checker-fn flymake-diagnostic-functions))) + +(with-eval-after-load 'eslint-disable-rule-flymake + (setq eslint-disable-rule-flymake--checker-fn #'emacs-flymake-eslint--checker) + (advice-add 'eslint-disable-rule-flymake--eslint-active-p + :override #'eslint-disable-rule--emacs-flymake-eslint-active-p)) -(autoload 'flymake-eslint-enable "flymake-eslint" "" t) (defun creature/flymake-add-eslint-backend () (when (and flymake-mode - (not creature/eslint-inited) (not (derived-mode-p 'js-json-mode 'json-mode 'json-ts-mode)) (derived-mode-p 'js-base-mode 'typescript-mode 'typescript-ts-base-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)) + (emacs-flymake-eslint-enable))) (provide 'init-flymake) diff --git a/site-lisp/emacs-flymake-eslint b/site-lisp/emacs-flymake-eslint new file mode 160000 index 0000000..e67819a --- /dev/null +++ b/site-lisp/emacs-flymake-eslint @@ -0,0 +1 @@ +Subproject commit e67819a556fcab455cd87f3254e7a1b8116a33d8 diff --git a/site-lisp/flymake-eslint b/site-lisp/flymake-eslint deleted file mode 160000 index 82b1345..0000000 --- a/site-lisp/flymake-eslint +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82b1345c699172b6092e13be2c4cc10551d88b90