Last active
August 22, 2019 16:26
-
-
Save manandearth/5a5a5052878fa3849ec2e8da7cbcfc0a to your computer and use it in GitHub Desktop.
eslint shell-command hook for js modes
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
(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) | |
(when (or(eq major-mode 'js2-mode) | |
(eq major-mode 'rjsx-mode) | |
(eq major-mode 'js2-jsx-mode)) | |
(eslint-fix-file) | |
;;the third t argument is for preserving the modes on revert. | |
(revert-buffer t t t) | |
;;closing any returned output from shell | |
(other-window 1) | |
(if (equal (buffer-name) "*Shell Command Output*") | |
(progn (kill-buffer) (message "linted with output")) | |
(message "linted")) | |
(other-window 1) | |
)) | |
(add-hook 'js2-mode-hook | |
(lambda () | |
(add-hook 'after-save-hook #'eslint-fix-file-and-revert))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the
kill-buffer
to depend onbuffer-name
so it now works in all cases