Skip to content

Commit ac0058b

Browse files
marschatthabrynary
andauthored
Add golangci lint suggestions (#1145)
Co-authored-by: Bryan Helmkamp <bryan@brynary.com>
1 parent f79e7b8 commit ac0058b

File tree

12 files changed

+537
-22
lines changed

12 files changed

+537
-22
lines changed

plugins/linters/golangci-lint/fixtures/__snapshots__/basic_v1.59.1.shot

+32-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=basic version=1.59.1 1`] = `
55
"issues": [
66
{
77
"category": "CATEGORY_LINT",
8-
"level": "LEVEL_HIGH",
8+
"level": "LEVEL_MEDIUM",
99
"location": {
1010
"path": "basic.in.go",
1111
"range": {
12-
"endColumn": 12,
13-
"endLine": 8,
1412
"startColumn": 12,
1513
"startLine": 8,
1614
},
@@ -32,12 +30,10 @@ func main() {
3230
},
3331
{
3432
"category": "CATEGORY_LINT",
35-
"level": "LEVEL_HIGH",
33+
"level": "LEVEL_MEDIUM",
3634
"location": {
3735
"path": "basic.in.go",
3836
"range": {
39-
"endColumn": 34,
40-
"endLine": 6,
4137
"startColumn": 34,
4238
"startLine": 6,
4339
},
@@ -55,6 +51,36 @@ import "time"
5551
func main() {
5652
time.Parse("asdf", "")
5753
}",
54+
"suggestions": [
55+
{
56+
"patch": "--- original
57+
+++ modified
58+
@@ -3,7 +3,7 @@
59+
import "time"
60+
61+
// ✋✋✋✋
62+
-// this is the main function 🏃
63+
+// this is the main function 🏃.
64+
func main() {
65+
time.Parse("asdf", "")
66+
}
67+
",
68+
"replacements": [
69+
{
70+
"data": "// this is the main function 🏃.",
71+
"location": {
72+
"path": "basic.in.go",
73+
"range": {
74+
"endColumn": 34,
75+
"endLine": 6,
76+
"startLine": 6,
77+
},
78+
},
79+
},
80+
],
81+
"source": "SUGGESTION_SOURCE_TOOL",
82+
},
83+
],
5884
"tool": "golangci-lint",
5985
},
6086
],

plugins/linters/golangci-lint/fixtures/__snapshots__/basic_v1.61.0.shot

+32-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=basic version=1.61.0 1`] = `
55
"issues": [
66
{
77
"category": "CATEGORY_LINT",
8-
"level": "LEVEL_HIGH",
8+
"level": "LEVEL_MEDIUM",
99
"location": {
1010
"path": "basic.in.go",
1111
"range": {
12-
"endColumn": 12,
13-
"endLine": 8,
1412
"startColumn": 12,
1513
"startLine": 8,
1614
},
@@ -32,12 +30,10 @@ func main() {
3230
},
3331
{
3432
"category": "CATEGORY_LINT",
35-
"level": "LEVEL_HIGH",
33+
"level": "LEVEL_MEDIUM",
3634
"location": {
3735
"path": "basic.in.go",
3836
"range": {
39-
"endColumn": 34,
40-
"endLine": 6,
4137
"startColumn": 34,
4238
"startLine": 6,
4339
},
@@ -55,6 +51,36 @@ import "time"
5551
func main() {
5652
time.Parse("asdf", "")
5753
}",
54+
"suggestions": [
55+
{
56+
"patch": "--- original
57+
+++ modified
58+
@@ -3,7 +3,7 @@
59+
import "time"
60+
61+
// ✋✋✋✋
62+
-// this is the main function 🏃
63+
+// this is the main function 🏃.
64+
func main() {
65+
time.Parse("asdf", "")
66+
}
67+
",
68+
"replacements": [
69+
{
70+
"data": "// this is the main function 🏃.",
71+
"location": {
72+
"path": "basic.in.go",
73+
"range": {
74+
"endColumn": 34,
75+
"endLine": 6,
76+
"startLine": 6,
77+
},
78+
},
79+
},
80+
],
81+
"source": "SUGGESTION_SOURCE_TOOL",
82+
},
83+
],
5884
"tool": "golangci-lint",
5985
},
6086
],

plugins/linters/golangci-lint/fixtures/__snapshots__/unused_func_v1.59.1.shot

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=unused_func version=1.59.1 1`] = `
55
"issues": [
66
{
77
"category": "CATEGORY_LINT",
8-
"level": "LEVEL_HIGH",
8+
"level": "LEVEL_MEDIUM",
99
"location": {
1010
"path": "unused_func.in.go",
1111
"range": {
12-
"endColumn": 6,
13-
"endLine": 5,
1412
"startColumn": 6,
1513
"startLine": 5,
1614
},

plugins/linters/golangci-lint/fixtures/__snapshots__/unused_func_v1.61.0.shot

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=unused_func version=1.61.0 1`] = `
55
"issues": [
66
{
77
"category": "CATEGORY_LINT",
8-
"level": "LEVEL_HIGH",
8+
"level": "LEVEL_MEDIUM",
99
"location": {
1010
"path": "unused_func.in.go",
1111
"range": {
12-
"endColumn": 6,
13-
"endLine": 5,
1412
"startColumn": 6,
1513
"startLine": 5,
1614
},

plugins/linters/golangci-lint/plugin.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ security = true
2323
suggested = "targets"
2424

2525
[plugins.definitions.golangci-lint.drivers.lint]
26-
script = "golangci-lint run --out-format sarif --timeout 10m --exclude gofmt --allow-parallel-runners --issues-exit-code 0 ${target}"
26+
script = "golangci-lint run --out-format json --timeout 10m --exclude gofmt --allow-parallel-runners --issues-exit-code 0 ${target}"
2727
target = { type = "literal", path = "./..." }
2828
runs_from = { type = "root_or_parent_with", path = "go.mod" }
2929
success_codes = [0, 2, 7]
3030
output = "stdout"
31-
output_format = "sarif"
31+
output_format = "golangci_lint"
3232
suggested = "targets"
3333

3434
[[plugins.definitions.golangci-lint.environment]]

qlty-check/src/executor/driver.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::parser::bandit::Bandit;
55
use crate::parser::clippy::Clippy;
66
use crate::parser::coffeelint::Coffeelint;
77
use crate::parser::eslint::Eslint;
8+
use crate::parser::golangci_lint::GolangciLint;
89
use crate::parser::hadolint::Hadolint;
910
use crate::parser::knip::Knip;
1011
use crate::parser::markdownlint::Markdownlint;
@@ -428,6 +429,7 @@ impl Driver {
428429
OutputFormat::Radarlint => Box::new(Radarlint {}),
429430
OutputFormat::Coffeelint => Box::new(Coffeelint {}),
430431
OutputFormat::Ruff => Box::new(Ruff {}),
432+
OutputFormat::GolangciLint => Box::new(GolangciLint {}),
431433

432434
OutputFormat::Sarif => {
433435
let level = match self.output_level {

qlty-check/src/parser.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod taplo;
2626
pub mod trivy_sarif;
2727
pub mod trufflehog;
2828
pub mod tsc;
29+
pub mod golangci_lint;
2930

3031
pub trait Parser {
3132
fn parse(&self, plugin_name: &str, output: &str) -> Result<Vec<Issue>>;

0 commit comments

Comments
 (0)