feat: add testableexamples linter (#3170)
This commit is contained in:
parent
3a2ad9083a
commit
281e1847f1
@ -2011,6 +2011,7 @@ linters:
|
|||||||
- stylecheck
|
- stylecheck
|
||||||
- tagliatelle
|
- tagliatelle
|
||||||
- tenv
|
- tenv
|
||||||
|
- testableexamples
|
||||||
- testpackage
|
- testpackage
|
||||||
- thelper
|
- thelper
|
||||||
- tparallel
|
- tparallel
|
||||||
@ -2116,6 +2117,7 @@ linters:
|
|||||||
- stylecheck
|
- stylecheck
|
||||||
- tagliatelle
|
- tagliatelle
|
||||||
- tenv
|
- tenv
|
||||||
|
- testableexamples
|
||||||
- testpackage
|
- testpackage
|
||||||
- thelper
|
- thelper
|
||||||
- tparallel
|
- tparallel
|
||||||
|
1
go.mod
1
go.mod
@ -58,6 +58,7 @@ require (
|
|||||||
github.com/ldez/tagliatelle v0.3.1
|
github.com/ldez/tagliatelle v0.3.1
|
||||||
github.com/leonklingele/grouper v1.1.0
|
github.com/leonklingele/grouper v1.1.0
|
||||||
github.com/lufeee/execinquery v1.2.1
|
github.com/lufeee/execinquery v1.2.1
|
||||||
|
github.com/maratori/testableexamples v1.0.0
|
||||||
github.com/maratori/testpackage v1.1.0
|
github.com/maratori/testpackage v1.1.0
|
||||||
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0
|
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0
|
||||||
github.com/mattn/go-colorable v0.1.13
|
github.com/mattn/go-colorable v0.1.13
|
||||||
|
2
go.sum
generated
2
go.sum
generated
@ -341,6 +341,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ
|
|||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||||
|
github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI=
|
||||||
|
github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE=
|
||||||
github.com/maratori/testpackage v1.1.0 h1:GJY4wlzQhuBusMF1oahQCBtUV/AQ/k69IZ68vxaac2Q=
|
github.com/maratori/testpackage v1.1.0 h1:GJY4wlzQhuBusMF1oahQCBtUV/AQ/k69IZ68vxaac2Q=
|
||||||
github.com/maratori/testpackage v1.1.0/go.mod h1:PeAhzU8qkCwdGEMTEupsHJNlQu2gZopMC6RjbhmHeDc=
|
github.com/maratori/testpackage v1.1.0/go.mod h1:PeAhzU8qkCwdGEMTEupsHJNlQu2gZopMC6RjbhmHeDc=
|
||||||
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 h1:pWxk9e//NbPwfxat7RXkts09K+dEBJWakUWwICVqYbA=
|
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 h1:pWxk9e//NbPwfxat7RXkts09K+dEBJWakUWwICVqYbA=
|
||||||
|
19
pkg/golinters/testableexamples.go
Normal file
19
pkg/golinters/testableexamples.go
Normal file
@ -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)
|
||||||
|
}
|
@ -750,6 +750,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
|||||||
WithLoadForGoAnalysis().
|
WithLoadForGoAnalysis().
|
||||||
WithURL("https://github.com/sivchari/tenv"),
|
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)).
|
linter.NewConfig(golinters.NewTestpackage(testpackageCfg)).
|
||||||
WithSince("v1.25.0").
|
WithSince("v1.25.0").
|
||||||
WithPresets(linter.PresetStyle, linter.PresetTest).
|
WithPresets(linter.PresetStyle, linter.PresetTest).
|
||||||
|
23
test/testdata/testableexamples_test.go
vendored
Normal file
23
test/testdata/testableexamples_test.go
vendored
Normal file
@ -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")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user