Skip to content

Commit

Permalink
checkers: Add checker for vale
Browse files Browse the repository at this point in the history
  • Loading branch information
mohkale committed Mar 16, 2024
1 parent 93f3dec commit f1d889f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
75 changes: 75 additions & 0 deletions src/checkers/flymake-collection-vale.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
;;; flymake-collection-vale.el --- vale diagnostic function -*- lexical-binding: t -*-

;; Copyright (c) 2024 Mohsin Kaleem

;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:

;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.

;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.

;;; Commentary:

;; `flymake' syntax checker for prose using vale.

;;; Code:

(require 'flymake)
(require 'flymake-collection)

(eval-when-compile
(require 'flymake-collection-define))

;;;###autoload (autoload 'flymake-collection-vale "flymake-collection-vale")
(flymake-collection-define-enumerate flymake-collection-vale
"A prose syntax and style checker using vale.
See https://vale.sh/."
:title "vale"
:pre-let ((vale-exec (executable-find "vale")))
:pre-check (unless vale-exec
(error "Cannot find vale executable"))
:write-type 'pipe
:command `(,vale-exec
,@(let* ((file-name (buffer-file-name flymake-collection-source))
(extension (and file-name (file-name-extension file-name))))
(when extension
(list (concat "--ext=." extension))))
"--output=JSON")
:generator
(cdaar
(flymake-collection-parse-json
(buffer-substring-no-properties
(point-min) (point-max))))
:enumerate-parser
(let-alist it
`(,flymake-collection-source
,@(with-current-buffer flymake-collection-source
(save-excursion
(goto-char (point-min))
(unless (and (eq .Line 1)
(not (bolp)))
(forward-line (1- .Line)))
(list (+ (point) (1- (car .Span)))
(+ (point) (cadr .Span)))))
,(pcase .Severity
("suggestion" :note)
("warning" :warning)
((or "error" _) :error))
,(concat (propertize (concat "[" .Check "]") 'face 'flymake-collection-diag-id) " "
.Message))))

(provide 'flymake-collection-vale)
;;; flymake-collection-vale.el ends here
7 changes: 5 additions & 2 deletions src/flymake-collection-hook.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
(less-mode flymake-collection-less)
(markdown-mode
flymake-collection-markdownlint
flymake-collection-proselint)
flymake-collection-proselint
(flymake-collection-vale :disabled t))
(lua-mode
flymake-collection-luacheck
(flymake-collection-lua :disabled t))
Expand All @@ -84,7 +85,9 @@
flymake-collection-yamllint)
((web-mode html-ts-mode) .
(flymake-collection-html-tidy))
(org-mode flymake-collection-proselint)
(org-mode
flymake-collection-proselint
(flymake-collection-vale :disabled t))
(notmuch-message-mode flymake-collection-proselint)
(nxml-mode flymake-collection-xmllint))
"Configuration mapping major-modes to `flymake' backends."
Expand Down
18 changes: 18 additions & 0 deletions tests/checkers/installers/vale.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cd "$(mktemp -d)" || exit 1
curl -L https://github.com/errata-ai/vale/releases/download/v3.3.0/vale_3.3.0_Linux_64-bit.tar.gz |
tar -xzv

mv vale /usr/bin/
cat > /.vale.ini <<-EOF
# Generated through https://vale.sh/generator
StylesPath = styles
MinAlertLevel = suggestion
Packages = Google, proselint
[*]
BasedOnStyles = Vale, Google, proselint
EOF
vale sync

rm -rf "$(pwd)"
cd - || exit 1
13 changes: 13 additions & 0 deletions tests/checkers/test-cases/vale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
checker: flymake-collection-vale
tests:
- name: no-lints
file: ""
lints: []
- name: Mispelling
file: |
# Foo Bar Baz
lints:
- point: [1, 10]
level: error
message: "[Vale.Spelling] Did you really mean 'Baz'? (vale)"

0 comments on commit f1d889f

Please sign in to comment.