Skip to content

Commit

Permalink
Add golangci lint suggestions (#1145)
Browse files Browse the repository at this point in the history
Co-authored-by: Bryan Helmkamp <[email protected]>
  • Loading branch information
marschattha and brynary authored Nov 18, 2024
1 parent f79e7b8 commit ac0058b
Show file tree
Hide file tree
Showing 12 changed files with 537 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=basic version=1.59.1 1`] = `
"issues": [
{
"category": "CATEGORY_LINT",
"level": "LEVEL_HIGH",
"level": "LEVEL_MEDIUM",
"location": {
"path": "basic.in.go",
"range": {
"endColumn": 12,
"endLine": 8,
"startColumn": 12,
"startLine": 8,
},
Expand All @@ -32,12 +30,10 @@ func main() {
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_HIGH",
"level": "LEVEL_MEDIUM",
"location": {
"path": "basic.in.go",
"range": {
"endColumn": 34,
"endLine": 6,
"startColumn": 34,
"startLine": 6,
},
Expand All @@ -55,6 +51,36 @@ import "time"
func main() {
time.Parse("asdf", "")
}",
"suggestions": [
{
"patch": "--- original
+++ modified
@@ -3,7 +3,7 @@
import "time"

// ✋✋✋✋
-// this is the main function 🏃
+// this is the main function 🏃.
func main() {
time.Parse("asdf", "")
}
",
"replacements": [
{
"data": "// this is the main function 🏃.",
"location": {
"path": "basic.in.go",
"range": {
"endColumn": 34,
"endLine": 6,
"startLine": 6,
},
},
},
],
"source": "SUGGESTION_SOURCE_TOOL",
},
],
"tool": "golangci-lint",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=basic version=1.61.0 1`] = `
"issues": [
{
"category": "CATEGORY_LINT",
"level": "LEVEL_HIGH",
"level": "LEVEL_MEDIUM",
"location": {
"path": "basic.in.go",
"range": {
"endColumn": 12,
"endLine": 8,
"startColumn": 12,
"startLine": 8,
},
Expand All @@ -32,12 +30,10 @@ func main() {
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_HIGH",
"level": "LEVEL_MEDIUM",
"location": {
"path": "basic.in.go",
"range": {
"endColumn": 34,
"endLine": 6,
"startColumn": 34,
"startLine": 6,
},
Expand All @@ -55,6 +51,36 @@ import "time"
func main() {
time.Parse("asdf", "")
}",
"suggestions": [
{
"patch": "--- original
+++ modified
@@ -3,7 +3,7 @@
import "time"

// ✋✋✋✋
-// this is the main function 🏃
+// this is the main function 🏃.
func main() {
time.Parse("asdf", "")
}
",
"replacements": [
{
"data": "// this is the main function 🏃.",
"location": {
"path": "basic.in.go",
"range": {
"endColumn": 34,
"endLine": 6,
"startLine": 6,
},
},
},
],
"source": "SUGGESTION_SOURCE_TOOL",
},
],
"tool": "golangci-lint",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=unused_func version=1.59.1 1`] = `
"issues": [
{
"category": "CATEGORY_LINT",
"level": "LEVEL_HIGH",
"level": "LEVEL_MEDIUM",
"location": {
"path": "unused_func.in.go",
"range": {
"endColumn": 6,
"endLine": 5,
"startColumn": 6,
"startLine": 5,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ exports[`linter=golangci-lint fixture=unused_func version=1.61.0 1`] = `
"issues": [
{
"category": "CATEGORY_LINT",
"level": "LEVEL_HIGH",
"level": "LEVEL_MEDIUM",
"location": {
"path": "unused_func.in.go",
"range": {
"endColumn": 6,
"endLine": 5,
"startColumn": 6,
"startLine": 5,
},
Expand Down
4 changes: 2 additions & 2 deletions plugins/linters/golangci-lint/plugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ security = true
suggested = "targets"

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

[[plugins.definitions.golangci-lint.environment]]
Expand Down
2 changes: 2 additions & 0 deletions qlty-check/src/executor/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::parser::bandit::Bandit;
use crate::parser::clippy::Clippy;
use crate::parser::coffeelint::Coffeelint;
use crate::parser::eslint::Eslint;
use crate::parser::golangci_lint::GolangciLint;
use crate::parser::hadolint::Hadolint;
use crate::parser::knip::Knip;
use crate::parser::markdownlint::Markdownlint;
Expand Down Expand Up @@ -428,6 +429,7 @@ impl Driver {
OutputFormat::Radarlint => Box::new(Radarlint {}),
OutputFormat::Coffeelint => Box::new(Coffeelint {}),
OutputFormat::Ruff => Box::new(Ruff {}),
OutputFormat::GolangciLint => Box::new(GolangciLint {}),

OutputFormat::Sarif => {
let level = match self.output_level {
Expand Down
1 change: 1 addition & 0 deletions qlty-check/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod taplo;
pub mod trivy_sarif;
pub mod trufflehog;
pub mod tsc;
pub mod golangci_lint;

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

0 comments on commit ac0058b

Please sign in to comment.