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

@@ -96,7 +96,7 @@ func (a *asciidocConverter) getAsciidocContent(src []byte, ctx converter.Documen
}
func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
var cfg = a.cfg.MarkupConfig.AsciidocExt
cfg := a.cfg.MarkupConfig.AsciidocExt
args := []string{}
args = a.appendArg(args, "-b", cfg.Backend, asciidocext_config.CliDefault.Backend, asciidocext_config.AllowedBackend)
@@ -137,7 +137,6 @@ func (a *asciidocConverter) parseArgs(ctx converter.DocumentContext) []string {
file := filepath.Base(ctx.Filename)
if a.cfg.Cfg.GetBool("uglyUrls") || file == "_index.adoc" || file == "index.adoc" {
outDir, err = filepath.Abs(filepath.Dir(filepath.Join(destinationDir, ctx.DocumentName)))
} else {
postDir := ""
page, ok := ctx.Document.(pageSubset)

View File

@@ -246,7 +246,6 @@ func TestAsciidoctorAttributes(t *testing.T) {
c.Assert(args[2], qt.Equals, "-a")
c.Assert(expectedValues[args[3]], qt.Equals, true)
c.Assert(args[4], qt.Equals, "--no-header-footer")
}
func TestConvert(t *testing.T) {

View File

@@ -52,7 +52,6 @@ func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error)
cfg: cfg,
}, nil
}), nil
}
type blackfridayConverter struct {
@@ -125,7 +124,6 @@ func (c *blackfridayConverter) getHTMLRenderer(renderTOC bool) blackfriday.Rende
}
func getFlags(renderTOC bool, cfg blackfriday_config.Config) int {
var flags int
if renderTOC {

View File

@@ -129,7 +129,7 @@ func TestGetAllFlags(t *testing.T) {
actualFlags := getFlags(false, b)
var expectedFlags int
//OR-ing flags together...
// OR-ing flags together...
for _, d := range allFlags {
expectedFlags |= d.testFlag
}

View File

@@ -130,6 +130,4 @@ type RenderContext struct {
RenderHooks *hooks.Renderers
}
var (
FeatureRenderHooks = identity.NewPathIdentity("markup", "renderingHooks")
)
var FeatureRenderHooks = identity.NewPathIdentity("markup", "renderingHooks")

View File

@@ -125,7 +125,6 @@ func (ids *idFactory) Generate(value []byte, kind ast.NodeKind) []byte {
}
ids.vals[buf.String()] = struct{}{}
})
}

View File

@@ -91,7 +91,6 @@ func TestSanitizeAnchorNameAsciiOnly(t *testing.T) {
c.Assert(sanitizeAnchorNameString("god is神真美好 good", goldmark_config.AutoHeadingIDTypeGitHubAscii), qt.Equals, "god-is-good")
c.Assert(sanitizeAnchorNameString("Resumé", goldmark_config.AutoHeadingIDTypeGitHubAscii), qt.Equals, "resume")
}
func TestSanitizeAnchorNameBlackfriday(t *testing.T) {
@@ -106,7 +105,6 @@ func BenchmarkSanitizeAnchorName(b *testing.B) {
result := sanitizeAnchorName(input, goldmark_config.AutoHeadingIDTypeGitHub)
if len(result) != 24 {
b.Fatalf("got %d", len(result))
}
}
}
@@ -118,7 +116,6 @@ func BenchmarkSanitizeAnchorNameAsciiOnly(b *testing.B) {
result := sanitizeAnchorName(input, goldmark_config.AutoHeadingIDTypeGitHubAscii)
if len(result) != 12 {
b.Fatalf("got %d", len(result))
}
}
}
@@ -130,7 +127,6 @@ func BenchmarkSanitizeAnchorNameBlackfriday(b *testing.B) {
result := sanitizeAnchorName(input, goldmark_config.AutoHeadingIDTypeBlackfriday)
if len(result) != 24 {
b.Fatalf("got %d", len(result))
}
}
}

View File

@@ -62,9 +62,7 @@ func (p provide) New(cfg converter.ProviderConfig) (converter.Provider, error) {
}), nil
}
var (
_ converter.AnchorNameSanitizer = (*goldmarkConverter)(nil)
)
var _ converter.AnchorNameSanitizer = (*goldmarkConverter)(nil)
type goldmarkConverter struct {
md goldmark.Markdown
@@ -156,7 +154,6 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
)
return md
}
var _ identity.IdentitiesProvider = (*converterResult)(nil)
@@ -267,7 +264,6 @@ func (c *goldmarkConverter) Convert(ctx converter.RenderContext) (result convert
ids: rcx.ids.GetIdentities(),
toc: pctx.TableOfContents(),
}, nil
}
var featureSet = map[identity.Identity]bool{
@@ -329,7 +325,6 @@ func newHighlighting(cfg highlight.Config) goldmark.Extender {
}
w.WriteString("</div>")
}),
)
}

View File

@@ -31,7 +31,6 @@ import (
)
func convert(c *qt.C, mconf markup_config.Config, content string) converter.Result {
p, err := Provider.New(
converter.ProviderConfig{
MarkupConfig: mconf,
@@ -163,7 +162,6 @@ description
c.Assert(ok, qt.Equals, true)
tocHTML := toc.TableOfContents().ToHTML(1, 2, false)
c.Assert(tocHTML, qt.Contains, "TableOfContents")
}
func TestConvertAutoIDAsciiOnly(t *testing.T) {
@@ -212,7 +210,6 @@ func TestConvertIssues(t *testing.T) {
c.Assert(got, qt.Contains, "<custom-element>\n <div>This will be \"slotted\" into the custom element.</div>\n</custom-element>\n")
})
}
func TestCodeFence(t *testing.T) {
@@ -257,7 +254,6 @@ LINE5
</code></pre></div>`)
result = convertForConfig(c, cfg, `echo "Hugo Rocks!"`, "unknown")
c.Assert(result, qt.Equals, "<pre><code class=\"language-unknown\" data-lang=\"unknown\">echo &quot;Hugo Rocks!&quot;\n</code></pre>")
})
c.Run("Highlight lines, default config", func(c *qt.C) {

View File

@@ -115,7 +115,6 @@ func (r *hookedRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
// https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404
func (r *hookedRenderer) RenderAttributes(w util.BufWriter, node ast.Node) {
for _, attr := range node.Attributes() {
_, _ = w.WriteString(" ")
_, _ = w.Write(attr.Name)
@@ -189,7 +188,6 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N
ctx.AddIdentity(h.ImageRenderer)
return ast.WalkContinue, err
}
// Fall back to the default Goldmark render funcs. Method below borrowed from:

View File

@@ -53,7 +53,8 @@ And then some.
p, err := Provider.New(
converter.ProviderConfig{
MarkupConfig: markup_config.Default,
Logger: loggers.NewErrorLogger()})
Logger: loggers.NewErrorLogger(),
})
c.Assert(err, qt.IsNil)
conv, err := p.New(converter.DocumentContext{})
c.Assert(err, qt.IsNil)

View File

@@ -71,7 +71,7 @@ func (cfg Config) ToHTMLOptions() []html.Option {
if cfg.LineAnchors != "" {
lineAnchors = cfg.LineAnchors + "-"
}
var options = []html.Option{
options := []html.Option{
html.TabWidth(cfg.TabWidth),
html.WithLineNumbers(cfg.LineNos),
html.BaseLineNumber(cfg.LineNoStart),
@@ -126,7 +126,6 @@ func ApplyLegacyConfig(cfg config.Provider, conf *Config) error {
}
return nil
}
func parseOptions(in string) (map[string]interface{}, error) {
@@ -199,5 +198,4 @@ func hlLinesToRanges(startLine int, s string) ([][2]int, error) {
ranges = append(ranges, r)
}
return ranges, nil
}

View File

@@ -40,7 +40,6 @@ func TestConfig(t *testing.T) {
c.Assert(cfg.CodeFences, qt.Equals, false)
c.Assert(cfg.LineNos, qt.Equals, true)
c.Assert(cfg.LineNumbersInTable, qt.Equals, false)
})
c.Run("parseOptions", func(c *qt.C) {
@@ -54,6 +53,5 @@ func TestConfig(t *testing.T) {
c.Assert(cfg.LineNumbersInTable, qt.Equals, false)
c.Assert(cfg.LineNoStart, qt.Equals, 32)
c.Assert(cfg.Hl_Lines, qt.Equals, "3-8 10-20")
})
}

View File

@@ -46,7 +46,6 @@ User-Agent: foo
c.Assert(result, qt.Equals, `<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash"><span class="nb">echo</span> <span class="s2">&#34;Hugo Rocks!&#34;</span></code></pre></div>`)
result, _ = h.Highlight(`echo "Hugo Rocks!"`, "unknown", "")
c.Assert(result, qt.Equals, `<pre><code class="language-unknown" data-lang="unknown">echo &#34;Hugo Rocks!&#34;</code></pre>`)
})
c.Run("Highlight lines, default config", func(c *qt.C) {
@@ -147,5 +146,4 @@ User-Agent: foo
c.Assert(result, qt.Contains, "hello")
c.Assert(result, qt.Contains, "}")
})
}

View File

@@ -12,7 +12,6 @@ func ExternallyRenderContent(
cfg converter.ProviderConfig,
ctx converter.DocumentContext,
content []byte, path string, args []string) []byte {
logger := cfg.Logger
cmd := exec.Command(path, args...)
cmd.Stdin = bytes.NewReader(content)

View File

@@ -97,7 +97,7 @@ func NewConverterProvider(cfg converter.ProviderConfig) (ConverterProvider, erro
type ConverterProvider interface {
Get(name string) converter.Provider
//Default() converter.Provider
// Default() converter.Provider
GetMarkupConfig() markup_config.Config
Highlight(code, lang, optsStr string) (string, error)
}

View File

@@ -83,7 +83,6 @@ func applyLegacyConfig(cfg config.Provider, conf *Config) error {
}
return nil
}
var Default = Config{

View File

@@ -73,5 +73,4 @@ func TestConfig(t *testing.T) {
c.Assert(conf.Highlight.CodeFences, qt.Equals, true)
c.Assert(conf.Highlight.GuessSyntax, qt.Equals, true)
})
}

View File

@@ -47,5 +47,4 @@ func TestConverterRegistry(t *testing.T) {
checkName("pandoc")
checkName("org")
checkName("blackfriday")
}

View File

@@ -51,7 +51,6 @@ func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error)
cfg: cfg,
}, nil
}), nil
}
type mmarkConverter struct {
@@ -74,7 +73,6 @@ func getHTMLRenderer(
ctx converter.DocumentContext,
cfg blackfriday_config.Config,
pcfg converter.ProviderConfig) mmark.Renderer {
var (
flags int
documentID string
@@ -99,7 +97,6 @@ func getHTMLRenderer(
Config: pcfg,
Renderer: mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters),
}
}
func getMmarkExtensions(cfg blackfriday_config.Config) int {

View File

@@ -29,7 +29,7 @@ import (
func TestGetMmarkExtensions(t *testing.T) {
b := blackfriday_config.Default
//TODO: This is doing the same just with different marks...
// TODO: This is doing the same just with different marks...
type data struct {
testFlag int
}

View File

@@ -36,7 +36,6 @@ func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error)
cfg: cfg,
}, nil
}), nil
}
type pandocConverter struct {

View File

@@ -81,7 +81,7 @@ func (c *rstConverter) getRstContent(src []byte, ctx converter.DocumentContext)
// TODO(bep) check if rst2html has a body only option.
bodyStart := bytes.Index(result, []byte("<body>\n"))
if bodyStart < 0 {
bodyStart = -7 //compensate for length
bodyStart = -7 // compensate for length
}
bodyEnd := bytes.Index(result, []byte("\n</body>"))

View File

@@ -131,8 +131,8 @@ func (b *tocBuilder) writeHeaders(level, indent int, h Headers) {
b.s.WriteString("\n")
b.indent(indent)
}
}
func (b *tocBuilder) writeHeader(level, indent int, h Header) {
b.indent(indent)
b.s.WriteString("<li>")

View File

@@ -152,5 +152,4 @@ func TestTocMissingParent(t *testing.T) {
</li>
</ol>
</nav>`, qt.Commentf(got))
}