mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Fix errors reported by Go Vet
This commit is contained in:
parent
c4c19ad303
commit
103ea842f8
9 changed files with 21 additions and 21 deletions
|
@ -34,7 +34,7 @@ func TestFixUrl(t *testing.T) {
|
||||||
serverPort = test.Port
|
serverPort = test.Port
|
||||||
result, err := fixUrl(BaseUrl)
|
result, err := fixUrl(BaseUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Test #%d %s: unexpected error %s", err)
|
t.Errorf("Test #%d %s: unexpected error %s", i, test.TestName, err)
|
||||||
}
|
}
|
||||||
if result != test.Result {
|
if result != test.Result {
|
||||||
t.Errorf("Test #%d %s: expected %q, got %q", i, test.TestName, test.Result, result)
|
t.Errorf("Test #%d %s: expected %q, got %q", i, test.TestName, test.Result, result)
|
||||||
|
|
|
@ -111,7 +111,7 @@ func BytesToHTML(b []byte) template.HTML {
|
||||||
return template.HTML(string(b))
|
return template.HTML(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Renderer {
|
func GetHtmlRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
||||||
renderParameters := blackfriday.HtmlRendererParameters{
|
renderParameters := blackfriday.HtmlRendererParameters{
|
||||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||||
|
@ -141,7 +141,7 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere
|
||||||
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
|
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMarkdownExtensions(ctx RenderingContext) int {
|
func GetMarkdownExtensions(ctx *RenderingContext) int {
|
||||||
flags := 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
flags := 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
||||||
blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
|
blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
|
||||||
blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
|
blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
|
||||||
|
@ -155,12 +155,12 @@ func GetMarkdownExtensions(ctx RenderingContext) int {
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func MarkdownRender(ctx RenderingContext) []byte {
|
func MarkdownRender(ctx *RenderingContext) []byte {
|
||||||
return blackfriday.Markdown(ctx.Content, GetHtmlRenderer(0, ctx),
|
return blackfriday.Markdown(ctx.Content, GetHtmlRenderer(0, ctx),
|
||||||
GetMarkdownExtensions(ctx))
|
GetMarkdownExtensions(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func MarkdownRenderWithTOC(ctx RenderingContext) []byte {
|
func MarkdownRenderWithTOC(ctx *RenderingContext) []byte {
|
||||||
return blackfriday.Markdown(ctx.Content,
|
return blackfriday.Markdown(ctx.Content,
|
||||||
GetHtmlRenderer(blackfriday.HTML_TOC, ctx),
|
GetHtmlRenderer(blackfriday.HTML_TOC, ctx),
|
||||||
GetMarkdownExtensions(ctx))
|
GetMarkdownExtensions(ctx))
|
||||||
|
@ -219,7 +219,7 @@ func (c *RenderingContext) getConfig() *Blackfriday {
|
||||||
return c.Config
|
return c.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderBytesWithTOC(ctx RenderingContext) []byte {
|
func RenderBytesWithTOC(ctx *RenderingContext) []byte {
|
||||||
switch ctx.PageFmt {
|
switch ctx.PageFmt {
|
||||||
default:
|
default:
|
||||||
return MarkdownRenderWithTOC(ctx)
|
return MarkdownRenderWithTOC(ctx)
|
||||||
|
@ -230,7 +230,7 @@ func RenderBytesWithTOC(ctx RenderingContext) []byte {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderBytes(ctx RenderingContext) []byte {
|
func RenderBytes(ctx *RenderingContext) []byte {
|
||||||
switch ctx.PageFmt {
|
switch ctx.PageFmt {
|
||||||
default:
|
default:
|
||||||
return MarkdownRender(ctx)
|
return MarkdownRender(ctx)
|
||||||
|
|
|
@ -204,7 +204,7 @@ func TestDoArithmetic(t *testing.T) {
|
||||||
result, err := DoArithmetic(this.a, this.b, this.op)
|
result, err := DoArithmetic(this.a, this.b, this.op)
|
||||||
if b, ok := this.expect.(bool); ok && !b {
|
if b, ok := this.expect.(bool); ok && !b {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("[%d] doArithmetic didn't return an expected error")
|
t.Errorf("[%d] doArithmetic didn't return an expected error", i)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -107,7 +107,7 @@ func TestMakePathRelative(t *testing.T) {
|
||||||
_, error := MakePathRelative("a/b/c.ss", "/a/c", "/d/c", "/e/f")
|
_, error := MakePathRelative("a/b/c.ss", "/a/c", "/d/c", "/e/f")
|
||||||
|
|
||||||
if error == nil {
|
if error == nil {
|
||||||
t.Errorf("Test #%d failed. Expected error")
|
t.Errorf("Test failed, expected error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ func TestFileAndExt(t *testing.T) {
|
||||||
t.Errorf("Test %d failed. Expected filename %q got %q.", i, d.expectedFile, file)
|
t.Errorf("Test %d failed. Expected filename %q got %q.", i, d.expectedFile, file)
|
||||||
}
|
}
|
||||||
if d.expectedExt != ext {
|
if d.expectedExt != ext {
|
||||||
t.Errorf("Test %d failed. Expected extension $q got %q.", i, d.expectedExt, ext)
|
t.Errorf("Test %d failed. Expected extension %q got %q.", i, d.expectedExt, ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,7 +564,7 @@ func TestFindCWD(t *testing.T) {
|
||||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expectedDir, dir)
|
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expectedDir, dir)
|
||||||
}
|
}
|
||||||
if d.expectedErr != err {
|
if d.expectedErr != err {
|
||||||
t.Error("Test %d failed. Expected %q but got %q", i, d.expectedErr, err)
|
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expectedErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ func TestWriteToDisk(t *testing.T) {
|
||||||
}
|
}
|
||||||
contents, e := ioutil.ReadFile(d.filename)
|
contents, e := ioutil.ReadFile(d.filename)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
t.Error("Test %d failed. Could not read file %s. Reason: %s\n", i, d.filename, e)
|
t.Errorf("Test %d failed. Could not read file %s. Reason: %s\n", i, d.filename, e)
|
||||||
}
|
}
|
||||||
if randomString != string(contents) {
|
if randomString != string(contents) {
|
||||||
t.Errorf("Test %d failed. Expected contents %q but got %q", i, randomString, string(contents))
|
t.Errorf("Test %d failed. Expected contents %q but got %q", i, randomString, string(contents))
|
||||||
|
|
|
@ -199,12 +199,12 @@ func (p *Page) setSummary() {
|
||||||
|
|
||||||
func (p *Page) renderBytes(content []byte) []byte {
|
func (p *Page) renderBytes(content []byte) []byte {
|
||||||
return helpers.RenderBytes(
|
return helpers.RenderBytes(
|
||||||
helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
|
&helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
|
||||||
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
|
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) renderContent(content []byte) []byte {
|
func (p *Page) renderContent(content []byte) []byte {
|
||||||
return helpers.RenderBytesWithTOC(helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
|
return helpers.RenderBytesWithTOC(&helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
|
||||||
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
|
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ func renderShortcode(sc shortcode, p *Page, t tpl.Template) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc.doMarkup {
|
if sc.doMarkup {
|
||||||
newInner := helpers.RenderBytes(helpers.RenderingContext{
|
newInner := helpers.RenderBytes(&helpers.RenderingContext{
|
||||||
Content: []byte(inner), PageFmt: p.guessMarkupType(),
|
Content: []byte(inner), PageFmt: p.guessMarkupType(),
|
||||||
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
|
DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ func TestTargetPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Section() != test.expectedSection {
|
if p.Section() != test.expectedSection {
|
||||||
t.Errorf("%s => p.Section expected: %s, got: %s", test.doc, test.expectedSection, p.Section)
|
t.Errorf("%s => p.Section expected: %s, got: %s", test.doc, test.expectedSection, p.Section())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -835,7 +835,7 @@ func Highlight(in interface{}, lang string) template.HTML {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Markdownify(text string) template.HTML {
|
func Markdownify(text string) template.HTML {
|
||||||
return template.HTML(helpers.RenderBytes(helpers.RenderingContext{Content: []byte(text), PageFmt: "markdown"}))
|
return template.HTML(helpers.RenderBytes(&helpers.RenderingContext{Content: []byte(text), PageFmt: "markdown"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func refPage(page interface{}, ref, methodName string) template.HTML {
|
func refPage(page interface{}, ref, methodName string) template.HTML {
|
||||||
|
|
|
@ -941,7 +941,7 @@ func TestSafeHtml(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
tmpl, err := template.New("test").Parse(this.tmplStr)
|
tmpl, err := template.New("test").Parse(this.tmplStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("[%d] unable to create new html template %q: %s", this.tmplStr, err)
|
t.Errorf("[%d] unable to create new html template %q: %s", i, this.tmplStr, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,7 +976,7 @@ func TestSafeHtmlAttr(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
tmpl, err := template.New("test").Parse(this.tmplStr)
|
tmpl, err := template.New("test").Parse(this.tmplStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("[%d] unable to create new html template %q: %s", this.tmplStr, err)
|
t.Errorf("[%d] unable to create new html template %q: %s", i, this.tmplStr, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1011,7 +1011,7 @@ func TestSafeCss(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
tmpl, err := template.New("test").Parse(this.tmplStr)
|
tmpl, err := template.New("test").Parse(this.tmplStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("[%d] unable to create new html template %q: %s", this.tmplStr, err)
|
t.Errorf("[%d] unable to create new html template %q: %s", i, this.tmplStr, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1046,7 +1046,7 @@ func TestSafeUrl(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
tmpl, err := template.New("test").Parse(this.tmplStr)
|
tmpl, err := template.New("test").Parse(this.tmplStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("[%d] unable to create new html template %q: %s", this.tmplStr, err)
|
t.Errorf("[%d] unable to create new html template %q: %s", i, this.tmplStr, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue