
Checking Text with Vale
I’m currently reading Brian P. Hogan‘s book ‘Write Better with Vale‘, about Vale (a command line tool to ease follwing style guides in prose text).
While intended for prose text (as far as I know), Vale can also process any text file, including code.
When I tried to copy & paste commands from the epub version of the book, into my shell, I got an error message:
> vale .
E100 [NewE201] Runtime error
The path ‘…/vale_example_project/../styles’ does not exist.
Execution stopped with code 1.
After some exploration, I figured that some zero-width-space characters were in the INI file I copied into my example project (and reported it over at the books feedback site).
Then I realised that I could create my own Vale rule to detect these invisible characters in text files.
Now, Vale is configured using an INI file. There you declare where it can find the styles and which rules should be applied for which files (see https://vale.sh/docs/vale-ini for more details).
I set up a new rule in a file …/styles/Custom/NoZeroWidthSpaces.yml
:
# Styles/Custom/NoZeroWidthSpace.yml extends: existence message: "Avoid using zero-width or invisible characters (%s)." level: error scope: raw raw: - '[\u200B\u200C\u200D\u2060\uFEFF]'
I set up Vale to use this new Custom
rule in .vale.ini
like this:
StylesPath = styles [*.md] BasedOnStyles = Custom
With that, I get a nice message when running vale
against a file riddled with those characters::
> vale . example.md 1:111 error Avoid using zero-width or Custom.NoZeroWidthSpaces invisible characters ().
Admittedly, the empty looking parentheses aren’t very instructive, since they contain invisible characters. At least it’s possible to copy-&-paste them to find out what they are in other tools.