From d90e37e0c6e812f9913bf256c9c81aa05b7a08aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 2 Dec 2020 13:23:25 +0100 Subject: all: Format code with gofumpt See https://github.com/mvdan/gofumpt --- scripts/fork_go_templates/main.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'scripts/fork_go_templates') diff --git a/scripts/fork_go_templates/main.go b/scripts/fork_go_templates/main.go index 04202b254..c295ab734 100644 --- a/scripts/fork_go_templates/main.go +++ b/scripts/fork_go_templates/main.go @@ -35,7 +35,6 @@ func main() { goimports(htmlRoot) gofmt(forkRoot) - } const ( @@ -97,36 +96,41 @@ package parse } return content - } var goPackages = []goPackage{ - goPackage{srcPkg: "text/template", dstPkg: "texttemplate", - replacer: func(name, content string) string { return textTemplateReplacers.Replace(commonReplace(name, content)) }}, - goPackage{srcPkg: "html/template", dstPkg: "htmltemplate", replacer: func(name, content string) string { - if strings.HasSuffix(name, "content.go") { - // Remove template.HTML types. We need to use the Go types. - content = removeAll(`(?s)// Strings of content.*?\)\n`, content) - } + { + srcPkg: "text/template", dstPkg: "texttemplate", + replacer: func(name, content string) string { return textTemplateReplacers.Replace(commonReplace(name, content)) }, + }, + { + srcPkg: "html/template", dstPkg: "htmltemplate", replacer: func(name, content string) string { + if strings.HasSuffix(name, "content.go") { + // Remove template.HTML types. We need to use the Go types. + content = removeAll(`(?s)// Strings of content.*?\)\n`, content) + } - content = commonReplace(name, content) + content = commonReplace(name, content) - return htmlTemplateReplacers.Replace(content) - }, + return htmlTemplateReplacers.Replace(content) + }, rewriter: func(name string) { for _, s := range []string{"CSS", "HTML", "HTMLAttr", "JS", "JSStr", "URL", "Srcset"} { rewrite(name, fmt.Sprintf("%s -> htmltemplate.%s", s, s)) } rewrite(name, `"text/template/parse" -> "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"`) - }}, - goPackage{srcPkg: "internal/fmtsort", dstPkg: "fmtsort", rewriter: func(name string) { + }, + }, + {srcPkg: "internal/fmtsort", dstPkg: "fmtsort", rewriter: func(name string) { rewrite(name, `"internal/fmtsort" -> "github.com/gohugoio/hugo/tpl/internal/go_templates/fmtsort"`) }}, - goPackage{srcPkg: "internal/testenv", dstPkg: "testenv", + { + srcPkg: "internal/testenv", dstPkg: "testenv", replacer: func(name, content string) string { return testEnvReplacers.Replace(content) }, rewriter: func(name string) { rewrite(name, `"internal/testenv" -> "github.com/gohugoio/hugo/tpl/internal/go_templates/testenv"`) - }}, - goPackage{srcPkg: "internal/cfg", dstPkg: "cfg", rewriter: func(name string) { + }, + }, + {srcPkg: "internal/cfg", dstPkg: "cfg", rewriter: func(name string) { rewrite(name, `"internal/cfg" -> "github.com/gohugoio/hugo/tpl/internal/go_templates/cfg"`) }}, } @@ -196,7 +200,6 @@ func doWithGoFiles(dir string, func removeAll(expression, content string) string { re := regexp.MustCompile(expression) return re.ReplaceAllString(content, "") - } func rewrite(filename, rule string) { -- cgit v1.2.3