File tree 6 files changed +95
-0
lines changed
6 files changed +95
-0
lines changed Original file line number Diff line number Diff line change @@ -2088,6 +2088,7 @@ linters:
2088
2088
- typecheck
2089
2089
- unconvert
2090
2090
- unparam
2091
+ - untypedconst
2091
2092
- unused
2092
2093
- usestdlibvars
2093
2094
- varcheck
@@ -2198,6 +2199,7 @@ linters:
2198
2199
- typecheck
2199
2200
- unconvert
2200
2201
- unparam
2202
+ - untypedconst
2201
2203
- unused
2202
2204
- usestdlibvars
2203
2205
- varcheck
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ require (
49
49
github.com/hashicorp/go-version v1.6.0
50
50
github.com/hexops/gotextdiff v1.0.3
51
51
github.com/jgautheron/goconst v1.5.1
52
+ github.com/jiftechnify/untypedconst v0.0.0-20211230012903-7f805b5dad89
52
53
github.com/jingyugao/rowserrcheck v1.1.1
53
54
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
54
55
github.com/julz/importas v0.1.0
Original file line number Diff line number Diff line change
1
+ package golinters
2
+
3
+ import (
4
+ "github.com/jiftechnify/untypedconst"
5
+ "golang.org/x/tools/go/analysis"
6
+
7
+ "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8
+ )
9
+
10
+ func NewUntypedConst () * goanalysis.Linter {
11
+ a := untypedconst .Analyzer
12
+
13
+ return goanalysis .NewLinter (
14
+ a .Name ,
15
+ a .Doc ,
16
+ []* analysis.Analyzer {a },
17
+ nil ,
18
+ ).WithLoadMode (goanalysis .LoadModeTypesInfo )
19
+ }
Original file line number Diff line number Diff line change @@ -821,6 +821,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
821
821
WithLoadForGoAnalysis ().
822
822
WithURL ("https://github.com/mvdan/unparam" ),
823
823
824
+ linter .NewConfig (golinters .NewUntypedConst ()).
825
+ WithSince ("v1.51.0" ).
826
+ WithPresets (linter .PresetBugs ).
827
+ WithURL ("https://github.com/jiftechnify/untypedconst" ),
828
+
824
829
linter .NewConfig (golinters .NewUnused (unusedCfg )).
825
830
WithSince ("v1.20.0" ).
826
831
WithLoadForGoAnalysis ().
Original file line number Diff line number Diff line change
1
+ //golangcitest:args -Euntypedconst
2
+ package testdata
3
+
4
+ type ExString string
5
+
6
+ func retExString () ExString {
7
+ if true {
8
+ return ExString ("hoge" )
9
+ } else {
10
+ return "hoge" // want `returning untyped constant as defined type "command-line-arguments.ExString"`
11
+ }
12
+ }
13
+
14
+ type ExInt int
15
+
16
+ func retExInt () ExInt {
17
+ if true {
18
+ return ExInt (1 )
19
+ } else {
20
+ return 1 // want `returning untyped constant as defined type "command-line-arguments.ExInt"`
21
+ }
22
+ }
23
+
24
+ type ExFloat float64
25
+
26
+ func retExFloat () ExFloat {
27
+ if true {
28
+ return ExFloat (0.5 )
29
+ } else {
30
+ return 0.5 // want `returning untyped constant as defined type "command-line-arguments.ExFloat"`
31
+ }
32
+ }
33
+
34
+ type ExComplex complex128
35
+
36
+ func retExComplex () ExComplex {
37
+ if true {
38
+ return ExComplex (1.0 + 0.5i )
39
+ } else {
40
+ return 1.0 + 0.5i // want `returning untyped constant as defined type "command-line-arguments.ExComplex"`
41
+ }
42
+ }
43
+
44
+ type ExRune rune
45
+
46
+ func retExRune () ExRune {
47
+ if true {
48
+ return ExRune ('a' )
49
+ } else {
50
+ return 'a' // want `returning untyped constant as defined type "command-line-arguments.ExRune"`
51
+ }
52
+ }
53
+
54
+ type ExBool bool
55
+
56
+ func retExBool () ExBool {
57
+ if true {
58
+ return ExBool (true )
59
+ } else {
60
+ return true // want `returning untyped constant as defined type "command-line-arguments.ExBool"`
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments