Guest User

Untitled

a guest
Dec 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. (defun is-ruby-file (f)
  2. (if (string-match "\\.rb$" f)
  3. t
  4. nil
  5. ))
  6.  
  7. (defun is-javascript-file (f)
  8. (if (or
  9. (string-match "\\.jsx?$" f)
  10. (string-match "\\.json$" f))
  11. t
  12. nil
  13. ))
  14.  
  15. ;;; runs eslint --fix on the current file after save
  16. ;;; alpha quality -- use at your own risk
  17.  
  18. (defun prettier-fix-file ()
  19. (interactive)
  20. (shell-command (concat "yarn prettier --write " (buffer-file-name))))
  21.  
  22. (defun prettier-fix-file-and-revert ()
  23. (interactive)
  24. (if (is-javascript-file (buffer-file-name))
  25. (funcall (lambda ()
  26. (prettier-fix-file)
  27. (revert-buffer t t)))))
  28.  
  29. (defun rubocop-fix-file ()
  30. (interactive)
  31. (shell-command (concat "bundle exec rubocop -a " (buffer-file-name) )))
  32.  
  33. (defun rubocop-fix-file-and-revert ()
  34. (interactive)
  35. (if (is-ruby-file (buffer-file-name))
  36. (funcall (lambda ()
  37. (rubocop-fix-file)
  38. (revert-buffer t t)))))
  39.  
  40. (add-hook 'after-save-hook #'rubocop-fix-file-and-revert)
  41. (add-hook 'after-save-hook #'prettier-fix-file-and-revert)
Add Comment
Please, Sign In to add comment