File tree Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ require (
31
31
github.com/golangci/revgrep v0.0.0-20210208091834-cd28932614b5
32
32
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
33
33
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254
34
+ github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5
34
35
github.com/gostaticanalysis/nilerr v0.1.1
35
36
github.com/jgautheron/goconst v1.4.0
36
37
github.com/jingyugao/rowserrcheck v0.0.0-20210130005344-c6a0c12dd98d
Original file line number Diff line number Diff line change
1
+ package golinters
2
+
3
+ import (
4
+ "github.com/gostaticanalysis/forcetypeassert"
5
+ "golang.org/x/tools/go/analysis"
6
+
7
+ "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8
+ )
9
+
10
+ func NewForceTypeAssert () * goanalysis.Linter {
11
+ a := forcetypeassert .Analyzer
12
+
13
+ return goanalysis .NewLinter (
14
+ a .Name ,
15
+ "finds forced type assertions" ,
16
+ []* analysis.Analyzer {a },
17
+ nil ,
18
+ ).WithLoadMode (goanalysis .LoadModeTypesInfo )
19
+ }
Original file line number Diff line number Diff line change @@ -390,6 +390,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
390
390
WithLoadForGoAnalysis ().
391
391
WithPresets (linter .PresetBugs ).
392
392
WithURL ("https://github.com/gostaticanalysis/nilerr" ),
393
+ linter .NewConfig (golinters .NewForceTypeAssert ()).
394
+ WithPresets (linter .PresetStyle ).
395
+ WithLoadForGoAnalysis ().
396
+ WithURL ("https://github.com/gostaticanalysis/forcetypeassert" ),
393
397
394
398
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
395
399
linter .NewConfig (golinters .NewNoLintLint ()).
Original file line number Diff line number Diff line change
1
+ //args: -Eforcetypeassert
2
+ package testdata
3
+
4
+ import "fmt"
5
+
6
+ func forcetypeassertInvalid () {
7
+ var a interface {}
8
+ _ = a .(int ) // ERROR "type assertion must be checked"
9
+
10
+ var b interface {}
11
+ bi := b .(int ) // ERROR "type assertion must be checked"
12
+ fmt .Println (bi )
13
+ }
14
+
15
+ func forcetypeassertValid () {
16
+ var a interface {}
17
+ if ai , ok := a .(int ); ok {
18
+ fmt .Println (ai )
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments