Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitad1ca78

Browse files
committed
feat: add untypedconst linter
Implements#3478.
1 parent474fdaf commitad1ca78

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

‎.golangci.next.reference.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ linters:
111111
-tparallel
112112
-unconvert
113113
-unparam
114+
-untypedconst
114115
-unused
115116
-usestdlibvars
116117
-usetesting
@@ -227,6 +228,7 @@ linters:
227228
-tparallel
228229
-unconvert
229230
-unparam
231+
-untypedconst
230232
-unused
231233
-usestdlibvars
232234
-usetesting

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ require (
5555
github.com/gostaticanalysis/nilerrv0.1.1
5656
github.com/hashicorp/go-versionv1.7.0
5757
github.com/jgautheron/goconstv1.7.1
58+
github.com/jiftechnify/untypedconstv0.1.0
5859
github.com/jingyugao/rowserrcheckv1.1.1
5960
github.com/jjti/go-spancheckv0.6.4
6061
github.com/julz/importasv0.2.0

‎go.sum‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//golangcitest:args -Euntypedconst
2+
package testdata
3+
4+
import (
5+
"fmt"
6+
)
7+
8+
typeExStringstring
9+
10+
funcretExString()ExString {
11+
iftrue {
12+
returnExString("hoge")
13+
}else {
14+
fmt.Println("This should never happen")
15+
return"hoge"// want `returning untyped constant as defined type "command-line-arguments.ExString"`
16+
}
17+
}
18+
19+
typeExIntint
20+
21+
funcretExInt()ExInt {
22+
iftrue {
23+
returnExInt(1)
24+
}else {
25+
return1// want `returning untyped constant as defined type "command-line-arguments.ExInt"`
26+
}
27+
}
28+
29+
typeExFloatfloat64
30+
31+
funcretExFloat()ExFloat {
32+
iftrue {
33+
returnExFloat(0.5)
34+
}else {
35+
return0.5// want `returning untyped constant as defined type "command-line-arguments.ExFloat"`
36+
}
37+
}
38+
39+
typeExComplexcomplex128
40+
41+
funcretExComplex()ExComplex {
42+
iftrue {
43+
returnExComplex(1.0+0.5i)
44+
}else {
45+
return1.0+0.5i// want `returning untyped constant as defined type "command-line-arguments.ExComplex"`
46+
}
47+
}
48+
49+
typeExRunerune
50+
51+
funcretExRune()ExRune {
52+
iftrue {
53+
returnExRune('a')
54+
}else {
55+
return'a'// want `returning untyped constant as defined type "command-line-arguments.ExRune"`
56+
}
57+
}
58+
59+
typeExBoolbool
60+
61+
funcretExBool()ExBool {
62+
iftrue {
63+
returnExBool(true)
64+
}else {
65+
returntrue// want `returning untyped constant as defined type "command-line-arguments.ExBool"`
66+
}
67+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package untypedconst
2+
3+
import (
4+
"github.com/jiftechnify/untypedconst"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/goanalysis"
8+
)
9+
10+
funcNew()*goanalysis.Linter {
11+
a:=untypedconst.Analyzer
12+
13+
returngoanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
19+
}

‎pkg/lint/lintersdb/builder_linter.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import (
104104
"github.com/golangci/golangci-lint/pkg/golinters/tparallel"
105105
"github.com/golangci/golangci-lint/pkg/golinters/unconvert"
106106
"github.com/golangci/golangci-lint/pkg/golinters/unparam"
107+
"github.com/golangci/golangci-lint/pkg/golinters/untypedconst"
107108
"github.com/golangci/golangci-lint/pkg/golinters/unused"
108109
"github.com/golangci/golangci-lint/pkg/golinters/usestdlibvars"
109110
"github.com/golangci/golangci-lint/pkg/golinters/usetesting"
@@ -817,6 +818,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
817818
WithLoadForGoAnalysis().
818819
WithURL("https://github.com/mvdan/unparam"),
819820

821+
linter.NewConfig(untypedconst.New()).
822+
WithSince("v1.65.0").
823+
WithPresets(linter.PresetBugs).
824+
WithLoadForGoAnalysis().
825+
WithURL("https://github.com/jiftechnify/untypedconst"),
826+
820827
linter.NewConfig(unused.New(&cfg.LintersSettings.Unused)).
821828
WithEnabledByDefault().
822829
WithSince("v1.20.0").

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp