Fix current buffer automatically
This package have 2 important buffer local variables auto-fix-command
and auto-fix-option
. Please let you set using the hook.
This is the command to fix code. Default value is nil
.
This is the option string to fix for the command. Default value is --fix
.
This is the prefix for temprary file. Default value is auto_fix_
.
To enable auto-fix before saving add the following to your init file:
(add-hook 'auto-fix-mode-hook
(lambda () (add-hook 'before-save-hook #'auto-fix-before-save)))
(defun setup-ruby-auto-fix ()
(setq-local auto-fix-command "rubocop")
(setq-local auto-fix-option "-a")
(auto-fix-mode +1))
(add-hook 'ruby-mode-hook #'setup-ruby-auto-fix)
(add-hook 'auto-fix-mode-hook
(lambda () (add-hook 'before-save-hook #'auto-fix-before-save)))
(defun setup-ts-auto-fix ()
(setq-local auto-fix-command "tslint")
(auto-fix-mode +1))
(add-hook 'typescript-mode-hook #'setup-ts-auto-fix)
;; Flycheck using project linter
(defun my-use-local-lint ()
"Use local lint if exist it."
(let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory) "node_modules"))
(tslint (and root (expand-file-name "node_modules/.bin/tslint" root))))
(when (and tslint (file-executable-p tslint))
(setq-local flycheck-typescript-tslint-executable tslint)
(setq-local auto-fix-command tslint))))
(add-hook 'flycheck-mode-hook #'my-use-local-lint)
;; auto fix
(add-hook 'auto-fix-mode-hook
(lambda () (add-hook 'before-save-hook #'auto-fix-before-save)))
(add-hook 'typescript-mode-hook #'auto-fix-mode)