|
| 1 | +--- |
| 2 | +navigation_title: Vale linter |
| 3 | +--- |
| 4 | + |
| 5 | +# Elastic style guide for Vale |
| 6 | + |
| 7 | +[Vale](https://github.com/errata-ai/vale) is an open source prose linter that checks the content of documents in several formats against style guide rules. The goal of a prose linter is automating style guide checks in docs-as-code environments, so that style issues are detected before deploy or while editing documentation in a code editor. |
| 8 | + |
| 9 | +The Elastic Vale package contains a set of linting rules based on the Elastic style guide and recommendations. |
| 10 | + |
| 11 | +## Get started |
| 12 | + |
| 13 | +Run these commands to install the Elastic style guide locally: |
| 14 | + |
| 15 | +::::{tab-set} |
| 16 | + |
| 17 | +:::{tab-item} macOS |
| 18 | + |
| 19 | +```bash |
| 20 | +curl -fsSL https://raw.githubusercontent.com/elastic/vale-rules/main/install-macos.sh | bash |
| 21 | +``` |
| 22 | + |
| 23 | +::: |
| 24 | + |
| 25 | +:::{tab-item} Linux |
| 26 | + |
| 27 | +```bash |
| 28 | +curl -fsSL https://raw.githubusercontent.com/elastic/vale-rules/main/install-linux.sh | bash |
| 29 | +``` |
| 30 | + |
| 31 | +::: |
| 32 | + |
| 33 | +:::{tab-item} Windows |
| 34 | + |
| 35 | +```powershell |
| 36 | +Invoke-WebRequest -Uri https://raw.githubusercontent.com/elastic/vale-rules/main/install-windows.ps1 -OutFile install-windows.ps1 |
| 37 | +powershell -ExecutionPolicy Bypass -File .\install-windows.ps1 |
| 38 | +``` |
| 39 | + |
| 40 | +::: |
| 41 | +:::: |
| 42 | + |
| 43 | +:::{warning} |
| 44 | +The installation script might overwrite your existing global Vale configuration. Install the style manually if you're using styles other than Elastic. |
| 45 | +::: |
| 46 | + |
| 47 | +### Install the Visual Studio Code extension |
| 48 | + |
| 49 | +Install the [Vale VSCode](https://marketplace.visualstudio.com/items?itemName=ChrisChinchilla.vale-vscode) extension to view Vale checks when saving a document. The extension is also available for other editors that support the Open VSX Registry. |
| 50 | + |
| 51 | +## Add the Vale action to your repo |
| 52 | + |
| 53 | +Add the Elastic Vale linter to your repository's CI/CD pipeline using a two-workflow setup that supports fork PRs: |
| 54 | + |
| 55 | +```yaml |
| 56 | +# .github/workflows/vale-lint.yml |
| 57 | +name: Vale Documentation Linting |
| 58 | + |
| 59 | +on: |
| 60 | + pull_request: |
| 61 | + paths: |
| 62 | + - '**.md' |
| 63 | + - '**.adoc' |
| 64 | + |
| 65 | +permissions: |
| 66 | + contents: read |
| 67 | + |
| 68 | +jobs: |
| 69 | + vale: |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@v5 |
| 74 | + with: |
| 75 | + fetch-depth: 0 |
| 76 | + |
| 77 | + - name: Run Vale Linter |
| 78 | + uses: elastic/vale-rules/lint@main |
| 79 | +``` |
| 80 | +
|
| 81 | +```yaml |
| 82 | +# .github/workflows/vale-report.yml |
| 83 | +name: Vale Report |
| 84 | + |
| 85 | +on: |
| 86 | + workflow_run: |
| 87 | + workflows: ["Vale Documentation Linting"] |
| 88 | + types: |
| 89 | + - completed |
| 90 | + |
| 91 | +permissions: |
| 92 | + pull-requests: read |
| 93 | + |
| 94 | +jobs: |
| 95 | + report: |
| 96 | + runs-on: ubuntu-latest |
| 97 | + if: github.event.workflow_run.event == 'pull_request' |
| 98 | + permissions: |
| 99 | + pull-requests: write |
| 100 | + |
| 101 | + steps: |
| 102 | + - name: Post Vale Results |
| 103 | + uses: elastic/vale-rules/report@main |
| 104 | + with: |
| 105 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | +``` |
| 107 | +
|
| 108 | +For detailed documentation and examples, refer to [ACTION_USAGE.md](https://github.com/elastic/vale-rules/blob/main/ACTION_USAGE.md). |
| 109 | +
|
| 110 | +## Exclude content from linting |
| 111 | +
|
| 112 | +You can use HTML comments in your Markdown files to control Vale's behavior for specific sections of content. This is useful when you need to temporarily turn off checks or exclude certain content from linting. |
| 113 | +
|
| 114 | +### Turn off all Vale checks |
| 115 | +
|
| 116 | +To exclude a section of content from linting, wrap it with `vale off` and `vale on` comments: |
| 117 | + |
| 118 | +```markdown |
| 119 | +<!-- vale off --> |
| 120 | +
|
| 121 | +This entire section will be ignored by Vale. |
| 122 | +
|
| 123 | +<!-- vale on --> |
| 124 | +``` |
| 125 | + |
| 126 | +### Turn off a specific rule |
| 127 | + |
| 128 | +To turn off a specific Elastic style rule for a section, use the rule name with `= NO` and `= YES` to turn it back on: |
| 129 | + |
| 130 | +```markdown |
| 131 | +<!-- vale Elastic.RuleName = NO --> |
| 132 | +
|
| 133 | +This content will ignore only the specified rule. |
| 134 | +
|
| 135 | +<!-- vale Elastic.RuleName = YES --> |
| 136 | +``` |
| 137 | + |
| 138 | +For example, to turn off the `Elastic.WordChoice` rule: |
| 139 | + |
| 140 | +```markdown |
| 141 | +<!-- vale Elastic.WordChoice = NO --> |
| 142 | +
|
| 143 | +This section can contain mispellings without triggering warnings. |
| 144 | +
|
| 145 | +<!-- vale Elastic.WordChoice = YES --> |
| 146 | +``` |
| 147 | + |
| 148 | +:::{tip} |
| 149 | +You can find the exact rule names in the [Elastic Vale rules repository](https://github.com/elastic/vale-rules/tree/main/styles/Elastic). Each rule is defined in a separate `.yml` file, and the filename (without the extension) is the rule name you use in comments. |
| 150 | +::: |
| 151 | + |
| 152 | +For more information about comment-based configuration, refer to the [Vale Markdown documentation](https://vale.sh/docs/formats/markdown#comments). |
| 153 | + |
| 154 | +## Update the style guide |
| 155 | + |
| 156 | +To update the Elastic style guide to the latest rules, rerun the installation script. |
| 157 | + |
| 158 | +## Resources |
| 159 | + |
| 160 | +- [Vale's official documentation](https://vale.sh/docs/vale-cli/overview/) |
| 161 | +- [Elastic Vale rules repository](https://github.com/elastic/vale-rules) |
| 162 | + |
0 commit comments