Merge pull request #59 from golangci/feature/enabled-tests-linting-by-default

#52: #36: lint test files by default
This commit is contained in:
Isaev Denis 2018-06-02 18:30:08 +03:00 committed by GitHub
commit 68e1295340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 12 deletions

View File

@ -1,6 +1,3 @@
run:
tests: true
linters-settings:
govet:
check-shadowing: true

View File

@ -223,7 +223,7 @@ Flags:
--issues-exit-code int Exit code when issues were found (default 1)
--build-tags strings Build tags (not all linters support them)
--deadline duration Deadline for total work (default 1m0s)
--tests Analyze tests (*_test.go)
--tests Analyze tests (*_test.go) (default true)
--print-resources-usage Print avg and max memory usage of golangci-lint and total time
-c, --config PATH Read config from file path PATH
--no-config Don't read config
@ -293,9 +293,6 @@ There is a [`.golangci.yml`](https://github.com/golangci/golangci-lint/blob/mast
It's a [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) of this repo: we enable more linters than by default and make their settings more strict:
```yaml
run:
tests: true
linters-settings:
govet:
check-shadowing: true

View File

@ -69,7 +69,7 @@ func (e *Executor) initFlagSet(fs *pflag.FlagSet) {
1, wh("Exit code when issues were found"))
fs.StringSliceVar(&rc.BuildTags, "build-tags", []string{}, wh("Build tags (not all linters support them)"))
fs.DurationVar(&rc.Deadline, "deadline", time.Minute, wh("Deadline for total work"))
fs.BoolVar(&rc.AnalyzeTests, "tests", false, wh("Analyze tests (*_test.go)"))
fs.BoolVar(&rc.AnalyzeTests, "tests", true, wh("Analyze tests (*_test.go)"))
fs.BoolVar(&rc.PrintResourcesUsage, "print-resources-usage", false, wh("Print avg and max memory usage of golangci-lint and total time"))
fs.StringVarP(&rc.Config, "config", "c", "", wh("Read config from file path `PATH`"))
fs.BoolVar(&rc.NoConfig, "no-config", false, wh("Don't read config"))

View File

@ -20,22 +20,20 @@ func installBinary(t assert.TestingT) {
}
func TestCongratsMessageIfNoIssues(t *testing.T) {
installBinary(t)
out, exitCode := runGolangciLint(t, "../...")
assert.Equal(t, 0, exitCode)
assert.Equal(t, "Congrats! No issues were found.\n", out)
}
func TestDeadline(t *testing.T) {
installBinary(t)
out, exitCode := runGolangciLint(t, "--no-config", "--deadline=1ms", "../...")
assert.Equal(t, 4, exitCode)
assert.Equal(t, "", out) // no 'Congrats! No issues were found.'
}
func runGolangciLint(t *testing.T, args ...string) (string, int) {
installBinary(t)
runArgs := append([]string{"run"}, args...)
cmd := exec.Command("golangci-lint", runArgs...)
out, err := cmd.Output()
@ -54,3 +52,8 @@ func runGolangciLint(t *testing.T, args ...string) (string, int) {
ws := cmd.ProcessState.Sys().(syscall.WaitStatus)
return string(out), ws.ExitStatus()
}
func TestTestsAreLintedByDefault(t *testing.T) {
out, exitCode := runGolangciLint(t, "--no-config", "./testdata/withtests")
assert.Equal(t, 0, exitCode, out)
}

23
test/testdata/withtests/p.go vendored Normal file
View File

@ -0,0 +1,23 @@
package withtests
import "fmt"
var varUsedOnlyInTests bool
func usedOnlyInTests() {}
type someType struct {
fieldUsedOnlyInTests bool
fieldUsedHere bool
}
func usedHere() {
v := someType{
fieldUsedHere: true,
}
fmt.Println(v)
}
func init() {
usedHere()
}

14
test/testdata/withtests/p_test.go vendored Normal file
View File

@ -0,0 +1,14 @@
package withtests
import (
"fmt"
"testing"
)
func TestSomething(t *testing.T) {
v := someType{
fieldUsedOnlyInTests: true,
}
fmt.Println(v, varUsedOnlyInTests)
usedOnlyInTests()
}