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

Fix lint issues in js/compiler #3478

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions js/compiler/compiler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package compiler implements additional functionality for k6 to compile js code.
// more specifically transpiling through babel in case that is needed.
package compiler

import (
Expand All @@ -22,7 +24,7 @@ import (
var babelSrc string

var (
DefaultOpts = map[string]interface{}{
defaultOpts = map[string]interface{}{ //nolint:gochecknoglobals
// "presets": []string{"latest"},
"plugins": []interface{}{
// es2015 https://github.com/babel/babel/blob/v6.26.0/packages/babel-preset-es2015/src/index.js
Expand Down Expand Up @@ -111,13 +113,13 @@ func (c *Compiler) Transform(src, filename string, inputSrcMap []byte) (code str
c.babel = globalBabel
}
if err != nil {
return
return "", nil, err
}

sourceMapEnabled := c.Options.SourceMapLoader != nil
maxSrcLenForBabelSourceMapOnce.Do(func() {
// TODO: drop this code and everything it's connected to when babel is dropped
v := os.Getenv(maxSrcLenForBabelSourceMapVarName)
v := os.Getenv(maxSrcLenForBabelSourceMapVarName) //nolint:forbidigo
if len(v) > 0 {
i, err := strconv.Atoi(v) //nolint:govet // we shadow err on purpose
if err != nil {
Expand Down Expand Up @@ -145,8 +147,7 @@ func (c *Compiler) Transform(src, filename string, inputSrcMap []byte) (code str
" not be accepted by Babel, so it was disabled", filename)
}
}
code, srcMap, err = c.babel.transformImpl(c.logger, src, filename, sourceMapEnabled, inputSrcMap)
return
return c.babel.transformImpl(c.logger, src, filename, sourceMapEnabled, inputSrcMap)
}

// Options are options to the compiler
Expand Down Expand Up @@ -307,7 +308,7 @@ func (b *babel) transformImpl(
b.m.Lock()
defer b.m.Unlock()
opts := make(map[string]interface{})
for k, v := range DefaultOpts {
for k, v := range defaultOpts {
opts[k] = v
}
if sourceMapsEnabled {
Expand Down