-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This code is merely an adaptation for flycheck eslint to use `source' instead of `source-original' as the argument for commandline. For more details, ref: flycheck/flycheck#2011
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
;;; bvr-flycheck-eslint --- Flycheck eslint adaptor | ||
;;; --------------------------------------------------- | ||
|
||
;;; Usage: | ||
;;; --------------------------------------------------- | ||
;;; Include this in your load-path, and either, with | ||
;;; use-package : | ||
;;; | ||
;;; (use-package bvr-flycheck-eslint) | ||
;;; | ||
;;; or otherwise simply | ||
;;; | ||
;;; (require 'bvr-flycheck-eslint) | ||
|
||
;;; Commentary: | ||
;;; --------------------------------------------------- | ||
;;; This code is merely an adaptation for flycheck | ||
;;; eslint to use `source' instead of `source-original' | ||
;;; as the argument for commandline. | ||
;;; | ||
;;; For more details, ref: | ||
;;; https://github.com/flycheck/flycheck/issues/2011 | ||
|
||
;;; Code: | ||
;;; --------------------------------------------------- | ||
(defun bvr-flycheck-eslint--find-working-directory (_checker) | ||
"Look for a working directory to run ESLint CHECKER in. | ||
This will be the directory that contains the `node_modules' | ||
directory. If no such directory is found in the directory | ||
hierarchy, it looks first for `.eslintignore' and then for | ||
`.eslintrc' files to detect the project root." | ||
(let* ((file (or (buffer-file-name) default-directory))) | ||
(when file | ||
(or (locate-dominating-file file "node_modules") | ||
(locate-dominating-file file ".eslintignore") | ||
(locate-dominating-file file ".eslintrc") | ||
(locate-dominating-file file ".eslintrc.js") | ||
(locate-dominating-file file ".eslintrc.json") | ||
(locate-dominating-file file ".eslintrc.yaml") | ||
(locate-dominating-file file ".eslintrc.yml"))))) | ||
|
||
|
||
|
||
(flycheck-define-checker bvr-javascript-eslint | ||
"A Javascript syntax and style checker using eslint. | ||
See URL `https://eslint.org/'." | ||
:command ("eslint" "--format=json" | ||
(option-list "--rulesdir" flycheck-eslint-rules-directories) | ||
(eval flycheck-eslint-args) | ||
"--stdin" "--stdin-filename" source) | ||
:standard-input t | ||
:error-parser flycheck-parse-eslint | ||
:enabled (lambda () (flycheck-eslint-config-exists-p)) | ||
:modes (js-mode js-jsx-mode js2-mode js2-jsx-mode js3-mode rjsx-mode | ||
typescript-mode js-ts-mode typescript-ts-mode tsx-ts-mode) | ||
:working-directory bvr-flycheck-eslint--find-working-directory | ||
:verify | ||
(lambda (_) | ||
(let* ((default-directory | ||
(flycheck-compute-working-directory 'bvr-javascript-eslint)) | ||
(have-config (flycheck-eslint-config-exists-p))) | ||
(list | ||
(flycheck-verification-result-new | ||
:label "config file" | ||
:message (if have-config "found" "missing or incorrect") | ||
:face (if have-config 'success '(bold error)))))) | ||
:error-explainer | ||
(lambda (err) | ||
(let ((error-code (flycheck-error-id err)) | ||
(url "https://eslint.org/docs/rules/%s")) | ||
(and error-code | ||
;; skip non-builtin rules | ||
(not ;; `seq-contains-p' is only in seq >= 2.21 | ||
(with-no-warnings (seq-contains error-code ?/))) | ||
`(url . ,(format url error-code)))))) | ||
|
||
|
||
(add-to-list 'flycheck-checkers 'bvr-javascript-eslint) | ||
|
||
(provide 'bvr-flycheck-eslint) | ||
;;; bvr-flycheck-eslint.el ends here |