From 5dcf96152bc9ca8222dc9c25449e3716e119e40b Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 7 Dec 2023 15:04:42 +0200 Subject: [PATCH 1/5] Lint fixes for ./cmd/... packages --- cmd/root.go | 2 +- cmd/state/state.go | 2 +- cmd/tests/cmd_run_test.go | 3 ++- cmd/version.go | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 9dc28be9c64..b50a7de56ad 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 diff --git a/cmd/state/state.go b/cmd/state/state.go index 35b2da2f0ab..a2a8695f28b 100644 --- a/cmd/state/state.go +++ b/cmd/state/state.go @@ -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 } diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index cf22b77de37..f6d642a23ee 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -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) } @@ -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"; diff --git a/cmd/version.go b/cmd/version.go index e5f977c48a1..661ce378fd7 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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", From beabde44f2a90d9214f1928dcc997c9a15e5b146 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 7 Dec 2023 15:10:20 +0200 Subject: [PATCH 2/5] Fix lint issues in js/common package --- js/common/bridge.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/common/bridge.go b/js/common/bridge.go index 6347819aa27..aefbced9023 100644 --- a/js/common/bridge.go +++ b/js/common/bridge.go @@ -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 "" @@ -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' { From c650df77d298231903d78f1bee81f3024da361b7 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 7 Dec 2023 15:13:27 +0200 Subject: [PATCH 3/5] Fix lint issues in loader package --- loader/github.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader/github.go b/loader/github.go index cbd76c39882..028d8c773b6 100644 --- a/loader/github.go +++ b/loader/github.go @@ -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] From 59adca0501ea55618429cbe84c0be00e9b7e86dc Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 7 Dec 2023 15:19:35 +0200 Subject: [PATCH 4/5] Fix lint issues and small rewrite around ui/console --- cmd/state/state.go | 16 ++++++++-------- cmd/ui.go | 4 ++-- ui/console/writer.go | 9 ++++----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/state/state.go b/cmd/state/state.go index a2a8695f28b..c9a183985af 100644 --- a/cmd/state/state.go +++ b/cmd/state/state.go @@ -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()) diff --git a/cmd/ui.go b/cmd/ui.go index 3367223f1af..d857233999e 100644 --- a/cmd/ui.go +++ b/cmd/ui.go @@ -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") @@ -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 diff --git a/ui/console/writer.go b/ui/console/writer.go index 9e42e08fe44..760b6f0cab6 100644 --- a/ui/console/writer.go +++ b/ui/console/writer.go @@ -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() From 5696308475173210b179c2e9e072ab0f02f85ad1 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Thu, 7 Dec 2023 15:19:52 +0200 Subject: [PATCH 5/5] Lint fixes for ui package --- ui/form_fields.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/form_fields.go b/ui/form_fields.go index 71c6617632d..43daa30a2a8 100644 --- a/ui/form_fields.go +++ b/ui/form_fields.go @@ -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") }