Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add govet linter with fieldalignment #1994

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ linters:
- goimports
- revive
- gofmt
- govet

issues:
exclude-rules:
Expand All @@ -30,3 +31,6 @@ linters-settings:
- cancelled
goimports:
local-prefixes: go.opentelemetry.io
govet:
enable:
- fieldalignment
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ test-coverage:

.PHONY: lint
lint: misspell lint-modules | $(GOLANGCI_LINT)
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
EXIT=0; \
for dir in $(ALL_GO_MOD_DIRS); do \
echo "golangci-lint in $${dir}"; \
(cd "$${dir}" && \
$(GOLANGCI_LINT) run --fix && \
$(GOLANGCI_LINT) run); \
done
$(GOLANGCI_LINT) run ) \
|| EXIT=$$? ; \
done; \
exit $$EXIT

.PHONY: misspell
misspell: | $(MISSPELL)
Expand Down
6 changes: 3 additions & 3 deletions attribute/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestKeyValueConstructors(t *testing.T) {
tt := []struct {
tt := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
actual attribute.KeyValue
expected attribute.KeyValue
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestAny(t *testing.T) {
invalidStruct := struct {
N complex64
}{complex(0, 0)}
for _, testcase := range []struct {
for _, testcase := range []struct { //nolint:govet // ignore 'fieldalignment' error
key string
value interface{}
wantType attribute.Type
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestAny(t *testing.T) {
}

func TestKeyValueValid(t *testing.T) {
tests := []struct {
tests := []struct { //nolint:govet // ignore 'fieldalignment' error
desc string
valid bool
kv attribute.KeyValue
Expand Down
2 changes: 1 addition & 1 deletion attribute/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"go.opentelemetry.io/otel/attribute"
)

type testCase struct {
type testCase struct { //nolint:govet // ignore 'fieldalignment' error
kvs []attribute.KeyValue

keyRe *regexp.Regexp
Expand Down
4 changes: 2 additions & 2 deletions attribute/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestValue(t *testing.T) {
k := attribute.Key("test")
bli := getBitlessInfo(42)
for _, testcase := range []struct {
for _, testcase := range []struct { //nolint:govet // ignore 'fieldalignment' error
name string
value attribute.Value
wantType attribute.Type
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestValue(t *testing.T) {
}
}

type bitlessInfo struct {
type bitlessInfo struct { //nolint:govet // ignore 'fieldalignment' error
intValue int
uintValue uint
signedType attribute.Type
Expand Down
4 changes: 2 additions & 2 deletions baggage/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func TestBaggageParse(t *testing.T) {
}
tooManyMembers := strings.Join(m, listDelimiter)

testcases := []struct {
testcases := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
in string
want baggage.List
Expand Down Expand Up @@ -401,7 +401,7 @@ func TestBaggageParse(t *testing.T) {
}

func TestBaggageString(t *testing.T) {
testcases := []struct {
testcases := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
out string
baggage baggage.List
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func TestNewAggregationFromPoints(t *testing.T) {
now := time.Now()
for _, tc := range []struct {
for _, tc := range []struct { //nolint:govet // ignore 'fieldalignment' error
desc string
input []metricdata.Point
expectedKind aggregation.Kind
Expand Down
10 changes: 5 additions & 5 deletions bridge/opencensus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
)

type fakeExporter struct {
type fakeExporter struct { //nolint:govet // ignore 'fieldalignment' error
export.Exporter
records []export.Record
err error
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestExportMetrics(t *testing.T) {
)
fakeErrorHandler := &fakeErrorHandler{}
otel.SetErrorHandler(fakeErrorHandler)
for _, tc := range []struct {
for _, tc := range []struct { //nolint:govet // ignore 'fieldalignment' error
desc string
input []*metricdata.Metric
exportErr error
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestConvertLabels(t *testing.T) {
attribute.KeyValue{Key: attribute.Key("first"), Value: attribute.StringValue("1")},
attribute.KeyValue{Key: attribute.Key("second"), Value: attribute.StringValue("2")},
)
for _, tc := range []struct {
for _, tc := range []struct { //nolint:govet // ignore 'fieldalignment' error
desc string
inputKeys []metricdata.LabelKey
inputValues []metricdata.LabelValue
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestConvertLabels(t *testing.T) {
}
}
func TestConvertResource(t *testing.T) {
for _, tc := range []struct {
for _, tc := range []struct { //nolint:govet // ignore 'fieldalignment' error
desc string
input *ocresource.Resource
expected *resource.Resource
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestConvertResource(t *testing.T) {
}
}
func TestConvertDescriptor(t *testing.T) {
for _, tc := range []struct {
for _, tc := range []struct { //nolint:govet // ignore 'fieldalignment' error
desc string
input metricdata.Descriptor
expected metric.Descriptor
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func TestOTelSpanContextToOC(t *testing.T) {
for _, tc := range []struct {
for _, tc := range []struct { //nolint:govet // ignore 'fieldalignment' error
description string
input trace.SpanContext
expected octrace.SpanContext
Expand Down
4 changes: 2 additions & 2 deletions bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type MockContextKeyValue struct {
Value interface{}
}

type MockTracer struct {
type MockTracer struct { //nolint:govet // ignore 'fieldalignment' error
FinishedSpans []*MockSpan
SpareTraceIDs []trace.TraceID
SpareSpanIDs []trace.SpanID
Expand Down Expand Up @@ -181,7 +181,7 @@ type MockEvent struct {
Attributes []attribute.KeyValue
}

type MockSpan struct {
type MockSpan struct { //nolint:govet // ignore 'fieldalignment' error
mockTracer *MockTracer
officialTracer trace.Tracer
spanContext trace.SpanContext
Expand Down
12 changes: 6 additions & 6 deletions bridge/opentracing/mix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"go.opentelemetry.io/otel/bridge/opentracing/internal"
)

type mixedAPIsTestCase struct {
type mixedAPIsTestCase struct { //nolint:govet // ignore 'fieldalignment' error
desc string

setup func(*testing.T, *internal.MockTracer)
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestMixedAPIs(t *testing.T) {

// simple test

type simpleTest struct {
type simpleTest struct { //nolint:govet // ignore 'fieldalignment' error
traceID trace.TraceID
spanIDs []trace.SpanID
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (st *simpleTest) noop(t *testing.T, ctx context.Context) context.Context {

// current/active span test

type currentActiveSpanTest struct {
type currentActiveSpanTest struct { //nolint:govet // ignore 'fieldalignment' error
traceID trace.TraceID
spanIDs []trace.SpanID

Expand Down Expand Up @@ -316,7 +316,7 @@ type bipBaggage struct {
value string
}

type baggageItemsPreservationTest struct {
type baggageItemsPreservationTest struct { //nolint:govet // ignore 'fieldalignment' error
baggageItems []bipBaggage

step int
Expand Down Expand Up @@ -408,7 +408,7 @@ func (bip *baggageItemsPreservationTest) addAndRecordBaggage(t *testing.T, ctx c

// baggage interoperation test

type baggageInteroperationTest struct {
type baggageInteroperationTest struct { //nolint:govet // ignore 'fieldalignment' error
baggageItems []bipBaggage

step int
Expand Down Expand Up @@ -654,7 +654,7 @@ func runOTOtelOT(t *testing.T, ctx context.Context, name string, callback func(*
}

func TestOtTagToOTelLabel_CheckTypeConversions(t *testing.T) {
tableTest := []struct {
tableTest := []struct { //nolint:govet // ignore 'fieldalignment' error
key string
value interface{}
expectedValueType attribute.Type
Expand Down
4 changes: 2 additions & 2 deletions codes/codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func TestCodeString(t *testing.T) {
tests := []struct {
tests := []struct { //nolint:govet // ignore 'fieldalignment' error
code Code
want string
}{
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestCodeMarshalJSONNil(t *testing.T) {
}

func TestCodeMarshalJSON(t *testing.T) {
tests := []struct {
tests := []struct { //nolint:govet // ignore 'fieldalignment' error
code Code
want string
}{
Expand Down
2 changes: 1 addition & 1 deletion exporters/jaeger/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestEnvOrWithAgentHostPortFromEnv(t *testing.T) {
}

func TestEnvOrWithCollectorEndpointOptionsFromEnv(t *testing.T) {
testCases := []struct {
testCases := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
envEndpoint string
envUsername string
Expand Down
6 changes: 3 additions & 3 deletions exporters/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
)

func TestNewRawExporter(t *testing.T) {
testCases := []struct {
testCases := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
endpoint EndpointOption
}{
Expand Down Expand Up @@ -170,7 +170,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
instrLibName := "instrumentation-library"
instrLibVersion := "semver:1.0.0"

tests := []struct {
tests := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
data tracetest.SpanStub
want *gen.Span
Expand Down Expand Up @@ -680,7 +680,7 @@ func TestJaegerBatchList(t *testing.T) {
func TestProcess(t *testing.T) {
v1 := "v1"

testCases := []struct {
testCases := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
res *resource.Resource
defaultServiceName string
Expand Down
6 changes: 3 additions & 3 deletions exporters/otlp/otlpmetric/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func pointTime() uint64 {
return uint64(intervalEnd.UnixNano())
}

type checkpointSet struct {
type checkpointSet struct { //nolint:govet // ignore 'fieldalignment' error
sync.RWMutex
records []metricsdk.Record
}
Expand All @@ -97,7 +97,7 @@ func (m *checkpointSet) ForEach(_ metricsdk.ExportKindSelector, fn func(metricsd
return nil
}

type record struct {
type record struct { //nolint:govet // ignore 'fieldalignment' error
name string
iKind metric.InstrumentKind
nKind number.Kind
Expand Down Expand Up @@ -687,7 +687,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
}

func TestStatelessExportKind(t *testing.T) {
type testcase struct {
type testcase struct { //nolint:govet // ignore 'fieldalignment' error
name string
instrumentKind metric.InstrumentKind
aggTemporality metricpb.AggregationTemporality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ func TestSumErrUnknownValueType(t *testing.T) {
}

type testAgg struct {
kind aggregation.Kind
agg aggregation.Aggregation
kind aggregation.Kind
}

func (t *testAgg) Kind() aggregation.Kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func TestStringToHeader(t *testing.T) {
tests := []struct {
tests := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
value string
want map[string]string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestConfigs(t *testing.T) {
tlsCert, err := otlpconfig.CreateTLSConfig([]byte(WeakCertificate))
assert.NoError(t, err)

tests := []struct {
tests := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
opts []otlpconfig.GenericOption
env env
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestNewExporter_collectorConnectionDiesThenReconnectsWhenInRestMode(t *test
}

func TestExporterExportFailureAndRecoveryModes(t *testing.T) {
tts := []struct {
tts := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
errors []error
rs otlpmetricgrpc.RetrySettings
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestNewExporter_withHeaders(t *testing.T) {
}

func TestNewExporter_WithTimeout(t *testing.T) {
tts := []struct {
tts := []struct { //nolint:govet // ignore 'fieldalignment' error
name string
fn func(exp *otlpmetric.Exporter) error
timeout time.Duration
Expand Down