Function: yaml-ts-mode-flymake

yaml-ts-mode-flymake is a byte-compiled function defined in yaml-ts-mode.el.gz.

Signature

(yaml-ts-mode-flymake REPORT-FN &rest ARGS)

Documentation

YAML backend for Flymake.

Calls REPORT-FN directly.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/yaml-ts-mode.el.gz
(defun yaml-ts-mode-flymake (report-fn &rest _args)
  "YAML backend for Flymake.
Calls REPORT-FN directly."
  (when (process-live-p yaml-ts-mode--flymake-process)
    (kill-process yaml-ts-mode--flymake-process))
  (let ((yamllint (executable-find "yamllint"))
        (params (append yaml-ts-mode-yamllint-options '("-f" "parsable" "-")))
        (source (current-buffer))
        (diagnostics-pattern (eval-when-compile
                               (rx bol (+? nonl) ":" ; every diagnostic line start with the filename
                                   (group (1+ digit)) ":" ; 1: line
                                   (group (1+ digit)) ":" ; 2: column
                                   (+ (syntax whitespace))
                                   (group (or "[error]" "[warning]")) ; 3: type
                                   (+ (syntax whitespace))
                                   (group (+? nonl)) ;; 4: message
                                   eol))))

    (if (not yamllint)
        (error "Unable to find yamllint command")
      (save-restriction
        (widen)
        (setq yaml-ts-mode--flymake-process
              (make-process
               :name "yaml-ts-mode-flymake"
               :noquery t
               :connection-type 'pipe
               :buffer (generate-new-buffer " *yaml-ts-mode-flymake*")
               :command `(,yamllint ,@params)
               :sentinel
               (lambda (proc _event)
                 (when (eq 'exit (process-status proc))
                   (unwind-protect
                       (if (with-current-buffer source
                             (eq proc yaml-ts-mode--flymake-process))
                           (with-current-buffer (process-buffer proc)
                             (goto-char (point-min))
                             (let (diags)
                               (while (search-forward-regexp
                                       diagnostics-pattern
                                       nil t)
                                 (let* ((beg
                                         (car (flymake-diag-region
                                               source
                                               (string-to-number (match-string 1))
                                               (string-to-number (match-string 2)))))
                                        (end
                                         (cdr (flymake-diag-region
                                               source
                                               (string-to-number (match-string 1))
                                               (string-to-number (match-string 2)))))
                                        (msg (match-string 4))
                                        (type (if (string= "[warning]" (match-string 3))
                                                  :warning
                                                :error)))
                                   (push (flymake-make-diagnostic
                                          source beg end type msg)
                                         diags))
                                 (funcall report-fn diags))))
                         (flymake-log :warning "Canceling obsolete check %s" proc))
                     (kill-buffer (process-buffer proc)))))))
        (process-send-region yaml-ts-mode--flymake-process (point-min) (point-max))
        (process-send-eof yaml-ts-mode--flymake-process)))))