Skip to content

Commit

Permalink
feat(staticcheck): turn off compile errors by default
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJi committed Jan 20, 2024
1 parent 5f4d521 commit 1bb7298
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
16 changes: 16 additions & 0 deletions internal/linters/go/staticcheck/staticcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func staticcheckHandler(log *xlog.Logger, linterConfig config.Linter, agent lint
return nil, err
}

if isEmpty(linterConfig.Args...) {
// turn off compile errors by default
linterConfig.Args = append([]string{}, "-debug.no-compile-errors=true", "./...")
}

output, err := executor.Run(log, linterConfig.Args...)
if err != nil {
log.Errorf("staticcheck run failed: %v", err)
Expand All @@ -58,6 +63,16 @@ func staticcheckHandler(log *xlog.Logger, linterConfig config.Linter, agent lint
return parsedOutput, nil
}

func isEmpty(args ...string) bool {
for _, arg := range args {
if arg != "" {
return false
}
}

return true
}

// Staticcheck is an executor that knows how to execute Staticcheck commands.
type Staticcheck struct {
// dir is the location of this repo.
Expand All @@ -82,6 +97,7 @@ func NewStaticcheckExecutor(dir string) (linters.Linter, error) {
execute: func(dir, command string, args ...string) ([]byte, error) {
c := exec.Command(command, args...)
c.Dir = dir
log.Printf("final command: %v \n", c)
return c.Output()
},
}, nil
Expand Down
24 changes: 21 additions & 3 deletions internal/linters/go/staticcheck/staticcheck_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
Copyright 2024 Qiniu Cloud (qiniu.com).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -72,3 +72,21 @@ func TestFormatStaticcheckLine(t *testing.T) {
}
}
}

func TestIsEmpty(t *testing.T) {
tcs := []struct {
input []string
expected bool
}{
{[]string{}, true},
{[]string{""}, true},
{[]string{" "}, false},
{[]string{"a"}, false},
}
for _, tc := range tcs {
actual := isEmpty(tc.input...)
if actual != tc.expected {
t.Errorf("expected: %v, got: %v", tc.expected, actual)
}
}
}

0 comments on commit 1bb7298

Please sign in to comment.