Skip to content

Commit c55822f

Browse files
authored
[chore] enable exhaustive option explicit-exhaustive-switch (#24412)
1 parent fa253b6 commit c55822f

File tree

3 files changed

+18
-153
lines changed

3 files changed

+18
-153
lines changed

.golangci.yml

Lines changed: 4 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ linters-settings:
123123
files:
124124
- "!**/*_test.go"
125125

126+
exhaustive:
127+
explicit-exhaustive-switch: true
128+
126129
linters:
127130
enable:
128131
- depguard
@@ -153,141 +156,4 @@ issues:
153156
- gosec
154157
- text: "G402:"
155158
linters:
156-
- gosec
157-
# Following exclude-rules are used to exclude the existing components which do not pass exhaustive lint,
158-
# in order to enable the exhaustive lint check.
159-
# We should not add more exclude-rules.
160-
# The progress of solving existing exclude-rules will be tracked in https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/23266
161-
- path: fluentforwardreceiver
162-
linters:
163-
- exhaustive
164-
- path: prometheusreceiver
165-
linters:
166-
- exhaustive
167-
- path: deltatorateprocessor
168-
linters:
169-
- exhaustive
170-
- path: filterprocessor
171-
linters:
172-
- exhaustive
173-
- path: metricsgenerationprocessor
174-
linters:
175-
- exhaustive
176-
- path: metricstransformprocessor
177-
linters:
178-
- exhaustive
179-
- path: probabilisticsamplerprocessor
180-
linters:
181-
- exhaustive
182-
- path: servicegraphprocessor
183-
linters:
184-
- exhaustive
185-
- path: resourcedetectionprocessor
186-
linters:
187-
- exhaustive
188-
- path: tailsamplingprocessor
189-
linters:
190-
- exhaustive
191-
- path: transformprocessor
192-
linters:
193-
- exhaustive
194-
- path: alibabacloudlogserviceexporter
195-
linters:
196-
- exhaustive
197-
- path: awsemfexporter
198-
linters:
199-
- exhaustive
200-
- path: awsxrayexporter
201-
linters:
202-
- exhaustive
203-
- path: azuremonitorexporter
204-
linters:
205-
- exhaustive
206-
- path: azuredataexplorerexporter
207-
linters:
208-
- exhaustive
209-
- path: carbonexporter
210-
linters:
211-
- exhaustive
212-
- path: coralogixexporter
213-
linters:
214-
- exhaustive
215-
- path: datasetexporter
216-
linters:
217-
- exhaustive
218-
- path: elasticsearchexporter
219-
linters:
220-
- exhaustive
221-
- path: googlecloudpubsubexporter
222-
linters:
223-
- exhaustive
224-
- path: instanaexporter
225-
linters:
226-
- exhaustive
227-
- path: jaegerthrifthttpexporter
228-
linters:
229-
- exhaustive
230-
- path: logzioexporter
231-
linters:
232-
- exhaustive
233-
- path: prometheusexporter
234-
linters:
235-
- exhaustive
236-
- path: prometheusremotewriteexporter
237-
linters:
238-
- exhaustive
239-
- path: skywalkingexporter
240-
linters:
241-
- exhaustive
242-
- path: splunkhecexporter
243-
linters:
244-
- exhaustive
245-
- path: tanzuobservabilityexporter
246-
linters:
247-
- exhaustive
248-
- path: k8sobserver
249-
linters:
250-
- exhaustive
251-
- path: containerinsight
252-
linters:
253-
- exhaustive
254-
- path: filter
255-
linters:
256-
- exhaustive
257-
- path: coreinternal
258-
linters:
259-
- exhaustive
260-
- path: k8sconfig
261-
linters:
262-
- exhaustive
263-
- path: ottl
264-
linters:
265-
- exhaustive
266-
- path: resourcetotelemetry
267-
linters:
268-
- exhaustive
269-
- path: jaeger
270-
linters:
271-
- exhaustive
272-
- path: prometheus
273-
linters:
274-
- exhaustive
275-
- path: loki
276-
linters:
277-
- exhaustive
278-
- path: opencensus
279-
linters:
280-
- exhaustive
281-
- path: zipkin
282-
linters:
283-
- exhaustive
284-
- path: configschema
285-
linters:
286-
- exhaustive
287-
- path: testbed
288-
linters:
289-
- exhaustive
290-
# Preserve original source code in attributed package.
291-
- path: ctimefmt
292-
linters:
293-
- revive
159+
- gosec

internal/coreinternal/timeutils/internal/ctimefmt/ctimefmt.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
var ctimeRegexp = regexp.MustCompile(`%.`)
2020
var decimalsRegexp = regexp.MustCompile(`\d`)
2121

22-
var ctimeSubstitutes map[string]string = map[string]string{
22+
var ctimeSubstitutes = map[string]string{
2323
"%Y": "2006",
2424
"%y": "06",
2525
"%m": "01",
@@ -129,9 +129,8 @@ func ToNative(format string) (string, error) {
129129
replaceFunc := func(directive string) string {
130130
if subst, ok := ctimeSubstitutes[directive]; ok {
131131
return subst
132-
} else {
133-
errs = append(errs, errors.New("unsupported ctimefmt.ToNative() directive: "+directive))
134132
}
133+
errs = append(errs, errors.New("unsupported ctimefmt.ToNative() directive: "+directive))
135134
return ""
136135
}
137136

internal/coreinternal/timeutils/internal/ctimefmt/ctimefmt_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"time"
1515
)
1616

17-
var format1 string = "%Y-%m-%d %H:%M:%S.%f"
18-
var format2 string = "%Y-%m-%d %l:%M:%S.%L %P, %a"
19-
var value1 string = "2019-01-02 15:04:05.666666"
20-
var value2 string = "2019-01-02 3:04:05.666 pm, Wed"
21-
var dt1 time.Time = time.Date(2019, 1, 2, 15, 4, 5, 666666000, time.UTC)
22-
var dt2 time.Time = time.Date(2019, 1, 2, 15, 4, 5, 666000000, time.UTC)
17+
var format1 = "%Y-%m-%d %H:%M:%S.%f"
18+
var format2 = "%Y-%m-%d %l:%M:%S.%L %P, %a"
19+
var value1 = "2019-01-02 15:04:05.666666"
20+
var value2 = "2019-01-02 3:04:05.666 pm, Wed"
21+
var dt1 = time.Date(2019, 1, 2, 15, 4, 5, 666666000, time.UTC)
22+
var dt2 = time.Date(2019, 1, 2, 15, 4, 5, 666000000, time.UTC)
2323

2424
func TestFormat(t *testing.T) {
2525
s, err := Format(format1, dt1)
@@ -40,17 +40,17 @@ func TestFormat(t *testing.T) {
4040
}
4141

4242
func TestParse(t *testing.T) {
43-
dt_, err := Parse(format1, value1)
43+
dt, err := Parse(format1, value1)
4444
if err != nil {
4545
t.Error(err)
46-
} else if dt_ != dt1 {
47-
t.Errorf("Given: %v, expected: %v", dt_, dt1)
46+
} else if dt != dt1 {
47+
t.Errorf("Given: %v, expected: %v", dt, dt1)
4848
}
4949

50-
dt_, err = Parse(format2, value2)
50+
dt, err = Parse(format2, value2)
5151
if err != nil {
5252
t.Error(err)
53-
} else if dt_ != dt2 {
54-
t.Errorf("Given: %v, expected: %v", dt_, dt2)
53+
} else if dt != dt2 {
54+
t.Errorf("Given: %v, expected: %v", dt, dt2)
5555
}
5656
}

0 commit comments

Comments
 (0)