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

update linter settings to match knative/pkg #1155

Merged
merged 1 commit into from
Jan 13, 2025
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
update linter settings to match knative/pkg
  • Loading branch information
dprotaso committed Jan 10, 2025
commit 907151e01282244917b00097a72a3721db27a548
225 changes: 188 additions & 37 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
run:
timeout: 10m
allow-parallel-runners: true

build-tags:
- e2e
- performance
- probe
- preupgrade
- postupgrade
- postdowngrade

exclude-dirs:
- pkg/client

exclude-files:
- ".pb.go$"
- pkg/client
build-tags:
- e2e

output:
sort-results: true
Expand All @@ -23,39 +13,200 @@ output:
- file
show-stats: true

issues:
uniq-by-line: true
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: test # Excludes /test, *_test.go etc.
linters:
- gosec
- unparam
- noctx
- protogetter
- linters: ["gocritic"]
# Fixes are non-trivial do in a follow up
text: "ifElseChain"

linters-settings:
# goimports:
# local-prefixes: knative.dev/pkg
gomodguard:
blocked:
modules:
- github.com/ghodss/yaml:
recommendations:
- sigs.k8s.io/yaml
- go.uber.org/atomic:
recommendations:
- sync/atomic
- io/ioutil:
recommendations:
- os
- io
- github.com/hashicorp/go-multierror:
reason: "use errors.Join"
recommendations:
- errors
- go.uber.org/multierr:
reason: "use errors.Join"
recommendations:
- errors
revive:
rules:
# use unparam linter instead - defaults are better
- name: unused-parameter
disabled: true

linters:
disable:
- errcheck
enable:
# Check for pass []any as any in variadic func(...any).
- asasalint

# Only use ASCII chars in indentifiers
- asciicheck

# Dangerous unicode characters
- bidichk

# Checks whether HTTP response body is closed successfully.
- bodyclose

# Canonicalheader checks whether net/http.Header uses canonical header.
- canonicalheader

# TODO - do a follow up PR
# # Containedctx is a linter that detects struct contained context.Context
# # field.
# - containedctx

# TODO - do a follow up PR
# # Check whether the function uses a non-inherited context.
# - contextcheck

# Copyloopvar is a linter detects places where loop variables are copied.
- copyloopvar

# Check declaration order of types, consts, vars and funcs.
- decorder

# Check for two durations multiplied together.
- durationcheck

# Checks that sentinel errors are prefixed with the Err- and error types
# are suffixed with the -Error.
- errname

# Errorlint is a linter for that can be used to find code that will cause
# problems with the error wrapping scheme introduced in Go 1.13.
- errorlint

# Detects nested contexts in loops.
- fatcontext

# Checks that go compiler directive comments (//go:) are valid.
- gocheckcompilerdirectives

# Provides diagnostics that check for bugs, performance and style issues.
# Extensible without recompilation through dynamic rules.
# Dynamic rules are written declaratively with AST patterns, filters,
# report message and optional suggestion.
- gocritic

# Gofmt checks whether code was gofmt-ed. By default this tool runs
# with -s option to check for code simplification.
- gofmt

# Gofumpt checks whether code was gofumpt-ed.
- gofumpt

# Check import statements are formatted according to the 'goimport'
# command. Reformat imports in autofix mode.
- goimports

# See config below
- gomodguard

# Inspects source code for security problems.
- gosec

# Linter that specializes in simplifying code.
- gosimple
- govet

# Intrange is a linter to find places where for loops could make use of
# an integer range.
- intrange

# Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
- loggercheck

# Finds slice declarations with non-zero initial length.
- makezero

# Reports wrong mirror patterns of bytes/strings usage
- mirror

# Finds commonly misspelled English words.
- misspell

# Finds the code that returns nil even if it checks that the error is not nil.
- nilerr

# Finds sending HTTP request without context.Context.
- noctx

# Reports ill-formed or insufficient nolint directives.
- nolintlint

# Checks for misuse of Sprintf to construct a host with port in a URL.
- nosprintfhostport

# Checks that fmt.Sprintf can be replaced with a faster alternative.
- perfsprint

# Finds slice declarations that could potentially be pre-allocated.
- prealloc

# Reports direct reads from proto message fields when getters should be used.
- protogetter

# Checks that package variables are not reassigned.
- reassign

# Fast, configurable, extensible, flexible, and beautiful linter for
# Go. Drop-in replacement of golint.
- revive

# Checks for mistakes with OpenTelemetry/Census spans.
- spancheck

# Stylecheck is a replacement for golint.
- stylecheck
- tparallel

# Tenv is analyzer that detects using os.Setenv instead of t.Setenv
# since Go1.17.
- tenv

# Linter checks if examples are testable (have an expected output).
- testableexamples

# Remove unnecessary type conversions.
- unconvert

# Reports unused function parameters and results in your code.
- unparam
disable:
- errcheck

linters-settings:
revive:
rules:
# use unparam linter instead - defaults are better
- name: unused-parameter
disabled: true
# A linter that detect the possibility to use variables/constants from the
# Go standard library.
- usestdlibvars

# Finds wasted assignment statements.
- wastedassign

# Whitespace is a linter that checks for unnecessary newlines at the start
# and end of functions, if, for, etc.
- whitespace

issues:
uniq-by-line: true
exclude-rules:
- path: test # Excludes /test, *_test.go etc.
linters:
- gosec
- unparam
- noctx
- dot-imports

# Allow source and sink receivers in conversion code for clarity.
- path: _conversion\.go
text: "ST1016:"
linters:
- stylecheck
6 changes: 3 additions & 3 deletions pkg/reconciler/contour/config/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
ContourConfigName = "config-contour"

visibilityConfigKey = "visibility"
// nolint:gosec // Not an actual secret.
//nolint:gosec // Not an actual secret.
defaultTLSSecretConfigKey = "default-tls-secret"
timeoutPolicyIdleKey = "timeout-policy-idle"
timeoutPolicyResponseKey = "timeout-policy-response"
Expand All @@ -63,8 +63,8 @@ type visibilityValue struct {
// NewContourFromConfigMap creates a Contour config from the supplied ConfigMap
func NewContourFromConfigMap(configMap *corev1.ConfigMap) (*Contour, error) {
var tlsSecret *types.NamespacedName
var timeoutPolicyResponse = "infinity"
var timeoutPolicyIdle = "infinity"
timeoutPolicyResponse := "infinity"
timeoutPolicyIdle := "infinity"
var contourCORSPolicy *v1.CORSPolicy

if err := configmap.Parse(configMap.Data,
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/contour/config/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ maxAge: "10m"
t.Errorf("Got = %v, want: %v, diff:\n%s", got, want, cmp.Diff(got, want))
}
}

func TestCORSPolicyConfigurationErrors(t *testing.T) {
tests := []struct {
name string
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package contour
import (
"context"
"fmt"
"strconv"

"go.uber.org/zap"
"k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ing *v1alpha1.Ingress) r
// a generation's endpoints.
labels.Set(map[string]string{
resources.ParentKey: ing.Name,
resources.GenerationKey: fmt.Sprintf("%d", ing.Generation),
resources.GenerationKey: strconv.FormatInt(ing.Generation, 10),
}).AsSelector()); err != nil {
return err
} else if len(currentGeneration) == 0 {
Expand Down Expand Up @@ -184,7 +185,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ing *v1alpha1.Ingress) r
return err
}
for _, port := range svc.Spec.Ports {

if port.Name == networking.ServicePortNameH2C {
if cfg.Network != nil && cfg.Network.SystemInternalTLSEnabled() {
serviceToProtocol[name] = resources.InternalEncryptionH2Protocol
Expand Down
12 changes: 8 additions & 4 deletions pkg/reconciler/contour/contour_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ func TestReconcile(t *testing.T) {
controller.Options{
ConfigStore: &testConfigStore{
config: defaultConfig,
}})
},
})

return ingr
}))
Expand Down Expand Up @@ -594,7 +595,8 @@ func TestReconcileInternalEncryption(t *testing.T) {
controller.Options{
ConfigStore: &testConfigStore{
config: internalEncryptionConfig,
}})
},
})
}))
}

Expand Down Expand Up @@ -636,7 +638,8 @@ func TestReconcileProberNotReady(t *testing.T) {
controller.Options{
ConfigStore: &testConfigStore{
config: defaultConfig,
}})
},
})
}))
}

Expand Down Expand Up @@ -684,7 +687,8 @@ func TestReconcileProbeError(t *testing.T) {
controller.Options{
ConfigStore: &testConfigStore{
config: defaultConfig,
}})
},
})

// The Reconciler won't do any work until it becomes the leader.
if la, ok := ingr.(reconciler.LeaderAware); ok {
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/contour/resources/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const (
)

const (
//InternalEncryptionProtocol is the protocol to set on the Services in
//the HTTPProxy when InternalEncryption is enabled. This prompt's
//Contour's Envoys to encrypt the traffic to the activator.
// InternalEncryptionProtocol is the protocol to set on the Services in
// the HTTPProxy when InternalEncryption is enabled. This prompt's
// Contour's Envoys to encrypt the traffic to the activator.
InternalEncryptionProtocol = "tls"
InternalEncryptionH2Protocol = "h2"

//HttpChallengePath is the path that gets added to routes when using
//auto-TLS with an http01 solver as the issuer.
// HttpChallengePath is the path that gets added to routes when using
// auto-TLS with an http01 solver as the issuer.
HTTPChallengePath = "/.well-known/acme-challenge"
)

Expand Down
Loading
Loading