Skip to content

Vale documentation tests

Vale is a grammar, style, and word usage linter for the English language. Vale's configuration is stored in the .vale.ini file located in the root directory of projects.

Vale supports creating custom tests that extend any of several types of checks, which we store in the .linting/vale/styles/gitlab directory in the documentation directory of projects.

Some example Vale configurations:

This configuration is also used in build pipelines, where error-level rules are enforced.

You can use Vale:

Install Vale

Install vale using either:

  • If using asdf, the asdf-vale plugin. In a checkout of a GitLab project with a .tool-versions file (example), run:

    asdf plugin add vale && asdf install vale
  • A package manager:

    • macOS using brew, run: brew install vale.
    • Linux, use your distribution's package manager or a released binary.

Configure Vale in your editor

Using linters in your editor is more convenient than having to run the commands from the command line.

To configure Vale in your editor, install one of the following as appropriate:

  • Visual Studio Code ChrisChinchilla.vale-vscode extension. You can configure the plugin to display only a subset of alerts.

  • Sublime Text SublimeLinter-vale package. To have Vale suggestions appears as blue instead of red (which is how errors appear), add vale configuration to your SublimeLinter configuration:

    "vale": {
      "styles": [{
        "mark_style": "outline",
        "scope": "region.bluish",
        "types": ["suggestion"]
      }]
    }
  • LSP for Sublime Text package LSP-vale-ls.

  • Vim ALE plugin.

  • JetBrains IDEs - No plugin exists, but this issue comment contains tips for configuring an external tool.

  • Emacs Flycheck extension. A minimal configuration for Flycheck to work with Vale could look like:

    (flycheck-define-checker vale
      "A checker for prose"
      :command ("vale" "--output" "line" "--no-wrap"
                source)
      :standard-input nil
      :error-patterns
        ((error line-start (file-name) ":" line ":" column ":" (id (one-or-more (not (any ":")))) ":" (message)   line-end))
      :modes (markdown-mode org-mode text-mode)
      :next-checkers ((t . markdown-markdownlint-cli))
    )
    
    (add-to-list 'flycheck-checkers 'vale)

    In this setup the markdownlint checker is set as a "next" checker from the defined vale checker. Enabling this custom Vale checker provides error linting from both Vale and markdownlint.

Result types

Vale returns three types of results:

  • Error - For branding guidelines, trademark guidelines, and anything that causes content on the documentation site to render incorrectly.
  • Warning - For general style guide rules, tenets, and best practices.
  • Suggestion - For technical writing style preferences that may require refactoring of documentation or updates to an exceptions list.

The result types have these attributes:

Result type Displays in CI/CD job output Displays in MR diff Causes CI/CD jobs to fail Vale rule link
error {check-circle} Yes {check-circle} Yes {check-circle} Yes Error-level Vale rules
warning {dotted-circle} No {check-circle} Yes {dotted-circle} No Warning-level Vale rules
suggestion {dotted-circle} No {dotted-circle} No {dotted-circle} No Suggestion-level Vale rules

When to add a new Vale rule

It's tempting to add a Vale rule for every style guide rule. However, we should be mindful of the effort to create and enforce a Vale rule, and the noise it creates.

In general, follow these guidelines:

  • If you add an error-level Vale rule, you must fix the existing occurrences of the issue in the documentation before you can add the rule.

    If there are too many issues to fix in a single merge request, add the rule at a warning level. Then, fix the existing issues in follow-up merge requests. When the issues are fixed, promote the rule to an error.

  • If you add a warning-level or suggestion-level rule, consider:

    • How many more warnings or suggestions it creates in the Vale output. If the number of additional warnings is significant, the rule might be too broad.

    • How often an author might ignore it because it's acceptable in the context. If the rule is too subjective, it cannot be adequately enforced and creates unnecessary additional warnings.

    • Whether it's appropriate to display in the merge request diff in the GitLab UI. If the rule is difficult to implement directly in the merge request (for example, it requires page refactoring), set it to suggestion-level so it displays in local editors only.

Limit which tests are run

You can set Visual Studio Code to display only a subset of Vale alerts when viewing files:

  1. Go to Preferences > Settings > Extensions > Vale.
  2. In Vale CLI: Min Alert Level, select the minimum alert level you want displayed in files.

To display only a subset of Vale alerts when running Vale from the command line, use the --minAlertLevel flag, which accepts error, warning, or suggestion. Combine it with --config to point to the configuration file in the project, if needed:

vale --config .vale.ini --minAlertLevel error doc/**/*.md

Omit the flag to display all alerts, including suggestion level alerts.

Test one rule at a time

To test only a single rule when running Vale from the command line, modify this command, replacing OutdatedVersions with the name of the rule:

vale --no-wrap --filter='.Name=="gitlab.OutdatedVersions"' doc/**/*.md

Disable Vale tests

You can disable a specific Vale linting rule or all Vale linting rules for any portion of a document:

  • To disable a specific rule, add a <!-- vale gitlab.rulename = NO --> tag before the text, and a <!-- vale gitlab.rulename = YES --> tag after the text, replacing rulename with the filename of a test in the GitLab styles directory.
  • To disable all Vale linting rules, add a <!-- vale off --> tag before the text, and a <!-- vale on --> tag after the text.

Whenever possible, exclude only the problematic rule and lines.

Ignore statements do not work for Vale rules with the raw scope. For more information, see this issue.

For more information on Vale scoping rules, see Vale's documentation.

Show Vale warnings on push

By default, lefthook shows only Vale errors when pushing changes to a branch. The default branches have no Vale errors, so any errors listed here are introduced by commits to the branch.

To also see the Vale warnings when pushing to a branch, set a local environment variable: VALE_WARNINGS=true.

Enable Vale warnings on push to improve the documentation suite by:

  • Detecting warnings you might be introducing with your commits.
  • Identifying warnings that already exist in the page, which you can resolve to reduce technical debt.

These warnings:

  • Don't stop the push from working.
  • Don't result in a broken pipeline.
  • Include all warnings for a file, not just warnings that are introduced by the commits.

To enable Vale warnings on push:

  • Automatically, add VALE_WARNINGS=true to your shell configuration.

  • Manually, prepend VALE_WARNINGS=true to invocations of lefthook. For example:

    VALE_WARNINGS=true bundle exec lefthook run pre-push

You can also configure your editor to show Vale warnings.

Resolve problems Vale identifies

Spelling test

When Vale flags a valid word as a spelling mistake, you can fix it following these guidelines:

Flagged word Guideline
jargon Rewrite the sentence to avoid it.
correctly-capitalized name of a product or service Add the word to the Vale spelling exceptions list.
name of a person Remove the name if it's not needed, or add the Vale exception code inline.
a command, variable, code, or similar Put it in backticks or a code block. For example: The git clone command can be used with the CI_COMMIT_BRANCH variable. -> The `git clone` command can be used with the `CI_COMMIT_BRANCH` variable.
UI text from GitLab Verify it correctly matches the UI, then: If it does not match the UI, update it. If it matches the UI, but the UI seems incorrect, create an issue to see if the UI needs to be fixed. If it matches the UI and seems correct, add it to the Vale spelling exceptions list.
UI text from a third-party product Rewrite the sentence to avoid it, or add the Vale exception code in-line.

Uppercase (acronym) test

The Uppercase.yml test checks for incorrect usage of words in all capitals. For example, avoid usage like This is NOT important.

If the word must be in all capitals, follow these guidelines:

Flagged word Guideline
Acronym (likely known by the average visitor to that page) Add the acronym to the list of words and acronyms in Uppercase.yml.
Acronym (likely not known by the average visitor to that page) The first time the acronym is used, write it out fully followed by the acronym in parentheses. In later uses, use just the acronym by itself. For example: This feature uses the File Transfer Protocol (FTP). FTP is....
Correctly capitalized name of a product or service Add the name to the list of words and acronyms in Uppercase.yml.
Command, variable, code, or similar Put it in backticks or a code block. For example: Use `FALSE` as the variable value.
UI text from a third-party product Rewrite the sentence to avoid it, or add the vale exception code in-line.

Readability score

In ReadingLevel.yml, we have implemented the Flesch-Kincaid grade level test to determine the readability of our documentation.

As a general guideline, the lower the score, the more readable the documentation. For example, a page that scores 12 before a set of changes, and 9 after, indicates an iterative improvement to readability. The score is not an exact science, but is meant to help indicate the general complexity level of the page.

The readability score is calculated based on the number of words per sentence, and the number of syllables per word. For more information, see the Vale documentation.

Export Vale results to a file

To export all (or filtered) Vale results to a file, modify this command:

# Returns results of types suggestion, warning, and error
find . -name '*.md' | sort | xargs vale --minAlertLevel suggestion --output line > ../../results.txt

# Returns only warnings and errors
find . -name '*.md' | sort | xargs vale --minAlertLevel warning --output line > ../../results.txt

# Returns only errors
find . -name '*.md' | sort | xargs vale --minAlertLevel error --output line > ../../results.txt

These results can be used with the create_issues.js script to generate documentation-related issues for Hackathons.

Enable custom rules locally

Vale 3.0 and later supports using two locations for rules. This change enables you to create and use your own custom rules alongside the rules included in a project.

To create and use custom rules locally on macOS:

  1. Create a local file in the Application Support folder for Vale:

    touch ~/Library/Application\ Support/vale/.vale.ini
  2. Add these lines to the .vale.ini file you just created:

    [*.md]
    BasedOnStyles = local
  3. If the folder ~/Library/Application Support/vale/styles/local does not exist, create it:

    mkdir ~/Library/Application\ Support/vale/styles/local
  4. Add your desired rules to ~/Library/Application Support/vale/styles/local.

Rules in your local style directory are prefixed with local instead of gitlab in Vale results, like this:

$ vale --minAlertLevel warning doc/ci/yaml/index.md

 doc/ci/yaml/index.md
    ...[snip]...
 3876:17   warning  Instead of future tense 'will   gitlab.FutureTense
                    be', use present tense.
 3897:26   error    Remove 'documentation'          local.new-rule

✖ 1 error, 5 warnings and 0 suggestions in 1 file.

Related topics