branch: elpa/flymake-collection
commit f1d889f166934a4d8ec0f0e159e179314c2e8791
Author: Mohsin Kaleem <mohk...@kisara.moe>
Commit: Mohsin Kaleem <mohk...@kisara.moe>

    checkers: Add checker for vale
---
 src/checkers/flymake-collection-vale.el | 75 +++++++++++++++++++++++++++++++++
 src/flymake-collection-hook.el          |  7 ++-
 tests/checkers/installers/vale.bash     | 18 ++++++++
 tests/checkers/test-cases/vale.yml      | 13 ++++++
 4 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/src/checkers/flymake-collection-vale.el 
b/src/checkers/flymake-collection-vale.el
new file mode 100644
index 0000000000..a02105bf77
--- /dev/null
+++ b/src/checkers/flymake-collection-vale.el
@@ -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
diff --git a/src/flymake-collection-hook.el b/src/flymake-collection-hook.el
index 29aa4a686c..1a22b7fefc 100644
--- a/src/flymake-collection-hook.el
+++ b/src/flymake-collection-hook.el
@@ -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))
@@ -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."
diff --git a/tests/checkers/installers/vale.bash 
b/tests/checkers/installers/vale.bash
new file mode 100755
index 0000000000..9e2f9cecd1
--- /dev/null
+++ b/tests/checkers/installers/vale.bash
@@ -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
diff --git a/tests/checkers/test-cases/vale.yml 
b/tests/checkers/test-cases/vale.yml
new file mode 100644
index 0000000000..a1d7f90607
--- /dev/null
+++ b/tests/checkers/test-cases/vale.yml
@@ -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)"

Reply via email to