Skip to content

Commit

Permalink
oak: address some basic linting (deadcode, misspell)
Browse files Browse the repository at this point in the history
  • Loading branch information
200sc committed May 23, 2021
1 parent 3bf0f7e commit 2fd8313
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 60 deletions.
2 changes: 1 addition & 1 deletion alg/range/intrange/infinite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// NewInfinite returns a range which will always return math.MaxInt32 and
// is unchangable.
// is unchangeable.
func NewInfinite() Range {
return Infinite{}
}
Expand Down
2 changes: 1 addition & 1 deletion audio/fontManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestFontManager(t *testing.T) {
t.Fatalf("expected duplicate font to fail")
}
if fm.Get("notafont") != nil {
t.Fatalf("expected non existant get font to fail")
t.Fatalf("expected non existent get font to fail")
}
if fm.GetDefault() == nil {
t.Fatalf("expected def get font to succeed")
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Config struct {
Fullscreen bool `json:"fullscreen"`
}

// A Duration is a wrapper arouind time.Duration that allows for easier json formatting.
// A Duration is a wrapper around time.Duration that allows for easier json formatting.
type Duration time.Duration

func (d Duration) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion debugConsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (c *Controller) fullScreen(sub []string) {
// It returns an error if the command doesn't exist.
func (c *Controller) RunCommand(cmd string, args ...string) error {
fn, ok := c.commands[cmd]
if ok == false {
if !ok {
return fmt.Errorf("Unknown command %s", cmd)
}
fn(args)
Expand Down
2 changes: 1 addition & 1 deletion entities/x/btn/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (g Generator) Generate() Btn {

func (g Generator) generate(parent *Generator) Btn {
var box render.Modifiable
// handle differnt renderable options that could be passed to the generator
// handle different renderable options that could be passed to the generator
switch {
case g.Toggle != nil:
//Handles checks and other toggle situations
Expand Down
9 changes: 7 additions & 2 deletions event/bus_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package event

import (
"fmt"
"testing"
)

func TestBusStop(t *testing.T) {
b := NewBus()
phase := 0
wait := make(chan struct{})
var topErr error
go func() {
if err := b.Stop(); err != nil {
t.Fatalf("stop errored: %v", err)
topErr = fmt.Errorf("stop errored: %v", err)
}
if phase != 1 {
t.Fatalf("expected phase %v, got %v", 1, phase)
topErr = fmt.Errorf("expected phase %v, got %v", 1, phase)
}
wait <- struct{}{}
}()
Expand All @@ -22,4 +24,7 @@ func TestBusStop(t *testing.T) {
phase = 1
b.doneCh <- struct{}{}
<-wait
if topErr != nil {
t.Fatal(topErr)
}
}
2 changes: 1 addition & 1 deletion event/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Entity interface {
// So to effectively do this you would need something like:
// func DefaultEntity(parent interface{}) *DefaultEntity {}
// ... where the structure would store and pass down the parent.
// This introduces empty interfaces, would make initalization
// This introduces empty interfaces, would make initialization
// more difficult, and would use slightly more memory.
//
// Feel free to use this idea in your own implementations, but
Expand Down
10 changes: 0 additions & 10 deletions event/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ import (
"testing"
)

type testEntity struct {
id CID
name string
}

func (t *testEntity) Init() CID {
t.id = NextID(t)
return t.id
}

func TestGetEntityFails(t *testing.T) {
entity := GetEntity(100)
if entity != nil {
Expand Down
3 changes: 1 addition & 2 deletions oakerr/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ func TestErrorsAreErrors(t *testing.T) {
languages := []Language{English, Deutsch}
for _, lang := range languages {
SetLanguage(lang)
var err error
err = NotFound{}
var err error = NotFound{}
if err.Error() == "" {
t.Fatalf("NotFound error was empty")
}
Expand Down
2 changes: 1 addition & 1 deletion oakerr/format_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
func errorString(code errCode, inputs ...interface{}) string {
format, ok := errFmtStrings[currentLanguage][code]
if !ok {
format, _ = errFmtStrings[English][code]
format = errFmtStrings[English][code]
}
return fmt.Sprintf(format, inputs...)
}
Expand Down
4 changes: 2 additions & 2 deletions render/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestRegisterDecoder(t *testing.T) {
}
err = RegisterDecoder(".new", nil)
if err != nil {
t.Fatalf("expected registering .new to suceed: %v", err)
t.Fatalf("expected registering .new to succeed: %v", err)
}
}

Expand All @@ -26,6 +26,6 @@ func TestRegisterCfgDecoder(t *testing.T) {
}
err = RegisterCfgDecoder(".new", nil)
if err != nil {
t.Fatalf("expected registering .new to suceed: %v", err)
t.Fatalf("expected registering .new to succeed: %v", err)
}
}
2 changes: 1 addition & 1 deletion scene/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestMap(t *testing.T) {
}
exists := &oakerr.ExistingElement{}
if !errors.As(err, exists) {
t.Fatalf("expected ExistingElement error type, got %+t", err)
t.Fatalf("expected ExistingElement error type, got %+T", err)
}
if exists.InputName != "test" {
t.Fatalf("expected error input 'test', got %q", exists.InputName)
Expand Down
6 changes: 3 additions & 3 deletions shape/bezier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func TestBezierCurve(t *testing.T) {
}
bn, ok := b.(BezierNode)
if !ok {
t.Fatalf("expected BezierNode, got %+t", b)
t.Fatalf("expected BezierNode, got %+T", b)
}
expectedLeft := BezierPoint{x1, y1}
left, ok := bn.Left.(BezierPoint)
if !ok {
t.Fatalf("expected left of bezier to be BezierNode, got %+t", bn.Left)
t.Fatalf("expected left of bezier to be BezierNode, got %+T", bn.Left)
}
if left != expectedLeft {
t.Fatalf("expected left point %+v, got %+v", expectedLeft, left)
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestBezierCurveErrors(t *testing.T) {
}
insufficient := &oakerr.InsufficientInputs{}
if !errors.As(err, insufficient) {
t.Fatalf("expected insufficent error, got %+t", err)
t.Fatalf("expected insufficient error, got %+t", err)
}
if insufficient.AtLeast != 2 {
t.Fatalf("expected at least to be '2', got %v", insufficient.AtLeast)
Expand Down
2 changes: 1 addition & 1 deletion shiny/driver/internal/win32/win32.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ var (
)

// initCommon attempts to set up some standard icons.
// TODO: Consider running this only once if succesful.
// TODO: Consider running this only once if successful.
func initCommon() (err error) {
hDefaultIcon, err = LoadIcon(0, IDI_APPLICATION)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion shiny/driver/internal/win32/zsyscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func _GetKeyState(virtkey int32) (keystatus int16) {

func _PostQuitMessage(exitCode int32) {
syscall.Syscall(procPostQuitMessage.Addr(), 1, uintptr(exitCode), 0, 0)
return
}

func _ToUnicodeEx(wVirtKey uint32, wScanCode uint32, lpKeyState *byte, pwszBuff *uint16, cchBuff int32, wFlags uint32, dwhkl syscall.Handle) (ret int32) {
Expand Down
16 changes: 8 additions & 8 deletions shiny/driver/x11driver/texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ func trifanPoints(src2dst *f64.Aff3, sr image.Rectangle) [4]render.Pointfix {
minY := float64(sr.Min.Y)
maxY := float64(sr.Max.Y)
return [4]render.Pointfix{{
f64ToFixed(src2dst[0]*minX + src2dst[1]*minY + src2dst[2]),
f64ToFixed(src2dst[3]*minX + src2dst[4]*minY + src2dst[5]),
X: f64ToFixed(src2dst[0]*minX + src2dst[1]*minY + src2dst[2]),
Y: f64ToFixed(src2dst[3]*minX + src2dst[4]*minY + src2dst[5]),
}, {
f64ToFixed(src2dst[0]*maxX + src2dst[1]*minY + src2dst[2]),
f64ToFixed(src2dst[3]*maxX + src2dst[4]*minY + src2dst[5]),
X: f64ToFixed(src2dst[0]*maxX + src2dst[1]*minY + src2dst[2]),
Y: f64ToFixed(src2dst[3]*maxX + src2dst[4]*minY + src2dst[5]),
}, {
f64ToFixed(src2dst[0]*maxX + src2dst[1]*maxY + src2dst[2]),
f64ToFixed(src2dst[3]*maxX + src2dst[4]*maxY + src2dst[5]),
X: f64ToFixed(src2dst[0]*maxX + src2dst[1]*maxY + src2dst[2]),
Y: f64ToFixed(src2dst[3]*maxX + src2dst[4]*maxY + src2dst[5]),
}, {
f64ToFixed(src2dst[0]*minX + src2dst[1]*maxY + src2dst[2]),
f64ToFixed(src2dst[3]*minX + src2dst[4]*maxY + src2dst[5]),
X: f64ToFixed(src2dst[0]*minX + src2dst[1]*maxY + src2dst[2]),
Y: f64ToFixed(src2dst[3]*minX + src2dst[4]*maxY + src2dst[5]),
}}
}

Expand Down
23 changes: 0 additions & 23 deletions viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package oak
import (
"github.com/oakmound/oak/v3/alg/intgeom"
"github.com/oakmound/oak/v3/event"
"github.com/oakmound/oak/v3/key"
)

// SetScreen positions the viewport to be at x,y
Expand Down Expand Up @@ -78,25 +77,3 @@ func (c *Controller) SetViewportBounds(rect intgeom.Rect2) {
c.setViewport(intgeom.Point2{newViewX, newViewY})
}
}

func (c *Controller) moveViewportBinding(speed int) func(event.CID, interface{}) int {
return func(cID event.CID, n interface{}) int {
dX := 0
dY := 0
if c.IsDown(key.UpArrow) {
dY--
}
if c.IsDown(key.DownArrow) {
dY++
}
if c.IsDown(key.LeftArrow) {
dX--
}
if c.IsDown(key.RightArrow) {
dX++
}
c.viewPos[0] += dX * speed
c.viewPos[1] += dY * speed
return 0
}
}

0 comments on commit 2fd8313

Please sign in to comment.