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

ci: enable more linters #817

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@ issues:
fix: true
exclude-rules:
- linters:
- gosec
- gosec
text: 'G101'
path: 'pkg/test/resource/v3/secret.go'
max-issues-per-linter: 0
max-same-issues: 0

linters:
presets:
- bugs

enable:
- bodyclose
- errorlint
- gofumpt
- goimports
- gosec
- misspell
- revive
- unconvert
- unparam

disable:
- scopelint # deprecated but still enabled in the bugs preset
- bodyclose
- contextcheck
- errcheck
- errorlint
- gofumpt
- goimports
- gosec
- misspell
- revive
- unconvert
- unparam
- unused
- whitespace

linters-settings:
exhaustive:
default-signifies-exhaustive: true
gofumpt:
extra-rules: true
goimports:
local-prefixes: github.com/envoyproxy/go-control-plane
misspell:
locale: US
gofmt:
simplify: true
unparam:
check-exported: false
goimports:
local-prefixes: github.com/envoyproxy/go-control-plane
exhaustive:
default-signifies-exhaustive: true

run:
timeout: 10m
7 changes: 4 additions & 3 deletions pkg/cache/v3/linear.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@ func (cache *LinearCache) CreateWatch(request *Request, _ stream.StreamState, va
cache.mu.Lock()
defer cache.mu.Unlock()

if err != nil {
switch {
case err != nil:
stale = true
staleResources = request.GetResourceNames()
} else if len(request.GetResourceNames()) == 0 {
case len(request.GetResourceNames()) == 0:
stale = lastVersion != cache.version
} else {
default:
for _, name := range request.GetResourceNames() {
// When a resource is removed, its version defaults 0 and it is not considered stale.
if lastVersion < cache.versionVector[name] {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/delta/v3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *server) processDelta(str stream.DeltaStream, reqCh <-chan *discovery.De
return "", err
}

streamNonce = streamNonce + 1
streamNonce++
response.Nonce = strconv.FormatInt(streamNonce, 10)
if s.callbacks != nil {
s.callbacks.OnStreamDeltaResponse(streamID, resp.GetDeltaRequest(), response)
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/v3/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (stream *mockDeltaStream) Context() context.Context {

func (stream *mockDeltaStream) Send(resp *discovery.DeltaDiscoveryResponse) error {
// Check that nonce is incremented by one
stream.nonce = stream.nonce + 1
stream.nonce++
if resp.GetNonce() != fmt.Sprintf("%d", stream.nonce) {
stream.t.Errorf("Nonce => got %q, want %d", resp.GetNonce(), stream.nonce)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/v3/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (stream *mockStream) Context() context.Context {

func (stream *mockStream) Send(resp *discovery.DiscoveryResponse) error {
// check that nonce is monotonically incrementing
stream.nonce = stream.nonce + 1
stream.nonce++
assert.Equal(stream.t, resp.GetNonce(), fmt.Sprintf("%d", stream.nonce))
// check that version is set
assert.NotEmpty(stream.t, resp.GetVersionInfo())
Expand Down
8 changes: 4 additions & 4 deletions pkg/test/resource/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func (ts *TestSnapshot) generateHTTPListeners(numListeners int, clusters []types
listeners := []types.Resource{}
routeConfigs := []types.Resource{}

if len(clusters) <= 0 {
if len(clusters) == 0 {
return nil, nil
}

Expand All @@ -578,7 +578,7 @@ func (ts *TestSnapshot) generateScopedHTTPListeners(numListeners int, clusters [
scopedRouteConfigs := []types.Resource{}
routeConfigs := []types.Resource{}

if len(clusters) <= 0 {
if len(clusters) == 0 {
return nil, nil, nil
}

Expand All @@ -605,7 +605,7 @@ func (ts *TestSnapshot) generateVHDSHTTPListeners(numListeners int, clusters []t
routeConfigs := []types.Resource{}
virtualHosts := []types.Resource{}

if len(clusters) <= 0 {
if len(clusters) == 0 {
return nil, nil, nil
}

Expand All @@ -630,7 +630,7 @@ func (ts *TestSnapshot) generateVHDSHTTPListeners(numListeners int, clusters []t
func (ts *TestSnapshot) generateTCPListeners(numListeners int, clusters []types.Resource) []types.Resource {
listeners := []types.Resource{}

if len(clusters) <= 0 {
if len(clusters) == 0 {
return nil
}

Expand Down