Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint fixes #3495

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func newRootCommand(gs *state.GlobalState) *rootCommand {
return c
}

func (c *rootCommand) persistentPreRunE(cmd *cobra.Command, args []string) error {
func (c *rootCommand) persistentPreRunE(_ *cobra.Command, _ []string) error {
err := c.setupLoggers(c.stopLoggersCh)
if err != nil {
return err
Expand Down
18 changes: 9 additions & 9 deletions cmd/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type GlobalState struct {
SignalNotify func(chan<- os.Signal, ...os.Signal)
SignalStop func(chan<- os.Signal)

Logger *logrus.Logger
Logger *logrus.Logger //nolint:forbidigo //TODO:change to FieldLogger
FallbackLogger logrus.FieldLogger
}

Expand All @@ -69,16 +69,16 @@ func NewGlobalState(ctx context.Context) *GlobalState {
stderrTTY := !isDumbTerm && (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd()))
outMutex := &sync.Mutex{}
stdout := &console.Writer{
RawOut: os.Stdout,
Mutex: outMutex,
Writer: colorable.NewColorable(os.Stdout),
IsTTY: stdoutTTY,
RawOutFd: int(os.Stdout.Fd()),
Mutex: outMutex,
Writer: colorable.NewColorable(os.Stdout),
IsTTY: stdoutTTY,
}
stderr := &console.Writer{
RawOut: os.Stderr,
Mutex: outMutex,
Writer: colorable.NewColorable(os.Stderr),
IsTTY: stderrTTY,
RawOutFd: int(os.Stderr.Fd()),
Mutex: outMutex,
Writer: colorable.NewColorable(os.Stderr),
IsTTY: stderrTTY,
}

env := BuildEnvMap(os.Environ())
Expand Down
3 changes: 2 additions & 1 deletion cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func TestAbortedByScriptSetupErrorWithDependency(t *testing.T) {
assert.Contains(t, stdout, "bogus summary")
}

func runTestWithNoLinger(t *testing.T, ts *GlobalTestState) {
func runTestWithNoLinger(_ *testing.T, ts *GlobalTestState) {
cmd.ExecuteWithGlobalState(ts.GlobalState)
}

Expand Down Expand Up @@ -1791,6 +1791,7 @@ func TestPrometheusRemoteWriteOutput(t *testing.T) {
func BenchmarkReadResponseBody(b *testing.B) {
httpSrv := httpmultibin.NewHTTPMultiBin(b)

//nolint:goconst
script := httpSrv.Replacer.Replace(`
import http from "k6/http";
import { check, sleep } from "k6";
Expand Down
4 changes: 2 additions & 2 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func showProgress(ctx context.Context, gs *state.GlobalState, pbs []*pb.Progress
var errTermGetSize bool
termWidth := defaultTermWidth
if gs.Stdout.IsTTY {
tw, _, err := term.GetSize(int(gs.Stdout.RawOut.Fd()))
tw, _, err := term.GetSize(gs.Stdout.RawOutFd)
if !(tw > 0) || err != nil {
errTermGetSize = true
logger.WithError(err).Warn("error getting terminal size")
Expand Down Expand Up @@ -314,7 +314,7 @@ func showProgress(ctx context.Context, gs *state.GlobalState, pbs []*pb.Progress
updateFreq := 1 * time.Second
var stdoutFD int
if gs.Stdout.IsTTY {
stdoutFD = int(gs.Stdout.RawOut.Fd())
stdoutFD = gs.Stdout.RawOutFd
updateFreq = 100 * time.Millisecond
gs.OutMutex.Lock()
gs.Stdout.PersistentText = printProgressBars
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func versionString() string {
return v
}

func getCmdVersion(gs *state.GlobalState) *cobra.Command {
func getCmdVersion(_ *state.GlobalState) *cobra.Command {
// versionCmd represents the version command.
return &cobra.Command{
Use: "version",
Expand Down
4 changes: 2 additions & 2 deletions js/common/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var fieldNameExceptions = map[string]string{

// FieldName Returns the JS name for an exported struct field. The name is snake_cased, with respect for
// certain common initialisms (URL, ID, HTTP, etc).
func FieldName(t reflect.Type, f reflect.StructField) string {
func FieldName(_ reflect.Type, f reflect.StructField) string {
// PkgPath is non-empty for unexported fields.
if f.PkgPath != "" {
return ""
Expand Down Expand Up @@ -53,7 +53,7 @@ var methodNameExceptions = map[string]string{

// MethodName Returns the JS name for an exported method. The first letter of the method's name is
// lowercased, otherwise it is unaltered.
func MethodName(t reflect.Type, m reflect.Method) string {
func MethodName(_ reflect.Type, m reflect.Method) string {
// A field with a name beginning with an X is a constructor, and just gets the prefix stripped.
// Note: They also get some special treatment from Bridge(), see further down.
if m.Name[0] == 'X' {
Expand Down
2 changes: 1 addition & 1 deletion loader/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package loader

import "github.com/sirupsen/logrus"

func github(_ logrus.FieldLogger, path string, parts []string) (string, error) {
func github(_ logrus.FieldLogger, _ string, parts []string) (string, error) {
username := parts[0]
repo := parts[1]
filepath := parts[2]
Expand Down
9 changes: 4 additions & 5 deletions ui/console/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package console
import (
"bytes"
"io"
"os"
"sync"
)

// Writer syncs writes with a mutex and, if the output is a TTY, clears before
// newlines.
type Writer struct {
RawOut *os.File
Mutex *sync.Mutex
Writer io.Writer
IsTTY bool
RawOutFd int
Mutex *sync.Mutex
Writer io.Writer
IsTTY bool

// Used for flicker-free persistent objects like the progressbars
PersistentText func()
Expand Down
2 changes: 1 addition & 1 deletion ui/form_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (f PasswordField) GetLabelExtra() string {

// GetContents simply reads a string in cleartext from the supplied reader
func (f PasswordField) GetContents(r io.Reader) (string, error) {
stdin, ok := r.(*os.File)
stdin, ok := r.(*os.File) //nolint:forbidigo
if !ok {
return "", errors.New("cannot read password from the supplied terminal")
}
Expand Down