diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-03-24 10:11:16 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-03-24 16:14:51 +0100 |
commit | b5f39d23b86f9cb83c51da9fe4abb4c19c01c3b7 (patch) | |
tree | cf23180dc07698391cf47c2fe525755417729020 /hugolib | |
parent | 3011f36c27ecde309325e6c75ca377f4f87fa97a (diff) |
all: Apply staticcheck recommendations
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/filesystems/basefs.go | 20 | ||||
-rw-r--r-- | hugolib/page.go | 21 | ||||
-rw-r--r-- | hugolib/paths/baseURL.go | 2 | ||||
-rw-r--r-- | hugolib/site.go | 3 | ||||
-rw-r--r-- | hugolib/site_test.go | 4 | ||||
-rw-r--r-- | hugolib/testhelpers_test.go | 24 |
6 files changed, 17 insertions, 57 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index ee1c870d9..d88141efd 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -17,7 +17,6 @@ package filesystems import ( "errors" - "io" "os" "path/filepath" "strings" @@ -759,22 +758,3 @@ func removeDuplicatesKeepRight(in []string) []string { return out } - -func printFs(fs afero.Fs, path string, w io.Writer) { - if fs == nil { - return - } - afero.Walk(fs, path, func(path string, info os.FileInfo, err error) error { - if info != nil && !info.IsDir() { - s := path - if lang, ok := info.(hugofs.LanguageAnnouncer); ok { - s = s + "\tLANG: " + lang.Lang() - } - if fp, ok := info.(hugofs.FilePather); ok { - s = s + "\tRF: " + fp.Filename() + "\tBP: " + fp.BaseDir() - } - fmt.Fprintln(w, " ", s) - } - return nil - }) -} diff --git a/hugolib/page.go b/hugolib/page.go index 24d659fb1..576342cfa 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -20,12 +20,10 @@ import ( "os" "path" "path/filepath" - "runtime" "sort" "strings" "github.com/bep/gitmap" - "github.com/spf13/cast" "github.com/gohugoio/hugo/helpers" @@ -831,19 +829,6 @@ func (ps pageStatePages) findPagePosByFilnamePrefix(prefix string) int { return currPos } -func content(c resource.ContentProvider) string { - cc, err := c.Content() - if err != nil { - panic(err) - } - - ccs, err := cast.ToStringE(cc) - if err != nil { - panic(err) - } - return ccs -} - func (s *Site) sectionsFromFile(fi source.File) []string { dirname := fi.Dir() dirname = strings.Trim(dirname, helpers.FilePathSeparator) @@ -861,9 +846,3 @@ func (s *Site) sectionsFromFile(fi source.File) []string { return parts } - -func printStackTrace(length int) string { - trace := make([]byte, length) - runtime.Stack(trace, true) - return string(trace) -} diff --git a/hugolib/paths/baseURL.go b/hugolib/paths/baseURL.go index de36c8636..a3c7e9d27 100644 --- a/hugolib/paths/baseURL.go +++ b/hugolib/paths/baseURL.go @@ -62,7 +62,7 @@ func (b BaseURL) WithProtocol(protocol string) (string, error) { if isFullProtocol && u.Opaque != "" { u.Opaque = "//" + u.Opaque } else if isOpaqueProtocol && u.Opaque == "" { - return "", fmt.Errorf("Cannot determine BaseURL for protocol %q", protocol) + return "", fmt.Errorf("cannot determine BaseURL for protocol %q", protocol) } return u.String(), nil diff --git a/hugolib/site.go b/hugolib/site.go index be70db5ee..145ae2d49 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -67,9 +67,6 @@ import ( "github.com/spf13/viper" ) -// used to indicate if run as a test. -var testMode bool - // Site contains all the information relevant for constructing a static // site. The basic flow of information is as follows: // diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 98fe1ff4f..21575072d 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -35,10 +35,6 @@ const ( templateWithURLAbs = "<a href=\"/foobar.jpg\">Going</a>" ) -func init() { - testMode = true -} - func TestRenderWithInvalidTemplate(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 7de2280c7..0a8fbe7f5 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -20,6 +20,7 @@ import ( "github.com/gohugoio/hugo/resources/page" "github.com/sanity-io/litter" "github.com/spf13/afero" + "github.com/spf13/cast" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/tpl" @@ -27,6 +28,8 @@ import ( "os" + "github.com/gohugoio/hugo/resources/resource" + "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/hugofs" "github.com/stretchr/testify/assert" @@ -672,6 +675,19 @@ func getPage(in page.Page, ref string) page.Page { return p } +func content(c resource.ContentProvider) string { + cc, err := c.Content() + if err != nil { + panic(err) + } + + ccs, err := cast.ToStringE(cc) + if err != nil { + panic(err) + } + return ccs +} + func dumpPages(pages ...page.Page) { fmt.Println("---------") for i, p := range pages { @@ -726,11 +742,3 @@ func parallel(t *testing.T) { t.Parallel() } } - -// Useful to debug nilpointers/panics in templates. -// Put "defer recoverStack()" in top of the failing function. -func recoverStack() { - if r := recover(); r != nil { - fmt.Println(printStackTrace(1000)) - } -} |