all: Format code with gofumpt

See https://github.com/mvdan/gofumpt
This commit is contained in:
Bjørn Erik Pedersen
2020-12-02 13:23:25 +01:00
parent 32471b57bd
commit d90e37e0c6
442 changed files with 1426 additions and 2254 deletions

View File

@@ -51,6 +51,7 @@ func DecodeOptions(m map[string]interface{}) (opts Options, err error) {
err = mapstructure.WeakDecode(m, &opts)
return
}
func (opts Options) toArgs() []string {
var args []string
@@ -111,7 +112,6 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
// Try PATH
binary = binaryName
if _, err := exec.LookPath(binary); err != nil {
// This may be on a CI server etc. Will fall back to pre-built assets.
return herrors.ErrFeatureNotAvailable
}

View File

@@ -55,7 +55,6 @@ func (t *fingerprintTransformation) Key() internal.ResourceTransformationKey {
// Transform creates a MD5 hash of the Resource content and inserts that hash before
// the extension in the filename.
func (t *fingerprintTransformation) Transform(ctx *resources.ResourceTransformationCtx) error {
h, err := newHash(t.algo)
if err != nil {
return err

View File

@@ -24,7 +24,6 @@ import (
)
func TestHashFromAlgo(t *testing.T) {
for _, algo := range []struct {
name string
bits int
@@ -35,7 +34,6 @@ func TestHashFromAlgo(t *testing.T) {
{"sha512", 512},
{"shaman", -1},
} {
t.Run(algo.name, func(t *testing.T) {
c := qt.New(t)
h, err := newHash(algo.name)
@@ -46,7 +44,6 @@ func TestHashFromAlgo(t *testing.T) {
c.Assert(err, qt.Not(qt.IsNil))
c.Assert(err.Error(), qt.Contains, "use either md5, sha256, sha384 or sha512")
}
})
}
}

View File

@@ -212,12 +212,10 @@ func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) {
build.OnResolve(api.OnResolveOptions{Filter: `.*`},
func(args api.OnResolveArgs) (api.OnResolveResult, error) {
return resolveImport(args)
})
build.OnLoad(api.OnLoadOptions{Filter: `.*`, Namespace: nsImportHugo},
func(args api.OnLoadArgs) (api.OnLoadResult, error) {
b, err := ioutil.ReadFile(args.Path)
if err != nil {
return api.OnLoadResult{}, errors.Wrapf(err, "failed to read %q", args.Path)
}
@@ -266,11 +264,9 @@ func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) {
}
return []api.Plugin{importResolver, paramsPlugin}, nil
}
func toBuildOptions(opts Options) (buildOptions api.BuildOptions, err error) {
var target api.Target
switch opts.Target {
case "", "esnext":
@@ -336,8 +332,8 @@ func toBuildOptions(opts Options) (buildOptions api.BuildOptions, err error) {
}
// By default we only need to specify outDir and no outFile
var outDir = opts.outDir
var outFile = ""
outDir := opts.outDir
outFile := ""
var sourceMap api.SourceMap
switch opts.SourceMap {
case "inline":
@@ -381,5 +377,4 @@ func toBuildOptions(opts Options) (buildOptions api.BuildOptions, err error) {
},
}
return
}

View File

@@ -76,7 +76,8 @@ func TestToBuildOptions(t *testing.T) {
opts, err = toBuildOptions(Options{
Target: "es2018", Format: "cjs", Minify: true, mediaType: media.JavascriptType,
SourceMap: "inline"})
SourceMap: "inline",
})
c.Assert(err, qt.IsNil)
c.Assert(opts, qt.DeepEquals, api.BuildOptions{
Bundle: true,
@@ -93,7 +94,8 @@ func TestToBuildOptions(t *testing.T) {
opts, err = toBuildOptions(Options{
Target: "es2018", Format: "cjs", Minify: true, mediaType: media.JavascriptType,
SourceMap: "inline"})
SourceMap: "inline",
})
c.Assert(err, qt.IsNil)
c.Assert(opts, qt.DeepEquals, api.BuildOptions{
Bundle: true,
@@ -107,5 +109,4 @@ func TestToBuildOptions(t *testing.T) {
Loader: api.LoaderJS,
},
})
}

View File

@@ -57,5 +57,4 @@ func (c *Client) Minify(res resources.ResourceTransformer) (resource.Resource, e
rs: c.rs,
m: c.m,
})
}

View File

@@ -39,5 +39,4 @@ func TestTransform(t *testing.T) {
content, err := transformed.(resource.ContentProvider).Content()
c.Assert(err, qt.IsNil)
c.Assert(content, qt.Equals, "<h1>Hugo Rocks!</h1>")
}

View File

@@ -19,6 +19,7 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"os/exec"
"path"
"path/filepath"
"regexp"
@@ -36,8 +37,6 @@ import (
"github.com/gohugoio/hugo/hugofs"
"github.com/pkg/errors"
"os/exec"
"github.com/mitchellh/mapstructure"
"github.com/gohugoio/hugo/common/herrors"
@@ -139,7 +138,6 @@ func (t *postcssTransformation) Key() internal.ResourceTransformationKey {
// npm install -g postcss-cli
// npm install -g autoprefixer
func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationCtx) error {
const localPostCSSPath = "node_modules/.bin/"
const binaryName = "postcss"
@@ -174,7 +172,6 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
if configFile == "" && t.options.Config != "" {
// Only fail if the user specificed config file is not found.
return errors.Errorf("postcss config %q not found:", configFile)
}
}
@@ -271,7 +268,6 @@ func (imp *importResolver) importRecursive(
lineNum int,
content string,
inPath string) (int, string, error) {
basePath := path.Dir(inPath)
var replacements []string
@@ -350,7 +346,6 @@ func (imp *importResolver) resolve() (io.Reader, error) {
}
return strings.NewReader(newContent), nil
}
// See https://www.w3schools.com/cssref/pr_import_rule.asp

View File

@@ -44,7 +44,6 @@ func TestDecodeOptions(t *testing.T) {
c.Assert(err, qt.IsNil)
c.Assert(opts2.NoMap, qt.Equals, true)
}
func TestShouldImport(t *testing.T) {
@@ -117,7 +116,6 @@ E_STYLE
Offset: 1,
Filename: "d.css",
})
}
func BenchmarkImportResolver(b *testing.B) {

View File

@@ -46,5 +46,4 @@ func TestReplaceRegularCSSImports(t *testing.T) {
reverted := replaceRegularImportsOut(res)
c.Assert(reverted, qt.Equals, scssWithImport)
}

View File

@@ -127,7 +127,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx
// more correct for the main entry path (main.scss typically), but
// it will mess up the import mappings. As a workaround, we do a replacement
// in the source map itself (see below).
//options.InputPath = inputPath
// options.InputPath = inputPath
options.to.SourceMapOptions.OutputPath = outName
options.to.SourceMapOptions.Contents = true
options.to.SourceMapOptions.OmitURL = false