Skip to content

Commit

Permalink
Replaces golint by revive and fix newly reported linter issues (#1946)
Browse files Browse the repository at this point in the history
* replaces golint by revive and fix newly reported linter issues

* add pull request ID to CHANGELOG.md

* Update internal/matchers/temporal_matcher.go

Co-authored-by: Robert Pająk <pellared@hotmail.com>

* fix pull request issues

* explains why the linter is disabled

* Update semconv/http.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Update metric/unit/unit.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* restores 'example/passthrough/go.sum' to original state

* fix after rebase

* export ErrInvalidAsyncRunner again and add nolint

* Update trace/tracestate.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Update sdk/metric/sdk.go

Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>

* Fix ContextWithoutBaggage comment

* Fix SpanEndOption comment

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
  • Loading branch information
5 people authored Jun 8, 2021
1 parent 46d9687 commit 7a0cee7
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ linters:
enable:
- misspell
- goimports
- golint
- revive
- gofmt

issues:
Expand All @@ -16,12 +16,12 @@ issues:
- path: _test\.go
text: "context.Context should be the first parameter of a function"
linters:
- golint
- revive
# Yes, they are, but it's okay in a test
- path: _test\.go
text: "exported func.*returns unexported type.*which can be annoying to use"
linters:
- golint
- revive

linters-settings:
misspell:
Expand Down
2 changes: 1 addition & 1 deletion baggage/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ContextWithBaggage(parent context.Context, b Baggage) context.Context {
return baggage.ContextWithList(parent, b.list)
}

// ContextWithBaggage returns a copy of parent with no baggage.
// ContextWithoutBaggage returns a copy of parent with no baggage.
func ContextWithoutBaggage(parent context.Context) context.Context {
// Delegate so any hooks for the OpenTracing bridge are handled.
return baggage.ContextWithList(parent, nil)
Expand Down
1 change: 1 addition & 0 deletions bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/otel/bridge/opentracing/migration"
)

//nolint:revive // ignoring missing comments for unexported global variables in an internal package.
var (
ComponentKey = attribute.Key("component")
ServiceKey = attribute.Key("service")
Expand Down
1 change: 1 addition & 0 deletions exporters/otlp/internal/otlpconfig/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"
)

//nolint:revive // ignoring missing comments for unexported constants in an internal package.
const (
WeakCertificate = `
-----BEGIN CERTIFICATE-----
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlphttp/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const contentTypeJSON = "application/json"
// have our own copy to avoid handling a situation where the
// DefaultTransport is overwritten with some different implementation
// of http.RoundTripper or it's modified by other package.
var ourTransport *http.Transport = &http.Transport{
var ourTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions internal/matchers/temporal_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package matchers

type TemporalMatcher byte

//nolint:revive // ignoring missing comments for unexported constants in an internal package
const (
Before TemporalMatcher = iota
BeforeOrSameTime
Expand Down
1 change: 1 addition & 0 deletions internal/metric/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.opentelemetry.io/otel/metric"
)

//nolint:revive // ignoring missing comments for exported error in an internal package
var ErrInvalidAsyncRunner = errors.New("unknown async runner type")

// AsyncCollector is an interface used between the MeterImpl and the
Expand Down
1 change: 1 addition & 0 deletions metric/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package unit // import "go.opentelemetry.io/otel/metric/unit"

type Unit string

// Units defined by OpenTelemetry.
const (
Dimensionless Unit = "1"
Bytes Unit = "By"
Expand Down
2 changes: 1 addition & 1 deletion propagation/propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type ctxKeyType uint

var (
ctxKey ctxKeyType = 0
ctxKey ctxKeyType
)

type carrier []string
Expand Down
2 changes: 2 additions & 0 deletions sdk/export/metric/aggregation/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type (
Kind string
)

// Kind description constants.
const (
SumKind Kind = "Sum"
MinMaxSumCountKind Kind = "MinMaxSumCount"
Expand All @@ -136,6 +137,7 @@ const (
ExactKind Kind = "Exact"
)

// Sentinel errors for Aggregation interface.
var (
ErrNegativeInput = fmt.Errorf("negative value is out of range for this instrument")
ErrNaNInput = fmt.Errorf("NaN value is an invalid input")
Expand Down
4 changes: 2 additions & 2 deletions sdk/export/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ type Processor interface {

// Process is called by the SDK once per internal record,
// passing the export Accumulation (a Descriptor, the corresponding
// Labels, and the checkpointed Aggregator). This call has no
// Labels, and the checkpointed Aggregator). This call has no
// Context argument because it is expected to perform only
// computation. An SDK is not expected to call exporters from
// computation. An SDK is not expected to call exporters from
// with Process, use a controller for that (see
// ./controllers/{pull,push}.
Process(accum Accumulation) error
Expand Down
2 changes: 1 addition & 1 deletion sdk/export/metric/metrictest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *CheckpointSet) ForEach(_ export.ExportKindSelector, f func(export.Recor
return nil
}

// Takes a slice of []some.Aggregator and returns a slice of []export.Aggregator
// Unslice2 takes a slice of []some.Aggregator and returns a slice of []export.Aggregator
func Unslice2(sl interface{}) (one, two export.Aggregator) {
slv := reflect.ValueOf(sl)
if slv.Type().Kind() != reflect.Slice {
Expand Down
4 changes: 2 additions & 2 deletions sdk/metric/aggregator/aggregatortest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func RunProfiles(t *testing.T, f func(*testing.T, Profile)) {
}
}

// Ensure local struct alignment prior to running tests.
// TestMain ensures local struct alignment prior to running tests.
func TestMain(m *testing.M) {
fields := []ottest.FieldOffset{
{
Expand Down Expand Up @@ -148,7 +148,7 @@ func (n *Numbers) Points() []number.Number {
return n.numbers
}

// Performs the same range test the SDK does on behalf of the aggregator.
// CheckedUpdate performs the same range test the SDK does on behalf of the aggregator.
func CheckedUpdate(t *testing.T, agg export.Aggregator, number number.Number, descriptor *metric.Descriptor) {
ctx := context.Background()

Expand Down
6 changes: 2 additions & 4 deletions sdk/metric/controller/basic/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,10 @@ func (c *Controller) collect(ctx context.Context) error {
if c.exporter == nil {
return nil
}

// Note: this is not subject to collectTimeout. This blocks the next
// collection despite collectTimeout because it holds a lock.
if err := c.export(ctx); err != nil {
return err
}
return nil
return c.export(ctx)
}

// checkpoint calls the Accumulator and Checkpointer interfaces to
Expand Down
4 changes: 4 additions & 0 deletions sdk/metric/processor/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ type (
var _ export.Processor = &Processor{}
var _ export.Checkpointer = &Processor{}
var _ export.CheckpointSet = &state{}

// ErrInconsistentState is returned when the sequence of collection's starts and finishes are incorrectly balanced.
var ErrInconsistentState = fmt.Errorf("inconsistent processor state")

// ErrInvalidExportKind is returned for unknown metric.ExportKind.
var ErrInvalidExportKind = fmt.Errorf("invalid export kind")

// New returns a basic Processor that is also a Checkpointer using the provided
Expand Down
1 change: 1 addition & 0 deletions sdk/metric/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ var (
_ metric.SyncImpl = &syncInstrument{}
_ metric.BoundSyncImpl = &record{}

// ErrUninitializedInstrument is returned when an instrument is used when uninitialized.
ErrUninitializedInstrument = fmt.Errorf("use of an uninitialized instrument")
)

Expand Down
2 changes: 1 addition & 1 deletion sdk/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Resource struct {
var (
emptyResource Resource

defaultResource *Resource = func(r *Resource, err error) *Resource {
defaultResource = func(r *Resource, err error) *Resource {
if err != nil {
otel.Handle(err)
}
Expand Down
1 change: 1 addition & 0 deletions sdk/trace/batch_span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.opentelemetry.io/otel"
)

// Defaults for BatchSpanProcessorOptions.
const (
DefaultMaxQueueSize = 2048
DefaultBatchTimeout = 5000 * time.Millisecond
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (ts traceIDRatioSampler) Description() string {
// always sample. Fractions < 0 are treated as zero. To respect the
// parent trace's `SampledFlag`, the `TraceIDRatioBased` sampler should be used
// as a delegate of a `Parent` sampler.
//nolint:golint // golint complains about stutter of `trace.TraceIDRatioBased`
//nolint:revive // revive complains about stutter of `trace.TraceIDRatioBased`
func TraceIDRatioBased(fraction float64) Sampler {
if fraction >= 1 {
return AlwaysSample()
Expand Down
4 changes: 2 additions & 2 deletions sdk/trace/sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ func TestParentBasedDefaultDescription(t *testing.T) {
NeverSample().Description())

if sampler.Description() != expectedDescription {
t.Error(fmt.Sprintf("Sampler description should be %s, got '%s' instead",
t.Errorf("Sampler description should be %s, got '%s' instead",
expectedDescription,
sampler.Description(),
))
)
}

}
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var (
sid trace.SpanID
sc trace.SpanContext

handler *storingHandler = &storingHandler{}
handler = &storingHandler{}

k1, k2, k3 attribute.Key
kv1, kv2, kv3 attribute.KeyValue
Expand Down
1 change: 1 addition & 0 deletions semconv/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.opentelemetry.io/otel/codes"
)

// HTTP scheme attributes.
var (
HTTPSchemeHTTP = HTTPSchemeKey.String("http")
HTTPSchemeHTTPS = HTTPSchemeKey.String("https")
Expand Down
4 changes: 2 additions & 2 deletions trace/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func (fn spanOptionFunc) applySpanStart(cfg *SpanConfig) {
fn(cfg)
}

// SpanEndOptions applies an option to a SpanConfig. These options are applicable
// only when the span is ended.
// SpanEndOption applies an option to a SpanConfig. These options are
// applicable only when the span is ended.
type SpanEndOption interface {
applySpanEnd(*SpanConfig)
}
Expand Down
6 changes: 3 additions & 3 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (e errorConst) Error() string {
}

// TraceID is a unique identity of a trace.
// nolint:golint
// nolint:revive // revive complains about stutter of `trace.TraceID`.
type TraceID [16]byte

var nilTraceID TraceID
Expand Down Expand Up @@ -94,7 +94,7 @@ func (s SpanID) String() string {
// TraceIDFromHex returns a TraceID from a hex string if it is compliant with
// the W3C trace-context specification. See more at
// https://www.w3.org/TR/trace-context/#trace-id
// nolint:golint
// nolint:revive // revive complains about stutter of `trace.TraceIDFromHex`.
func TraceIDFromHex(h string) (TraceID, error) {
t := TraceID{}
if len(h) != 32 {
Expand Down Expand Up @@ -152,7 +152,7 @@ func decodeHex(h string, b []byte) error {
}

// TraceFlags contains flags that can be set on a SpanContext
type TraceFlags byte //nolint:golint
type TraceFlags byte //nolint:revive // revive complains about stutter of `trace.TraceFlags`.

// IsSampled returns if the sampling bit is set in the TraceFlags.
func (tf TraceFlags) IsSampled() bool {
Expand Down
2 changes: 1 addition & 1 deletion trace/tracestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (m member) String() string {
// that conform to the specification. Specifically, this means that all
// list-member's key/value pairs are valid, no duplicate list-members exist,
// and the maximum number of list-members (32) is not exceeded.
type TraceState struct { //nolint:golint
type TraceState struct { //nolint:revive // revive complains about stutter of `trace.TraceState`
// list is the members in order.
list []member
}
Expand Down

0 comments on commit 7a0cee7

Please sign in to comment.