Created
January 12, 2016 23:59
-
-
Save ustun/73321bfcb01a8657e5b8 to your computer and use it in GitHub Desktop.
run eslint --fix on emacs file save
This file contains hidden or 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
;;; runs eslint --fix on the current file after save | |
;;; alpha quality -- use at your own risk | |
(defun eslint-fix-file () | |
(interactive) | |
(message "eslint --fixing the file" (buffer-file-name)) | |
(shell-command (concat "eslint --fix " (buffer-file-name)))) | |
(defun eslint-fix-file-and-revert () | |
(interactive) | |
(eslint-fix-file) | |
(revert-buffer t t)) | |
(add-hook 'js2-mode-hook | |
(lambda () | |
(add-hook 'after-save-hook #'eslint-fix-file-and-revert))) |
I ended up integrating this into flycheck so that eslint fixes things continuously, without saving.
Hi @mattdeboard I must have missed your message. Glad it was useful.
@rpatterson Thanks, looks great to have it interested.
FWIW, I have been using prettier-mode recently and using eslint at the last minute. I also use the tide-mode in js to do some checks.
Hi every one,
thanks a lot for the snippet.
If, like me, you call it manually and you get an annoyoing buffer that display shell message,
replace shell-command
with call-process-shell-command
(grabbed at https://stackoverflow.com/questions/11613974/how-can-the-shell-command-output-buffer-be-kept-in-the-background)
(defun tim-eslint-fix-file ()
(interactive)
(message "eslint --fix the file" (buffer-file-name))
(call-process-shell-command
(concat "yarn eslint --fix " (buffer-file-name))
nil "*Shell Command Output*" t)
(revert-buffer t t))
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the snippet Ustun! Imagine my surprise when googling "emacs eslint fix" took me to this snippet. We met a few years ago @ Strange Loop iirc :)