Skip to content

Commit

Permalink
added lint target to Makefile
Browse files Browse the repository at this point in the history
checks that linters exist before proceeding. project URL for each linter
in the Makefile comments

only go-errorlint and unconvert used at the moment

fixed all lint errors for the added linters
  • Loading branch information
JetSetIlly committed Nov 23, 2024
1 parent 554064e commit f66d020
Show file tree
Hide file tree
Showing 50 changed files with 134 additions and 103 deletions.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ endif


### support targets
.PHONY: all clean tidy generate check_git check_glsl glsl_validate check_pandoc readme_spell patch_file_integrity vet
.PHONY: all clean tidy generate glsl_validate readme_spell patch_file_integrity vet lint
.PHONY: check_glsl check_pandoc check_awk check_linters

all:
@echo "use 'release' to build release binary"
Expand Down Expand Up @@ -83,6 +84,20 @@ vet: check_awk
END { if (ct > 0) {exit 1} }\
'

check_linters:
# https://github.com/polyfloyd/go-errorlint
ifeq (, $(shell which go-errorlint))
$(error "go-errorlint not installed")
endif
# https://github.com/mdempsky/unconvert
ifeq (, $(shell which unconvert))
$(error "unconvert not installed")
endif

lint: check_linters
go-errorlint -c 0 -errorf -errorf-multi ./...
unconvert ./...

### testing targets
.PHONY: test race race_debug fuzz

Expand Down
10 changes: 5 additions & 5 deletions archivefs/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ func (afs *Path) Set(path string, fallback bool) error {
if fallback {
return afs.Set(prevSearch, false)
}
return fmt.Errorf("archivefs: set: %v", err)
return fmt.Errorf("archivefs: set: %w", err)
}

zfi, err := zf.Stat()
if err != nil {
if fallback {
return afs.Set(prevSearch, false)
}
return fmt.Errorf("archivefs: set: %v", err)
return fmt.Errorf("archivefs: set: %w", err)
}

afs.isDir = zfi.IsDir()
Expand All @@ -326,7 +326,7 @@ func (afs *Path) Set(path string, fallback bool) error {
if fallback {
return afs.Set(prevSearch, false)
}
return fmt.Errorf("archivefs: set: %v", err)
return fmt.Errorf("archivefs: set: %w", err)
}

afs.isDir = fi.IsDir()
Expand All @@ -345,7 +345,7 @@ func (afs *Path) Set(path string, fallback bool) error {
if fallback {
return afs.Set(prevSearch, false)
}
return fmt.Errorf("archivefs: set: %v", err)
return fmt.Errorf("archivefs: set: %w", err)
}
}
}
Expand All @@ -355,7 +355,7 @@ func (afs *Path) Set(path string, fallback bool) error {
var err error
afs.current, err = filepath.Abs(search)
if err != nil {
return fmt.Errorf("archivefs: set: %v", err)
return fmt.Errorf("archivefs: set: %w", err)
}

// make sure path is clean
Expand Down
2 changes: 1 addition & 1 deletion coprocessor/developer/developer.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (dev *Developer) SearchStaticMemory(output io.Writer, data uint32, width in
if !ok {
return fmt.Errorf("address %08x not found in segment (it should be)", addr)
}
if v == uint32(data) {
if v == data {
output.Write([]byte(fmt.Sprintf("%s %08x", seg.Name, addr)))
}
}
Expand Down
18 changes: 9 additions & 9 deletions coprocessor/developer/dwarf/dwarf_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newBuild(dwrf *dwarf.Data, debug_loc *loclistSection, debug_frame *frameSec
for {
entry, err := r.Next()
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break // for loop
}
return nil, err
Expand Down Expand Up @@ -591,7 +591,7 @@ func (bld *build) buildVariables(src *Source, ef *elf.File,

fld := e.AttrField(dwarf.AttrLowpc)
if fld != nil {
compilationUnitAddress += uint64(fld.Val.(uint64))
compilationUnitAddress += fld.Val.(uint64)
}

continue // for loop
Expand All @@ -605,7 +605,7 @@ func (bld *build) buildVariables(src *Source, ef *elf.File,

fld := e.AttrField(dwarf.AttrLowpc)
if fld != nil {
low = addressAdjustment + uint64(fld.Val.(uint64))
low = addressAdjustment + fld.Val.(uint64)

fld = e.AttrField(dwarf.AttrHighpc)
if fld == nil {
Expand All @@ -618,7 +618,7 @@ func (bld *build) buildVariables(src *Source, ef *elf.File,
high = low + uint64(fld.Val.(int64))
case dwarf.ClassAddress:
// dwarf-2
high = uint64(fld.Val.(uint64))
high = fld.Val.(uint64)
default:
}

Expand Down Expand Up @@ -1036,7 +1036,7 @@ func (bld *build) buildFunctions(src *Source, addressAdjustment uint64) error {
// 2.17.3)."
fld := e.AttrField(dwarf.AttrLowpc)
if fld != nil {
compilationUnitAddress += uint64(fld.Val.(uint64))
compilationUnitAddress += fld.Val.(uint64)
}
case dwarf.TagSubprogram:
// check address against low/high fields
Expand All @@ -1050,7 +1050,7 @@ func (bld *build) buildFunctions(src *Source, addressAdjustment uint64) error {
// either concrete Subprograms or concrete InlinedSubroutines
continue // for loop
}
low = addressAdjustment + uint64(fld.Val.(uint64))
low = addressAdjustment + fld.Val.(uint64)

fld = e.AttrField(dwarf.AttrHighpc)
if fld == nil {
Expand All @@ -1063,7 +1063,7 @@ func (bld *build) buildFunctions(src *Source, addressAdjustment uint64) error {
high = low + uint64(fld.Val.(int64))
case dwarf.ClassAddress:
// dwarf-2
high = uint64(fld.Val.(uint64))
high = fld.Val.(uint64)
default:
return fmt.Errorf("AttrLowpc without AttrHighpc for Subprogram")
}
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func (bld *build) buildFunctions(src *Source, addressAdjustment uint64) error {

fld := e.AttrField(dwarf.AttrLowpc)
if fld != nil {
low = addressAdjustment + uint64(fld.Val.(uint64))
low = addressAdjustment + fld.Val.(uint64)

// high PC
fld = e.AttrField(dwarf.AttrHighpc)
Expand All @@ -1184,7 +1184,7 @@ func (bld *build) buildFunctions(src *Source, addressAdjustment uint64) error {
high = low + uint64(fld.Val.(int64))
case dwarf.ClassAddress:
// dwarf-2
high = uint64(fld.Val.(uint64))
high = fld.Val.(uint64)
default:
return fmt.Errorf("AttrLowpc without AttrHighpc for InlinedSubroutine")
}
Expand Down
4 changes: 2 additions & 2 deletions coprocessor/developer/dwarf/dwarf_frame_instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func decodeFrameInstruction(coproc coprocessor.CartCoProc, byteOrder binary.Byte
if int(reg) >= len(tab.rows[0].registers) {
// ignore extended registers for now
} else {
tab.rows[0].registers[reg].value = int64(offset) * cie.dataAlignment
tab.rows[0].registers[reg].value = offset * cie.dataAlignment
}

return frameInstruction{
Expand Down Expand Up @@ -477,7 +477,7 @@ func decodeFrameInstruction(coproc coprocessor.CartCoProc, byteOrder binary.Byte
if int(reg) >= len(tab.rows[0].registers) {
err = fmt.Errorf("bad register %d", reg)
} else {
tab.rows[0].registers[reg].value = int64(offset)
tab.rows[0].registers[reg].value = offset
}

return frameInstruction{
Expand Down
4 changes: 2 additions & 2 deletions coprocessor/developer/dwarf/leb128/leb128.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func DecodeSLEB128(encoded []uint8) (int64, int) {
var n int
for _, v = range encoded {
n++
result |= int64((int64(v) & 0x7f) << shift)
result |= (int64(v) & 0x7f) << shift
shift += 7
if v&0x80 == 0x00 {
break
Expand All @@ -60,5 +60,5 @@ func DecodeSLEB128(encoded []uint8) (int64, int) {
result |= -(1 << shift)
}

return int64(result), n
return result, n
}
16 changes: 8 additions & 8 deletions coprocessor/developer/dwarf/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func NewSource(romFile string, cart Cartridge, elfFile string) (*Source, error)
}
b, err := debug_info.Data()
if err != nil {
return nil, fmt.Errorf("dwarf: %v", err)
return nil, fmt.Errorf("dwarf: %w", err)
}
version := ef.ByteOrder.Uint16(b[4:])
if version != 4 {
Expand Down Expand Up @@ -302,7 +302,7 @@ func NewSource(romFile string, cart Cartridge, elfFile string) (*Source, error)

// if ELF file was manually specified prefer
if elfFile != "" {
addressAdjustment = uint64(ef.Entry)
addressAdjustment = ef.Entry
adjust = true
} else {
if c, ok := bus.(coprocessor.CartCoProcOrigin); ok {
Expand Down Expand Up @@ -399,7 +399,7 @@ func NewSource(romFile string, cart Cartridge, elfFile string) (*Source, error)
for {
e, err := r.Next()
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break // for loop
}
return nil, fmt.Errorf("dwarf: %w", err)
Expand All @@ -421,7 +421,7 @@ func NewSource(romFile string, cart Cartridge, elfFile string) (*Source, error)

fld := e.AttrField(dwarf.AttrLowpc)
if fld != nil {
unit.address = addressAdjustment + uint64(fld.Val.(uint64))
unit.address = addressAdjustment + fld.Val.(uint64)
}

// assuming DWARF never has duplicate compile unit entries
Expand Down Expand Up @@ -604,7 +604,7 @@ func allocateSourceLines(src *Source, dwrf *dwarf.Data, addressAdjustment uint64
for {
err := r.Next(&le)
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break // line entry for loop. will continue with compile unit loop
}
return err
Expand Down Expand Up @@ -680,7 +680,7 @@ func allocateSourceLines(src *Source, dwrf *dwarf.Data, addressAdjustment uint64
for {
err := r.Next(&le)
if err != nil {
if err == io.EOF {
if errors.Is(err, io.EOF) {
break // line entry for loop. will continue with compile unit loop
}
return err
Expand Down Expand Up @@ -841,12 +841,12 @@ func addFunctionStubs(src *Source, ef *elf.File) error {
if typ == 0x02 {
// align address
// TODO: this is a bit of ARM specific knowledge that should be removed
a := uint64(s.Value & 0xfffffffe)
a := s.Value & 0xfffffffe
symbolTableFunctions = append(symbolTableFunctions, fn{
name: s.Name,
rng: SourceRange{
Start: a,
End: a + uint64(s.Size) - 1,
End: a + s.Size - 1,
},
})
}
Expand Down
4 changes: 2 additions & 2 deletions database/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func StartSession(path string, activity Activity, init func(*Session) error) (*S

db.dbfile, err = os.OpenFile(path, flags, 0600)
if err != nil {
switch err.(type) {
case *os.PathError:
var pathError *os.PathError
if errors.As(err, &pathError) {
return nil, fmt.Errorf("%w: %s", NotAvailable, path)
}
return nil, fmt.Errorf("database: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion debugger/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func (dbg *Debugger) processTokens(tokens *commandline.Tokens) error {

var ok bool

ln, ok = src.LinesByAddress[uint64(addr)]
ln, ok = src.LinesByAddress[addr]
if !ok {
dbg.printLine(terminal.StyleError, fmt.Sprintf("address %x does not correspond to a source line", addr))
} else {
Expand Down
2 changes: 1 addition & 1 deletion debugger/halt_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func parseTarget(dbg *Debugger, tokens *commandline.Tokens) (*target, error) {
trg = &target{
label: "RDY",
value: func() targetValue {
return bool(dbg.vcs.CPU.RdyFlg)
return dbg.vcs.CPU.RdyFlg
},
format: "%v",
instructionBoundary: true,
Expand Down
2 changes: 1 addition & 1 deletion debugger/terminal/colorterm/easyterm/easyterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (et *EasyTerm) UpdateGeometry() error {
uintptr(unsafe.Pointer(&et.geometry)))

if errno != 0 {
return fmt.Errorf("error updating terminal geometry information (%d)", errno)
return fmt.Errorf("error updating terminal geometry information (%w)", errno)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions gopher2600.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func launch(sync *mainSync, args []string) {
// execution modes summary and return
err := flgs.Parse(args)
if err != nil {
if err == flag.ErrHelp {
if errors.Is(err, flag.ErrHelp) {
fmt.Println("Execution Modes: RUN, DEBUG, DISASM, PERFORMANCE, REGRESS, VERSION")
sync.state <- stateRequest{req: reqQuit, args: 20}
return
Expand Down Expand Up @@ -616,7 +616,7 @@ func regress(mode string, args []string) error {
flgs := flag.NewFlagSet(mode, flag.ContinueOnError)
err := flgs.Parse(args)
if err != nil {
if err == flag.ErrHelp {
if errors.Is(err, flag.ErrHelp) {
fmt.Println("Sub modes: RUN, LIST, DELETE, ADD, REDUX, CLEANUP")
}
return nil
Expand Down Expand Up @@ -749,7 +749,7 @@ func regressAdd(mode string, args []string) error {
// parse args and get copy of remaining arguments
err := flgs.Parse(args)
if err != nil {
if err == flag.ErrHelp {
if errors.Is(err, flag.ErrHelp) {
fmt.Println()
fmt.Println(`The regression test to be added can be the path to a cartridge file or a previously
recorded playback file. For playback files, the flags marked [not playback files] do not
Expand Down
2 changes: 1 addition & 1 deletion gui/sdlimgui/imgui_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func drawRegister(id string, val uint8, mask uint8, col imgui.PackedColor, onWri
if seq.rectFill(col) {
v := val ^ (0x80 >> i)
if onWrite != nil {
onWrite(uint8(v & mask))
onWrite(v & mask)
}
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions gui/sdlimgui/manager_hotkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package sdlimgui

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -93,8 +94,8 @@ func (wm *manager) loadManagerHotkeys() (rerr error) {
// open an existing hotkeys file
f, err := fs.Open(pth)
if err != nil {
switch err.(type) {
case *os.PathError:
var pathError *os.PathError
if errors.As(err, &pathError) {
return nil
}
return fmt.Errorf("manager hotkeys: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions gui/sdlimgui/manager_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package sdlimgui

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -121,8 +122,8 @@ func (wm *manager) loadManagerState() (rerr error) {
// open an existing state file
f, err := fs.Open(pth)
if err != nil {
switch err.(type) {
case *os.PathError:
var pathError *os.PathError
if errors.As(err, &pathError) {
return nil
}
return fmt.Errorf("manager state: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion gui/sdlimgui/win_cart_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (win *winCartStatic) draw(static mapper.CartStatic) {
switch varb.Type.Size {
case 4:
if d, ok := currStatic.Read32bit(addr); ok {
value = uint32(d)
value = d
currValue = fmt.Sprintf("%08x", d)
}
if d, ok := compStatic.Read32bit(addr); ok {
Expand Down
Loading

0 comments on commit f66d020

Please sign in to comment.