From 3850e115a3f6f6c6350dae353062c528f672d749 Mon Sep 17 00:00:00 2001 From: Ryan Hang Date: Mon, 6 Nov 2023 23:07:08 -0800 Subject: [PATCH] lint: Pass zapcore and zaptest packages golangci-lint running revive currently fails on master. Exempt the dot-import failures since these are used to reduce a large number of qualifiers in the zapcore packages's _test package tests. This change also simplifies an if/else statement with a logical equivalent and standardizes a test that imported a package and a dot-import of the same package simultaneously. --- zapcore/console_encoder_bench_test.go | 1 + zapcore/console_encoder_test.go | 1 + zapcore/core_test.go | 1 + zapcore/encoder_test.go | 1 + zapcore/error_test.go | 4 ++-- zapcore/field_test.go | 5 +++-- zapcore/hook_test.go | 1 + zapcore/increase_level_test.go | 2 ++ zapcore/json_encoder_bench_test.go | 1 + zapcore/sampler_bench_test.go | 2 ++ zapcore/sampler_test.go | 1 + zapcore/tee_logger_bench_test.go | 1 + zapcore/tee_test.go | 1 + zaptest/observer/observer_test.go | 2 ++ 14 files changed, 20 insertions(+), 4 deletions(-) diff --git a/zapcore/console_encoder_bench_test.go b/zapcore/console_encoder_bench_test.go index 62feaea71..a2a360ff0 100644 --- a/zapcore/console_encoder_bench_test.go +++ b/zapcore/console_encoder_bench_test.go @@ -23,6 +23,7 @@ package zapcore_test import ( "testing" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) diff --git a/zapcore/console_encoder_test.go b/zapcore/console_encoder_test.go index 8b42b6bc0..be8adc71d 100644 --- a/zapcore/console_encoder_test.go +++ b/zapcore/console_encoder_test.go @@ -24,6 +24,7 @@ import ( "time" "github.com/stretchr/testify/assert" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) diff --git a/zapcore/core_test.go b/zapcore/core_test.go index e3186311a..3b23d2dea 100644 --- a/zapcore/core_test.go +++ b/zapcore/core_test.go @@ -27,6 +27,7 @@ import ( "time" "go.uber.org/zap/internal/ztest" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" "github.com/stretchr/testify/assert" diff --git a/zapcore/encoder_test.go b/zapcore/encoder_test.go index 9b8142f5d..f89f489fd 100644 --- a/zapcore/encoder_test.go +++ b/zapcore/encoder_test.go @@ -30,6 +30,7 @@ import ( "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) diff --git a/zapcore/error_test.go b/zapcore/error_test.go index c5d61b040..41f243ac4 100644 --- a/zapcore/error_test.go +++ b/zapcore/error_test.go @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/multierr" - "go.uber.org/zap/zapcore" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) @@ -205,6 +205,6 @@ func (enc brokenArrayObjectEncoder) AddArray(key string, marshaler ArrayMarshale })) } -func (enc brokenArrayObjectEncoder) AppendObject(zapcore.ObjectMarshaler) error { +func (enc brokenArrayObjectEncoder) AppendObject(ObjectMarshaler) error { return enc.Err } diff --git a/zapcore/field_test.go b/zapcore/field_test.go index a0c1e16d3..06bcef2e1 100644 --- a/zapcore/field_test.go +++ b/zapcore/field_test.go @@ -31,6 +31,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" + + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) @@ -88,9 +90,8 @@ type errObj struct { func (eobj *errObj) Error() string { if eobj.kind == 1 { panic("panic in Error() method") - } else { - return eobj.errMsg } + return eobj.errMsg } func TestUnknownFieldType(t *testing.T) { diff --git a/zapcore/hook_test.go b/zapcore/hook_test.go index 46e3c3588..360b22260 100644 --- a/zapcore/hook_test.go +++ b/zapcore/hook_test.go @@ -23,6 +23,7 @@ package zapcore_test import ( "testing" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" diff --git a/zapcore/increase_level_test.go b/zapcore/increase_level_test.go index f80d79098..14cd857b2 100644 --- a/zapcore/increase_level_test.go +++ b/zapcore/increase_level_test.go @@ -27,6 +27,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap" + + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" ) diff --git a/zapcore/json_encoder_bench_test.go b/zapcore/json_encoder_bench_test.go index 9182b3951..d870e07dd 100644 --- a/zapcore/json_encoder_bench_test.go +++ b/zapcore/json_encoder_bench_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) diff --git a/zapcore/sampler_bench_test.go b/zapcore/sampler_bench_test.go index 100e2268e..1b250cdeb 100644 --- a/zapcore/sampler_bench_test.go +++ b/zapcore/sampler_bench_test.go @@ -28,6 +28,8 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/zap/internal/ztest" + + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) diff --git a/zapcore/sampler_test.go b/zapcore/sampler_test.go index df726a2e9..55b4afabf 100644 --- a/zapcore/sampler_test.go +++ b/zapcore/sampler_test.go @@ -29,6 +29,7 @@ import ( "time" "go.uber.org/zap/internal/ztest" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" diff --git a/zapcore/tee_logger_bench_test.go b/zapcore/tee_logger_bench_test.go index b30a17354..d2fc42b7c 100644 --- a/zapcore/tee_logger_bench_test.go +++ b/zapcore/tee_logger_bench_test.go @@ -24,6 +24,7 @@ import ( "testing" "go.uber.org/zap/internal/ztest" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" ) diff --git a/zapcore/tee_test.go b/zapcore/tee_test.go index f6be13316..f6b14eb44 100644 --- a/zapcore/tee_test.go +++ b/zapcore/tee_test.go @@ -25,6 +25,7 @@ import ( "testing" "go.uber.org/zap/internal/ztest" + //revive:disable:dot-imports . "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" diff --git a/zaptest/observer/observer_test.go b/zaptest/observer/observer_test.go index 0a57a0f32..0cf631c03 100644 --- a/zaptest/observer/observer_test.go +++ b/zaptest/observer/observer_test.go @@ -29,6 +29,8 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" + + //revive:disable:dot-imports . "go.uber.org/zap/zaptest/observer" )