From 198305ecfc2603eba35e50f724c81d138054ce76 Mon Sep 17 00:00:00 2001 From: bump Date: Thu, 4 Aug 2022 22:04:21 +0000 Subject: [PATCH 1/2] Update github-golangci-lint from 1.47.3 to 1.48.0 Release notes https://github.com/golangci/golangci-lint/releases/tag/v1.48.0 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 200430fd..d05a3cb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: pull_request: env: - GOLANGCILINT_VERSION: 1.47.3 + GOLANGCILINT_VERSION: 1.48.0 jobs: lint: From 3c21b058e465586044ffcc9b864fe8086f1d22fd Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Fri, 5 Aug 2022 00:20:14 +0200 Subject: [PATCH 2/2] lint: Fix ioutil deprecation, reformat for new doc standard --- dev/fuzzbytes.go | 4 ++-- dev/tmpl.go | 4 ++-- format/all/all.go | 1 + format/format.go | 1 + format/fuzz_test.go | 7 +++---- format/id3/id3v2.go | 10 +++++++--- format/inet.go | 1 + format/matroska/ebml_matroska/ebml_matroska_gen.go | 1 + format/media.go | 2 ++ format/mpeg/shared.go | 3 ++- format/rtmp/rtmp.go | 3 ++- internal/colorjson/encoder.go | 1 + internal/difftest/difftest.go | 7 +++---- internal/gojqextra/types.go | 3 ++- internal/mathextra/float16.go | 13 +++++++------ pkg/decode/decode.go | 5 ++--- pkg/decode/read.go | 3 ++- pkg/fqtest/fqtest.go | 3 +-- pkg/interp/binary.go | 3 +-- pkg/interp/decode.go | 3 +-- pkg/interp/interp.go | 3 +-- 21 files changed, 45 insertions(+), 36 deletions(-) diff --git a/dev/fuzzbytes.go b/dev/fuzzbytes.go index a2ef39fd..d4f99b06 100644 --- a/dev/fuzzbytes.go +++ b/dev/fuzzbytes.go @@ -4,13 +4,13 @@ package main import ( "bytes" - "io/ioutil" + "io" "os" "strconv" ) func main() { - bs, err := ioutil.ReadAll(os.Stdin) + bs, err := io.ReadAll(os.Stdin) if err != nil { panic(err) } diff --git a/dev/tmpl.go b/dev/tmpl.go index 770c75c8..2a93922e 100644 --- a/dev/tmpl.go +++ b/dev/tmpl.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "errors" - "io/ioutil" + "io" "log" "os" "strconv" @@ -82,7 +82,7 @@ func main() { _ = json.NewDecoder(r).Decode(&data) } - templateBytes, err := ioutil.ReadAll(os.Stdin) + templateBytes, err := io.ReadAll(os.Stdin) if err != nil { panic(err) } diff --git a/format/all/all.go b/format/all/all.go index d791b36c..5cad64d2 100644 --- a/format/all/all.go +++ b/format/all/all.go @@ -1,4 +1,5 @@ // Package all registers all builtin formats with the default registry +// //nolint:revive package all diff --git a/format/format.go b/format/format.go index b3057c2d..504aceb3 100644 --- a/format/format.go +++ b/format/format.go @@ -8,6 +8,7 @@ const ( ) // TODO: change to CamelCase? +// //nolint:revive const ( ALL = "all" diff --git a/format/fuzz_test.go b/format/fuzz_test.go index f8d90200..e51952e3 100644 --- a/format/fuzz_test.go +++ b/format/fuzz_test.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "os" "path/filepath" "testing" @@ -46,8 +45,8 @@ func (ft *fuzzTest) Platform() interp.Platform { return interp.Platform{} } func (ft *fuzzTest) Stdin() interp.Input { return fuzzTestInput{FileReader: interp.FileReader{R: bytes.NewBuffer(ft.b)}} } -func (ft *fuzzTest) Stdout() interp.Output { return fuzzTestOutput{ioutil.Discard} } -func (ft *fuzzTest) Stderr() interp.Output { return fuzzTestOutput{ioutil.Discard} } +func (ft *fuzzTest) Stdout() interp.Output { return fuzzTestOutput{io.Discard} } +func (ft *fuzzTest) Stderr() interp.Output { return fuzzTestOutput{io.Discard} } func (ft *fuzzTest) InterruptChan() chan struct{} { return nil } func (ft *fuzzTest) Environ() []string { return nil } func (ft *fuzzTest) Args() []string { @@ -85,7 +84,7 @@ func FuzzFormats(f *testing.F) { return err } - b, readErr := ioutil.ReadFile(path) + b, readErr := os.ReadFile(path) if readErr != nil { f.Fatal(err) } diff --git a/format/id3/id3v2.go b/format/id3/id3v2.go index 47de0d13..52a015ed 100644 --- a/format/id3/id3v2.go +++ b/format/id3/id3v2.go @@ -227,10 +227,14 @@ const ( // $00 ISO-8859-1 [ISO-8859-1]. Terminated with $00. // $01 UTF-16 [UTF-16] encoded Unicode [UNICODE] with BOM. All -// strings in the same frame SHALL have the same byteorder. -// Terminated with $00 00. +// +// strings in the same frame SHALL have the same byteorder. +// Terminated with $00 00. +// // $02 UTF-16BE [UTF-16] encoded Unicode [UNICODE] without BOM. -// Terminated with $00 00. +// +// Terminated with $00 00. +// // $03 UTF-8 [UTF-8] encoded Unicode [UNICODE]. Terminated with $00. var encodingNames = scalar.UToSymStr{ encodingISO8859_1: "iso_8859-1", diff --git a/format/inet.go b/format/inet.go index 8dff0184..3033b0c6 100644 --- a/format/inet.go +++ b/format/inet.go @@ -4,6 +4,7 @@ import "github.com/wader/fq/pkg/scalar" // from https://www.tcpdump.org/linktypes.html // TODO cleanup +// //nolint:revive const ( LinkTypeNULL = 0 diff --git a/format/matroska/ebml_matroska/ebml_matroska_gen.go b/format/matroska/ebml_matroska/ebml_matroska_gen.go index 8d3c3d63..57e7407a 100644 --- a/format/matroska/ebml_matroska/ebml_matroska_gen.go +++ b/format/matroska/ebml_matroska/ebml_matroska_gen.go @@ -1,4 +1,5 @@ // Code below generated from ebml_matroska.xml +// //nolint:revive package ebml_matroska diff --git a/format/media.go b/format/media.go index b62ccbd1..5228a905 100644 --- a/format/media.go +++ b/format/media.go @@ -5,6 +5,7 @@ import ( ) // based on ffmpeg libavformat/isom.c ff_mp4_obj_type +// //nolint:revive const ( MPEGObjectTypeMOV_TEXT = 0x08 @@ -191,6 +192,7 @@ var MPEGAudioObjectTypeNames = scalar.UToScalar{ } // based on ffmpeg/libavutil/pixfmt.h +// //nolint:revive var ISO_23091_2_ColourPrimariesMap = scalar.UToScalar{ 1: {Sym: "bt709", Description: "ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B"}, diff --git a/format/mpeg/shared.go b/format/mpeg/shared.go index ec0cdbc0..73843daf 100644 --- a/format/mpeg/shared.go +++ b/format/mpeg/shared.go @@ -73,7 +73,8 @@ func decodeEscapeValueAbsFn(b1 int, b2 int, b3 int) func(d *decode.D) uint64 { } // add values and escaped values -//nolint: deadcode,unused +// +//nolint:deadcode,unused func decodeEscapeValueAddFn(b1 int, b2 int, b3 int) func(d *decode.D) uint64 { return decodeEscapeValueFn(0, b1, b2, b3) } diff --git a/format/rtmp/rtmp.go b/format/rtmp/rtmp.go index 728972d4..a86b492a 100644 --- a/format/rtmp/rtmp.go +++ b/format/rtmp/rtmp.go @@ -195,7 +195,8 @@ var videoMessageH264PacketTypeNames = scalar.UToSymStr{ } // TODO: invalid warning that timestampDelta is unused -//nolint: unused + +//nolint:unused type messageHeader struct { timestamp uint64 timestampDelta uint64 diff --git a/internal/colorjson/encoder.go b/internal/colorjson/encoder.go index bea6942b..f54da165 100644 --- a/internal/colorjson/encoder.go +++ b/internal/colorjson/encoder.go @@ -24,6 +24,7 @@ // // skip errcheck to keep code similar to gojq version +// //nolint:errcheck package colorjson diff --git a/internal/difftest/difftest.go b/internal/difftest/difftest.go index b071fcce..2561ee34 100644 --- a/internal/difftest/difftest.go +++ b/internal/difftest/difftest.go @@ -11,7 +11,6 @@ package difftest import ( - "io/ioutil" "os" "path/filepath" "strings" @@ -139,7 +138,7 @@ func TestWithOptions(t *testing.T, opts Options) { for _, p := range paths { t.Run(p, func(t *testing.T) { t.Helper() - input, err := ioutil.ReadFile(p) + input, err := os.ReadFile(p) if err != nil { t.Fatal(err) } @@ -149,13 +148,13 @@ func TestWithOptions(t *testing.T, opts Options) { t.Fatal(err) } - expectedOutput, expectedOutputErr := ioutil.ReadFile(outputPath) + expectedOutput, expectedOutputErr := os.ReadFile(outputPath) if opts.WriteOutput { if expectedOutputErr == nil && string(expectedOutput) == output { return } - if err := ioutil.WriteFile(outputPath, []byte(output), 0644); err != nil { //nolint:gosec + if err := os.WriteFile(outputPath, []byte(output), 0644); err != nil { //nolint:gosec t.Fatal(err) } return diff --git a/internal/gojqextra/types.go b/internal/gojqextra/types.go index 382b6406..1f2abc91 100644 --- a/internal/gojqextra/types.go +++ b/internal/gojqextra/types.go @@ -16,7 +16,8 @@ import ( ) // Cast gojq value to go value -//nolint: forcetypeassert, unconvert +// +//nolint:forcetypeassert,unconvert func CastFn[T any](v any, structFn func(input any, result any) error) (T, bool) { var t T switch any(t).(type) { diff --git a/internal/mathextra/float16.go b/internal/mathextra/float16.go index 3b89c096..6bff9b67 100644 --- a/internal/mathextra/float16.go +++ b/internal/mathextra/float16.go @@ -4,13 +4,14 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// //nolint:revive package mathextra @@ -19,11 +20,11 @@ import "unsafe" // Float16 represents a 16-bit floating point number, containing a single sign bit, 5 exponent bits // and 10 fractional bits. This corresponds to IEEE 754-2008 binary16 (or half precision float) type. // -// MSB LSB -// ╔════╦════╤════╤════╤════╤════╦════╤════╤════╤════╤════╤════╤════╤════╤════╤════╗ -// ║Sign║ E₄ │ E₃ │ E₂ │ E₁ │ E₀ ║ F₉ │ F₈ │ F₇ │ F₆ │ F₅ │ F₄ │ F₃ │ F₂ │ F₁ │ F₀ ║ -// ╚════╩════╧════╧════╧════╧════╩════╧════╧════╧════╧════╧════╧════╧════╧════╧════╝ -// Where E is the exponent bits and F is the fractional bits. +// MSB LSB +// ╔════╦════╤════╤════╤════╤════╦════╤════╤════╤════╤════╤════╤════╤════╤════╤════╗ +// ║Sign║ E₄ │ E₃ │ E₂ │ E₁ │ E₀ ║ F₉ │ F₈ │ F₇ │ F₆ │ F₅ │ F₄ │ F₃ │ F₂ │ F₁ │ F₀ ║ +// ╚════╩════╧════╧════╧════╧════╩════╧════╧════╧════╧════╧════╧════╧════╧════╧════╝ +// Where E is the exponent bits and F is the fractional bits. type Float16 uint16 const ( diff --git a/pkg/decode/decode.go b/pkg/decode/decode.go index 723cff7c..2104977e 100644 --- a/pkg/decode/decode.go +++ b/pkg/decode/decode.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "math/big" "regexp" @@ -1129,7 +1128,7 @@ func (d *D) FieldFormatReaderLen(name string, nBits int64, fn func(r io.Reader) if err != nil { d.IOPanic(err, "FieldFormatReaderLen: fn") } - rBuf, err := ioutil.ReadAll(r) + rBuf, err := io.ReadAll(r) if err != nil { d.IOPanic(err, "FieldFormatReaderLen: ReadAll") } @@ -1149,7 +1148,7 @@ func (d *D) TryFieldReaderRangeFormat(name string, startBit int64, nBits int64, return 0, nil, nil, nil, err } r := bitio.NewIOReadSeeker(br) - rb, err := ioutil.ReadAll(fn(r)) + rb, err := io.ReadAll(fn(r)) if err != nil { return 0, nil, nil, nil, err } diff --git a/pkg/decode/read.go b/pkg/decode/read.go index 38f7aae1..a67b4ee9 100644 --- a/pkg/decode/read.go +++ b/pkg/decode/read.go @@ -145,7 +145,8 @@ func (d *D) tryText(nBytes int, e encoding.Encoding) (string, error) { // read length prefixed text (ex pascal short string) // lBits length prefix // fixedBytes if != -1 read nBytes but trim to length -//nolint: unparam +// +//nolint:unparam func (d *D) tryTextLenPrefixed(lenBits int, fixedBytes int, e encoding.Encoding) (string, error) { if lenBits < 0 { return "", fmt.Errorf("tryTextLenPrefixed lenBits must be >= 0 (%d)", lenBits) diff --git a/pkg/fqtest/fqtest.go b/pkg/fqtest/fqtest.go index b51cb66a..94401ba4 100644 --- a/pkg/fqtest/fqtest.go +++ b/pkg/fqtest/fqtest.go @@ -2,7 +2,6 @@ package fqtest import ( "context" - "io/ioutil" "os" "strconv" "testing" @@ -19,7 +18,7 @@ func TestPath(t *testing.T, registry *interp.Registry) { ColorDiff: os.Getenv("DIFF_COLOR") != "", WriteOutput: os.Getenv("WRITE_ACTUAL") != "", Fn: func(t *testing.T, path, input string) (string, string, error) { - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { t.Fatal(err) } diff --git a/pkg/interp/binary.go b/pkg/interp/binary.go index 8fc5e634..30aaef1a 100644 --- a/pkg/interp/binary.go +++ b/pkg/interp/binary.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "math/big" "github.com/wader/fq/internal/aheadreadseeker" @@ -217,7 +216,7 @@ func (i *Interp) _open(c any) any { } if fRS == nil { - buf, err := ioutil.ReadAll(ctxreadseeker.New(i.EvalInstance.Ctx, &ioextra.ReadErrSeeker{Reader: f})) + buf, err := io.ReadAll(ctxreadseeker.New(i.EvalInstance.Ctx, &ioextra.ReadErrSeeker{Reader: f})) if err != nil { f.Close() return err diff --git a/pkg/interp/decode.go b/pkg/interp/decode.go index 5faa8283..662081d4 100644 --- a/pkg/interp/decode.go +++ b/pkg/interp/decode.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "reflect" "strings" @@ -143,7 +142,7 @@ func (i *Interp) _registry(c any) any { if err != nil { return err } - b, err := ioutil.ReadAll(f) + b, err := io.ReadAll(f) if err != nil { return err } diff --git a/pkg/interp/interp.go b/pkg/interp/interp.go index 4197ed72..cc009417 100644 --- a/pkg/interp/interp.go +++ b/pkg/interp/interp.go @@ -11,7 +11,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "math/big" "path" "strconv" @@ -917,7 +916,7 @@ func (i *Interp) Eval(ctx context.Context, c any, expr string, opts EvalOpts) (g output := opts.output if opts.output == nil { - output = ioutil.Discard + output = io.Discard } runCtx, runCtxCancelFn := i.interruptStack.Push(ctx)