Skip to content

Commit

Permalink
Fix some golint warnings (#118)
Browse files Browse the repository at this point in the history
These are the simple ones. There are more.

Common lints include:
* Not making use of type inference
* Underscore in identifier name
* Receiver name is not consistent
* Simplify `if` statements where the `else` part can be removed
* Use `foo++` instead of `foo += 1`; similarly for `foo--`
* Errors should not have a newline at the end
  • Loading branch information
fhs authored and rjkroege committed Sep 7, 2018
1 parent 6076914 commit 4fa21de
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 90 deletions.
4 changes: 2 additions & 2 deletions acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var loadfileflag = flag.String("l", "", "Load file name")
var mtptflag = flag.String("m", "", "Mountpoint")
var swapscrollbuttonsflag = flag.Bool("r", false, "Swap scroll buttons")
var winsize = flag.String("W", "1024x768", "Window Size (WidthxHeight)")
var ncol int = 2
var ncol = 2

var mainpid int

Expand Down Expand Up @@ -202,7 +202,7 @@ func readfile(c *Column, filename string) {
xfidlog(w, "new")
}

var fontCache map[string]*draw.Font = make(map[string]*draw.Font)
var fontCache = make(map[string]*draw.Font)

func fontget(name string, display *draw.Display) *draw.Font {
var font *draw.Font
Expand Down
5 changes: 2 additions & 3 deletions dat.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const (
NRange = 10 // TODO(flux): No reason for this static limit anymore; should we remove?
// Infinity = 0x7FFFFFFF

// STACK = 65536
EVENTSIZE = 256
BUFSIZE = MaxBlock + plan9.IOHDRSZ
RBUFSIZE = BUFSIZE / utf8.UTFMax
Expand Down Expand Up @@ -117,7 +116,7 @@ var (
tagcolors [frame.NumColours]*draw.Image
textcolors [frame.NumColours]*draw.Image
wdir string
editing int = Inactive
editing = Inactive
messagesize int
globalautoindent bool
dodollarsigns bool
Expand All @@ -140,7 +139,7 @@ var (

editoutlk *sync.Mutex

WinId int = 0
WinID = 0
)

type Range struct {
Expand Down
32 changes: 16 additions & 16 deletions disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,24 @@ func TestReadWriteBig(t *testing.T) {
}
bigstring := b.String()

original_large_blk := disk.NewBlock(uint(4 * 100))
new_large_blk := writereadtestcore(t, "big write-read test", bigstring, original_large_blk, disk)
originalLargeBlk := disk.NewBlock(uint(4 * 100))
newLargeBlk := writereadtestcore(t, "big write-read test", bigstring, originalLargeBlk, disk)

if original_large_blk != new_large_blk {
t.Errorf("without resizing, new_large_blk should equal original_large_blk")
if originalLargeBlk != newLargeBlk {
t.Errorf("without resizing, newLargeBlk should equal originalLargeBlk")
}

// Resize it with a little string.
new_small_blk := writereadtestcore(t, "small size-changing write-read test", "c日本d", new_large_blk, disk)
if new_small_blk == original_large_blk {
t.Errorf("with resizing, new_small_blk should not equal original_large_blk")
newSmallBlk := writereadtestcore(t, "small size-changing write-read test", "c日本d", newLargeBlk, disk)
if newSmallBlk == originalLargeBlk {
t.Errorf("with resizing, newSmallBlk should not equal originalLargeBlk")
}

if original_large_blk != disk.free[2] {
t.Errorf("with resizing, original_large_blk should be in the free-bucket for re-use")
if originalLargeBlk != disk.free[2] {
t.Errorf("with resizing, originalLargeBlk should be in the free-bucket for re-use")
}
if original_large_blk.next != nil {
t.Errorf("Release failed to make original_large_blk.next point to nothing")
if originalLargeBlk.next != nil {
t.Errorf("Release failed to make originalLargeBlk.next point to nothing")
}

// Resize with a big string, make sure that we reuse the block
Expand All @@ -123,12 +123,12 @@ func TestReadWriteBig(t *testing.T) {
}
bigstring = b.String()

different_large_blk := writereadtestcore(t, "small to large size-changing write-read test", bigstring, new_small_blk, disk)
if new_small_blk == different_large_blk {
t.Errorf("with resizing, from small to large, different_large_blk should not equal new_small_blk")
differentLargeBlk := writereadtestcore(t, "small to large size-changing write-read test", bigstring, newSmallBlk, disk)
if newSmallBlk == differentLargeBlk {
t.Errorf("with resizing, from small to large, differentLargeBlk should not equal newSmallBlk")
}
if different_large_blk != original_large_blk {
t.Errorf("with resizing to a previously-used large block, should have reused original_large_blk")
if differentLargeBlk != originalLargeBlk {
t.Errorf("with resizing to a previously-used large block, should have reused originalLargeBlk")
}
if disk.free[2] != nil {
t.Errorf("reusing block from bucket should have removed the block")
Expand Down
2 changes: 1 addition & 1 deletion ecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func mkaddr(f *File) (a Address) {
return a
}

var none Address = Address{Range{0, 0}, nil}
var none = Address{Range{0, 0}, nil}

func cmdexec(t *Text, cp *Cmd) bool {
w := (*Window)(nil)
Expand Down
8 changes: 4 additions & 4 deletions elog.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func (e *Elog) Term() {
(*e).warned = false
}

func (e *ElogOperation) reset() {
e.t = Null
e.nd = 0
e.r = e.r[0:0]
func (eo *ElogOperation) reset() {
eo.t = Null
eo.nd = 0
eo.r = eo.r[0:0]
}

func elogclose(f *File) {}
Expand Down
3 changes: 1 addition & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ func printarg(argt *Text, q0 int, q1 int) string {
}
if q0 == q1 {
return fmt.Sprintf("%s:#%d", argt.file.name, q0)
} else {
return fmt.Sprintf("%s:#%d,#%d", argt.file.name, q0, q1)
}
return fmt.Sprintf("%s:#%d,#%d", argt.file.name, q0, q1)
}

func getarg(argt *Text, doaddr bool, dofile bool) (string, string) {
Expand Down
4 changes: 2 additions & 2 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func (h *FileHash) Set(b []byte) {
copy(h[:], b)
}

func (h0 FileHash) Eq(h1 FileHash) bool {
return bytes.Compare(h0[:], h1[:]) == 0
func (h FileHash) Eq(h1 FileHash) bool {
return bytes.Compare(h[:], h1[:]) == 0
}

func calcFileHash(b []byte) FileHash {
Expand Down
4 changes: 2 additions & 2 deletions frame/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func runeindex(p []byte, n int) int {
offs := 0
for i := 0; i < n; i++ {
if p[offs] < 0x80 {
offs += 1
offs++
} else {
_, size := utf8.DecodeRune(p[offs:])
offs += size
Expand Down Expand Up @@ -166,7 +166,7 @@ func (f *frameimpl) validateboxmodel(format string, args ...interface{}) {
total := 0
for _, b := range f.box {
if b.Nrune < 0 {
total += 1
total++
} else {
total += b.Nrune
}
Expand Down
12 changes: 6 additions & 6 deletions frame/box_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func (bx SimpleBoxModelTest) Try() interface{} {
return struct{}{}
}

func (tv SimpleBoxModelTest) Verify(t *testing.T, prefix string, result interface{}) {
testcore(t, prefix, tv.name, tv.frame, tv.nbox, tv.afterboxes)
func (bx SimpleBoxModelTest) Verify(t *testing.T, prefix string, result interface{}) {
testcore(t, prefix, bx.name, bx.frame, bx.nbox, bx.afterboxes)
}

func TestRunIndex(t *testing.T) {
Expand Down Expand Up @@ -366,11 +366,11 @@ func (bx FindBoxModelTest) Try() interface{} {
return bx.stim(bx.frame)
}

func (tv FindBoxModelTest) Verify(t *testing.T, prefix string, result interface{}) {
func (bx FindBoxModelTest) Verify(t *testing.T, prefix string, result interface{}) {
r := result.(int)
testcore(t, prefix, tv.name, tv.frame, tv.nbox, tv.afterboxes)
if got, want := r, tv.foundbox; got != want {
t.Errorf("%s-%s: running stim got %d but want %d\n", prefix, tv.name, got, want)
testcore(t, prefix, bx.name, bx.frame, bx.nbox, bx.afterboxes)
if got, want := r, bx.foundbox; got != want {
t.Errorf("%s-%s: running stim got %d but want %d\n", prefix, bx.name, got, want)
}
}

Expand Down
12 changes: 6 additions & 6 deletions frame/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ func (bx InsertTest) Try() interface{} {
return InsertTestResult{a, b, c}
}

func (tv InsertTest) Verify(t *testing.T, prefix string, result interface{}) {
func (bx InsertTest) Verify(t *testing.T, prefix string, result interface{}) {
r := result.(InsertTestResult)

if got, want := r.ppt, tv.ppt; got != want {
t.Errorf("%s-%s: running stim ppt got %d but want %d\n", prefix, tv.name, got, want)
if got, want := r.ppt, bx.ppt; got != want {
t.Errorf("%s-%s: running stim ppt got %d but want %d\n", prefix, bx.name, got, want)
}
if got, want := r.resultpt, tv.resultpt; got != want {
t.Errorf("%s-%s: running stim resultpt got %d but want %d\n", prefix, tv.name, got, want)
if got, want := r.resultpt, bx.resultpt; got != want {
t.Errorf("%s-%s: running stim resultpt got %d but want %d\n", prefix, bx.name, got, want)
}
// We use the global frame here to make sure that bxscan works as desired.
// I note in passing that encapsulation here could be improved.
testcore(t, prefix, tv.name, r.frame, tv.nbox, tv.afterboxes)
testcore(t, prefix, bx.name, r.frame, bx.nbox, bx.afterboxes)
}

func mkRu(s string) []rune {
Expand Down
6 changes: 2 additions & 4 deletions frame/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ func (f *frameimpl) canfit(pt image.Point, b *frbox) (int, bool) {
if b.Nrune < 0 {
if int(b.Minwid) <= left {
return 1, true
} else {
return 0, false
}
return 0, false
}

if left >= b.Wid {
Expand Down Expand Up @@ -152,9 +151,8 @@ func nbyte(f *frbox) int {
func nrune(b *frbox) int {
if b.Nrune < 0 {
return 1
} else {
return b.Nrune
}
return b.Nrune
}

func Rpt(min, max image.Point) image.Rectangle {
Expand Down
12 changes: 6 additions & 6 deletions frame/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ func (bx BoxModelTest) Try() interface{} {
}
}

func (tv BoxModelTest) Verify(t *testing.T, prefix string, result interface{}) {
func (bx BoxModelTest) Verify(t *testing.T, prefix string, result interface{}) {
r := result.(BoxModelTestResult)

if got, want := r.result, tv.result; got != want {
t.Errorf("%s-%s: running stim got %d but want %d\n", prefix, tv.name, got, want)
if got, want := r.result, bx.result; got != want {
t.Errorf("%s-%s: running stim got %d but want %d\n", prefix, bx.name, got, want)
}
if got, want := r.boolresult, tv.boolresult; got != want {
t.Errorf("%s-%s: running stim bool got %v but want %v\n", prefix, tv.name, got, want)
if got, want := r.boolresult, bx.boolresult; got != want {
t.Errorf("%s-%s: running stim bool got %v but want %v\n", prefix, bx.name, got, want)
}

testcore(t, prefix, tv.name, tv.frame, tv.nbox, tv.afterboxes)
testcore(t, prefix, bx.name, bx.frame, bx.nbox, bx.afterboxes)
}

func TestCanfit(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions fsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const (
DEBUG = 0
)

var fids map[uint32]*Fid = make(map[uint32]*Fid)
var fids = make(map[uint32]*Fid)

type fsfunc func(*Xfid, *Fid) *Xfid

var fcall []fsfunc = make([]fsfunc, plan9.Tmax)
var fcall = make([]fsfunc, plan9.Tmax)

func initfcall() {
fcall[plan9.Tflush] = fsysflush
Expand All @@ -53,7 +53,7 @@ var (
Enotdir = errors.New("not a directory")
)

var dirtab []*DirTab = []*DirTab{
var dirtab = []*DirTab{
{".", plan9.QTDIR, Qdir, 0500 | plan9.DMDIR},
{"acme", plan9.QTDIR, Qacme, 0500 | plan9.DMDIR},
{"cons", plan9.QTFILE, Qcons, 0600},
Expand All @@ -67,7 +67,7 @@ var dirtab []*DirTab = []*DirTab{
// { nil, }
}

var dirtabw []*DirTab = []*DirTab{
var dirtabw = []*DirTab{
{".", plan9.QTDIR, Qdir, 0500 | plan9.DMDIR},
{"addr", plan9.QTFILE, QWaddr, 0600},
{"body", plan9.QTAPPEND, QWbody, 0600 | plan9.DMAPPEND},
Expand All @@ -92,7 +92,7 @@ type Mnt struct {
var mnt Mnt

var (
username string = "Wile E. Coyote"
username = "Wile E. Coyote"
closing int
)

Expand Down Expand Up @@ -191,7 +191,7 @@ func fsysdelid(idm *MntDir) {
prev = m
}

cerr <- fmt.Errorf("fsysdelid: can't find id %d\n", idm.id)
cerr <- fmt.Errorf("fsysdelid: can't find id %d", idm.id)
}

// Called only in exec.c:/^run(), from a different FD group
Expand Down
3 changes: 1 addition & 2 deletions fsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ func startAcme(t *testing.T) *Acme {
if i >= 9 {
t.Fatalf("Failed to mount acme: %v", err)
return nil
} else {
time.Sleep(time.Second)
}
time.Sleep(time.Second)
} else {
break
}
Expand Down
8 changes: 3 additions & 5 deletions look.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func plumbthread() {
plumbeditfidbr := bufio.NewReader(plumbeditfid)
// Relay messages.
for {
var m *plumb.Message = &plumb.Message{}
var m = &plumb.Message{}
err := m.Recv(plumbeditfidbr)
if err != nil {
break
Expand Down Expand Up @@ -585,9 +585,8 @@ func expandfile(t *Text, q0 int, q1 int, e *Expand) (success bool) {
_, _, e.a1 = address(true, nil, Range{-1, -1}, Range{0, 0}, e.a0, amax,
func(q int) rune { return t.ReadC(q) }, false)
return true
} else {
r = t.DirName(string([]rune(r)[:nname]))
}
r = t.DirName(string([]rune(r)[:nname]))
}
e.bname = r
// if it's already a window name, it's a file
Expand Down Expand Up @@ -622,9 +621,8 @@ func expand(t *Text, q0 int, q1 int) (Expand, bool) {
e.agetc = func(q int) rune {
if q < t.Nc() {
return t.ReadC(q)
} else {
return 0
}
return 0
}

// if in selection, choose selection
Expand Down
8 changes: 4 additions & 4 deletions row_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type loadfontstest struct {
val string
}

const short_file = `/Users/rjkroege/tools/gopkg/src/github.com/rjkroege/edwood
const shortFile = `/Users/rjkroege/tools/gopkg/src/github.com/rjkroege/edwood
/mnt/font/GoRegular/13a/font
`

const full_file = `/Users/rjkroege/tools/gopkg/src/github.com/rjkroege/edwood
const fullFile = `/Users/rjkroege/tools/gopkg/src/github.com/rjkroege/edwood
/mnt/font/GoRegular/13a/font
/mnt/font/Iosevka/12a/font
`
Expand Down Expand Up @@ -47,7 +47,7 @@ func TestLoadFonts(t *testing.T) {
if err != nil {
t.Fatal("TestLoadFonts short_file can't create file:", err)
}
if _, err := f.WriteString(short_file); err != nil {
if _, err := f.WriteString(shortFile); err != nil {
t.Fatal("TestLoadFonts short_file can't write file:", err)
}
f.Close()
Expand All @@ -60,7 +60,7 @@ func TestLoadFonts(t *testing.T) {
if err != nil {
t.Fatal("TestLoadFonts full_file can't create file:", err)
}
if _, err := f.WriteString(full_file); err != nil {
if _, err := f.WriteString(fullFile); err != nil {
t.Fatal("TestLoadFonts full_file can't write file:", err)
}
f.Close()
Expand Down
Loading

0 comments on commit 4fa21de

Please sign in to comment.