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

Strict nolint format #2599

Merged
merged 3 commits into from
Jul 14, 2022
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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ issues:
text: "does not use range value in test Run"

linters-settings:
nolintlint:
# Disable to ensure that nolint directives don't have a leading space. Default is true.
allow-leading-space: false
exhaustive:
default-signifies-exhaustive: true
govet:
Expand Down
2 changes: 1 addition & 1 deletion cloudapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// Config holds all the necessary data and options for sending metrics to the Load Impact cloud.
//nolint: lll
//nolint:lll
type Config struct {
// TODO: refactor common stuff between cloud execution and output
Token null.String `json:"token" envconfig:"K6_CLOUD_TOKEN"`
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *cmdCloud) preRun(cmd *cobra.Command, args []string) error {
}

// TODO: split apart some more
// nolint: funlen,gocognit,cyclop
//nolint:funlen,gocognit,cyclop
func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
printBanner(c.gs)

Expand Down
2 changes: 1 addition & 1 deletion cmd/login_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ This will set the default token used when just "k6 run -o cloud" is passed.`,
},
},
}
if !term.IsTerminal(int(syscall.Stdin)) { // nolint: unconvert
if !term.IsTerminal(int(syscall.Stdin)) { //nolint:unconvert
globalState.logger.Warn("Stdin is not a terminal, falling back to plain text input")
}
var vals map[string]string
Expand Down
2 changes: 1 addition & 1 deletion cmd/login_influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ This will set the default server used when just "-o influxdb" is passed.`,
},
},
}
if !term.IsTerminal(int(syscall.Stdin)) { // nolint: unconvert
if !term.IsTerminal(int(syscall.Stdin)) { //nolint:unconvert
globalState.logger.Warn("Stdin is not a terminal, falling back to plain text input")
}
vals, err := form.Run(globalState.stdIn, globalState.stdOut)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func printExecutionDescription(
}
}

//nolint: funlen
//nolint:funlen
func renderMultipleBars(
nocolor, isTTY, goBack bool, maxLeft, termWidth, widthDelta int, pbs []*pb.ProgressBar,
) (string, int) {
Expand Down Expand Up @@ -291,7 +291,7 @@ func renderMultipleBars(
// TODO: show other information here?
// TODO: add a no-progress option that will disable these
// TODO: don't use global variables...
// nolint:funlen,gocognit
//nolint:funlen,gocognit
func showProgress(ctx context.Context, gs *globalState, pbs []*pb.ProgressBar, logger *logrus.Logger) {
if gs.flags.quiet {
return
Expand Down
3 changes: 1 addition & 2 deletions core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestEngineOutput(t *testing.T) {
}
metric := test.engine.MetricsEngine.ObservedMetrics["test_metric"]
if assert.NotNil(t, metric) {
sink := metric.Sink.(*metrics.TrendSink) // nolint: forcetypeassert
sink := metric.Sink.(*metrics.TrendSink) //nolint:forcetypeassert
if assert.NotNil(t, sink) {
numOutputSamples := len(cSamples)
numEngineSamples := len(sink.Values)
Expand Down Expand Up @@ -1153,7 +1153,6 @@ func TestMetricsEmission(t *testing.T) {
}
}

//nolint: funlen
func TestMinIterationDurationInSetupTeardownStage(t *testing.T) {
t.Parallel()
setupScript := `
Expand Down
2 changes: 1 addition & 1 deletion errext/exitcodes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

// Package exitcodes contains the constants representing possible k6 exit error codes.
//nolint: golint
//nolint:golint
package exitcodes

// ExitCode is just a type representing a process exit code for k6
Expand Down
4 changes: 2 additions & 2 deletions js/common/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// if a fieldName is the key of this map exactly than the value for the given key should be used as
// the name of the field in js
//nolint: gochecknoglobals
//nolint:gochecknoglobals
var fieldNameExceptions = map[string]string{
"OCSP": "ocsp",
}
Expand Down Expand Up @@ -41,7 +41,7 @@ func FieldName(t reflect.Type, f reflect.StructField) string {

// if a methodName is the key of this map exactly than the value for the given key should be used as
// the name of the method in js
//nolint: gochecknoglobals
//nolint:gochecknoglobals
var methodNameExceptions = map[string]string{
"JSON": "json",
"HTML": "html",
Expand Down
16 changes: 8 additions & 8 deletions js/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ var (
maxSrcLenForBabelSourceMap = 250 * 1024 //nolint:gochecknoglobals
maxSrcLenForBabelSourceMapOnce sync.Once //nolint:gochecknoglobals

onceBabelCode sync.Once // nolint:gochecknoglobals
globalBabelCode *goja.Program // nolint:gochecknoglobals
globalBabelCodeErr error // nolint:gochecknoglobals
onceBabel sync.Once // nolint:gochecknoglobals
globalBabel *babel // nolint:gochecknoglobals
onceBabelCode sync.Once //nolint:gochecknoglobals
globalBabelCode *goja.Program //nolint:gochecknoglobals
errGlobalBabelCode error //nolint:gochecknoglobals
onceBabel sync.Once //nolint:gochecknoglobals
globalBabel *babel //nolint:gochecknoglobals
)

const (
Expand Down Expand Up @@ -265,10 +265,10 @@ type babel struct {

func newBabel() (*babel, error) {
onceBabelCode.Do(func() {
globalBabelCode, globalBabelCodeErr = goja.Compile("<internal/k6/compiler/lib/babel.min.js>", babelSrc, false)
globalBabelCode, errGlobalBabelCode = goja.Compile("<internal/k6/compiler/lib/babel.min.js>", babelSrc, false)
})
if globalBabelCodeErr != nil {
return nil, globalBabelCodeErr
if errGlobalBabelCode != nil {
return nil, errGlobalBabelCode
}
vm := goja.New()
_, err := vm.RunProgram(globalBabelCode)
Expand Down
1 change: 0 additions & 1 deletion js/module_loading_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ func TestLoadCycleBinding(t *testing.T) {
func TestBrowserified(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
//nolint: lll
require.NoError(t, afero.WriteFile(fs, "/browserified.js", []byte(`
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.npmlibs = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
module.exports.A = function () {
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestEncodingAlgorithms(t *testing.T) {
}`)
assert.NoError(t, err)
})
t.Run("DefaultArrayBufferDec", func(t *testing.T) { //nolint: paralleltest // weird that it triggers here, and these tests can't be parallel
t.Run("DefaultArrayBufferDec", func(t *testing.T) { //nolint:paralleltest // weird that it triggers here, and these tests can't be parallel
_, err := rt.RunString(`
var exp = "hello";
var decBin = encoding.b64decode("aGVsbG8=");
Expand Down
4 changes: 2 additions & 2 deletions js/modules/k6/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ func TestAbortTest(t *testing.T) { //nolint:tparallel
require.Equal(t, v.Reason, reason)
}

t.Run("default reason", func(t *testing.T) { //nolint: paralleltest
t.Run("default reason", func(t *testing.T) { //nolint:paralleltest
prove(t, "exec.test.abort()", errext.AbortTest)
})
t.Run("custom reason", func(t *testing.T) { //nolint: paralleltest
t.Run("custom reason", func(t *testing.T) { //nolint:paralleltest
prove(t, `exec.test.abort("mayday")`, fmt.Sprintf("%s: mayday", errext.AbortTest))
})
}
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"go.k6.io/k6/metrics"
)

//nolint: golint, revive
//nolint:golint, revive
func getTestModuleInstance(
t testing.TB, ctx context.Context, state *lib.State,
) (*goja.Runtime, *ModuleInstance) {
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *Client) responseFromHTTPext(resp *httpext.Response) *Response {
}

// TODO: break this function up
//nolint: gocyclo, cyclop, funlen, gocognit
//nolint:gocyclo, cyclop, funlen, gocognit
func (c *Client) parseRequest(
method string, reqURL, body interface{}, params goja.Value,
) (*httpext.ParsedHTTPRequest, error) {
Expand Down
2 changes: 1 addition & 1 deletion js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ func TestRequestCancellation(t *testing.T) {

func TestRequestArrayBufferBody(t *testing.T) {
t.Parallel()
tb, _, _, rt, _ := newRuntime(t) //nolint: dogsled
tb, _, _, rt, _ := newRuntime(t) //nolint:dogsled
sr := tb.Replacer.Replace

tb.Mux.HandleFunc("/post-arraybuffer", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions js/modules/k6/ws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (mi *WS) Exports() modules.Exports {

// Connect establishes a WebSocket connection based on the parameters provided.
// TODO: refactor to reduce the method complexity
//nolint: funlen,gocognit,gocyclo,cyclop
//nolint:funlen,gocognit,gocyclo
func (mi *WS) Connect(url string, args ...goja.Value) (*WSHTTPResponse, error) {
ctx := mi.vu.Context()
rt := mi.vu.Runtime()
Expand Down Expand Up @@ -594,7 +594,7 @@ func (s *Socket) closeConnection(code int) error {
}

// Wraps conn.ReadMessage in a channel
func (s *Socket) readPump(readChan chan *message, errorChan chan error, closeChan chan int) { //nolint: cyclop
func (s *Socket) readPump(readChan chan *message, errorChan chan error, closeChan chan int) {
for {
messageType, data, err := s.conn.ReadMessage()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions js/modules/k6/ws/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func TestSession(t *testing.T) {
})
}

func TestSocketSendBinary(t *testing.T) { //nolint: tparallel
func TestSocketSendBinary(t *testing.T) { //nolint:tparallel
t.Parallel()
tb := httpmultibin.NewHTTPMultiBin(t)
sr := tb.Replacer.Replace
Expand All @@ -552,10 +552,10 @@ func TestSocketSendBinary(t *testing.T) { //nolint: tparallel
rt := goja.New()
rt.SetFieldNameMapper(common.FieldNameMapper{})
samples := make(chan metrics.SampleContainer, 1000)
state := &lib.State{ //nolint: exhaustivestruct
state := &lib.State{ //nolint:exhaustivestruct
Group: root,
Dialer: tb.Dialer,
Options: lib.Options{ //nolint: exhaustivestruct
Options: lib.Options{ //nolint:exhaustivestruct
SystemTags: metrics.NewSystemTagSet(
metrics.TagURL,
metrics.TagProto,
Expand Down Expand Up @@ -619,7 +619,7 @@ func TestSocketSendBinary(t *testing.T) { //nolint: tparallel
{"function() {}", "Function"},
}

for _, tc := range errTestCases { //nolint: paralleltest
for _, tc := range errTestCases { //nolint:paralleltest
tc := tc
t.Run(fmt.Sprintf("err_%s", tc.expErrType), func(t *testing.T) {
_, err = rt.RunString(fmt.Sprintf(sr(`
Expand Down
6 changes: 3 additions & 3 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ lib.Runner = &Runner{}
// TODO: https://github.com/grafana/k6/issues/2186
// An advanced TLS support should cover the rid of the warning
//
// nolint:gochecknoglobals
//nolint:gochecknoglobals
var nameToCertWarning sync.Once

type Runner struct {
Expand Down Expand Up @@ -149,7 +149,7 @@ func (r *Runner) NewVU(idLocal, idGlobal uint64, samplesOut chan<- metrics.Sampl
return lib.InitializedVU(vu), nil
}

// nolint:funlen
//nolint:funlen
func (r *Runner) newVU(idLocal, idGlobal uint64, samplesOut chan<- metrics.SampleContainer) (*VU, error) {
// Instantiate a new bundle, make a VU out of it.
bi, err := r.Bundle.Instantiate(r.Logger, idLocal)
Expand Down Expand Up @@ -213,7 +213,7 @@ func (r *Runner) newVU(idLocal, idGlobal uint64, samplesOut chan<- metrics.Sampl
"and let k6 automatically detect from the provided certificate. It follows the Go's NameToCertificate " +
"deprecation - https://pkg.go.dev/crypto/[email protected]#Config.")
})
// nolint:staticcheck // ignore SA1019 we can deprecate it but we have to continue to support the previous code.
//nolint:staticcheck // ignore SA1019 we can deprecate it but we have to continue to support the previous code.
tlsConfig.NameToCertificate = nameToCert
}
transport := &http.Transport{
Expand Down
2 changes: 1 addition & 1 deletion js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,7 @@ func TestMinIterationDurationIsCancellable(t *testing.T) {
}
}

// nolint:paralleltest
//nolint:paralleltest
func TestForceHTTP1Feature(t *testing.T) {
cases := map[string]struct {
godebug string
Expand Down
1 change: 0 additions & 1 deletion lib/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"go.k6.io/k6/loader"
)

//nolint: gochecknoglobals, lll
var (
volumeRE = regexp.MustCompile(`^[/\\]?([a-zA-Z]):(.*)`)
sharedRE = regexp.MustCompile(`^\\\\([^\\]+)`) // matches a shared folder in Windows before backslack replacement. i.e \\VMBOXSVR\k6\script.js
Expand Down
2 changes: 1 addition & 1 deletion lib/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
const Version = "0.39.0"

// VersionDetails can be set externally as part of the build process
var VersionDetails = "" // nolint:gochecknoglobals
var VersionDetails = "" //nolint:gochecknoglobals

// FullVersion returns the maximally full version and build information for
// the currently running k6 executable.
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/externally_controlled.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func (rs *externallyControlledRunState) handleConfigChange(oldCfg, newCfg Extern
// Run constantly loops through as many iterations as possible on a variable
// dynamically controlled number of VUs either for the specified duration, or
// until the test is manually stopped.
// nolint:funlen,gocognit,cyclop
//nolint:funlen,gocognit
func (mex *ExternallyControlled) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
mex.configLock.RLock()
// Safely get the current config - it's important that the close of the
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package executor

import "go.k6.io/k6/metrics"

func sumMetricValues(samples chan metrics.SampleContainer, metricName string) (sum float64) { // nolint: unparam
func sumMetricValues(samples chan metrics.SampleContainer, metricName string) (sum float64) { //nolint:unparam
for _, sc := range metrics.GetBufferedSamples(samples) {
samples := sc.GetSamples()
for _, s := range samples {
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/per_vu_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ type PerVUIterations struct {
var _ lib.Executor = &PerVUIterations{}

// Run executes a specific number of iterations with each configured VU.
// nolint:funlen
//nolint:funlen
func (pvi PerVUIterations) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
numVUs := pvi.config.GetVUs(pvi.executionState.ExecutionTuple)
iterations := pvi.config.GetIterations()
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/ramping_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (varr *RampingArrivalRate) Init(ctx context.Context) error {
varr.et = et
varr.iterSegIndex = lib.NewSegmentedIndex(et)

return err //nolint: wrapcheck
return err //nolint:wrapcheck
}

// cal calculates the transtitions between stages and gives the next full value produced by the
Expand Down
2 changes: 1 addition & 1 deletion lib/executor/shared_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (si *SharedIterations) Init(ctx context.Context) error {

// Run executes a specific total number of iterations, which are all shared by
// the configured VUs.
// nolint:funlen
//nolint:funlen
func (si SharedIterations) Run(parentCtx context.Context, out chan<- metrics.SampleContainer) (err error) {
numVUs := si.config.GetVUs(si.executionState.ExecutionTuple)
iterations := si.et.ScaleInt64(si.config.Iterations.Int64)
Expand Down
1 change: 0 additions & 1 deletion lib/netext/httpext/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
// CompressionType is used to specify what compression is to be used to compress the body of a
// request
// The conversion and validation methods are auto-generated with https://github.com/alvaroloes/enumer:
//nolint: lll
//go:generate enumer -type=CompressionType -transform=snake -trimprefix CompressionType -output compression_type_gen.go
type CompressionType uint

Expand Down
4 changes: 2 additions & 2 deletions lib/netext/httpext/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func http2ErrCodeOffset(code http2.ErrCode) errCode {
return 1 + errCode(code)
}

//nolint: errorlint,cyclop
//nolint:errorlint
func errorCodeForNetOpError(err *net.OpError) (errCode, string) {
// TODO: refactor this further - a big switch would be more readable, maybe
// we should even check for *os.SyscallError in the main switch body in the
Expand Down Expand Up @@ -172,7 +172,7 @@ func errorCodeForNetOpError(err *net.OpError) (errCode, string) {
}

// errorCodeForError returns the errorCode and a specific error message for given error.
//nolint: errorlint, cyclop
//nolint:errorlint
func errorCodeForError(err error) (errCode, string) {
// We explicitly check for `Unwrap()` in the default switch branch, but
// checking for the concrete error types first gives us the opportunity to
Expand Down
2 changes: 1 addition & 1 deletion lib/netext/httpext/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func updateK6Response(k6Response *Response, finishedReq *finishedRequest) {
// MakeRequest makes http request for tor the provided ParsedHTTPRequest.
//
// TODO: split apart...
// nolint: cyclop, gocyclo, funlen, gocognit
//nolint:cyclop, gocyclo, funlen, gocognit
func MakeRequest(ctx context.Context, state *lib.State, preq *ParsedHTTPRequest) (*Response, error) {
respReq := &Request{
Method: preq.Req.Method,
Expand Down
2 changes: 1 addition & 1 deletion lib/netext/httpext/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// ResponseType is used in the request to specify how the response body should be treated
// The conversion and validation methods are auto-generated with https://github.com/alvaroloes/enumer:
//nolint: lll
//nolint:lll
//go:generate enumer -type=ResponseType -transform=snake -json -text -trimprefix ResponseType -output response_type_gen.go
type ResponseType uint

Expand Down
2 changes: 1 addition & 1 deletion lib/netext/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type cacheResolver struct {
func NewResolver(
actRes MultiResolver, ttl time.Duration, sel types.DNSSelect, pol types.DNSPolicy,
) Resolver {
r := rand.New(rand.NewSource(time.Now().UnixNano())) // nolint: gosec
r := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
res := resolver{
resolve: actRes,
selectIndex: sel,
Expand Down
Loading