Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci lint suggestions #1145

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading