1
1
mirror of https://github.com/wader/fq.git synced 2024-11-22 07:16:49 +03:00

lint: Fix ioutil deprecation, reformat for new doc standard

This commit is contained in:
Mattias Wadman 2022-08-05 00:20:14 +02:00
parent 198305ecfc
commit 3c21b058e4
21 changed files with 45 additions and 36 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -1,4 +1,5 @@
// Package all registers all builtin formats with the default registry
//
//nolint:revive
package all

View File

@ -8,6 +8,7 @@ const (
)
// TODO: change to CamelCase?
//
//nolint:revive
const (
ALL = "all"

View File

@ -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)
}

View File

@ -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",

View File

@ -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

View File

@ -1,4 +1,5 @@
// Code below generated from ebml_matroska.xml
//
//nolint:revive
package ebml_matroska

View File

@ -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"},

View File

@ -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)
}

View File

@ -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

View File

@ -24,6 +24,7 @@
//
// skip errcheck to keep code similar to gojq version
//
//nolint:errcheck
package colorjson

View File

@ -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

View File

@ -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) {

View File

@ -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 (

View File

@ -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
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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

View File

@ -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
}

View File

@ -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)