File tree 6 files changed +118
-0
lines changed
6 files changed +118
-0
lines changed Original file line number Diff line number Diff line change @@ -1911,6 +1911,7 @@ linters:
1911
1911
- prealloc
1912
1912
- predeclared
1913
1913
- promlinter
1914
+ - reusestdlibvars
1914
1915
- revive
1915
1916
- rowserrcheck
1916
1917
- scopelint
@@ -2012,6 +2013,7 @@ linters:
2012
2013
- prealloc
2013
2014
- predeclared
2014
2015
- promlinter
2016
+ - reusestdlibvars
2015
2017
- revive
2016
2018
- rowserrcheck
2017
2019
- scopelint
Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ require (
74
74
github.com/ryancurrah/gomodguard v1.2.3
75
75
github.com/ryanrolds/sqlclosecheck v0.3.0
76
76
github.com/sanposhiho/wastedassign/v2 v2.0.6
77
+ github.com/sashamelentyev/reusestdlibvars v1.3.0
77
78
github.com/securego/gosec/v2 v2.12.0
78
79
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c
79
80
github.com/shirou/gopsutil/v3 v3.22.6
Original file line number Diff line number Diff line change
1
+ package golinters
2
+
3
+ import (
4
+ "github.com/sashamelentyev/reusestdlibvars/pkg/analyzer"
5
+ "golang.org/x/tools/go/analysis"
6
+
7
+ "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8
+ )
9
+
10
+ func NewReuseStdlibVars () * goanalysis.Linter {
11
+ a := analyzer .New ()
12
+
13
+ return goanalysis .NewLinter (
14
+ a .Name ,
15
+ a .Doc ,
16
+ []* analysis.Analyzer {a },
17
+ nil ,
18
+ ).WithLoadMode (goanalysis .LoadModeSyntax )
19
+ }
Original file line number Diff line number Diff line change @@ -665,6 +665,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
665
665
WithPresets (linter .PresetStyle ).
666
666
WithURL ("https://github.com/yeya24/promlinter" ),
667
667
668
+ linter .NewConfig (golinters .NewReuseStdlibVars ()).
669
+ WithSince ("v1.48.0" ).
670
+ WithPresets (linter .PresetStyle ).
671
+ WithURL ("https://github.com/sashamelentyev/reusestdlibvars" ),
672
+
668
673
linter .NewConfig (golinters .NewRevive (reviveCfg )).
669
674
WithSince ("v1.37.0" ).
670
675
WithPresets (linter .PresetStyle , linter .PresetMetaLinter ).
Original file line number Diff line number Diff line change
1
+ //golangcitest:args -Ereusestdlibvars
2
+ package testdata
3
+
4
+ import "net/http"
5
+
6
+ func _200 () {
7
+ _ = 200
8
+ }
9
+
10
+ func _200_1 () {
11
+ var w http.ResponseWriter
12
+ w .WriteHeader (200 ) // ERROR `can use http.StatusOK instead "200"`
13
+ }
14
+
15
+ func sunday () {
16
+ _ = "Sunday" // ERROR `can use time.Sunday.String\(\) instead "Sunday"`
17
+ }
18
+
19
+ func monday () {
20
+ _ = "Monday" // ERROR `can use time.Monday.String\(\) instead "Monday"`
21
+ }
22
+
23
+ func tuesday () {
24
+ _ = "Tuesday" // ERROR `can use time.Tuesday.String\(\) instead "Tuesday"`
25
+ }
26
+
27
+ func wednesday () {
28
+ _ = "Wednesday" // ERROR `can use time.Wednesday.String\(\) instead "Wednesday"`
29
+ }
30
+
31
+ func thursday () {
32
+ _ = "Thursday" // ERROR `can use time.Thursday.String\(\) instead "Thursday"`
33
+ }
34
+
35
+ func friday () {
36
+ _ = "Friday" // ERROR `can use time.Friday.String\(\) instead "Friday"`
37
+ }
38
+
39
+ func saturday () {
40
+ _ = "Saturday" // ERROR `can use time.Saturday.String\(\) instead "Saturday"`
41
+ }
42
+
43
+ func january () {
44
+ _ = "January" // ERROR `can use time.January.String\(\) instead "January"`
45
+ }
46
+
47
+ func february () {
48
+ _ = "February" // ERROR `can use time.February.String\(\) instead "February"`
49
+ }
50
+
51
+ func march () {
52
+ _ = "March" // ERROR `can use time.March.String\(\) instead "March"`
53
+ }
54
+
55
+ func april () {
56
+ _ = "April" // ERROR `can use time.April.String\(\) instead "April"`
57
+ }
58
+
59
+ func may () {
60
+ _ = "May" // ERROR `can use time.May.String\(\) instead "May"`
61
+ }
62
+
63
+ func june () {
64
+ _ = "June" // ERROR `can use time.June.String\(\) instead "June"`
65
+ }
66
+
67
+ func july () {
68
+ _ = "July" // ERROR `can use time.July.String\(\) instead "July"`
69
+ }
70
+
71
+ func august () {
72
+ _ = "August" // ERROR `can use time.August.String\(\) instead "August"`
73
+ }
74
+
75
+ func september () {
76
+ _ = "September" // ERROR `can use time.September.String\(\) instead "September"`
77
+ }
78
+
79
+ func october () {
80
+ _ = "October" // ERROR `can use time.October.String\(\) instead "October"`
81
+ }
82
+
83
+ func november () {
84
+ _ = "November" // ERROR `can use time.November.String\(\) instead "November"`
85
+ }
86
+
87
+ func december () {
88
+ _ = "December" // ERROR `can use time.December.String\(\) instead "December"`
89
+ }
You can’t perform that action at this time.
0 commit comments