mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Correct initialisms as suggested by golint
First step to use initialisms that golint suggests, for example: Line 116: func GetHtmlRenderer should be GetHTMLRenderer as see on http://goreportcard.com/report/spf13/hugo Thanks to @bep for the idea! Note that command-line flags (cobra and pflag) as well as struct fields like .BaseUrl and .Url that are used in Go HTML templates need more work to maintain backward-compatibility, and thus are NOT yet dealt with in this commit. First step in fixing #959.
This commit is contained in:
@@ -4,12 +4,12 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var absUrlInit sync.Once
|
||||
var ar *absurlReplacer
|
||||
var absURLInit sync.Once
|
||||
var ar *absURLReplacer
|
||||
|
||||
// for performance reasons, we reuse the first baseUrl given
|
||||
func initAbsurlReplacer(baseURL string) {
|
||||
absUrlInit.Do(func() {
|
||||
absURLInit.Do(func() {
|
||||
ar = newAbsurlReplacer(baseURL)
|
||||
})
|
||||
}
|
||||
@@ -18,7 +18,7 @@ func AbsURL(absURL string) (trs []link, err error) {
|
||||
initAbsurlReplacer(absURL)
|
||||
|
||||
trs = append(trs, func(content []byte) []byte {
|
||||
return ar.replaceInHtml(content)
|
||||
return ar.replaceInHTML(content)
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func AbsURLInXML(absURL string) (trs []link, err error) {
|
||||
initAbsurlReplacer(absURL)
|
||||
|
||||
trs = append(trs, func(content []byte) []byte {
|
||||
return ar.replaceInXml(content)
|
||||
return ar.replaceInXML(content)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ type contentlexer struct {
|
||||
start int // item start position
|
||||
width int // width of last element
|
||||
|
||||
matchers []absurlMatcher
|
||||
matchers []absURLMatcher
|
||||
state stateFunc
|
||||
prefixLookup *prefixes
|
||||
|
||||
@@ -101,13 +101,13 @@ func (l *contentlexer) emit() {
|
||||
|
||||
var mainPrefixRunes = []prefixRunes{{'s', 'r', 'c', '='}, {'h', 'r', 'e', 'f', '='}}
|
||||
|
||||
type absurlMatcher struct {
|
||||
type absURLMatcher struct {
|
||||
prefix int
|
||||
match []byte
|
||||
replacement []byte
|
||||
}
|
||||
|
||||
func (a absurlMatcher) isSourceType() bool {
|
||||
func (a absURLMatcher) isSourceType() bool {
|
||||
return a.prefix == matchPrefixSrc
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (l *contentlexer) replace() {
|
||||
}
|
||||
}
|
||||
|
||||
func doReplace(content []byte, matchers []absurlMatcher) []byte {
|
||||
func doReplace(content []byte, matchers []absURLMatcher) []byte {
|
||||
b := bp.GetBuffer()
|
||||
defer bp.PutBuffer(b)
|
||||
|
||||
@@ -191,48 +191,48 @@ func doReplace(content []byte, matchers []absurlMatcher) []byte {
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
type absurlReplacer struct {
|
||||
htmlMatchers []absurlMatcher
|
||||
xmlMatchers []absurlMatcher
|
||||
type absURLReplacer struct {
|
||||
htmlMatchers []absURLMatcher
|
||||
xmlMatchers []absURLMatcher
|
||||
}
|
||||
|
||||
func newAbsurlReplacer(baseUrl string) *absurlReplacer {
|
||||
u, _ := url.Parse(baseUrl)
|
||||
func newAbsurlReplacer(baseURL string) *absURLReplacer {
|
||||
u, _ := url.Parse(baseURL)
|
||||
base := strings.TrimRight(u.String(), "/")
|
||||
|
||||
// HTML
|
||||
dqHtmlMatch := []byte("\"/")
|
||||
sqHtmlMatch := []byte("'/")
|
||||
dqHTMLMatch := []byte("\"/")
|
||||
sqHTMLMatch := []byte("'/")
|
||||
|
||||
// XML
|
||||
dqXmlMatch := []byte(""/")
|
||||
sqXmlMatch := []byte("'/")
|
||||
dqXMLMatch := []byte(""/")
|
||||
sqXMLMatch := []byte("'/")
|
||||
|
||||
dqHtml := []byte("\"" + base + "/")
|
||||
sqHtml := []byte("'" + base + "/")
|
||||
dqHTML := []byte("\"" + base + "/")
|
||||
sqHTML := []byte("'" + base + "/")
|
||||
|
||||
dqXml := []byte(""" + base + "/")
|
||||
sqXml := []byte("'" + base + "/")
|
||||
dqXML := []byte(""" + base + "/")
|
||||
sqXML := []byte("'" + base + "/")
|
||||
|
||||
return &absurlReplacer{
|
||||
htmlMatchers: []absurlMatcher{
|
||||
{matchPrefixSrc, dqHtmlMatch, dqHtml},
|
||||
{matchPrefixSrc, sqHtmlMatch, sqHtml},
|
||||
{matchPrefixHref, dqHtmlMatch, dqHtml},
|
||||
{matchPrefixHref, sqHtmlMatch, sqHtml}},
|
||||
xmlMatchers: []absurlMatcher{
|
||||
{matchPrefixSrc, dqXmlMatch, dqXml},
|
||||
{matchPrefixSrc, sqXmlMatch, sqXml},
|
||||
{matchPrefixHref, dqXmlMatch, dqXml},
|
||||
{matchPrefixHref, sqXmlMatch, sqXml},
|
||||
return &absURLReplacer{
|
||||
htmlMatchers: []absURLMatcher{
|
||||
{matchPrefixSrc, dqHTMLMatch, dqHTML},
|
||||
{matchPrefixSrc, sqHTMLMatch, sqHTML},
|
||||
{matchPrefixHref, dqHTMLMatch, dqHTML},
|
||||
{matchPrefixHref, sqHTMLMatch, sqHTML}},
|
||||
xmlMatchers: []absURLMatcher{
|
||||
{matchPrefixSrc, dqXMLMatch, dqXML},
|
||||
{matchPrefixSrc, sqXMLMatch, sqXML},
|
||||
{matchPrefixHref, dqXMLMatch, dqXML},
|
||||
{matchPrefixHref, sqXMLMatch, sqXML},
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
func (au *absurlReplacer) replaceInHtml(content []byte) []byte {
|
||||
func (au *absURLReplacer) replaceInHTML(content []byte) []byte {
|
||||
return doReplace(content, au.htmlMatchers)
|
||||
}
|
||||
|
||||
func (au *absurlReplacer) replaceInXml(content []byte) []byte {
|
||||
func (au *absURLReplacer) replaceInXML(content []byte) []byte {
|
||||
return doReplace(content, au.xmlMatchers)
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ func TestChainZeroTransformers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAbsUrl(b *testing.B) {
|
||||
func BenchmarkAbsURL(b *testing.B) {
|
||||
absURL, _ := AbsURL("http://base")
|
||||
tr := NewChain(absURL...)
|
||||
|
||||
@@ -64,7 +64,7 @@ func BenchmarkAbsUrl(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAbsUrl(t *testing.T) {
|
||||
func TestAbsURL(t *testing.T) {
|
||||
absURL, _ := AbsURL("http://base")
|
||||
tr := NewChain(absURL...)
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestAbsUrl(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkXmlAbsUrl(b *testing.B) {
|
||||
func BenchmarkXMLAbsURL(b *testing.B) {
|
||||
absURLInXML, _ := AbsURLInXML("http://base")
|
||||
tr := NewChain(absURLInXML...)
|
||||
|
||||
@@ -82,7 +82,7 @@ func BenchmarkXmlAbsUrl(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestXMLAbsUrl(t *testing.T) {
|
||||
func TestXMLAbsURL(t *testing.T) {
|
||||
absURLInXML, _ := AbsURLInXML("http://base")
|
||||
tr := NewChain(absURLInXML...)
|
||||
apply(t.Errorf, tr, xml_abs_url_tests)
|
||||
|
Reference in New Issue
Block a user