Skip to content

Commit c463585

Browse files
authored
Enable modernize in golangci-lint and drop the standalone target (#7824)
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
1 parent 377177d commit c463585

22 files changed

Lines changed: 118 additions & 139 deletions

‎.github/workflows/test-build-deploy.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ jobs:
3838
run: make BUILD_IN_CONTAINER=false mod-check
3939
- name: Check Protos
4040
run: make BUILD_IN_CONTAINER=false check-protos
41-
- name: Check Modernize
42-
run: make BUILD_IN_CONTAINER=false check-modernize
4341

4442
test:
4543
strategy:

‎.golangci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ linters:
2323
enable:
2424
- depguard
2525
- misspell
26+
- modernize
2627
- revive
2728
- sloglint
2829
settings:

‎Makefile‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ GOVOLUMES= -v $(shell pwd)/.cache:/go/cache:delegated,z \
125125
-v $(shell pwd)/.pkg:/go/pkg:delegated,z \
126126
-v $(shell pwd):/go/src/github.com/cortexproject/cortex:delegated,z
127127

128-
exes $(EXES) protos $(PROTO_GOS) lint test cover shell mod-check check-protos doc modernize: build-image/$(UPTODATE)
128+
exes $(EXES) protos $(PROTO_GOS) lint test cover shell mod-check check-protos doc: build-image/$(UPTODATE)
129129
@mkdir -p $(shell pwd)/.pkg
130130
@mkdir -p $(shell pwd)/.cache
131131
@echo
@@ -222,9 +222,6 @@ mod-check:
222222
check-protos: clean-protos protos
223223
@git diff --exit-code -- $(PROTO_GOS)
224224

225-
modernize:
226-
GOTOOLCHAIN=auto go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.23.0 -fix ./...
227-
228225
# Generates the config file documentation.
229226
doc: clean-doc
230227
go run -tags slicelabels ./tools/doc-generator ./docs/configuration/config-file-reference.template > ./docs/configuration/config-file-reference.md
@@ -283,9 +280,6 @@ clean-white-noise:
283280
check-white-noise: clean-white-noise
284281
@git diff --exit-code --quiet -- '*.md' || (echo "Please remove trailing whitespaces running 'make clean-white-noise'" && false)
285282

286-
check-modernize: modernize
287-
@git diff --exit-code -- . || (echo "Please modernize running 'make modernize'" && false)
288-
289283
web-serve:
290284
cd website && hugo --config config.toml --minify -v server
291285

‎integration/active_series_tracker_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func TestActiveSeriesTrackerPerTenant(t *testing.T) {
2424
defer s.Close()
2525

2626
// Write runtime config with per-tenant active series trackers.
27-
runtimeConfig := map[string]interface{}{
28-
"overrides": map[string]interface{}{
29-
"user-1": map[string]interface{}{
27+
runtimeConfig := map[string]any{
28+
"overrides": map[string]any{
29+
"user-1": map[string]any{
3030
"active_series_trackers": []map[string]string{
3131
{"name": "api_metrics", "matchers": `{__name__=~"api_.*"}`},
3232
{"name": "node_metrics", "matchers": `{__name__=~"node_.*"}`},
@@ -123,9 +123,9 @@ func TestActiveSeriesTrackerPerTenant(t *testing.T) {
123123
require.Equal(t, 0.0, sum[0])
124124

125125
// Now update runtime config: remove node_metrics tracker for user-1.
126-
runtimeConfig2 := map[string]interface{}{
127-
"overrides": map[string]interface{}{
128-
"user-1": map[string]interface{}{
126+
runtimeConfig2 := map[string]any{
127+
"overrides": map[string]any{
128+
"user-1": map[string]any{
129129
"active_series_trackers": []map[string]string{
130130
{"name": "api_metrics", "matchers": `{__name__=~"api_.*"}`},
131131
},

‎integration/alertmanager_test.go‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,7 @@ func TestAlertmanagerShardingScaling(t *testing.T) {
639639

640640
// If the number of instances has not yet reached the replication
641641
// factor, then effective replication will be reduced.
642-
var expectedReplication int
643-
if len(instances) <= testCfg.replicationFactor {
644-
expectedReplication = len(instances)
645-
} else {
646-
expectedReplication = testCfg.replicationFactor
647-
}
642+
expectedReplication := min(len(instances), testCfg.replicationFactor)
648643

649644
require.NoError(t, ams.WaitSumMetrics(
650645
e2e.Equals(float64(numUsers*expectedReplication)),

‎integration/asserts.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func assertServiceMetricsPrefixes(t *testing.T, serviceType ServiceType, service
6464
blacklist := getBlacklistedMetricsPrefixesByService(serviceType)
6565

6666
// Ensure no metric name matches the blacklisted prefixes.
67-
for _, metricLine := range strings.Split(metrics, "\n") {
67+
for metricLine := range strings.SplitSeq(metrics, "\n") {
6868
metricLine = strings.TrimSpace(metricLine)
6969
if metricLine == "" || strings.HasPrefix(metricLine, "#") {
7070
continue

‎integration/backward_compatibility_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ func TestMetadataAPIWhenDeployment(t *testing.T) {
134134
metadataMetricNum := 5
135135
metadataPerMetrics := 2
136136
metadata := make([]prompb.MetricMetadata, 0, metadataMetricNum)
137-
for i := 0; i < metadataMetricNum; i++ {
138-
for j := 0; j < metadataPerMetrics; j++ {
137+
for i := range metadataMetricNum {
138+
for j := range metadataPerMetrics {
139139
metadata = append(metadata, prompb.MetricMetadata{
140140
MetricFamilyName: fmt.Sprintf("metadata_name_%d", i),
141141
Help: fmt.Sprintf("metadata_help_%d_%d", i, j),
@@ -220,7 +220,7 @@ func TestCanSupportHoltWintersFunc(t *testing.T) {
220220
numSamples := 240
221221
serieses := make([]prompb.TimeSeries, numSeries)
222222
lbls := make([]labels.Labels, numSeries)
223-
for i := 0; i < numSeries; i++ {
223+
for i := range numSeries {
224224
series := e2e.GenerateSeriesWithSamples("test_series", start, scrapeInterval, i*numSamples, numSamples, prompb.Label{Name: "job", Value: "test"}, prompb.Label{Name: "series", Value: strconv.Itoa(i)})
225225
serieses[i] = series
226226

‎integration/configs.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ blocks_storage:
186186
})
187187
)
188188

189-
func buildConfigFromTemplate(tmpl string, data interface{}) string {
189+
func buildConfigFromTemplate(tmpl string, data any) string {
190190
t, err := template.New("config").Parse(tmpl)
191191
if err != nil {
192192
panic(err)

‎integration/e2e/scenario_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestStartStop(t *testing.T) {
154154

155155
m1 := e2edb.NewMinio(9000, bktName)
156156

157-
for i := 0; i < 10; i++ {
157+
for range 10 {
158158
require.NoError(t, s.Start(m1))
159159
require.NoError(t, s.Stop(m1))
160160
}

‎integration/grpc_server_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestConcurrentGrpcCalls(t *testing.T) {
160160
wg := sync.WaitGroup{}
161161
n := 10000
162162
wg.Add(n)
163-
for i := 0; i < n; i++ {
163+
for i := range n {
164164
go func(i int) {
165165
defer wg.Done()
166166
ctx := context.Background()
@@ -185,7 +185,7 @@ func TestConcurrentGrpcCalls(t *testing.T) {
185185
wg := sync.WaitGroup{}
186186
n := 10000
187187
wg.Add(n)
188-
for i := 0; i < n; i++ {
188+
for i := range n {
189189
go func(i int) {
190190
defer wg.Done()
191191
stream, err := client.PushStream(ctx)
@@ -216,7 +216,7 @@ func TestConcurrentGrpcCalls(t *testing.T) {
216216
wg := sync.WaitGroup{}
217217
n := 10000
218218
wg.Add(n)
219-
for i := 0; i < n; i++ {
219+
for i := range n {
220220
go func(i int) {
221221
defer wg.Done()
222222
ctx := context.Background()
@@ -284,7 +284,7 @@ func createRequest(i int) *cortexpb.WriteRequest {
284284

285285
func createLabels(i int) []cortexpb.LabelAdapter {
286286
labels := make([]cortexpb.LabelAdapter, 0, 100)
287-
for j := 0; j < 100; j++ {
287+
for j := range 100 {
288288
labels = append(labels, cortexpb.LabelAdapter{
289289
Name: fmt.Sprintf("test%d_%d", i, j),
290290
Value: fmt.Sprintf("test%d_%d", i, j),

0 commit comments

Comments
 (0)