abingham / flycheck-vale

Flycheck integration for the vale natural language linter
MIT License
64 stars 16 forks source link

Use `flycheck-define-command-checker` to handle vale process #7

Closed nnicandro closed 7 years ago

nnicandro commented 7 years ago

As per the discussion in #6.

I also took the liberty of cleaning up the code a little bit more in flycheck-vale--output-to-errors.

I also made the :id of the flycheck errors be the Check key of the vale errors. This way you would be able to decide which specific checkers should be disabled.

marsam commented 7 years ago

FWIW, I personally use almost the same patch but with standard input and flycheck-parse-json.

(defun flycheck-vale-parse-errors (output checker buffer)
  (mapcar (lambda (err)
            (let-alist err
              (flycheck-error-new-at
               .Line
               (elt .Span 0)
               (pcase .Severity
                 (`"error"    'error)
                 (`"warning"  'warning)
                 ;; Default to error
                 (_           'error))
               .Message
               :id .Check
               :buffer buffer
               :checker checker)))
          ;; by default Vale return the errors in a object with "stdin.txt" key
          (cdr (assq 'stdin.txt (car (flycheck-parse-json output))))))

(flycheck-define-command-checker 'vale
  :command ("vale" "--output" "JSON")
  :standard-input t
  :error-parser #'flycheck-vale-parse-errors
  :predicate (lambda () flycheck-vale-enabled)
  :modes flycheck-vale-modes)