Skip to content

Commit

Permalink
[chore] enable exhaustive option explicit-exhaustive-switch (#24412)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatsheep9146 authored Jul 22, 2023
1 parent fa253b6 commit c55822f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 153 deletions.
142 changes: 4 additions & 138 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ linters-settings:
files:
- "!**/*_test.go"

exhaustive:
explicit-exhaustive-switch: true

linters:
enable:
- depguard
Expand Down Expand Up @@ -153,141 +156,4 @@ issues:
- gosec
- text: "G402:"
linters:
- gosec
# Following exclude-rules are used to exclude the existing components which do not pass exhaustive lint,
# in order to enable the exhaustive lint check.
# We should not add more exclude-rules.
# The progress of solving existing exclude-rules will be tracked in https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/23266
- path: fluentforwardreceiver
linters:
- exhaustive
- path: prometheusreceiver
linters:
- exhaustive
- path: deltatorateprocessor
linters:
- exhaustive
- path: filterprocessor
linters:
- exhaustive
- path: metricsgenerationprocessor
linters:
- exhaustive
- path: metricstransformprocessor
linters:
- exhaustive
- path: probabilisticsamplerprocessor
linters:
- exhaustive
- path: servicegraphprocessor
linters:
- exhaustive
- path: resourcedetectionprocessor
linters:
- exhaustive
- path: tailsamplingprocessor
linters:
- exhaustive
- path: transformprocessor
linters:
- exhaustive
- path: alibabacloudlogserviceexporter
linters:
- exhaustive
- path: awsemfexporter
linters:
- exhaustive
- path: awsxrayexporter
linters:
- exhaustive
- path: azuremonitorexporter
linters:
- exhaustive
- path: azuredataexplorerexporter
linters:
- exhaustive
- path: carbonexporter
linters:
- exhaustive
- path: coralogixexporter
linters:
- exhaustive
- path: datasetexporter
linters:
- exhaustive
- path: elasticsearchexporter
linters:
- exhaustive
- path: googlecloudpubsubexporter
linters:
- exhaustive
- path: instanaexporter
linters:
- exhaustive
- path: jaegerthrifthttpexporter
linters:
- exhaustive
- path: logzioexporter
linters:
- exhaustive
- path: prometheusexporter
linters:
- exhaustive
- path: prometheusremotewriteexporter
linters:
- exhaustive
- path: skywalkingexporter
linters:
- exhaustive
- path: splunkhecexporter
linters:
- exhaustive
- path: tanzuobservabilityexporter
linters:
- exhaustive
- path: k8sobserver
linters:
- exhaustive
- path: containerinsight
linters:
- exhaustive
- path: filter
linters:
- exhaustive
- path: coreinternal
linters:
- exhaustive
- path: k8sconfig
linters:
- exhaustive
- path: ottl
linters:
- exhaustive
- path: resourcetotelemetry
linters:
- exhaustive
- path: jaeger
linters:
- exhaustive
- path: prometheus
linters:
- exhaustive
- path: loki
linters:
- exhaustive
- path: opencensus
linters:
- exhaustive
- path: zipkin
linters:
- exhaustive
- path: configschema
linters:
- exhaustive
- path: testbed
linters:
- exhaustive
# Preserve original source code in attributed package.
- path: ctimefmt
linters:
- revive
- gosec
5 changes: 2 additions & 3 deletions internal/coreinternal/timeutils/internal/ctimefmt/ctimefmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var ctimeRegexp = regexp.MustCompile(`%.`)
var decimalsRegexp = regexp.MustCompile(`\d`)

var ctimeSubstitutes map[string]string = map[string]string{
var ctimeSubstitutes = map[string]string{
"%Y": "2006",
"%y": "06",
"%m": "01",
Expand Down Expand Up @@ -129,9 +129,8 @@ func ToNative(format string) (string, error) {
replaceFunc := func(directive string) string {
if subst, ok := ctimeSubstitutes[directive]; ok {
return subst
} else {
errs = append(errs, errors.New("unsupported ctimefmt.ToNative() directive: "+directive))
}
errs = append(errs, errors.New("unsupported ctimefmt.ToNative() directive: "+directive))
return ""
}

Expand Down
24 changes: 12 additions & 12 deletions internal/coreinternal/timeutils/internal/ctimefmt/ctimefmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"time"
)

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

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

func TestParse(t *testing.T) {
dt_, err := Parse(format1, value1)
dt, err := Parse(format1, value1)
if err != nil {
t.Error(err)
} else if dt_ != dt1 {
t.Errorf("Given: %v, expected: %v", dt_, dt1)
} else if dt != dt1 {
t.Errorf("Given: %v, expected: %v", dt, dt1)
}

dt_, err = Parse(format2, value2)
dt, err = Parse(format2, value2)
if err != nil {
t.Error(err)
} else if dt_ != dt2 {
t.Errorf("Given: %v, expected: %v", dt_, dt2)
} else if dt != dt2 {
t.Errorf("Given: %v, expected: %v", dt, dt2)
}
}

0 comments on commit c55822f

Please sign in to comment.