Skip to content

Commit f9bba13

Browse files
authored
Merge pull request #779 from pranc1ngpegasus/fix/migrate-to-golangci-lint-v2
fix: migrate to golangci-lint v2
2 parents c6764e1 + 5a4f816 commit f9bba13

File tree

7 files changed

+94
-31
lines changed

7 files changed

+94
-31
lines changed
File renamed without changes.

.github/.golangci.v2.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# https://golangci-lint.run/usage/configuration/
2+
version: "2"
3+
linters-settings:
4+
govet:
5+
check-shadowing: true
6+
misspell:
7+
locale: US
8+
errcheck:
9+
check-type-assertions: false
10+
check-blank: false
11+
12+
linters:
13+
default: none
14+
enable:
15+
- govet
16+
- misspell
17+
- errcheck
18+
exclusions:
19+
presets:
20+
- comments
21+
- common-false-positives
22+
- legacy
23+
- std-error-handling
24+
25+
formatters:
26+
default: none
27+
28+
issues:
29+
max-same-issues: 0

.github/workflows/reviewdog.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jobs:
77
golangci-lint:
88
name: runner / golangci-lint
99
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
golangci-lint-version: ["v1", "v2"]
1013
steps:
1114
- name: Check out code into the Go module directory
1215
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -15,14 +18,16 @@ jobs:
1518
with:
1619
github_token: ${{ secrets.github_token }}
1720
level: warning
18-
golangci_lint_flags: "--config=.github/.golangci.yml ./testdata"
21+
golangci_lint_version: ${{ matrix.golangci-lint-version == 'v1' && 'v1.64.8' || 'latest' }}
22+
golangci_lint_flags: "--config=.github/.golangci.${{ matrix.golangci-lint-version }}.yml ./testdata"
1923

2024
golangci-lint-platform:
2125
name: runner / golangci-lint-platform
2226
strategy:
2327
fail-fast: false
2428
matrix:
2529
platform: [ubuntu-latest, macos-latest, windows-latest]
30+
golangci-lint-version: ["v1", "v2"]
2631
runs-on: ${{ matrix.platform }}
2732
steps:
2833
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -32,7 +37,8 @@ jobs:
3237
github_token: ${{ secrets.github_token }}
3338
tool_name: golangci-lint-${{ matrix.platform }}
3439
level: warning
35-
golangci_lint_flags: "--config=.github/.golangci.yml ./testdata --timeout 10m"
40+
golangci_lint_version: ${{ matrix.golangci-lint-version == 'v1' && 'v1.64.8' || 'latest' }}
41+
golangci_lint_flags: "--config=.github/.golangci.${{ matrix.golangci-lint-version }}.yml ./testdata --timeout 10m"
3642

3743
golangci-lint-github-pr-review:
3844
name: runner / golangci-lint (github-pr-review)
@@ -88,7 +94,7 @@ jobs:
8894
github_token: ${{ secrets.github_token }}
8995
tool_name: "golangci-lint-all-in-one"
9096
level: warning
91-
golangci_lint_flags: "--enable-all --exclude-use-default=false ./testdata"
97+
golangci_lint_flags: "--default all ./testdata"
9298

9399
govet:
94100
name: runner / govet
@@ -100,7 +106,7 @@ jobs:
100106
uses: ./
101107
with:
102108
github_token: ${{ secrets.github_token }}
103-
golangci_lint_flags: "--disable-all -E govet ./testdata"
109+
golangci_lint_flags: "--default none -E govet ./testdata"
104110
tool_name: govet
105111

106112
staticcheck:
@@ -113,23 +119,9 @@ jobs:
113119
uses: ./
114120
with:
115121
github_token: ${{ secrets.github_token }}
116-
golangci_lint_flags: "--disable-all -E staticcheck ./testdata"
122+
golangci_lint_flags: "--default none -E staticcheck ./testdata"
117123
tool_name: staticcheck
118124

119-
golint:
120-
name: runner / golint
121-
runs-on: ubuntu-latest
122-
steps:
123-
- name: Check out code into the Go module directory
124-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
125-
- name: golint
126-
uses: ./
127-
with:
128-
github_token: ${{ secrets.github_token }}
129-
golangci_lint_flags: "--disable-all -E golint ./testdata"
130-
tool_name: golint
131-
level: warning
132-
133125
errcheck:
134126
name: runner / errcheck
135127
runs-on: ubuntu-latest
@@ -140,7 +132,7 @@ jobs:
140132
uses: ./
141133
with:
142134
github_token: ${{ secrets.github_token }}
143-
golangci_lint_flags: "--disable-all -E errcheck ./testdata"
135+
golangci_lint_flags: "--default none -E errcheck ./testdata"
144136
tool_name: errcheck
145137
level: warning
146138

@@ -154,7 +146,7 @@ jobs:
154146
uses: ./
155147
with:
156148
github_token: ${{ secrets.github_token }}
157-
golangci_lint_flags: "--disable-all -E misspell ./testdata"
149+
golangci_lint_flags: "--default none -E misspell ./testdata"
158150
tool_name: misspell
159151
level: info
160152

__test__/main.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { isGolangciLintV1 } from "../src/main";
2+
3+
describe("isV1", () => {
4+
it("should return false if the version is latest", () => {
5+
expect(isGolangciLintV1("latest")).toBe(false);
6+
});
7+
8+
it("should return true if the version is v1.x.x", () => {
9+
expect(isGolangciLintV1("v1.0.0")).toBe(true);
10+
});
11+
12+
it("should return true if the version is v2.x.x", () => {
13+
expect(isGolangciLintV1("v2.0.0")).toBe(false);
14+
});
15+
});

dist/index.js

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ async function run(): Promise<void> {
5858
}
5959

6060
const output = await core.group("Running golangci-lint ...", async (): Promise<exec.ExecOutput> => {
61-
return await exec.getExecOutput(
62-
golangci,
63-
["run", "--out-format", "line-number", ...flags.parse(golangciLintFlags)],
64-
{
65-
cwd,
66-
ignoreReturnCode: true,
67-
},
68-
);
61+
const options = isGolangciLintV1(golangciLintVersion)
62+
? ["run", "--out-format", "line-number", ...flags.parse(golangciLintFlags)]
63+
: ["run", "--output.text.path", "stdout", ...flags.parse(golangciLintFlags)];
64+
65+
return await exec.getExecOutput(golangci, options, {
66+
cwd,
67+
ignoreReturnCode: true,
68+
});
6969
});
7070

7171
switch (output.exitCode) {
@@ -132,4 +132,17 @@ async function run(): Promise<void> {
132132
}
133133
}
134134

135+
export function isGolangciLintV1(version: string): boolean {
136+
if (version === "latest") {
137+
return false;
138+
}
139+
140+
const match = version.match(/^v?(\d+)/);
141+
if (!match) {
142+
throw new Error(`Invalid golangci-lint version: ${version}`);
143+
}
144+
145+
return parseInt(match[1], 10) === 1;
146+
}
147+
135148
void run();

0 commit comments

Comments
 (0)