Skip to content

Instantly share code, notes, and snippets.

@AloisJanicek
Forked from ustun/eslint-auto.el
Last active February 10, 2022 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AloisJanicek/e1aec5c080da62683d17ece70b56120d to your computer and use it in GitHub Desktop.
Save AloisJanicek/e1aec5c080da62683d17ece70b56120d to your computer and use it in GitHub Desktop.
Run `prettier-stylelint --write` on css file opened in Emacs buffer when saving it
;;; runs `prettier-stylelint --write` on the current file after save
;;; alpha quality -- use at your own risk
(defun prettier-stylelint-fix-file-and-revert ()
"Prettify current file and apply fixes only in css-mode or scss-mode"
(interactive)
(when (or (eq major-mode 'css-mode) (eq major-mode 'scss-mode))
(message "prettier-stylelint fixing your file" (buffer-file-name)) ;;optional line, you can remove it
(shell-command (concat "prettier-stylelint --quiet --write " (buffer-file-name)))
(revert-buffer t t)))
(add-hook 'after-save-hook #'prettier-stylelint-fix-file-and-revert)
@AloisJanicek
Copy link
Author

AloisJanicek commented May 16, 2018

Really cool. prettier-stylelint not only prettifies current file, but also runs stylelint's --fix, so you end up with nice looking and fixed file with just one command.

But it is slooooow. I wish there was something like eslint_d and eslintd-fix, but for stylelint.

@AloisJanicek
Copy link
Author

Don't use this.
Instead use stylelintd-fix.el (based on eslintd-fix.el)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment