Use Vale on Neovim

Showing warnings from Vale inside Neovim using EFM-langserver

Vale is a command-line tool that brings code-like linting to prose. Very fast and works well with markup.

To use Vale with Neovim you will need to be able to run vale, process, and show the errors. A few plugins that can support this nvim-lint (builtin support), ale. As well as LSP servers EFM-langserver or null-ls.

I personally went with the LSP option as I handle most of my formatting and linting through it.

Vale and Error Format

To do this we will use the output from vale --output=line. This will output a line for each error.

/home/rockerboo/code/davelage/content/use-vale-on-neovim.md:9:105:[write-good.Weasel] 'few' is a weasel word!

This is formatted as

Path:Line:Column:Message

and using the vim errorformat we can extract this. See :h errorformat in Neovim for more details on this formatting system.

%f:%l:%c:%m

You will likely be able to set the format inside your linter of choice.

If you, like me, want to also have a severity, (error, warning, notice) then you’ll need to use a go template for making a custom output. Here is a simple example with Severity. You likely want to put this file somewhere in your user files since you will want to use it for every project. I chose ~/.config/vale/output.tmpl.

{{- /* Very much like `vale --output=line`, but with the severities too! -}}
{{- /* See also https://docs.errata.ai/vale/cli#template-examples */ -}}
{{- /* https://github.com/errata-ai/vale/issues/350 */ -}}
{{- range .Files}}
	{{- $p := .Path -}}
	{{- range .Alerts -}}
		{{- printf "%s:%d:%d:%s:[%s] %s" $p .Line (index .Span 0) .Severity .Check .Message }}
	{{end -}}
{{end}}

This gives us this format with the severity

/home/rockerboo/code/davelage/content/posts/use-vale-on-neovim.md:39:251:warning:[Google.Will] Avoid using 'will'.

Integration

And then I put it all together using EFM-langserver. This is part of the yaml config. EFM-langserver allows use of the vim.diagnostic API’s to interact with these alerts/errors.

Diagnostic floating window showing warning from Vale

vale: &vale
	lint-command: 'vale --output=/home/rockerboo/.config/vale/output.tmpl '
	lint-ignore-exit-code: true
	lint-formats:
		- '%f:%l:%c:%trror:%m'
		- '%f:%l:%c:%tarning:%m'
	require-marker: true
	root-markers:
		- '.vale.ini'