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))) |
I've updated the kill-buffer
to depend on buffer-name
so it now works in all cases
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purpose: Runs shell command eslint on the buffer's file on save and reverts the buffer.
a few issues
when
condition I added because I didn't manage to get this hook to prompt exclusively in js2-mode.I rather not have it.
q
( read only doesn't do it ) so I got rid of it all together in a kind of an ugly way.. Is there a better way?