Skip to content

Commit

Permalink
Add Vale linter (#759)
Browse files Browse the repository at this point in the history
Hi friends, working to add a new linter in
[Vale](https://vale.sh/explorer/).

## What I'm trying to do
Vale is a pretty extensible style checker for text files like Markdown,
doc source, blogs, etc.
Lets you lint beyond spell checks, also for style, diction, etc.

I'm trying to add Vale as a linter so I can use it in `trunk check`.

## What I added
- [x] Vale as a tool, downloaded from GitHub releases
- [x] Vale as a linter, output as line and parsed with regex
- [x] A basic smoke tests for tool
- [x] Success case and an issue case tests for linter

## Test plan
- Tests described above
- Some manual testing by running Vale check with vale enabled.

---------

Co-authored-by: Tyler Jang <[email protected]>
  • Loading branch information
Vincent (Wen Yu) Ge and TylerJang27 authored Apr 29, 2024
1 parent 5ae4524 commit dbefc22
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trunk check enable {linter}

| Technology | Linters |
| --------------- | -------------------------------------------------------------------------------------------------------------------- |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox] |
| All | [codespell], [cspell], [gitleaks], [git-diff-check], [pre-commit-hooks], [trunk-toolbox], [vale] |
| Ansible | [ansible-lint] |
| Apex | [pmd] |
| Bash | [shellcheck], [shfmt] |
Expand Down Expand Up @@ -187,6 +187,7 @@ trunk check enable {linter}
[trufflehog]: https://trunk.io/linters/security/trufflehog
[trunk-toolbox]: https://github.com/trunk-io/toolbox#readme
[txtpbfmt]: https://github.com/protocolbuffers/txtpbfmt#readme
[vale]: https://vale.sh/docs/
[yamllint]: https://trunk.io/linters/yaml/yamllint
[yapf]: https://github.com/google/yapf#readme

Expand Down
5 changes: 5 additions & 0 deletions linters/vale/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[formats]
markdoc = md

[*.md]
BasedOnStyles = Vale
46 changes: 46 additions & 0 deletions linters/vale/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: 0.1

downloads:
- name: vale
downloads:
- os:
linux: Linux
macos: macOS
cpu:
x86_64: 64-bit
arm_64: arm64
url: https://github.com/errata-ai/vale/releases/download/v${version}/vale_${version}_${os}_${cpu}.tar.gz
- os:
windows: Windows
cpu:
x86_64: 64-bit
arm_64: arm64
url: https://github.com/errata-ai/vale/releases/download/v${version}/vale_${version}_Windows_${cpu}.zip

tools:
definitions:
- name: vale
download: vale
shims: [vale]
known_good_version: 3.4.1
environment:
- name: PATH
list: ["${tool}"]

lint:
definitions:
- name: vale
files: [ALL]
description: Enforce editorial standards in your text documents
commands:
- name: lint
output: regex
parse_regex: (?P<path>.*):(?P<line>\d+):(?P<col>\d+):(?P<severity>[^:]+):(?P<message>.+)
run: vale --output=line ${target}
success_codes: [0, 1]
read_output_from: stdout
batch: true
suggest_if: config_present
tools: [vale]
known_good_version: 3.4.1
direct_configs: [.vale.ini]
2 changes: 2 additions & 0 deletions linters/vale/test_data/basic.in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello world!
Hallo, wurld?
53 changes: 53 additions & 0 deletions linters/vale/test_data/vale_v3.4.1_basic.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter vale test basic 1`] = `
{
"issues": [
{
"code": "error",
"column": "1",
"file": "test_data/basic.in.md",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "2",
"linter": "vale",
"message": "Did you really mean 'Hallo'?",
"targetType": "ALL",
},
{
"code": "error",
"column": "8",
"file": "test_data/basic.in.md",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "2",
"linter": "vale",
"message": "Did you really mean 'wurld'?",
"targetType": "ALL",
},
],
"lintActions": [
{
"command": "lint",
"fileGroupName": "ALL",
"linter": "vale",
"paths": [
"test_data/basic.in.md",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "ALL",
"linter": "vale",
"paths": [
"test_data/basic.in.md",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
}
`;
3 changes: 3 additions & 0 deletions linters/vale/vale.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { linterCheckTest } from "tests";

linterCheckTest({ linterName: "vale" });

0 comments on commit dbefc22

Please sign in to comment.