Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matthewpersico/eeeb263acd42570ba7abe1912ad5f506 to your computer and use it in GitHub Desktop.
Save matthewpersico/eeeb263acd42570ba7abe1912ad5f506 to your computer and use it in GitHub Desktop.
shellcheck-disable-error-at-point
(defun shellcheck-disable-error-at-point (&optional pos)
"Insert a shellcheck disable directive at the current error in the code."
(interactive)
(-when-let* ((error (tabulated-list-get-id pos))
(buffer (flycheck-error-buffer error))
(id (flycheck-error-id error))
;;(message (flycheck-error-message error))
)
(when (buffer-live-p buffer)
(if (eq (window-buffer) (get-buffer flycheck-error-list-buffer))
;; When called from within the error list, keep the error list,
;; otherwise replace the current buffer.
(pop-to-buffer buffer 'other-window)
(switch-to-buffer buffer))
(let ((pos (flycheck-error-pos error)))
(unless (eq (goto-char pos) (point))
;; If widening gets in the way of moving to the right place, remove it
;; and try again
(widen)
(goto-char pos))
;; Move to start of line with error position.
(beginning-of-line-text)
;; The only error I know of where the disable directive is AFTER the
;; error position, not before.
(when (string-equal id "SC2148")
(forward-line)
)
;; Insert the disable line
(insert (format "# shellcheck disable=%s\n" id))
;; Indent it
(indent-for-tab-command))
;; Re-highlight the errors
(flycheck-error-list-highlight-errors 'preserve-pos))))
(define-key flycheck-error-list-mode-map (kbd "d") #'shellcheck-disable-error-at-point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment