Skip to content

Commit

Permalink
feat: add testableexamples linter (#3170)
Browse files Browse the repository at this point in the history
  • Loading branch information
maratori committed Sep 6, 2022
1 parent 3a2ad90 commit 281e184
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Expand Up @@ -2011,6 +2011,7 @@ linters:
- stylecheck
- tagliatelle
- tenv
- testableexamples
- testpackage
- thelper
- tparallel
Expand Down Expand Up @@ -2116,6 +2117,7 @@ linters:
- stylecheck
- tagliatelle
- tenv
- testableexamples
- testpackage
- thelper
- tparallel
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -58,6 +58,7 @@ require (
github.com/ldez/tagliatelle v0.3.1
github.com/leonklingele/grouper v1.1.0
github.com/lufeee/execinquery v1.2.1
github.com/maratori/testableexamples v1.0.0
github.com/maratori/testpackage v1.1.0
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0
github.com/mattn/go-colorable v0.1.13
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/golinters/testableexamples.go
@@ -0,0 +1,19 @@
package golinters

import (
"github.com/maratori/testableexamples/pkg/testableexamples"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewTestableexamples() *goanalysis.Linter {
a := testableexamples.NewAnalyzer()

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
5 changes: 5 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -750,6 +750,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithLoadForGoAnalysis().
WithURL("https://github.com/sivchari/tenv"),

linter.NewConfig(golinters.NewTestableexamples()).
WithSince("v1.50.0").
WithPresets(linter.PresetTest).
WithURL("https://github.com/maratori/testableexamples"),

linter.NewConfig(golinters.NewTestpackage(testpackageCfg)).
WithSince("v1.25.0").
WithPresets(linter.PresetStyle, linter.PresetTest).
Expand Down
23 changes: 23 additions & 0 deletions test/testdata/testableexamples_test.go
@@ -0,0 +1,23 @@
//golangcitest:args -Etestableexamples
package testdata

import "fmt"

func Example_good() {
fmt.Println("hello")
// Output: hello
}

func Example_goodEmptyOutput() {
fmt.Println("")
// Output:
}

func Example_bad() { // want `^missing output for example, go test can't validate it$`
fmt.Println("hello")
}

//nolint:testableexamples
func Example_nolint() {
fmt.Println("hello")
}

0 comments on commit 281e184

Please sign in to comment.