Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Fieldalignment lintfix #1135

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ linters-settings:
govet:
enable-all: true
check-shadowing: true
disable:
# While struct sizes could be smaller if fields aligned properly, that also leads
# to possibly non-intuitive layout of struct fields (harder to read). Disable
# `fieldalignment` check here until we evaluate if it is worthwhile.
- fieldalignment
# https://github.com/golangci/golangci-lint/issues/1973
- sigchanyzer
lll:
line-length: 140
misspell:
Expand All @@ -58,7 +51,6 @@ linters:
- godox
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
Expand Down
50 changes: 26 additions & 24 deletions d2app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,31 @@ const (

// App represents the main application for the engine
type App struct {
lastTime float64
lastScreenAdvance float64
showFPS bool
timeScale float64
captureState captureState
capturePath string
captureFrames []*image.RGBA
gitBranch string
gitCommit string
language string
charset string
asset *d2asset.AssetManager
inputManager d2interface.InputManager
terminal d2interface.Terminal
scriptEngine *d2script.ScriptEngine
audio d2interface.AudioProvider
renderer d2interface.Renderer
screen *d2screen.ScreenManager
ui *d2ui.UIManager
tAllocSamples *ring.Ring
guiManager *d2gui.GuiManager
config *d2config.Configuration
terminal d2interface.Terminal
errorMessage error
audio d2interface.AudioProvider
renderer d2interface.Renderer
inputManager d2interface.InputManager
tAllocSamples *ring.Ring
guiManager *d2gui.GuiManager
screen *d2screen.ScreenManager
config *d2config.Configuration
*d2util.Logger
errorMessage error
scriptEngine *d2script.ScriptEngine
asset *d2asset.AssetManager
ui *d2ui.UIManager
*Options
charset string
language string
gitCommit string
gitBranch string
capturePath string
captureFrames []*image.RGBA
captureState captureState
timeScale float64
lastScreenAdvance float64
lastTime float64
showFPS bool
}

// Options is used to store all of the app options that can be set with arguments
Expand Down Expand Up @@ -141,7 +141,9 @@ func (a *App) startDedicatedServer() error {
return srvErr
}

c := make(chan os.Signal)
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) // This traps Control-c to safely shut down the server

go func() {
Expand Down
26 changes: 13 additions & 13 deletions d2app/console_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (

func (a *App) initTerminalCommands() {
terminalCommands := []struct {
fn func(args []string) error
name string
desc string
args []string
fn func(args []string) error
}{
{"dumpheap", "dumps the heap to pprof/heap.pprof", nil, a.dumpHeap},
{"fullscreen", "toggles fullscreen", nil, a.toggleFullScreen},
{"capframe", "captures a still frame", []string{"filename"}, a.setupCaptureFrame},
{"capgifstart", "captures an animation (start)", []string{"filename"}, a.startAnimationCapture},
{"capgifstop", "captures an animation (stop)", nil, a.stopAnimationCapture},
{"vsync", "toggles vsync", nil, a.toggleVsync},
{"fps", "toggle fps counter", nil, a.toggleFpsCounter},
{"timescale", "set scalar for elapsed time", []string{"float"}, a.setTimeScale},
{"quit", "exits the game", nil, a.quitGame},
{"screen-gui", "enters the gui playground screen", nil, a.enterGuiPlayground},
{"js", "eval JS scripts", []string{"code"}, a.evalJS},
{a.dumpHeap, "dumpheap", "dumps the heap to pprof/heap.pprof", nil},
{a.toggleFullScreen, "fullscreen", "toggles fullscreen", nil},
{a.setupCaptureFrame, "capframe", "captures a still frame", []string{"filename"}},
{a.startAnimationCapture, "capgifstart", "captures an animation (start)", []string{"filename"}},
{a.stopAnimationCapture, "capgifstop", "captures an animation (stop)", nil},
{a.toggleVsync, "vsync", "toggles vsync", nil},
{a.toggleFpsCounter, "fps", "toggle fps counter", nil},
{a.setTimeScale, "timescale", "set scalar for elapsed time", []string{"float"}},
{a.quitGame, "quit", "exits the game", nil},
{a.enterGuiPlayground, "screen-gui", "enters the gui playground screen", nil},
{a.evalJS, "js", "eval JS scripts", []string{"code"}},
}

for _, cmd := range terminalCommands {
Expand All @@ -37,7 +37,7 @@ func (a *App) initTerminalCommands() {

func (a *App) dumpHeap([]string) error {
if _, err := os.Stat("./pprof/"); os.IsNotExist(err) {
if err := os.Mkdir("./pprof/", 0750); err != nil {
if err := os.Mkdir("./pprof/", 0o750); err != nil {
a.Fatal(err.Error())
}
}
Expand Down
2 changes: 1 addition & 1 deletion d2common/d2cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
var _ d2interface.Cache = &Cache{} // Static check to confirm struct conforms to interface

type cacheNode struct {
value interface{}
next *cacheNode
prev *cacheNode
key string
value interface{}
weight int
}

Expand Down
24 changes: 12 additions & 12 deletions d2common/d2calculation/d2lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (t tokenType) String() string {

// Token is a lexical token of a calculation string.
type Token struct {
Type tokenType
Value string
Type tokenType
}

func (t *Token) String() string {
Expand All @@ -49,11 +49,11 @@ func (t *Token) String() string {

// Lexer is the tokenizer for calculation strings.
type Lexer struct {
data []byte
CurrentToken Token
nextToken Token
data []byte
index int
peeked bool
nextToken Token
}

// New creates a new Lexer for tokenizing the given data.
Expand All @@ -79,23 +79,23 @@ func (l *Lexer) extractOpToken() Token {
panic("Invalid operator at index!" + strconv.Itoa(l.index))
} else {
l.index += 2
return Token{Symbol, string(c) + "="}
return Token{Type: Symbol, Value: string(c) + "="}
}
}

if c == '<' || c == '>' {
next, ok := l.peekNext()
if ok == nil && next == '=' {
l.index += 2
return Token{Symbol, string(c) + "="}
return Token{Type: Symbol, Value: string(c) + "="}
}
l.index++

return Token{Symbol, string(c)}
return Token{Type: Symbol, Value: string(c)}
}
l.index++

return Token{Symbol, string(c)}
return Token{Type: Symbol, Value: string(c)}
}

func (l *Lexer) extractNumber() Token {
Expand All @@ -106,7 +106,7 @@ func (l *Lexer) extractNumber() Token {
l.index++
}

return Token{Number, sb.String()}
return Token{Type: Number, Value: sb.String()}
}

func (l *Lexer) extractString() Token {
Expand All @@ -119,7 +119,7 @@ func (l *Lexer) extractString() Token {
}
l.index++

return Token{String, sb.String()}
return Token{Type: String, Value: sb.String()}
}

func (l *Lexer) extractName() Token {
Expand All @@ -132,7 +132,7 @@ func (l *Lexer) extractName() Token {
l.index++
}

return Token{Name, sb.String()}
return Token{Type: Name, Value: sb.String()}
}

// Peek returns the next token, but does not advance the tokenizer.
Expand All @@ -143,7 +143,7 @@ func (l *Lexer) Peek() Token {
}

if l.index == len(l.data) {
l.nextToken = Token{EOF, ""}
l.nextToken = Token{Type: EOF, Value: ""}
return l.nextToken
}

Expand All @@ -152,7 +152,7 @@ func (l *Lexer) Peek() Token {
}

if l.index == len(l.data) {
l.nextToken = Token{EOF, ""}
l.nextToken = Token{Type: EOF, Value: ""}
return l.nextToken
}

Expand Down