Skip to content

Commit 2875452

Browse files
authored
Add support for remark-lint to plugins (#142)
1 parent d7e2024 commit 2875452

9 files changed

+260
-1
lines changed

.trunk/configs/.remarkrc.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins:
2+
- remark-preset-lint-consistent: true
3+
- remark-preset-lint-recommended: true
4+
- remark-lint-list-item-indent: true

linters/remark-lint/.remarkrc.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins:
2+
remark-preset-lint-consistent: true
3+
remark-preset-lint-recommended: true
4+
remark-lint-list-item-indent: true

linters/remark-lint/parse.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
remark output looks like this:
5+
6+
```
7+
[{
8+
"path": "linters/remark-lint/test_data/basic.in.md",
9+
"cwd": "/tmp/trunk-1001/OA3KSD",
10+
"history": ["linters/remark-lint/test_data/basic.in.md"],
11+
"messages": [{
12+
"reason": "Use spaces instead of tabs",
13+
"line": 13,
14+
"column": 5,
15+
"position": {
16+
"start": {
17+
"line": 13,
18+
"column": 5,
19+
"offset": 159
20+
},
21+
"end": {
22+
"line": null,
23+
"column": null
24+
}
25+
},
26+
"ruleId": "no-tabs",
27+
"source": "remark-lint",
28+
"fatal": false,
29+
"stack": null,
30+
"url": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-tabs#readme"
31+
}]
32+
}]
33+
```
34+
35+
"""
36+
37+
import json
38+
import sys
39+
40+
41+
def to_result_sarif(
42+
path: str, line_number: int, column_number: int, rule_id: str, message: str
43+
):
44+
return {
45+
"level": "error",
46+
"locations": [
47+
{
48+
"physicalLocation": {
49+
"artifactLocation": {
50+
"uri": path,
51+
},
52+
"region": {
53+
"startColumn": column_number,
54+
"startLine": line_number,
55+
},
56+
}
57+
}
58+
],
59+
"message": {
60+
"text": message,
61+
},
62+
"ruleId": rule_id,
63+
}
64+
65+
66+
def main(argv):
67+
results = []
68+
content_json = sys.stdin.read()
69+
content = json.loads(content_json)
70+
for file_content in content:
71+
messages = file_content.get("messages", [])
72+
if messages:
73+
for msg in messages:
74+
results.append(
75+
to_result_sarif(
76+
".", msg["line"], msg["column"], msg["ruleId"], msg["reason"]
77+
)
78+
)
79+
80+
sarif = {
81+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
82+
"version": "2.1.0",
83+
"runs": [{"results": results}],
84+
}
85+
86+
print(json.dumps(sarif, indent=2))
87+
88+
89+
if __name__ == "__main__":
90+
main(sys.argv)

linters/remark-lint/plugin.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: 0.1
2+
lint:
3+
definitions:
4+
- name: remark-lint
5+
files: [markdown]
6+
package: remark-cli
7+
extra_packages:
8+
- remark-preset-lint-consistent
9+
- remark-preset-lint-recommended
10+
- remark-lint-list-item-indent
11+
- vfile-reporter-json
12+
runtime: node
13+
known_good_version: 11.0.0
14+
is_recommended: false
15+
direct_configs:
16+
- .remarkrc
17+
- .remarkrc.json
18+
- .remarkrc.cjs
19+
- .remarkrc.mjs
20+
- .remarkrc.js
21+
- .remarkrc.yaml
22+
- .remarkrc.yml
23+
commands:
24+
- name: fmt
25+
output: rewrite
26+
run: remark ${target} --output
27+
formatter: true
28+
success_codes: [0]
29+
in_place: true
30+
cache_results: true
31+
- name: check
32+
output: sarif
33+
run: remark ${target} --frail --output --report=vfile-reporter-json
34+
success_codes: [0, 1]
35+
in_place: true
36+
cache_results: true
37+
read_output_from: stderr
38+
parser:
39+
runtime: python
40+
run: ${cwd}/parse.py
41+
symlinks:
42+
# symlink the tool node_modules into the sandbox. this enables
43+
# the hermetic tool to run correctly with plugins
44+
- from: ${linter_dir}/node_modules
45+
to: node_modules
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { linterCheckTest, linterFmtTest } from "tests";
2+
3+
linterFmtTest({ linterName: "remark-lint" });
4+
5+
linterCheckTest({ linterName: "remark-lint" });
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
* this is a list item
2+
indented with tabs
3+
4+
* this is a list item
5+
indented with spaces
6+
7+
Code:
8+
9+
this code block is indented by one tab
10+
11+
And:
12+
13+
this code block is indented by two tabs
14+
15+
And:
16+
17+
+ this is an example list item
18+
indented with tabs
19+
20+
+ this is an example list item
21+
indented with spaces
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing linter remark-lint test basic 1`] = `
4+
Object {
5+
"issues": Array [
6+
Object {
7+
"bucket": "remark-lint",
8+
"code": "no-tabs",
9+
"column": "5",
10+
"file": "test_data/basic.in.md",
11+
"level": "LEVEL_HIGH",
12+
"line": "13",
13+
"linter": "remark-lint",
14+
"message": "Use spaces instead of tabs",
15+
"targetType": "markdown",
16+
},
17+
Object {
18+
"bucket": "remark-lint",
19+
"code": "no-tabs",
20+
"column": "6",
21+
"file": "test_data/basic.in.md",
22+
"level": "LEVEL_HIGH",
23+
"line": "17",
24+
"linter": "remark-lint",
25+
"message": "Use spaces instead of tabs",
26+
"targetType": "markdown",
27+
},
28+
Object {
29+
"bucket": "remark-lint",
30+
"code": "no-tabs",
31+
"column": "5",
32+
"file": "test_data/basic.in.md",
33+
"level": "LEVEL_HIGH",
34+
"line": "18",
35+
"linter": "remark-lint",
36+
"message": "Use spaces instead of tabs",
37+
"targetType": "markdown",
38+
},
39+
],
40+
"lintActions": Array [
41+
Object {
42+
"command": "check",
43+
"fileGroupName": "markdown",
44+
"linter": "remark-lint",
45+
"paths": Array [
46+
"test_data/basic.in.md",
47+
],
48+
"verb": "TRUNK_VERB_CHECK",
49+
},
50+
Object {
51+
"command": "format",
52+
"fileGroupName": "markdown",
53+
"linter": "remark-lint",
54+
"paths": Array [
55+
"test_data/basic.in.md",
56+
],
57+
"verb": "TRUNK_VERB_FMT",
58+
},
59+
],
60+
"taskFailures": Array [],
61+
"unformattedFiles": Array [],
62+
}
63+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing formatter remark-lint test basic 1`] = `
4+
"* this is a list item
5+
indented with tabs
6+
7+
* this is a list item
8+
indented with spaces
9+
10+
Code:
11+
12+
this code block is indented by one tab
13+
14+
And:
15+
16+
this code block is indented by two tabs
17+
18+
And:
19+
20+
+ this is an example list item
21+
indented with tabs
22+
23+
+ this is an example list item
24+
indented with spaces
25+
"
26+
`;

readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ make the discovery, management and integration of new tools as straight-forward
5454
| JSON | [eslint], [prettier], [semgrep] |
5555
| Kotlin | [detekt]<sup><a href="#note-detekt">1</a></sup>, [ktlint] |
5656
| Kubernetes | [kube-linter] |
57-
| Markdown | [markdownlint] |
57+
| Markdown | [markdownlint], [remark-lint] |
5858
| Nix | [nixpkgs-fmt] |
5959
| package.json | [sort-package-json] |
6060
| PNG | [oxipng] |
@@ -113,6 +113,7 @@ make the discovery, management and integration of new tools as straight-forward
113113
[pragma-once]: linters/pragma-once/readme.md
114114
[prettier]: https://github.com/prettier/prettier#readme
115115
[pylint]: https://github.com/PyCQA/pylint#readme
116+
[remark-lint]: https://github.com/remarkjs/remark-lint#readme
116117
[renovate]: https://github.com/renovatebot/renovate#readme
117118
[rome]: https://github.com/rome/tools#readme
118119
[rubocop]: https://github.com/rubocop/rubocop#readme

0 commit comments

Comments
 (0)