Vale CMS Need more than a rule playground? Explore

← Blog

Vale lints markup now

The v3.30.0 release of Vale can lint a page's markup as well as its prose, and a new package reproduces markdownlint rule for rule.

Joseph Kato

·7 min read

On this page ›
  1. Six years of “out of scope”
  2. An example: blocks
  3. The top of the page
  4. Inside a block
  5. One way to write it
  6. Params
  7. Scripts
  8. The proof: markdownlint as a style
  9. Conclusion

The v3.30.0 release of Vale includes a significant, long-requested feature: the ability to lint a page’s markup, and not just its prose.

Vale has always read markup in order to skip it. It finds the prose in a Markdown page, a reStructuredText file, or a Go comment and checks that.

The problem is that a lot of what a style guide cares about isn’t prose at all: whether the headings skip a level, whether a list is indented by two spaces or four, whether a code block states its language. Up to this point, those questions had to go to a second tool.

With v3.30.0, a rule can read a page exactly as it’s written, one block at a time. There’s no new extension point to learn, either — the ones you already know (existence, metric, consistency, and script) do the work, and nearly everything new in this release is a scope.

Six years of “out of scope”

People have been asking for this since 2018. In 2020, a writer on GitLab’s documentation team asked for a way to match raw markup. Here’s what I said at the time:

I’m of the belief that a well-implemented linter for Markdown (or another such format) shouldn’t rely on regex for its understanding of the format.

That request eventually became scope: raw, which gives a rule the entire file as a single string. This works well enough for simple patterns, but the problem I was worried about is still there. A rule on raw has to figure out for itself where a code block ends and whether or not a # is a heading.

I still think that answer was the right one. The difference now is that a rule doesn’t have to understand the format — Vale’s parser already does, and it can tell a rule where everything is.

An example: blocks

In order to get a better idea of how this works, we’re going to look at a common request: a blank line after every code block. Here’s the rule:

yaml
# styles/House/CodeBlocks.yml extends: metric message: "Put a blank line after this code block." scope: 'raw & doc(pre.fenced)' formula: blank_after < 1 && last == 0

The new part is the scope. raw & doc(...) gives the rule each block that the selector matches, with its markers and indentation, exactly as it appears in the file.

The selector itself is CSS over the page’s structure (the same one you’d use in a doc(...) scope for prose).

The raw half is what makes this a rule about markup. On its own, doc(pre.fenced) is a prose scope: it gives a rule the text inside an element with the markup removed, and a code block has no prose to give. Adding raw asks for the same blocks as they’re written instead:

Pick a selector to see what each scope hands the rule.

Code block

The page

1# Install **Vale**
2
3Run the installer:
4
5```sh
6brew install vale
7```
8Then sync your styles:
9
10* Run the `sync` command.
11* Commit the [config](.vale.ini).

doc(pre.fenced)

The prose inside, markup removed.

Nothing. Code isn’t prose, so there is no text here for a rule to read.

raw & doc(pre.fenced)

Each block as written, and where it sits.

```sh
brew install vale
```

lines 5–7 · blank_before 1 · blank_after 0

One page and three selectors. A doc(...) scope reads an element's prose; raw & doc(...) reads the same element's lines as written, with the blank lines around it counted.

Each block also comes with a set of counts that a metric formula can read: its indentation, the blank lines around it, a heading’s level and the level of the heading before it, an item’s position in its list, and so on. This means that a rule for skipped heading levels is a single formula:

yaml
# styles/House/HeadingLevels.yml extends: metric message: "Don't skip a heading level." scope: 'raw & doc(:heading)' formula: heading_prev > 0 && heading_level > heading_prev + 1

The :heading selector is also new. It matches a heading of any level, so we don’t have to write out h1, h2, h3, h4, h5, h6, and it works with the rest of CSS: doc(:heading:has(code)) is every heading that contains a code span.

Now, let’s say we have a page that jumps from a level-one heading to a level-three one on line 3 and closes a code block on line 7 with text directly under it. When we run Vale, we get both alerts:

console
$ vale --output=line guide.md guide.md:3:1:House.HeadingLevels:Don't skip a heading level. guide.md:7:1:House.CodeBlocks:Put a blank line after this code block.

The top of the page

Many markup rules are about how a page starts, and front matter makes that harder to say than it should be: is the “first” block the front matter or the heading under it? There are two new scopes to help with this.

The first is :first-block, which is the block a page opens with after any front matter. Here’s a rule that requires a title, whether or not the page has front matter:

yaml
extends: existence message: "Open the page with a title." scope: 'raw & doc(:first-block:not(h1)::first-line)'

You may have noticed that this rule doesn’t have any tokens. When a rule is scoped to a part of the page as written, the scope can be the entire rule — Vale simply reports whatever the scope selects.

The second is raw & frontmatter, which is the front matter itself. It has the same counts as a block, so our code block rule from above only needs a different scope:

yaml
extends: metric message: "Put a blank line after the front matter." scope: 'raw & frontmatter' formula: blank_after < 1 && last == 0

Inside a block

Blocks contain code spans, links, emphasis, and footnotes, and a rule that’s about one of those shouldn’t have to find it first. Each one now has a scope of its own:

ScopeWhat it selects
raw & codeEach code span
raw & emphasis, raw & strongEach emphasis, from its opening marker to its closing one
raw & delimiterA pair of emphasis markers that didn’t make emphasis, * like this *
raw & urlWhere each link goes (url.bare is an address written on its own)
raw & labelThe [ref] a link refers to and the [label] a definition is written under
raw & infoWhat a fence says about its code
raw & mathThe content between dollar signs
raw & footnote.reference, raw & footnote.definitionEach footnote, where it’s referred to and where it’s defined

Some of these scopes know more than just their location. For example, a link written with a label knows whether or not the page defines that label, and a definition knows whether or not any link uses it. As a result, we can catch a broken reference link without writing a pattern:

yaml
extends: existence message: "No definition on this page has the label this link uses." scope: 'raw & link.full.undefined'

The delimiter scope solves a similar problem. If you put spaces inside of your emphasis markers, you don’t get emphasis — the parser leaves the markers as text, which used to mean there was nothing for a rule to select. Now, the pair is a scope:

yaml
extends: existence message: "Remove the spaces inside these emphasis markers." scope: 'raw & delimiter'

You can also use any of these names to exclude content. For instance, adding & ~code keeps a rule out of code spans and & ~math keeps it out of math.

One way to write it

Most markup rules come down to a choice between equivalent ways of writing the same thing. A consistency rule can now give each of them a name:

yaml
extends: consistency message: "Write emphasis one way on a page: '*' or '_'." nonword: true scope: 'raw & emphasis & ~emphasis.intraword' options: asterisk: '\A\*' underscore: '\A_'

By default, a page keeps whichever one it uses first. If you’d rather require one of them on every page, you can set it in your .vale.ini file:

ini
markdownlint.EmphasisStyle[prefer] = underscore

Params

Markup rules tend to have settings: which punctuation a heading can end with, what level a title should be, which languages a code block can name. While we could copy a rule every time we want a different value, wouldn’t it be nice if we could just set it from our configuration?

This is where params come into play. Any rule can now declare a list of named values and use each one wherever it writes ${name}:

yaml
# styles/House/HeadingEnds.yml extends: existence message: "Don't end a heading with '%s'." nonword: true scope: 'raw & doc(:heading)' params: marks: '.,:!' tokens: - '[${marks}]$'

To change a value, we use the same bracket syntax that Std introduced:

ini
House.HeadingEnds[marks] = .!

In a pattern, a value matches exactly what it spells — the . above is a period, not “any character” — and a list matches any one of its items. You can also use a param in a rule’s message or scope.

Scripts

Some rules need to look at more than one thing at a time (a table’s columns, for example), and a pattern isn’t a good fit for that. A script rule can now read a block’s counts and spans by name. When it’s scoped to the whole page, it’s given every block; when it’s scoped to a table, it’s given the table’s rows: each row’s text, its cells, and the position of each pipe.

The proof: markdownlint as a style

A design like this is only useful if real rules actually fit into it. To find out, I wrote all 53 markdownlint rules as a Vale style, which is now available as the Markdown package:

ini
StylesPath = styles Packages = Markdown [*.md] BasedOnStyles = markdownlint

Most of its rules are just a scope and a pattern or formula. They have the same names that markdownlint gives them (HeadingIncrement, UlIndent, NoBareUrls).

I used markdownlint as the reference. To check the style against it, I ran both over five documentation sets with their default settings:

DocumentationAlerts from markdownlintMissed by the styleExtra from the style
GitLab94,81500
Node.js75,10200
Docker25,89400
vale.sh2,27300
The Rust Programming Language1,46100

That’s 199,545 alerts that the style reports on the same lines, with none missed and none extra.

None of this is a reason to switch. If Markdown is all you lint, markdownlint is the right tool, and it’s the reference that every rule in the package is tested against.

The package is for teams that already run Vale and want their markup rules in the same pass.

Conclusion

The ability to lint markup means that your style guide, spelling, terminology, and markup rules can all live in a single .vale.ini file. There’s one set of comments for switching a rule off and one list of alerts in your editor and in CI.

It also means that the rules are yours to change. If your team wants headings no deeper than three levels, or a blank line before every table but not after, you only need a few lines of YAML against the same scopes that the package uses.

The block scopes and their counts already work in the other formats Vale supports, including AsciiDoc and reStructuredText. The scopes inside of a block are currently Markdown-only, and I’ll be working on bringing them to the other formats next.

If you have any questions or run into any problems, feel free to open an issue at the Vale repository.

Linted by Vale v3.29.0 in 156 ms — no errors Checked 2026-12-05
Words
1,447
Sentences
83
Paragraphs
40
FK grade
7.0
Flesch ease
75.8
SMOG
9.0
Complex
6%
Read
7 min

One vale run on this file, wall clock. Counts from vale ls-metrics; reading time at 200 words a minute.