Skip to content

Commit

Permalink
Enable fieldalignment linter, then ignore it
Browse files Browse the repository at this point in the history
This enables the fieldalignment linter by enabling all `govet` checks
except shadowing. I then configured it to ignore large swaths of code
(tests, cmd/, APIs), and nolint'd all the existing complaints because
they seemed irrelevant.

Also removed existing nolint:maligned, as the linter is off.

Closes #2325
  • Loading branch information
zmerlynn committed Nov 8, 2022
1 parent b397d34 commit ac61d55
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ linters:
- unparam

linters-settings:
govet:
disable-all: false
enable-all: true
disable:
# extremely noisy, also against common Go style in most cases
- shadow
gocritic:
enabled-tags:
- performance
Expand All @@ -90,3 +96,11 @@ issues:
exclude-use-default: false
exclude:
- Using the variable on range scope .* in function literal
exclude-rules:
# Skip fieldalignment checks on:
# - tests: memory footprint doesn't matter
# - cmd/: we assume these are one-off config entries
# - pkg/apis: Keep strong convention on TypeMeta/ObjectMeta/Spec/Status
- path: '(.+)_test\.go|^test/|^cmd/.*|^pkg/apis/.*'
# fieldalignment is in the `govet` linter, so exclude based on text instead of all of govet
text: '^fieldalignment: .*'
2 changes: 2 additions & 0 deletions pkg/cloudproduct/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var logger = runtime.NewLoggerWithSource("gke")
type gkeAutopilot struct{}

// hostPortAssignment is the JSON structure of the `host-port-assignment` annotation
//
//nolint:govet // API-like, keep consistent
type hostPortAssignment struct {
Min int32 `json:"min,omitempty"`
Max int32 `json:"max,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions pkg/fleetautoscalers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ import (
)

// fasThread is used for tracking each Fleet's autoscaling jobs
//
//nolint:govet // ignore fieldalignment, low count
type fasThread struct {
generation int64
cancel context.CancelFunc
}

// Controller is the FleetAutoscaler controller
//
//nolint:govet // ignore fieldalignment, singleton
type Controller struct {
baseLogger *logrus.Entry
clock clock.Clock
Expand Down
2 changes: 2 additions & 0 deletions pkg/gameserverallocations/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
)

// gameserver cache to keep the Ready state gameserver.
//
//nolint:govet // ignore fieldalignment, low count
type gameServerCacheEntry struct {
mu sync.RWMutex
cache map[string]*agonesv1.GameServer
Expand Down
2 changes: 2 additions & 0 deletions pkg/gameservers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const (
)

// Controller is a the main GameServer crd controller
//
//nolint:govet // ignore fieldalignment, singleton
type Controller struct {
baseLogger *logrus.Entry
sidecarImage string
Expand Down
2 changes: 2 additions & 0 deletions pkg/gameservers/pernodecounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
// Ready GameServers currently exist on each node.
// This is useful for scheduling allocations, fleet management
// mostly under a Packed strategy
//
//nolint:govet // ignore fieldalignment, singleton
type PerNodeCounter struct {
logger *logrus.Entry
gameServerSynced cache.InformerSynced
Expand Down
2 changes: 2 additions & 0 deletions pkg/gameservers/portallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type portAllocation map[int32]bool
// appropriate locking is taken.
// The PortAllocator does not currently support mixing static portAllocations (or any pods with defined HostPort)
// within the dynamic port range other than the ones it coordinates.
//
//nolint:govet // ignore fieldalignment, singleton
type PortAllocator struct {
logger *logrus.Entry
mutex sync.RWMutex
Expand Down
2 changes: 2 additions & 0 deletions pkg/gameserversets/gameserver_state_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

// gameServerSetCacheEntry manages a list of items created and deleted locally for a single game server set.
//
//nolint:govet // ignore fieldalignment, not many
type gameServerSetCacheEntry struct {
mu sync.Mutex
pendingCreation map[string]*agonesv1.GameServer
Expand Down
2 changes: 2 additions & 0 deletions pkg/metrics/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func init() {
}

// Controller is a metrics controller collecting Agones state metrics
//
//nolint:govet // ignore fieldalignment, singleton
type Controller struct {
logger *logrus.Entry
gameServerLister listerv1.GameServerLister
Expand Down
2 changes: 2 additions & 0 deletions pkg/sdkserver/localsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func defaultGs() *sdk.GameServer {
// LocalSDKServer type is the SDKServer implementation for when the sidecar
// is being run for local development, and doesn't connect to the
// Kubernetes cluster
//
//nolint:govet // ignore fieldalignment, singleton
type LocalSDKServer struct {
gsMutex sync.RWMutex
gs *sdk.GameServer
Expand Down
1 change: 0 additions & 1 deletion pkg/sdkserver/localsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ func TestLocalSDKServerPlayerConnectAndDisconnect(t *testing.T) {

e := &alpha.Empty{}

// nolint: maligned
fixtures := map[string]struct {
testMode bool
gs *agonesv1.GameServer
Expand Down
3 changes: 2 additions & 1 deletion pkg/sdkserver/sdkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ var (

// SDKServer is a gRPC server, that is meant to be a sidecar
// for a GameServer that will update the game server status on SDK requests
// nolint: maligned
//
//nolint:govet // ignore fieldalignment, singleton
type SDKServer struct {
logger *logrus.Entry
gameServerName string
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/workerqueue/workerqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Handler func(context.Context, string) error
// WorkerQueue is an opinionated queue + worker for use
// with controllers and related and processing Kubernetes watched
// events and synchronising resources
//
//nolint:govet // ignore fieldalignment, singleton
type WorkerQueue struct {
logger *logrus.Entry
keyName string
Expand Down

0 comments on commit ac61d55

Please sign in to comment.