Skip to content

Commit e4d5480

Browse files
authored
Update renovate settings (#117)
1 - Update renovate settings 2 - Integrate new linter for renovate configuration files + tests
1 parent 4015948 commit e4d5480

File tree

11 files changed

+16999
-4769
lines changed

11 files changed

+16999
-4769
lines changed

linters/renovate/parse.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
renovate-config-validae output looks like this:
5+
6+
```
7+
INFO: Validating renovate.json
8+
ERROR: renovate.json contains errors
9+
"errors": [
10+
{
11+
"topic": "Configuration Error",
12+
"message": "Invalid configuration option: packageRules[0].matchUpdateTypesd"
13+
}
14+
]
15+
```
16+
17+
Bad JSON parses like this
18+
```
19+
WARN: linters/renovate/test_data/bad_renovate.json could not be parsed
20+
"err": {
21+
"lineNumber": 12,
22+
"columnNumber": 1,
23+
"message": "JSON5: invalid end of input at 12:1",
24+
"stack": "SyntaxError: JSON5: invalid end of input at 12:1\n at syntaxError (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:1110:17)\n at invalidEOF (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:1059:12)\n at Object.afterPropertyValue (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:915:19)\n at Object.parse (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/json5/lib/parse.js:32:32)\n at getParsedContent (/home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/renovate/lib/workers/global/config/parse/file.ts:20:20)\n at /home/eli/.cache/trunk/tools/renovate/34.122.0-55cc21ab9187b50133f5b632efea6883/node_modules/renovate/lib/config-validator.ts:62:31"
25+
}
26+
```
27+
"""
28+
29+
import json
30+
import re
31+
import sys
32+
33+
34+
def to_result_sarif(
35+
path: str, line_number: int, column_number: int, rule_id: str, message: str
36+
):
37+
return {
38+
"level": "error",
39+
"locations": [
40+
{
41+
"physicalLocation": {
42+
"artifactLocation": {
43+
"uri": path,
44+
},
45+
"region": {
46+
"startColumn": column_number,
47+
"startLine": line_number,
48+
},
49+
}
50+
}
51+
],
52+
"message": {
53+
"text": message,
54+
},
55+
"ruleId": rule_id,
56+
}
57+
58+
59+
def main(argv):
60+
results = []
61+
content = sys.stdin.read()
62+
63+
parse_reg = "(.*WARN:.*could not be parsed)(.*)"
64+
error_section = content.find('"errors": [')
65+
66+
parse_result = re.fullmatch(parse_reg, content, flags=re.DOTALL)
67+
if parse_result:
68+
warn_section = parse_result.group(2)
69+
json_content = "{" + warn_section + "}"
70+
error_output = json.loads(json_content)
71+
err = error_output.get("err")
72+
results.append(
73+
to_result_sarif(
74+
".", err["lineNumber"], err["columnNumber"], "JSON", err["message"]
75+
)
76+
)
77+
pass
78+
# TODO - fix this up to read the exit code once that is available in the parser
79+
elif content.find("Config validated successfully") != -1:
80+
pass
81+
elif error_section == -1:
82+
# could not parse - dumping all content as the error
83+
results.append(to_result_sarif(".", 0, 0, "error", content))
84+
else:
85+
# Parse the output as json
86+
json_content = "{" + content[error_section:] + "}"
87+
error_output = json.loads(json_content)
88+
for entry in error_output.get("errors", []):
89+
results.append(to_result_sarif(".", 0, 0, entry["topic"], entry["message"]))
90+
91+
sarif = {
92+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
93+
"version": "2.1.0",
94+
"runs": [{"results": results}],
95+
}
96+
97+
print(json.dumps(sarif, indent=2))
98+
99+
100+
if __name__ == "__main__":
101+
main(sys.argv)

linters/renovate/plugin.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: 0.1
2+
lint:
3+
files:
4+
- name: renovate-config
5+
filenames:
6+
- renovate.json
7+
- renovate.json5
8+
- .renovaterc.json
9+
- .renovaterc.json5
10+
definitions:
11+
- name: renovate
12+
files: [renovate-config]
13+
runtime: node
14+
package: renovate
15+
commands:
16+
- name: validate
17+
run: renovate-config-validator ${target}
18+
success_codes: [0, 1]
19+
output: sarif
20+
read_output_from: stdout
21+
parser:
22+
runtime: python
23+
run: ${cwd}/parse.py
24+
affects_cache:
25+
- renovate.json
26+
- renovate.json5
27+
- .renovaterc.json
28+
- .renovaterc.json5
29+
known_good_version: 34.122.0
30+
version_command:
31+
parse_regex: ${semver}
32+
run: renovate --version

linters/renovate/renovate.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { customLinterCheckTest } from "tests";
2+
import { skipOS } from "tests/utils";
3+
4+
// python missing on mac
5+
customLinterCheckTest({
6+
linterName: "renovate",
7+
args: "-a",
8+
skipTestIf: skipOS(["darwin"]),
9+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["config:base"],
4+
"prConcurrentLimit": 3,
5+
"packageRules": [
6+
{
7+
"groupName": "all non-major dependencies",
8+
"groupSlug": "all-minor-patch",
9+
"matchPackagePatterns": ["*"],
10+
"matchUpdateTypes": ["minor", "patch"]
11+
}
12+
]
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["config:base"],
4+
"packageRules": [
5+
{
6+
"groupName": "all non-major dependencies",
7+
"groupSlug": "all-minor-patch",
8+
"matchPackagePatterns": ["*"],
9+
"matchUpdateTyped_badInfo": ["minor", "patch"]
10+
}
11+
]
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["config:base"],
4+
"packageRules": [
5+
{
6+
"groupName": "all non-major dependencies",
7+
"groupSlug": "all-minor-patch",
8+
"matchPackagePatterns": ["*"],
9+
"matchUpdateTyped_badInfo": ["minor", "patch"]
10+
}
11+
]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing linter renovate test CUSTOM 1`] = `
4+
Object {
5+
"issues": Array [
6+
Object {
7+
"bucket": "renovate",
8+
"code": "Configuration-Error",
9+
"file": "test_data/renovate.json",
10+
"level": "LEVEL_HIGH",
11+
"linter": "renovate",
12+
"message": "Invalid configuration option: packageRules[0].matchUpdateTyped_badInfo",
13+
"targetType": "renovate-config",
14+
},
15+
Object {
16+
"bucket": "renovate",
17+
"code": "JSON",
18+
"column": "1",
19+
"file": "test_data/renovate.json5",
20+
"level": "LEVEL_HIGH",
21+
"line": "12",
22+
"linter": "renovate",
23+
"message": "JSON5: invalid end of input at 12:1",
24+
"targetType": "renovate-config",
25+
},
26+
],
27+
"lintActions": Array [
28+
Object {
29+
"command": "validate",
30+
"fileGroupName": "renovate-config",
31+
"linter": "renovate",
32+
"paths": Array [
33+
"test_data/.renovaterc.json",
34+
],
35+
"verb": "TRUNK_VERB_CHECK",
36+
},
37+
Object {
38+
"command": "validate",
39+
"fileGroupName": "renovate-config",
40+
"linter": "renovate",
41+
"paths": Array [
42+
"test_data/renovate.json",
43+
],
44+
"verb": "TRUNK_VERB_CHECK",
45+
},
46+
Object {
47+
"command": "validate",
48+
"fileGroupName": "renovate-config",
49+
"linter": "renovate",
50+
"paths": Array [
51+
"test_data/renovate.json5",
52+
],
53+
"verb": "TRUNK_VERB_CHECK",
54+
},
55+
],
56+
"taskFailures": Array [],
57+
"unformattedFiles": Array [],
58+
}
59+
`;

0 commit comments

Comments
 (0)