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

Commitf1023ca

Browse files
committed
feat: add untypedconst linter
Implements#3478.
1 parentabe878d commitf1023ca

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

‎.golangci.reference.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,7 @@ linters:
20882088
-typecheck
20892089
-unconvert
20902090
-unparam
2091+
-untypedconst
20912092
-unused
20922093
-usestdlibvars
20932094
-varcheck
@@ -2198,6 +2199,7 @@ linters:
21982199
-typecheck
21992200
-unconvert
22002201
-unparam
2202+
-untypedconst
22012203
-unused
22022204
-usestdlibvars
22032205
-varcheck

‎go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
github.com/hashicorp/go-versionv1.6.0
5050
github.com/hexops/gotextdiffv1.0.3
5151
github.com/jgautheron/goconstv1.5.1
52+
github.com/jiftechnify/untypedconstv0.0.0-20211230012903-7f805b5dad89
5253
github.com/jingyugao/rowserrcheckv1.1.1
5354
github.com/jirfag/go-printf-func-namev0.0.0-20200119135958-7558a9eaa5af
5455
github.com/julz/importasv0.1.0

‎go.sum‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎pkg/golinters/untypedconst.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
funcNewUntypedConst()*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/manager.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
821821
WithLoadForGoAnalysis().
822822
WithURL("https://github.com/mvdan/unparam"),
823823

824+
linter.NewConfig(golinters.NewUntypedConst()).
825+
WithSince("v1.51.0").
826+
WithPresets(linter.PresetBugs).
827+
WithURL("https://github.com/jiftechnify/untypedconst"),
828+
824829
linter.NewConfig(golinters.NewUnused(unusedCfg)).
825830
WithSince("v1.20.0").
826831
WithLoadForGoAnalysis().

‎test/testdata/untypedconst.go‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//golangcitest:args -Euntypedconst
2+
package testdata
3+
4+
typeExStringstring
5+
6+
funcretExString()ExString {
7+
iftrue {
8+
returnExString("hoge")
9+
}else {
10+
return"hoge"// want `returning untyped constant as defined type "command-line-arguments.ExString"`
11+
}
12+
}
13+
14+
typeExIntint
15+
16+
funcretExInt()ExInt {
17+
iftrue {
18+
returnExInt(1)
19+
}else {
20+
return1// want `returning untyped constant as defined type "command-line-arguments.ExInt"`
21+
}
22+
}
23+
24+
typeExFloatfloat64
25+
26+
funcretExFloat()ExFloat {
27+
iftrue {
28+
returnExFloat(0.5)
29+
}else {
30+
return0.5// want `returning untyped constant as defined type "command-line-arguments.ExFloat"`
31+
}
32+
}
33+
34+
typeExComplexcomplex128
35+
36+
funcretExComplex()ExComplex {
37+
iftrue {
38+
returnExComplex(1.0+0.5i)
39+
}else {
40+
return1.0+0.5i// want `returning untyped constant as defined type "command-line-arguments.ExComplex"`
41+
}
42+
}
43+
44+
typeExRunerune
45+
46+
funcretExRune()ExRune {
47+
iftrue {
48+
returnExRune('a')
49+
}else {
50+
return'a'// want `returning untyped constant as defined type "command-line-arguments.ExRune"`
51+
}
52+
}
53+
54+
typeExBoolbool
55+
56+
funcretExBool()ExBool {
57+
iftrue {
58+
returnExBool(true)
59+
}else {
60+
returntrue// want `returning untyped constant as defined type "command-line-arguments.ExBool"`
61+
}
62+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp