Skip to content

Commit 001e89e

Browse files
authored
(Chore): Various repo cleanup and additional support (#1003)
- Adds `golangci-lint2`. This requires a new linter definition because of the new parser type and a different package install. Fixes #1000. Now recommend this linter instead of `golangci-lint` - Fixes ansible-lint snapshots - Fixes scalafmt snapshots - Fixes psscriptanalyzer download URL - Fixes snyk test flakiness
1 parent 16cb088 commit 001e89e

20 files changed

+1629
-164
lines changed

linters/ansible-lint/test_data/ansible_lint_v25.2.0_FQCN.check.shot

+595
Large diffs are not rendered by default.

linters/ansible-lint/test_data/ansible_lint_v25.2.0_non_FQCN.check.shot

+583
Large diffs are not rendered by default.

linters/golangci-lint/golangci_lint.test.ts

+54-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,59 @@
11
import path from "path";
2+
import semver from "semver";
23
import { customLinterCheckTest } from "tests";
34
import { TrunkLintDriver } from "tests/driver";
45
import { skipOS, TEST_DATA } from "tests/utils";
56

7+
const testGenerator = ({
8+
args,
9+
testName,
10+
preCheck,
11+
skipTestIf,
12+
}: {
13+
args: string;
14+
testName: string;
15+
preCheck?: (driver: TrunkLintDriver) => void;
16+
skipTestIf?: (version?: string) => boolean;
17+
}) => {
18+
const skipTest = (v1: boolean) => (version?: string) => {
19+
if (v1 && semver.gte(version ?? "", "2.0.0")) {
20+
return true;
21+
} else if (!v1 && semver.lt(version ?? "", "2.0.0")) {
22+
return true;
23+
}
24+
25+
if (skipTestIf) {
26+
return skipTestIf(version);
27+
}
28+
return false;
29+
};
30+
31+
const preCheckV2 = (driver: TrunkLintDriver) => {
32+
driver.moveFile(path.join(TEST_DATA, ".golangci.yml"), ".golangci2.yml");
33+
if (preCheck) {
34+
preCheck(driver);
35+
}
36+
};
37+
38+
customLinterCheckTest({
39+
linterName: "golangci-lint",
40+
args,
41+
testName,
42+
preCheck,
43+
skipTestIf: skipTest(true),
44+
});
45+
46+
customLinterCheckTest({
47+
linterName: "golangci-lint2",
48+
args,
49+
testName,
50+
preCheck: preCheckV2,
51+
skipTestIf: skipTest(false),
52+
});
53+
};
54+
655
// Don't run on Windows since the typecheck errors are dependent on system libs, and the set of diagnostics seems to vary.
7-
customLinterCheckTest({
8-
linterName: "golangci-lint",
56+
testGenerator({
957
args: `${TEST_DATA} -y`,
1058
testName: "all",
1159
skipTestIf: skipOS(["win32"]),
@@ -18,12 +66,11 @@ const addEmpty = (driver: TrunkLintDriver) => {
1866

1967
// Don't run on Windows since the typecheck errors are dependent on system libs, and for the sake of these tests
2068
// it is easier to simply skip these tests than handle additional setup.
21-
customLinterCheckTest({
22-
linterName: "golangci-lint",
23-
testName: "empty",
69+
testGenerator({
2470
args: TEST_DATA,
25-
preCheck: addEmpty,
71+
testName: "empty",
2672
skipTestIf: skipOS(["win32"]),
73+
preCheck: addEmpty,
2774
});
2875

2976
// Having an ignored file and no other files causes an error diagnostic to be surfaced.
@@ -32,8 +79,7 @@ const setupUnbuildable = (driver: TrunkLintDriver) => {
3279
driver.deleteFile(TEST_DATA);
3380
};
3481

35-
customLinterCheckTest({
36-
linterName: "golangci-lint",
82+
testGenerator({
3783
testName: "unbuildable",
3884
args: "unbuildable.go",
3985
preCheck: setupUnbuildable,

linters/golangci-lint/plugin.yaml

+59
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ tools:
77
package: github.com/golangci/golangci-lint/cmd/golangci-lint
88
shims: [golangci-lint]
99
known_good_version: 1.46.2
10+
- name: golangci-lint2
11+
runtime: go
12+
package: github.com/golangci/golangci-lint/v2/cmd/golangci-lint
13+
shims: [golangci-lint]
14+
known_good_version: 2.0.0
1015

1116
lint:
1217
definitions:
@@ -50,6 +55,60 @@ lint:
5055
run_from: ${root_or_parent_with(go.mod)}
5156
# TODO(Tyler): Audit golangci-lint running on upstream once sandboxing and relative path fix is landed.
5257
disable_upstream: true
58+
suggest_if: never
59+
direct_configs:
60+
- .golangci.json
61+
- .golangci.toml
62+
- .golangci.yaml
63+
- .golangci.yml
64+
affects_cache:
65+
- go.mod
66+
- go.sum
67+
issue_url_format: https://golangci-lint.run/usage/linters/
68+
known_good_version: 1.49.0
69+
version_command:
70+
parse_regex: ${semver}
71+
run: golangci-lint --version
72+
run_timeout: 10m
73+
- name: golangci-lint2
74+
files: [go]
75+
tools: [golangci-lint2]
76+
description: A powerful Go linter runner
77+
environment:
78+
- name: GOLANGCI_LINT_CACHE
79+
value: ${cachedir}
80+
# Needs to use system `diff` and `git`
81+
- name: PATH
82+
list: ["${env.PATH}"]
83+
- name: GO111MODULE
84+
value: auto
85+
# May need to git clone with ssh authentication for private packages.
86+
- name: SSH_AUTH_SOCK
87+
value: ${env.SSH_AUTH_SOCK}
88+
optional: true
89+
commands:
90+
- name: lint
91+
output: sarif
92+
read_output_from: tmp_file
93+
# We need to run golangci-lint on directories since running on files only works for --fast
94+
# and can also produce false positives.
95+
target: ${parent}
96+
# Exclude go linters we already include.
97+
run:
98+
golangci-lint run --output.sarif.path ${tmpfile} --timeout 10m --concurrency 1
99+
--allow-parallel-runners --issues-exit-code 0 ${target}
100+
# exit codes
101+
# 0 - success
102+
# 1 - issues found -> we override this to be 0
103+
# 2 - warning in test
104+
# 3 - failure
105+
# 4 - timeout
106+
# 5 - no go files
107+
# 6 - no config file detected
108+
# 7 - error logged
109+
success_codes: [0, 2, 7]
110+
run_from: ${root_or_parent_with(go.mod)}
111+
disable_upstream: true
53112
suggest_if: files_present
54113
direct_configs:
55114
- .golangci.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "2"
2+
linters:
3+
enable:
4+
- govet
5+
- asciicheck
6+
- bodyclose
7+
- depguard
8+
- dogsled
9+
- errcheck
10+
- gochecknoinits
11+
- godot
12+
- goheader
13+
- goprintffuncname
14+
- gosec
15+
- govet
16+
- ineffassign
17+
- misspell
18+
- nakedret
19+
- nolintlint
20+
- rowserrcheck
21+
- staticcheck
22+
- unconvert
23+
- unused
24+
- whitespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing linter golangci-lint2 test all 1`] = `
4+
{
5+
"issues": [
6+
{
7+
"code": "errcheck",
8+
"column": "12",
9+
"file": "test_data/basic.go",
10+
"issueClass": "ISSUE_CLASS_EXISTING",
11+
"issueUrl": "https://golangci-lint.run/usage/linters/",
12+
"level": "LEVEL_HIGH",
13+
"line": "8",
14+
"linter": "golangci-lint2",
15+
"message": "Error return value of \`time.Parse\` is not checked",
16+
"targetType": "go",
17+
},
18+
{
19+
"code": "unused",
20+
"column": "6",
21+
"file": "test_data/unused_func.go",
22+
"issueClass": "ISSUE_CLASS_EXISTING",
23+
"issueUrl": "https://golangci-lint.run/usage/linters/",
24+
"level": "LEVEL_HIGH",
25+
"line": "5",
26+
"linter": "golangci-lint2",
27+
"message": "func helper is unused",
28+
"targetType": "go",
29+
},
30+
{
31+
"code": "typecheck",
32+
"column": "1",
33+
"file": "test_data/wrapper/printer.go",
34+
"issueClass": "ISSUE_CLASS_EXISTING",
35+
"issueUrl": "https://golangci-lint.run/usage/linters/",
36+
"level": "LEVEL_HIGH",
37+
"line": "1",
38+
"linter": "golangci-lint2",
39+
"message": ": # golangcilint_linter_test/wrapper
40+
wrapper/printer.go:12:23: undefined: Wrapper2",
41+
"targetType": "go",
42+
},
43+
],
44+
"lintActions": [
45+
{
46+
"command": "lint",
47+
"fileGroupName": "go",
48+
"linter": "golangci-lint2",
49+
"paths": [
50+
"test_data",
51+
],
52+
"verb": "TRUNK_VERB_CHECK",
53+
},
54+
{
55+
"command": "lint",
56+
"fileGroupName": "go",
57+
"linter": "golangci-lint2",
58+
"paths": [
59+
"test_data/wrapper",
60+
],
61+
"verb": "TRUNK_VERB_CHECK",
62+
},
63+
],
64+
"taskFailures": [],
65+
"unformattedFiles": [],
66+
}
67+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing linter golangci-lint2 test empty 1`] = `
4+
{
5+
"issues": [
6+
{
7+
"code": "typecheck",
8+
"column": "1",
9+
"file": "test_data/empty.go",
10+
"issueClass": "ISSUE_CLASS_NEW",
11+
"issueUrl": "https://golangci-lint.run/usage/linters/",
12+
"level": "LEVEL_HIGH",
13+
"line": "1",
14+
"linter": "golangci-lint2",
15+
"message": "expected 'package', found 'EOF'",
16+
"targetType": "go",
17+
},
18+
{
19+
"code": "typecheck",
20+
"column": "1",
21+
"file": "test_data/wrapper/printer.go",
22+
"issueClass": "ISSUE_CLASS_EXISTING",
23+
"issueUrl": "https://golangci-lint.run/usage/linters/",
24+
"level": "LEVEL_HIGH",
25+
"line": "1",
26+
"linter": "golangci-lint2",
27+
"message": ": # golangcilint_linter_test/wrapper
28+
wrapper/printer.go:12:23: undefined: Wrapper2",
29+
"targetType": "go",
30+
},
31+
],
32+
"lintActions": [
33+
{
34+
"command": "lint",
35+
"fileGroupName": "go",
36+
"linter": "golangci-lint2",
37+
"paths": [
38+
"test_data",
39+
],
40+
"verb": "TRUNK_VERB_CHECK",
41+
},
42+
{
43+
"command": "lint",
44+
"fileGroupName": "go",
45+
"linter": "golangci-lint2",
46+
"paths": [
47+
"test_data/wrapper",
48+
],
49+
"verb": "TRUNK_VERB_CHECK",
50+
},
51+
],
52+
"taskFailures": [],
53+
"unformattedFiles": [],
54+
}
55+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing linter golangci-lint2 test unbuildable 1`] = `
4+
{
5+
"issues": [],
6+
"lintActions": [
7+
{
8+
"command": "lint",
9+
"fileGroupName": "go",
10+
"linter": "golangci-lint2",
11+
"paths": [
12+
".",
13+
],
14+
"verb": "TRUNK_VERB_CHECK",
15+
},
16+
],
17+
"taskFailures": [],
18+
"unformattedFiles": [],
19+
}
20+
`;

linters/psscriptanalyzer/plugin.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ downloads:
1212
linux: linux
1313
windows: windows
1414
macos: macos
15+
version: <=1.23.0
1516
url: https://github.com/PowerShell/PSScriptAnalyzer/releases/download/v${version}/PSScriptAnalyzer.${version}.nupkg
17+
- os:
18+
linux: linux
19+
windows: windows
20+
macos: macos
21+
url: https://github.com/PowerShell/PSScriptAnalyzer/releases/download/${version}/PSScriptAnalyzer.${version}.nupkg
1622
- name: converttosarif
1723
downloads:
1824
- os:

linters/scalafmt/plugin.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ lint:
4747
run: scalafmt --version
4848
known_good_version: 3.4.3
4949
# We don't support this semver format, and it's a prerelease
50-
known_bad_versions: [3.8.4-RC1]
50+
known_bad_versions: [3.8.4-RC1, 3.9.0]

linters/scalafmt/test_data/scalafmt_v3.9.0_basic.fmt.shot renamed to linters/scalafmt/test_data/scalafmt_v3.9.1_basic.fmt.shot

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// trunk-upgrade-validation:RELEASE
33

44
exports[`Testing formatter scalafmt test basic 1`] = `
5-
"case class Demo(a: String,
6-
b: Int,
7-
c: Char
8-
)
5+
"case class Demo(a: String, b: Int, c: Char)
96
"
107
`;

linters/scalafmt/test_data/scalafmt_v3.9.0_empty.check.shot renamed to linters/scalafmt/test_data/scalafmt_v3.9.1_empty.check.shot

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ exports[`Testing linter scalafmt test empty 1`] = `
1616
},
1717
],
1818
"taskFailures": [],
19-
"unformattedFiles": [],
19+
"unformattedFiles": [
20+
{
21+
"column": "1",
22+
"file": "test_data/empty.in.scala",
23+
"issueClass": "ISSUE_CLASS_UNFORMATTED",
24+
"level": "LEVEL_HIGH",
25+
"line": "1",
26+
"linter": "scalafmt",
27+
"message": "Incorrect formatting, autoformat by running 'trunk fmt'",
28+
},
29+
],
2030
}
2131
`;

linters/semgrep/plugin.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ lint:
3535
- name: PATH
3636
list: ["${env.PATH}"]
3737
known_good_version: 1.33.2
38-
known_bad_versions: [1.5.1] # Does not work on MacOS
38+
known_bad_versions: [1.5.1, 1.117.0] # Does not work on MacOS
3939
version_command:
4040
parse_regex: ${semver}
4141
run: semgrep --version

linters/snyk/snyk.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { customLinterCheckTest } from "tests";
2-
import { TEST_DATA } from "tests/utils";
1+
import { linterCheckTest } from "tests";
32

43
// Requires SNYK_TOKEN to run
5-
customLinterCheckTest({ linterName: "snyk", args: TEST_DATA, testName: "basic" });
4+
linterCheckTest({ linterName: "snyk" });
File renamed without changes.

0 commit comments

Comments
 (0)