Skip to content

Commit

Permalink
Merge pull request #988 from wader/bump-github-golangci-lint-1.60.1
Browse files Browse the repository at this point in the history
Update github-golangci-lint to 1.60.1 from 1.59.1
  • Loading branch information
wader authored Aug 14, 2024
2 parents 072588c + 2c38cf1 commit 72e026e
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:

env:
GOLANGCILINT_VERSION: "1.59.1"
GOLANGCILINT_VERSION: "1.60.1"

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/testing fq

### Build from source

Make sure you have [go](https://go.dev) 1.20 or later installed.
Make sure you have [go](https://go.dev) 1.21 or later installed.

To install directly from git repository (no git clone needed):
```sh
Expand Down
3 changes: 1 addition & 2 deletions format/flac/flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"github.com/wader/fq/format"
"github.com/wader/fq/internal/mathx"
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
Expand Down Expand Up @@ -65,7 +64,7 @@ func flacDecode(d *decode.D) any {

samplesInFrame := ffo.Samples
if streamTotalSamples > 0 {
samplesInFrame = mathx.Min(streamTotalSamples-streamDecodedSamples, ffo.Samples)
samplesInFrame = min(streamTotalSamples-streamDecodedSamples, ffo.Samples)
}
frameStreamSamplesBuf := ffo.SamplesBuf[0 : samplesInFrame*uint64(ffo.Channels*ffo.BitsPerSample/8)]
framesNDecodedSamples += ffo.Samples
Expand Down
3 changes: 1 addition & 2 deletions format/icc/icc_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package icc

import (
"github.com/wader/fq/format"
"github.com/wader/fq/internal/mathx"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
Expand Down Expand Up @@ -167,7 +166,7 @@ func iccProfileDecode(d *decode.D) any {
// was. instead add alignment after if offset+size does not align and to be sure clamp it if outside buffer.
alignStart := int64(offset) + int64(size)
alignBytes := (4 - (int64(offset)+int64(size))%4) % 4
alignBytes = mathx.Min(d.Len()/8-alignStart, alignBytes)
alignBytes = min(d.Len()/8-alignStart, alignBytes)
if alignBytes != 0 {
d.RangeFn(alignStart*8, alignBytes*8, func(d *decode.D) {
d.FieldRawLen("alignment", d.BitsLeft())
Expand Down
2 changes: 1 addition & 1 deletion format/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func decodeJSONEx(d *decode.D, lines bool) any {
break
}
} else if lines {
d.Fatalf(err.Error())
d.Fatalf("%s", err.Error())
}
break
}
Expand Down
3 changes: 1 addition & 2 deletions format/leveldb/leveldb_log_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package leveldb
// - MANIFEST-*

import (
"github.com/wader/fq/internal/mathx"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/scalar"
)
Expand Down Expand Up @@ -49,7 +48,7 @@ func readBlockSequence(rro recordReadOptions, d *decode.D) {

d.FieldArray("blocks", func(d *decode.D) {
for d.BitsLeft() >= headerSize {
d.LimitedFn(mathx.Min(blockSize, d.BitsLeft()), func(d *decode.D) {
d.LimitedFn(min(blockSize, d.BitsLeft()), func(d *decode.D) {
d.FieldStruct("block", bind(readLogBlock, rro))
})
}
Expand Down
5 changes: 2 additions & 3 deletions format/matroska/matroska.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ func matroskaDecode(d *decode.D) any {
if !ok {
panic(fmt.Sprintf("expected mpegASCOut got %#+v", v))
}
//nolint:gosimple
t.formatInArg = format.AAC_Frame_In{ObjectType: mpegASCOut.ObjectType}
case "A_OPUS":
t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, &opusPacketFrameGroup, nil)
Expand All @@ -494,14 +493,14 @@ func matroskaDecode(d *decode.D) any {
if !ok {
panic(fmt.Sprintf("expected AvcDcrOut got %#+v", v))
}
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize} //nolint:gosimple
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize}
case "V_MPEGH/ISO/HEVC":
_, v := t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, &mpegHEVCDCRGroup, nil)
hevcDcrOut, ok := v.(format.HEVC_DCR_Out)
if !ok {
panic(fmt.Sprintf("expected HevcDcrOut got %#+v", v))
}
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize} //nolint:gosimple
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize}
case "V_AV1":
t.parentD.FieldFormatRange("value", t.codecPrivatePos, t.codecPrivateTagSize, &av1CCRGroup, nil)
case "V_VP9":
Expand Down
2 changes: 1 addition & 1 deletion format/mp3/mp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func mp3Decode(d *decode.D) any {

unknownPercent := int(float64((d.Len() - knownSize)) / float64(d.Len()) * 100.0)
if unknownPercent > mi.MaxUnknown {
d.Errorf(fmt.Sprintf("exceeds max precent unknown bits, %d > %d", unknownPercent, mi.MaxUnknown))
d.Errorf("exceeds max precent unknown bits, %d > %d", unknownPercent, mi.MaxUnknown)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
panic(fmt.Sprintf("expected AvcDcrOut got %#+v", v))
}
if t := ctx.currentTrack(); t != nil {
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize} //nolint:gosimple
t.formatInArg = format.AVC_AU_In{LengthSize: avcDcrOut.LengthSize}
}
case "hvcC":
_, v := d.FieldFormat("descriptor", &hevcCDCRGroup, nil)
Expand All @@ -720,7 +720,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
panic(fmt.Sprintf("expected HevcDcrOut got %#+v", v))
}
if t := ctx.currentTrack(); t != nil {
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize} //nolint:gosimple
t.formatInArg = format.HEVC_AU_In{LengthSize: hevcDcrOut.LengthSize}
}
case "dfLa":
d.FieldU8("version")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/wader/fq

go 1.20
go 1.21

// fork of github.com/itchyny/gojq, see github.com/wader/gojq fq branch
require github.com/wader/gojq v0.12.1-0.20240401131232-6c6bc364201a
Expand Down
2 changes: 1 addition & 1 deletion internal/hexdump/hexdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (d *Dumper) WriteBits(p []byte, nBits int64) (n int64, err error) {
pos := int64(0)
rBits := nBits
if d.bitsBufN > 0 {
r := mathx.Min(8-d.bitsBufN, nBits)
r := min(8-d.bitsBufN, nBits)
v := bitio.Read64(p, 0, r)
bitio.Write64(v, r, d.bitsBuf, d.bitsBufN)

Expand Down
24 changes: 2 additions & 22 deletions internal/mathx/num.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,8 @@ func PadFormatBigInt(i *big.Int, base int, basePrefix bool, width int) string {
return padFormatNumber(i.Text(base), base, basePrefix, width)
}

func Max[T constraints.Ordered](v T, vs ...T) T {
m := v
for _, v := range vs {
if v > m {
m = v
}
}
return m
}

func Min[T constraints.Ordered](v T, vs ...T) T {
m := v
for _, v := range vs {
if v < m {
m = v
}
}
return m
}

func Clamp[T constraints.Ordered](min, max, v T) T {
return Max(min, Min(max, v))
func Clamp[T constraints.Ordered](a, b, v T) T {
return max(a, min(b, v))
}

type Bits uint64
Expand Down
4 changes: 1 addition & 3 deletions internal/stringsx/stringsx.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package stringsx

import "github.com/wader/fq/internal/mathx"

func TrimN(s string, n int, suffix string) string {
sl, tl := len(s), len(suffix)
if sl+tl <= n {
return s
}
return s[0:mathx.Max(n-tl, 0)] + suffix
return s[0:max(n-tl, 0)] + suffix
}
3 changes: 1 addition & 2 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path/filepath"
"runtime"

"github.com/wader/fq/internal/mathx"
"github.com/wader/fq/pkg/interp"
"golang.org/x/term"

Expand Down Expand Up @@ -92,7 +91,7 @@ type fdTerminal uintptr
func (fd fdTerminal) Size() (int, int) {
w, h, _ := term.GetSize(int(fd))
// TODO: old version return 0 on no terminal
w, h = mathx.Max(0, w), mathx.Max(0, h)
w, h = max(0, w), max(0, h)
return w, h
}
func (fd fdTerminal) IsTerminal() bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/decode/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (d *D) tryTextLenPrefixed(prefixLenBytes int, fixedBytes int, e encoding.En
if fixedBytes != -1 {
// TODO: error?
readBytes = fixedBytes - prefixLenBytes
lenBytes = mathx.Min(lenBytes, uint64(readBytes))
lenBytes = min(lenBytes, uint64(readBytes))
}

bs, err := d.TryBytesLen(readBytes)
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func dump(v *decode.Value, w io.Writer, opts *Options) error {
}

_ = v.WalkPreOrder(makeWalkFn(func(v *decode.Value, _ *decode.Value, _ int, rootDepth int) error {
maxAddrIndentWidth = mathx.Max(
maxAddrIndentWidth = max(
maxAddrIndentWidth,
rootIndentWidth*rootDepth+mathx.DigitsInBase(bitio.BitsByteCount(v.InnerRange().Stop()), true, opts.Addrbase),
)
Expand Down
10 changes: 5 additions & 5 deletions pkg/interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,13 +1057,13 @@ type Options struct {
func OptionsFromValue(v any) (*Options, error) {
var opts Options
_ = mapstruct.ToStruct(v, &opts)
opts.ArrayTruncate = mathx.Max(0, opts.ArrayTruncate)
opts.StringTruncate = mathx.Max(0, opts.StringTruncate)
opts.Depth = mathx.Max(0, opts.Depth)
opts.ArrayTruncate = max(0, opts.ArrayTruncate)
opts.StringTruncate = max(0, opts.StringTruncate)
opts.Depth = max(0, opts.Depth)
opts.Addrbase = mathx.Clamp(2, 36, opts.Addrbase)
opts.Sizebase = mathx.Clamp(2, 36, opts.Sizebase)
opts.LineBytes = mathx.Max(1, opts.LineBytes)
opts.DisplayBytes = mathx.Max(0, opts.DisplayBytes)
opts.LineBytes = max(1, opts.LineBytes)
opts.DisplayBytes = max(0, opts.DisplayBytes)
opts.Decorator = decoratorFromOptions(opts)
if fn, err := bitsFormatFnFromOptions(opts); err != nil {
return nil, err
Expand Down
14 changes: 0 additions & 14 deletions pkg/ranges/ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ import (
"golang.org/x/exp/slices"
)

func max(a, b int64) int64 {
if a < b {
return b
}
return a
}

func min(a, b int64) int64 {
if a > b {
return b
}
return a
}

type Range struct {
Start int64
Len int64
Expand Down

0 comments on commit 72e026e

Please sign in to comment.