Skip to content

Commit

Permalink
lint: Enable errcheck adnd revive
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 27, 2021
1 parent 5bf4bc7 commit 3ff0c9b
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 166 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
linters:
enable:
- revive
- errname
- goimports
- nilerr
- forcetypeassert
Expand Down Expand Up @@ -33,4 +35,3 @@ linters-settings:
# allow md5
- G401
- G501
unused:
1 change: 1 addition & 0 deletions format/all/all.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Package all imports and registers all formats in the default registry
//nolint:revive
package all

import (
Expand Down
1 change: 1 addition & 0 deletions format/av1/av1_obu.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func init() {
})
}

//nolint:revive
const (
OBU_SEQUENCE_HEADER = 1
OBU_TEMPORAL_DELIMITER = 2
Expand Down
3 changes: 3 additions & 0 deletions format/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/wader/fq/pkg/ranges"
)

//nolint:revive
const (
ALL = "all"

Expand Down Expand Up @@ -130,6 +131,7 @@ type HevcDcrOut struct {
}

// based on ffmpeg libavformat/isom.c ff_mp4_obj_type
//nolint:revive
const (
MPEGObjectTypeMOV_TEXT = 0x08
MPEGObjectTypeMPEG4 = 0x20
Expand Down Expand Up @@ -320,6 +322,7 @@ type ProtoBufIn struct {
Message ProtoBufMessage
}

//nolint:revive
const (
MPEGAudioObjectTypeMain = 1
MPEGAudioObjectTypeLC = 2
Expand Down
2 changes: 2 additions & 0 deletions format/elf/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
})
}

//nolint:revive
const (
SHT_NULL = 0x0
SHT_PROGBITS = 0x1
Expand Down Expand Up @@ -377,6 +378,7 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
var shname string
var typ uint64

//nolint:revive
const (
DT_NULL = 0
DT_NEEDED = 1
Expand Down
1 change: 1 addition & 0 deletions format/matroska/ebml_matroska/ebml_matroska.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:revive
package ebml_matroska

// https://raw.githubusercontent.com/cellar-wg/matroska-specification/aa2144a58b661baf54b99bab41113d66b0f5ff62/ebml_matroska.xml
Expand Down
1 change: 1 addition & 0 deletions format/matroska/ebml_matroska/ebml_matroska_gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Code below generated from ebml_matroska.xml
//nolint:revive
package ebml_matroska

import "github.com/wader/fq/format/matroska/ebml"
Expand Down
4 changes: 2 additions & 2 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,8 +1177,8 @@ func init() {
hasProgramID := d.FieldBool("has_program_id")
if hasProgramID {
d.FieldU16("short_program_id")
hasUuid := d.FieldBool("has_uuid")
if hasUuid {
hasUUID := d.FieldBool("has_uuid")
if hasUUID {
d.FieldBitBufLen("uuid", 16*8)
}
}
Expand Down
2 changes: 2 additions & 0 deletions format/mpeg/aac_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var SyntaxElementNames = map[uint64]string{
TERM: "TERM",
}

//nolint:revive
const (
EXT_FILL = 0x0
EXT_FILL_DATA = 0x1
Expand All @@ -61,6 +62,7 @@ var ExtensionPayloadIDNames = map[uint64]string{
EXT_SBR_DATA_CRC: "EXT_SBR_DATA_CRC",
}

//nolint:revive
const (
ONLY_LONG_SEQUENCE = 0x0
LONG_START_SEQUENCE = 0x1
Expand Down
1 change: 1 addition & 0 deletions format/mpeg/mpeg_es.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:revive
package mpeg

import (
Expand Down
1 change: 1 addition & 0 deletions format/mpeg/mpeg_spu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
})
}

//nolint:revive
const (
CMD_END = 0xff
FSTA_DSP = 0x00
Expand Down
6 changes: 3 additions & 3 deletions format/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func (r *Registry) Group(name string) ([]*decode.Format, error) {
}

func (r *Registry) MustGroup(name string) []*decode.Format {
if g, err := r.Group(name); err == nil {
g, err := r.Group(name)
if err == nil {
return g
} else {
panic(err)
}
panic(err)
}

func (r *Registry) MustAll() []*decode.Format {
Expand Down
1 change: 1 addition & 0 deletions format/tiff/tags.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:revive
package tiff

const (
Expand Down
1 change: 1 addition & 0 deletions format/vpx/vp9_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var vp9FeatureIDNames = map[uint64]string{
vp9FeatureChromaSubsampling: "Chroma Subsampling",
}

//nolint:revive
const (
CS_UNKNOWN = 0
CS_BT_601 = 1
Expand Down
10 changes: 5 additions & 5 deletions internal/progressreadseeker/progressreaderseeker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type ProgressFn func(approxReadBytes int64, totalSize int64)

type progressReaderSeeker struct {
type ProgressReaderSeeker struct {
rs io.ReadSeeker
pos int64
totalSize int64
Expand All @@ -16,12 +16,12 @@ type progressReaderSeeker struct {
progressFn ProgressFn
}

func New(rs io.ReadSeeker, precision int64, totalSize int64, fn ProgressFn) *progressReaderSeeker {
func New(rs io.ReadSeeker, precision int64, totalSize int64, fn ProgressFn) *ProgressReaderSeeker {
partitionSize := totalSize / precision
if totalSize%precision != 0 {
partitionSize++
}
return &progressReaderSeeker{
return &ProgressReaderSeeker{
rs: rs,
totalSize: totalSize,
partitionSize: partitionSize,
Expand All @@ -30,7 +30,7 @@ func New(rs io.ReadSeeker, precision int64, totalSize int64, fn ProgressFn) *pro
}
}

func (prs *progressReaderSeeker) Read(p []byte) (n int, err error) {
func (prs *ProgressReaderSeeker) Read(p []byte) (n int, err error) {
n, err = prs.rs.Read(p)
newPos := prs.pos + int64(n)
lastPartitionsReadCount := prs.partitionsReadCount
Expand Down Expand Up @@ -59,7 +59,7 @@ func (prs *progressReaderSeeker) Read(p []byte) (n int, err error) {
return n, err
}

func (prs *progressReaderSeeker) Seek(offset int64, whence int) (int64, error) {
func (prs *ProgressReaderSeeker) Seek(offset int64, whence int) (int64, error) {
pos, err := prs.rs.Seek(offset, whence)
prs.pos = pos
return pos, err
Expand Down
14 changes: 7 additions & 7 deletions pkg/bitio/bitio.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,13 @@ func (r *SectionBitReader) Seek(offset int64, whence int) (int64, error) {
}

// TODO: smart, track index?
type multiBitReader struct {
type MultiBitReader struct {
pos int64
readers []BitReadAtSeeker
readerEnds []int64
}

func NewMultiBitReader(rs []BitReadAtSeeker) (*multiBitReader, error) {
func NewMultiBitReader(rs []BitReadAtSeeker) (*MultiBitReader, error) {
readerEnds := make([]int64, len(rs))
var esSum int64
for i, r := range rs {
Expand All @@ -360,10 +360,10 @@ func NewMultiBitReader(rs []BitReadAtSeeker) (*multiBitReader, error) {
esSum += e
readerEnds[i] = esSum
}
return &multiBitReader{readers: rs, readerEnds: readerEnds}, nil
return &MultiBitReader{readers: rs, readerEnds: readerEnds}, nil
}

func (m *multiBitReader) ReadBitsAt(p []byte, nBits int, bitOff int64) (n int, err error) {
func (m *MultiBitReader) ReadBitsAt(p []byte, nBits int, bitOff int64) (n int, err error) {
end := m.readerEnds[len(m.readers)-1]
if end <= bitOff {
return 0, io.EOF
Expand All @@ -390,13 +390,13 @@ func (m *multiBitReader) ReadBitsAt(p []byte, nBits int, bitOff int64) (n int, e
return rBits, err
}

func (m *multiBitReader) ReadBits(p []byte, nBits int) (n int, err error) {
func (m *MultiBitReader) ReadBits(p []byte, nBits int) (n int, err error) {
n, err = m.ReadBitsAt(p, nBits, m.pos)
m.pos += int64(n)
return n, err
}

func (m *multiBitReader) SeekBits(bitOff int64, whence int) (int64, error) {
func (m *MultiBitReader) SeekBits(bitOff int64, whence int) (int64, error) {
var p int64
end := m.readerEnds[len(m.readerEnds)-1]

Expand All @@ -419,7 +419,7 @@ func (m *multiBitReader) SeekBits(bitOff int64, whence int) (int64, error) {
return p, nil
}

func (m *multiBitReader) Read(p []byte) (n int, err error) {
func (m *MultiBitReader) Read(p []byte) (n int, err error) {
n, err = m.ReadBitsAt(p, len(p)*8, m.pos)
m.pos += int64(n)

Expand Down
108 changes: 54 additions & 54 deletions pkg/bitio/rw64.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ func Read64(buf []byte, firstBit int, nBits int) uint64 {
}
// done
return n
}

b := buf[bytePos]

if byteBitPos == 0 {
// bitPos is byte aligned but not bitsLeft
if bitsLeft >= 8 {
// TODO: more cases left >= 16 etc
n = n<<8 | uint64(b)
bitPos += 8
bitsLeft -= 8
} else {
n = n<<bitsLeft | (uint64(b) >> (8 - bitsLeft))
// done
return n
}
} else {
b := buf[bytePos]

if byteBitPos == 0 {
// bitPos is byte aligned but not bitsLeft
if bitsLeft >= 8 {
// TODO: more cases left >= 16 etc
n = n<<8 | uint64(b)
bitPos += 8
bitsLeft -= 8
} else {
n = n<<bitsLeft | (uint64(b) >> (8 - bitsLeft))
// done
return n
}
// neither byteBitPos or bitsLeft byte aligned
byteBitsLeft := (8 - byteBitPos) & 0x7
if bitsLeft >= byteBitsLeft {
n = n<<byteBitsLeft | (uint64(b) & ((1 << byteBitsLeft) - 1))
bitPos += byteBitsLeft
bitsLeft -= byteBitsLeft
} else {
// neither byteBitPos or bitsLeft byte aligned
byteBitsLeft := (8 - byteBitPos) & 0x7
if bitsLeft >= byteBitsLeft {
n = n<<byteBitsLeft | (uint64(b) & ((1 << byteBitsLeft) - 1))
bitPos += byteBitsLeft
bitsLeft -= byteBitsLeft
} else {
n = n<<bitsLeft | (uint64(b)&((1<<byteBitsLeft)-1))>>(byteBitsLeft-bitsLeft)
// done
return n
}
n = n<<bitsLeft | (uint64(b)&((1<<byteBitsLeft)-1))>>(byteBitsLeft-bitsLeft)
// done
return n
}
}
}
Expand Down Expand Up @@ -134,37 +134,37 @@ func Write64(v uint64, nBits int, buf []byte, firstBit int) {
}
// done
return
}

b := buf[bytePos]

if byteBitPos == 0 {
// byteBitPos is byte aligned but not bitsLeft
if bitsLeft >= 8 {
// TODO: more cases left >= 16 etc
buf[bytePos] = byte(v >> (bitsLeft - 8))
bitPos += 8
bitsLeft -= 8
} else {
extraBits := 8 - bitsLeft
buf[bytePos] = byte(v)<<extraBits | b&((1<<extraBits)-1)
// done
return
}
} else {
b := buf[bytePos]

if byteBitPos == 0 {
// byteBitPos is byte aligned but not bitsLeft
if bitsLeft >= 8 {
// TODO: more cases left >= 16 etc
buf[bytePos] = byte(v >> (bitsLeft - 8))
bitPos += 8
bitsLeft -= 8
} else {
extraBits := 8 - bitsLeft
buf[bytePos] = byte(v)<<extraBits | b&((1<<extraBits)-1)
// done
return
}
// neither byteBitPos or bitsLeft byte aligned
byteBitsLeft := (8 - byteBitPos) & 0x7
if bitsLeft >= byteBitsLeft {
bMask := byte((1<<byteBitPos)-1) << (8 - byteBitPos)
buf[bytePos] = b&bMask | byte(v>>(bitsLeft-byteBitsLeft))
bitPos += byteBitsLeft
bitsLeft -= byteBitsLeft
} else {
// neither byteBitPos or bitsLeft byte aligned
byteBitsLeft := (8 - byteBitPos) & 0x7
if bitsLeft >= byteBitsLeft {
bMask := byte((1<<byteBitPos)-1) << (8 - byteBitPos)
buf[bytePos] = b&bMask | byte(v>>(bitsLeft-byteBitsLeft))
bitPos += byteBitsLeft
bitsLeft -= byteBitsLeft
} else {
extraBits := byteBitsLeft - bitsLeft
bMask := byte(((1<<byteBitPos)-1)<<(8-byteBitPos) | ((1 << extraBits) - 1))
buf[bytePos] = b&bMask | byte(v)<<extraBits
// done
return
}
extraBits := byteBitsLeft - bitsLeft
bMask := byte(((1<<byteBitPos)-1)<<(8-byteBitPos) | ((1 << extraBits) - 1))
buf[bytePos] = b&bMask | byte(v)<<extraBits
// done
return
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/crc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func MakeTable(poly int, bits int) Table {

for i := 0; i < 256; i++ {
// note sure about -8 for > 16 bit crc
var crc uint = uint(i << (bits - 8))
crc := uint(i << (bits - 8))
for j := 0; j < 8; j++ {
if crc&(1<<(bits-1)) != 0 {
crc = ((crc << 1) ^ uint(poly)) & mask
Expand Down
Loading

0 comments on commit 3ff0c9b

Please sign in to comment.