diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b7eccb49..3ee5bd9a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: pull_request: env: - GOLANGCILINT_VERSION: "1.59.1" + GOLANGCILINT_VERSION: "1.60.1" jobs: lint: diff --git a/README.md b/README.md index 2e7899a76..5ab49fc62 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/format/flac/flac.go b/format/flac/flac.go index 30c1a3382..02800bf54 100644 --- a/format/flac/flac.go +++ b/format/flac/flac.go @@ -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" @@ -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 diff --git a/format/icc/icc_profile.go b/format/icc/icc_profile.go index 1fdf1c3dd..529ef2cc7 100644 --- a/format/icc/icc_profile.go +++ b/format/icc/icc_profile.go @@ -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" @@ -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()) diff --git a/format/json/json.go b/format/json/json.go index 868ef34fc..34c52a32c 100644 --- a/format/json/json.go +++ b/format/json/json.go @@ -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 } diff --git a/format/leveldb/leveldb_log_blocks.go b/format/leveldb/leveldb_log_blocks.go index f88e1bbb5..6fd7136c1 100644 --- a/format/leveldb/leveldb_log_blocks.go +++ b/format/leveldb/leveldb_log_blocks.go @@ -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" ) @@ -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)) }) } diff --git a/format/matroska/matroska.go b/format/matroska/matroska.go index 1266a175c..b4ea0486d 100644 --- a/format/matroska/matroska.go +++ b/format/matroska/matroska.go @@ -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) @@ -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": diff --git a/format/mp3/mp3.go b/format/mp3/mp3.go index b2f7d4eb3..a7d08953a 100644 --- a/format/mp3/mp3.go +++ b/format/mp3/mp3.go @@ -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 diff --git a/format/mp4/boxes.go b/format/mp4/boxes.go index cf3f03836..e3fcc0df4 100644 --- a/format/mp4/boxes.go +++ b/format/mp4/boxes.go @@ -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) @@ -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") diff --git a/go.mod b/go.mod index efbc503fa..88b1ce74d 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/internal/hexdump/hexdump.go b/internal/hexdump/hexdump.go index 623e4f432..144630c5c 100644 --- a/internal/hexdump/hexdump.go +++ b/internal/hexdump/hexdump.go @@ -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) diff --git a/internal/mathx/num.go b/internal/mathx/num.go index ad2d44c99..343334d36 100644 --- a/internal/mathx/num.go +++ b/internal/mathx/num.go @@ -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 diff --git a/internal/stringsx/stringsx.go b/internal/stringsx/stringsx.go index d35a6b08e..f5ea2d21d 100644 --- a/internal/stringsx/stringsx.go +++ b/internal/stringsx/stringsx.go @@ -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 } diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index f697beab5..a63bebd3f 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -13,7 +13,6 @@ import ( "path/filepath" "runtime" - "github.com/wader/fq/internal/mathx" "github.com/wader/fq/pkg/interp" "golang.org/x/term" @@ -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 { diff --git a/pkg/decode/read.go b/pkg/decode/read.go index 618537845..21fda540d 100644 --- a/pkg/decode/read.go +++ b/pkg/decode/read.go @@ -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) diff --git a/pkg/interp/dump.go b/pkg/interp/dump.go index 822ed43b2..3f269e23f 100644 --- a/pkg/interp/dump.go +++ b/pkg/interp/dump.go @@ -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), ) diff --git a/pkg/interp/interp.go b/pkg/interp/interp.go index 5535e7c48..51216bab5 100644 --- a/pkg/interp/interp.go +++ b/pkg/interp/interp.go @@ -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 diff --git a/pkg/ranges/ranges.go b/pkg/ranges/ranges.go index a87ad6ffd..0cb856e16 100644 --- a/pkg/ranges/ranges.go +++ b/pkg/ranges/ranges.go @@ -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