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

feat: add testableexamples linter #3170

Merged
merged 2 commits into from Sep 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Expand Up @@ -1985,6 +1985,7 @@ linters:
- stylecheck
- tagliatelle
- tenv
- testableexamples
- testpackage
- thelper
- tparallel
Expand Down Expand Up @@ -2090,6 +2091,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 @@ -747,6 +747,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")
}