]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
all: Remove unused code
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 18 Dec 2023 16:41:15 +0000 (17:41 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 18 Dec 2023 18:51:26 +0000 (19:51 +0100)
Using x/tools/cmd/deadcode

30 files changed:
.github/workflows/test-dart-sass-v1.yml
.github/workflows/test.yml
common/herrors/errors.go
config/configProvider.go
helpers/content.go
helpers/emoji.go
helpers/general.go
htesting/testdata_builder.go [deleted file]
hugofs/fileinfo.go
hugofs/filename_filter_fs.go
hugofs/fs.go
hugofs/fs_test.go
hugolib/filesystems/basefs.go
hugolib/hugo_modules_test.go
hugolib/hugo_sites.go
hugolib/page.go
hugolib/shortcode.go
hugolib/template_test.go
hugolib/testhelpers_test.go
livereload/livereload.go
markup/goldmark/links/transform.go
markup/highlight/highlight.go
media/config.go
modules/collect.go
resources/image.go
resources/resource/resourcetypes.go
resources/resource_factories/create/remote.go
tpl/template.go
tpl/template_info.go
unused.sh [new file with mode: 0755]

index d3556a647b04010889228c0eeddcb9488f3c0c5b..fefb0e989e39bada6eeb08f79fd85ac4ea466cb3 100644 (file)
@@ -30,7 +30,7 @@ jobs:
           **/go.sum
           **/go.mod
     - name: Install Ruby
-      uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
+      uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b
       with:
         ruby-version: '2.7' 
         bundler-cache: true #
index c7dba1f913f0f7fd3547fc1d7a47263be6353ff4..3a76b768c56efa33f0fea965d245f2fd71984f0b 100644 (file)
@@ -32,7 +32,7 @@ jobs:
           **/go.sum
           **/go.mod
     - name: Install Ruby
-      uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
+      uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b
       with:
         ruby-version: '2.7'
         bundler-cache: true #
index 598c50b32fd24f22dfac98ee0edfc92cdaafa825..8e62b2c99b6503bfde15bc7ebcec89fa2bb6b430 100644 (file)
 package herrors
 
 import (
-       "bytes"
        "errors"
        "fmt"
        "io"
        "os"
        "runtime"
        "runtime/debug"
-       "strconv"
 )
 
 // PrintStackTrace prints the current stacktrace to w.
@@ -49,16 +47,6 @@ func Recover(args ...any) {
        }
 }
 
-// GetGID the current goroutine id. Used only for debugging.
-func GetGID() uint64 {
-       b := make([]byte, 64)
-       b = b[:runtime.Stack(b, false)]
-       b = bytes.TrimPrefix(b, []byte("goroutine "))
-       b = b[:bytes.IndexByte(b, ' ')]
-       n, _ := strconv.ParseUint(string(b), 10, 64)
-       return n
-}
-
 // IsFeatureNotAvailableError returns true if the given error is or contains a FeatureNotAvailableError.
 func IsFeatureNotAvailableError(err error) bool {
        return errors.Is(err, &FeatureNotAvailableError{})
index 8e2ab0334828effeca1b4c529c125791ca4405f1..11099e4079b8534e1f96dfbf043a6adf8651c708 100644 (file)
@@ -95,9 +95,3 @@ func GetStringSlicePreserveString(cfg Provider, key string) []string {
        sd := cfg.Get(key)
        return types.ToStringSlicePreserveString(sd)
 }
-
-func setIfNotSet(cfg Provider, key string, value any) {
-       if !cfg.IsSet(key) {
-               cfg.Set(key, value)
-       }
-}
index c0a6d822148668afdf2f37e8a76d4c3ad0902509..a3abb334d74da46213ce1f0ec9311e08c6c9cdf8 100644 (file)
@@ -266,24 +266,3 @@ func (c *ContentSpec) TrimShortHTML(input []byte) []byte {
 func isEndOfSentence(r rune) bool {
        return r == '.' || r == '?' || r == '!' || r == '"' || r == '\n'
 }
-
-// Kept only for benchmark.
-func (c *ContentSpec) truncateWordsToWholeSentenceOld(content string) (string, bool) {
-       words := strings.Fields(content)
-
-       if c.Cfg.SummaryLength() >= len(words) {
-               return strings.Join(words, " "), false
-       }
-
-       for counter, word := range words[c.Cfg.SummaryLength():] {
-               if strings.HasSuffix(word, ".") ||
-                       strings.HasSuffix(word, "?") ||
-                       strings.HasSuffix(word, ".\"") ||
-                       strings.HasSuffix(word, "!") {
-                       upper := c.Cfg.SummaryLength() + counter + 1
-                       return strings.Join(words[:upper], " "), (upper < len(words))
-               }
-       }
-
-       return strings.Join(words[:c.Cfg.SummaryLength()], " "), true
-}
index a1617c48d1f51243ac6be26fcb82135519cbc661..c103a54799546196222afa6ff04d56d1748379c6 100644 (file)
@@ -30,12 +30,6 @@ var (
        emojiMaxSize   int
 )
 
-// Emoji returns the emoji given a key, e.g. ":smile:", nil if not found.
-func Emoji(key string) []byte {
-       emojiInit.Do(initEmoji)
-       return emojis[key]
-}
-
 // Emojify "emojifies" the input source.
 // Note that the input byte slice will be modified if needed.
 // See http://www.emoji-cheat-sheet.com/
index 281414b2a5fcbf0d95432ce38a3b6eb5e69a2cd3..b16aec0b03d525cd979f58f98e5948d5e284b25f 100644 (file)
@@ -32,7 +32,6 @@ import (
        "github.com/jdkato/prose/transform"
 
        bp "github.com/gohugoio/hugo/bufferpool"
-       "github.com/spf13/pflag"
 )
 
 // FilePathSeparator as defined by os.Separator.
@@ -317,18 +316,6 @@ func IsWhitespace(r rune) bool {
        return r == ' ' || r == '\t' || r == '\n' || r == '\r'
 }
 
-// NormalizeHugoFlags facilitates transitions of Hugo command-line flags,
-// e.g. --baseUrl to --baseURL, --uglyUrls to --uglyURLs
-func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
-       switch name {
-       case "baseUrl":
-               name = "baseURL"
-       case "uglyUrls":
-               name = "uglyURLs"
-       }
-       return pflag.NormalizedName(name)
-}
-
 // PrintFs prints the given filesystem to the given writer starting from the given path.
 // This is useful for debugging.
 func PrintFs(fs afero.Fs, path string, w io.Writer) {
diff --git a/htesting/testdata_builder.go b/htesting/testdata_builder.go
deleted file mode 100644 (file)
index d7ba185..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2018 The Hugo Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package htesting
-
-import (
-       "path/filepath"
-       "testing"
-
-       "github.com/spf13/afero"
-)
-
-type testFile struct {
-       name    string
-       content string
-}
-
-type testdataBuilder struct {
-       t          testing.TB
-       fs         afero.Fs
-       workingDir string
-
-       files []testFile
-}
-
-func NewTestdataBuilder(fs afero.Fs, workingDir string, t testing.TB) *testdataBuilder {
-       workingDir = filepath.Clean(workingDir)
-       return &testdataBuilder{fs: fs, workingDir: workingDir, t: t}
-}
-
-func (b *testdataBuilder) Add(filename, content string) *testdataBuilder {
-       b.files = append(b.files, testFile{name: filename, content: content})
-       return b
-}
-
-func (b *testdataBuilder) Build() *testdataBuilder {
-       for _, f := range b.files {
-               if err := afero.WriteFile(b.fs, filepath.Join(b.workingDir, f.name), []byte(f.content), 0666); err != nil {
-                       b.t.Fatalf("failed to add %q: %s", f.name, err)
-               }
-       }
-       return b
-}
-
-func (b testdataBuilder) WithWorkingDir(dir string) *testdataBuilder {
-       b.workingDir = filepath.Clean(dir)
-       b.files = make([]testFile, 0)
-       return &b
-}
index c339972785a223b2a0d53944992552394dcd25f9..773352ea81044a5da2a74453772ea5b03e472d04 100644 (file)
@@ -15,6 +15,7 @@
 package hugofs
 
 import (
+       "errors"
        "os"
        "path/filepath"
        "reflect"
@@ -28,8 +29,6 @@ import (
        "github.com/gohugoio/hugo/hugofs/files"
        "golang.org/x/text/unicode/norm"
 
-       "errors"
-
        "github.com/gohugoio/hugo/common/hreflect"
        "github.com/gohugoio/hugo/common/htime"
 
@@ -224,7 +223,8 @@ func newDirNameOnlyFileInfo(name string, meta *FileMeta, fileOpener func() (afer
 func decorateFileInfo(
        fi os.FileInfo,
        fs afero.Fs, opener func() (afero.File, error),
-       filename, filepath string, inMeta *FileMeta) FileMetaInfo {
+       filename, filepath string, inMeta *FileMeta,
+) FileMetaInfo {
        var meta *FileMeta
        var fim FileMetaInfo
 
@@ -289,13 +289,6 @@ func fileInfosToNames(fis []os.FileInfo) []string {
        return names
 }
 
-func fromSlash(filenames []string) []string {
-       for i, name := range filenames {
-               filenames[i] = filepath.FromSlash(name)
-       }
-       return filenames
-}
-
 func sortFileInfos(fis []os.FileInfo) {
        sort.Slice(fis, func(i, j int) bool {
                fimi, fimj := fis[i].(FileMetaInfo), fis[j].(FileMetaInfo)
index 4ecd1f55a2c2ad0f708a48df69e4b1a49d782974..c101309c25b643dc764f01bfda68158f9c343b31 100644 (file)
@@ -23,9 +23,7 @@ import (
        "github.com/spf13/afero"
 )
 
-var (
-       _ FilesystemUnwrapper = (*filenameFilterFs)(nil)
-)
+var _ FilesystemUnwrapper = (*filenameFilterFs)(nil)
 
 func newFilenameFilterFs(fs afero.Fs, base string, filter *glob.FilenameFilter) afero.Fs {
        return &filenameFilterFs{
@@ -93,12 +91,6 @@ func (fs *filenameFilterFs) Stat(name string) (os.FileInfo, error) {
        return fi, err
 }
 
-func (fs *filenameFilterFs) getOpener(name string) func() (afero.File, error) {
-       return func() (afero.File, error) {
-               return fs.Open(name)
-       }
-}
-
 type filenameFilterDir struct {
        afero.File
        base   string
@@ -162,9 +154,11 @@ func (fs *filenameFilterFs) RemoveAll(p string) error {
 func (fs *filenameFilterFs) Rename(o, n string) error {
        return syscall.EPERM
 }
+
 func (fs *filenameFilterFs) Create(n string) (afero.File, error) {
        return nil, syscall.EPERM
 }
+
 func (fs *filenameFilterFs) Name() string {
        return "FinameFilterFS"
 }
index 9462afa249abe9a6a6d4048e099cd180f62ba58d..5b8a3adb22a97f1ab2be382e2004a92bdef0fad8 100644 (file)
@@ -60,14 +60,7 @@ type Fs struct {
        WorkingDirWritable afero.Fs
 }
 
-// NewDefault creates a new Fs with the OS file system
-// as source and destination file systems.
-func NewDefault(conf config.BaseConfig) *Fs {
-       fs := Os
-       return NewFrom(fs, conf)
-}
-
-func NewDefaultOld(cfg config.Provider) *Fs {
+func NewDefault(cfg config.Provider) *Fs {
        workingDir, publishDir := getWorkingPublishDir(cfg)
        fs := Os
        return newFs(fs, fs, workingDir, publishDir)
@@ -99,7 +92,6 @@ func getWorkingPublishDir(cfg config.Provider) (string, string) {
                publishDir = cfg.GetString("publishDir")
        }
        return workingDir, publishDir
-
 }
 
 func newFs(source, destination afero.Fs, workingDir, publishDir string) *Fs {
@@ -166,7 +158,7 @@ func MakeReadableAndRemoveAllModulePkgDir(fs afero.Fs, dir string) (int, error)
                }
                if info.IsDir() {
                        counter++
-                       fs.Chmod(path, 0777)
+                       fs.Chmod(path, 0o777)
                }
                return nil
        })
@@ -217,7 +209,6 @@ func WalkFilesystems(fs afero.Fs, fn WalkFn) bool {
                if WalkFilesystems(afs.UnwrapFilesystem(), fn) {
                        return true
                }
-
        } else if bfs, ok := fs.(FilesystemsUnwrapper); ok {
                for _, sf := range bfs.UnwrapFilesystems() {
                        if WalkFilesystems(sf, fn) {
index 509aca62f78db70dbf591f48e91416bef2f1239d..b2ed2e86e50e1f2be0e31444e30554e73f9a5544 100644 (file)
@@ -30,7 +30,6 @@ func TestIsOsFs(t *testing.T) {
        c.Assert(IsOsFs(&afero.MemMapFs{}), qt.Equals, false)
        c.Assert(IsOsFs(afero.NewBasePathFs(&afero.MemMapFs{}, "/public")), qt.Equals, false)
        c.Assert(IsOsFs(afero.NewBasePathFs(Os, t.TempDir())), qt.Equals, true)
-
 }
 
 func TestNewDefault(t *testing.T) {
@@ -38,7 +37,7 @@ func TestNewDefault(t *testing.T) {
        v := config.New()
        v.Set("workingDir", t.TempDir())
        v.Set("publishDir", "public")
-       f := NewDefaultOld(v)
+       f := NewDefault(v)
 
        c.Assert(f.Source, qt.IsNotNil)
        c.Assert(f.Source, hqt.IsSameType, new(afero.OsFs))
index d5c94799d5060a152391eb342bb6556a3b43e84c..a7c2a627162132c9db6bf7101bf874428e9e0911 100644 (file)
@@ -57,7 +57,6 @@ var filePathSeparator = string(filepath.Separator)
 // to underline that even if they can be composites, they all have a base path set to a specific
 // resource folder, e.g "/my-project/content". So, no absolute filenames needed.
 type BaseFs struct {
-
        // SourceFilesystems contains the different source file systems.
        *SourceFilesystems
 
@@ -180,7 +179,6 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
                                return filename, filepath.Join(meta.Filename, filename), nil
                        }
                }
-
        }
 
        return "", "", fmt.Errorf("could not determine content directory for %q", filename)
@@ -301,7 +299,6 @@ func (s SourceFilesystems) ContentStaticAssetFs(lang string) afero.Fs {
                        },
                },
        )
-
 }
 
 // StaticFs returns the static filesystem for the given language.
@@ -666,8 +663,8 @@ func (b *sourceFilesystemsBuilder) isStaticMount(mnt modules.Mount) bool {
 
 func (b *sourceFilesystemsBuilder) createOverlayFs(
        collector *filesystemsCollector,
-       mounts []mountsDescriptor) error {
-
+       mounts []mountsDescriptor,
+) error {
        if len(mounts) == 0 {
                appendNopIfEmpty := func(ofs *overlayfs.OverlayFs) *overlayfs.OverlayFs {
                        if ofs.NumFilesystems() > 0 {
@@ -857,13 +854,6 @@ func (c *filesystemsCollector) addDir(rfs *hugofs.RootMappingFs, componentFolder
        }
 }
 
-func (c *filesystemsCollector) reverseFis(fis []hugofs.FileMetaInfo) {
-       for i := len(fis)/2 - 1; i >= 0; i-- {
-               opp := len(fis) - 1 - i
-               fis[i], fis[opp] = fis[opp], fis[i]
-       }
-}
-
 type mountsDescriptor struct {
        modules.Module
        dir           string
index 88a0c3ec630ae222b489971125498a17158b5df8..44500cae578192565a95fff753e94ba55f1e0c67 100644 (file)
@@ -63,11 +63,11 @@ path="github.com/gohugoio/hugoTestModule2"
                b := newTestSitesBuilder(t)
                tempDir := t.TempDir()
                workingDir := filepath.Join(tempDir, "myhugosite")
-               b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil)
+               b.Assert(os.MkdirAll(workingDir, 0o777), qt.IsNil)
                cfg := config.New()
                cfg.Set("workingDir", workingDir)
                cfg.Set("publishDir", "public")
-               b.Fs = hugofs.NewDefaultOld(cfg)
+               b.Fs = hugofs.NewDefault(cfg)
                b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
                b.WithTemplates(
                        "index.html", `
@@ -352,7 +352,7 @@ ignoreVendorPaths = %q
                b := newTestSitesBuilder(t)
 
                // Need to use OS fs for this.
-               b.Fs = hugofs.NewDefaultOld(v)
+               b.Fs = hugofs.NewDefault(v)
 
                b.WithWorkingDir(workingDir).WithConfigFile("toml", config)
                b.WithContent("page.md", `
@@ -683,11 +683,11 @@ Data: {{ .Site.Data }}
        createDirsAndFiles := func(baseDir string) {
                for _, dir := range files.ComponentFolders {
                        realDir := filepath.Join(baseDir, dir, "real")
-                       c.Assert(os.MkdirAll(realDir, 0777), qt.IsNil)
-                       c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0777), qt.IsNil)
+                       c.Assert(os.MkdirAll(realDir, 0o777), qt.IsNil)
+                       c.Assert(afero.WriteFile(fs.Source, filepath.Join(realDir, "data.toml"), []byte("[hello]\nother = \"hello\""), 0o777), qt.IsNil)
                }
 
-               c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0777), qt.IsNil)
+               c.Assert(afero.WriteFile(fs.Source, filepath.Join(baseDir, "layouts", "index.html"), []byte(homeTemplate), 0o777), qt.IsNil)
        }
 
        // Create project dirs and files.
@@ -849,7 +849,7 @@ workingDir = %q
        cfg.Set("workingDir", workingDir)
        cfg.Set("publishDir", "public")
 
-       b.Fs = hugofs.NewDefaultOld(cfg)
+       b.Fs = hugofs.NewDefault(cfg)
 
        b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
        b.WithTemplatesAdded("index.html", `
@@ -877,8 +877,8 @@ workingDir = %q
 <a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank"{{ end }}>{{ .Text | safeHTML }}</a>
 `)
 
-       os.Mkdir(filepath.Join(workingDir, "mycontent"), 0777)
-       os.Mkdir(filepath.Join(workingDir, "mycontent", "mybundle"), 0777)
+       os.Mkdir(filepath.Join(workingDir, "mycontent"), 0o777)
+       os.Mkdir(filepath.Join(workingDir, "mycontent", "mybundle"), 0o777)
 
        b.WithSourceFile("README.md", `---
 title: "Readme Title"
@@ -974,9 +974,9 @@ workingDir = %q
                cfg := config.New()
                cfg.Set("workingDir", workingDir)
                cfg.Set("publishDir", "public")
-               b.Fs = hugofs.NewDefaultOld(cfg)
+               b.Fs = hugofs.NewDefault(cfg)
 
-               os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0777)
+               os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0o777)
 
                b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
 
@@ -1034,12 +1034,12 @@ title: P1
                defer test.clean()
 
                subContentDir := filepath.Join(test.workingDir, "mycontent", "sub")
-               os.MkdirAll(subContentDir, 0777)
+               os.MkdirAll(subContentDir, 0o777)
                myPartialsDir := filepath.Join(test.workingDir, "subdir", "mypartials")
-               os.MkdirAll(myPartialsDir, 0777)
+               os.MkdirAll(myPartialsDir, 0o777)
 
                absShortcodesDir := filepath.Join(absDir, "abs", "myshortcodes")
-               os.MkdirAll(absShortcodesDir, 0777)
+               os.MkdirAll(absShortcodesDir, 0o777)
 
                b.WithSourceFile("README.md", "---\ntitle: Readme\n---")
                b.WithSourceFile("mycontent/sub/p1.md", "---\ntitle: P1\n---")
@@ -1128,7 +1128,7 @@ title: Abs
 ---
 
 Content.
-`), 0777)
+`), 0o777)
 
        b.WithWorkingDir(workDir).WithConfigFile("toml", config)
        b.WithContent("dummy.md", "")
index eb0385cda469d84633e279534ee29b9a9fbe947e..f3f5c3eb262f4c607ad0344aeaac99e7236fe8d8 100644 (file)
@@ -50,7 +50,6 @@ import (
        "github.com/gohugoio/hugo/resources/kinds"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/page/pagemeta"
-       "github.com/gohugoio/hugo/tpl"
 )
 
 // HugoSites represents the sites to build. Each site represents a language.
@@ -319,21 +318,6 @@ func (h *HugoSites) loadGitInfo() error {
        return nil
 }
 
-func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.TemplateManager) error) func(templ tpl.TemplateManager) error {
-       return func(templ tpl.TemplateManager) error {
-               for _, wt := range withTemplates {
-                       if wt == nil {
-                               continue
-                       }
-                       if err := wt(templ); err != nil {
-                               return err
-                       }
-               }
-
-               return nil
-       }
-}
-
 // Reset resets the sites and template caches etc., making it ready for a full rebuild.
 func (h *HugoSites) reset(config *BuildCfg) {
        if config.ResetState {
@@ -659,7 +643,6 @@ func (h *HugoSites) errWithFileContext(err error, f source.File) error {
        realFilename := fim.Meta().Filename
 
        return herrors.NewFileErrorFromFile(err, realFilename, h.SourceSpec.Fs.Source, nil)
-
 }
 
 func (h *HugoSites) readData(f source.File) (any, error) {
index 2ea936af211d5bb81fa4b9ba416f7a27ca0d9abb..bf5e19ac42704ec9eef8671821d60a44c05f57c3 100644 (file)
@@ -851,10 +851,6 @@ func (p *pageState) pathOrTitle() string {
        return p.Title()
 }
 
-func (p *pageState) posFromPage(offset int) text.Position {
-       return p.posFromInput(p.source.parsed.Input(), offset)
-}
-
 func (p *pageState) posFromInput(input []byte, offset int) text.Position {
        if offset < 0 {
                return text.Position{
index c10896beffba0fb34adf7967a88ca564b14535a3..77c5b4e7ebf11541f113546426746d37d6a04d54 100644 (file)
@@ -484,10 +484,6 @@ func doRenderShortcode(
        return prerenderedShortcode{s: result, hasVariants: hasVariants}, err
 }
 
-func (s *shortcodeHandler) hasShortcodes() bool {
-       return s != nil && len(s.shortcodes) > 0
-}
-
 func (s *shortcodeHandler) addName(name string) {
        s.nameSetMu.Lock()
        defer s.nameSetMu.Unlock()
@@ -529,13 +525,6 @@ func (s *shortcodeHandler) prepareShortcodesForPage(ctx context.Context, p *page
        return rendered, nil
 }
 
-func (s *shortcodeHandler) parseError(err error, input []byte, pos int) error {
-       if s.p != nil {
-               return s.p.parseError(err, input, pos)
-       }
-       return err
-}
-
 // pageTokens state:
 // - before: positioned just before the shortcode start
 // - after: shortcode(s) consumed (plural when they are nested)
index 802ce40e280d1ffeb0130ed8bdf50d8cd137f5dd..d18b4c6f092ade0e5eb4d7aeae1384f560d55cbd 100644 (file)
@@ -16,7 +16,6 @@ package hugolib
 import (
        "fmt"
        "path/filepath"
-       "strings"
        "testing"
 
        "github.com/gohugoio/hugo/config"
@@ -636,10 +635,6 @@ func collectIdentities(set map[identity.Identity]bool, provider identity.Provide
        }
 }
 
-func ident(level int) string {
-       return strings.Repeat(" ", level)
-}
-
 func TestPartialInline(t *testing.T) {
        b := newTestSitesBuilder(t)
 
index 700aa8c3d5e33d63ca5c7b1876eecf90cfe30e3b..cf054897d03ca4bf6ae843edcce793a20224e34d 100644 (file)
@@ -43,7 +43,6 @@ import (
        "github.com/spf13/cast"
 
        "github.com/gohugoio/hugo/helpers"
-       "github.com/gohugoio/hugo/tpl"
 
        "github.com/gohugoio/hugo/resources/resource"
 
@@ -522,7 +521,7 @@ func (s *sitesBuilder) CreateSitesE() error {
                                "data",
                                "i18n",
                        } {
-                               if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0777); err != nil {
+                               if err := os.MkdirAll(filepath.Join(s.workingDir, dir), 0o777); err != nil {
                                        return fmt.Errorf("failed to create %q: %w", dir, err)
                                }
                        }
@@ -555,7 +554,6 @@ func (s *sitesBuilder) CreateSitesE() error {
        depsCfg.TestLogger = s.logger
 
        sites, err := NewHugoSites(depsCfg)
-
        if err != nil {
                return fmt.Errorf("failed to create sites: %w", err)
        }
@@ -878,20 +876,6 @@ func (th testHelper) assertFileContent(filename string, matches ...string) {
        }
 }
 
-func (th testHelper) assertFileContentRegexp(filename string, matches ...string) {
-       filename = th.replaceDefaultContentLanguageValue(filename)
-       content := readWorkingDir(th, th.Fs, filename)
-       for _, match := range matches {
-               match = th.replaceDefaultContentLanguageValue(match)
-               r := regexp.MustCompile(match)
-               matches := r.MatchString(content)
-               if !matches {
-                       fmt.Println("Expected to match regexp:\n"+match+"\nGot:\n", content)
-               }
-               th.Assert(matches, qt.Equals, true)
-       }
-}
-
 func (th testHelper) assertFileNotExist(filename string) {
        exists, err := helpers.Exists(filename, th.Fs.PublishDir)
        th.Assert(err, qt.IsNil)
@@ -908,16 +892,11 @@ func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
        return value
 }
 
-func loadTestConfig(fs afero.Fs) (*allconfig.Configs, error) {
-       res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Fs: fs})
-       return res, err
-}
-
 func loadTestConfigFromProvider(cfg config.Provider) (*allconfig.Configs, error) {
        workingDir := cfg.GetString("workingDir")
        fs := afero.NewMemMapFs()
        if workingDir != "" {
-               fs.MkdirAll(workingDir, 0755)
+               fs.MkdirAll(workingDir, 0o755)
        }
        res, err := allconfig.LoadConfig(allconfig.ConfigSourceDescriptor{Flags: cfg, Fs: fs})
        return res, err
@@ -972,18 +951,6 @@ func newTestSitesFromConfig(t testing.TB, afs afero.Fs, tomlConfig string, layou
        return th, h
 }
 
-func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ tpl.TemplateManager) error {
-       return func(templ tpl.TemplateManager) error {
-               for i := 0; i < len(additionalTemplates); i += 2 {
-                       err := templ.AddTemplate(additionalTemplates[i], additionalTemplates[i+1])
-                       if err != nil {
-                               return err
-                       }
-               }
-               return nil
-       }
-}
-
 // TODO(bep) replace these with the builder
 func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
        t.Helper()
index 59d4c128684a12e55a96e3e5aeb4df76d46b57be..f24b42f3798db6c4ea6b3235c6ac10480d060eb8 100644 (file)
@@ -113,12 +113,6 @@ func ForceRefresh() {
        RefreshPath("/x.js")
 }
 
-// NavigateToPath tells livereload to navigate to the given path.
-// This translates to `window.location.href = path` in the client.
-func NavigateToPath(path string) {
-       RefreshPath(hugoNavigatePrefix + path)
-}
-
 // NavigateToPathForPort is similar to NavigateToPath but will also
 // set window.location.port to the given port value.
 func NavigateToPathForPort(path string, port int) {
index b4f6b6dc52f75337eaae36ee9b56ff093b370c68..2a7815b7037279065c4fda97b984808a1da8b68c 100644 (file)
@@ -1,11 +1,9 @@
 package images
 
 import (
-       "github.com/yuin/goldmark"
        "github.com/yuin/goldmark/ast"
        "github.com/yuin/goldmark/parser"
        "github.com/yuin/goldmark/text"
-       "github.com/yuin/goldmark/util"
 )
 
 type (
@@ -20,18 +18,6 @@ const (
        AttrIsBlock = "_h__isBlock"
 )
 
-func New(wrapStandAloneImageWithinParagraph bool) goldmark.Extender {
-       return &linksExtension{wrapStandAloneImageWithinParagraph: wrapStandAloneImageWithinParagraph}
-}
-
-func (e *linksExtension) Extend(m goldmark.Markdown) {
-       m.Parser().AddOptions(
-               parser.WithASTTransformers(
-                       util.Prioritized(&Transformer{wrapStandAloneImageWithinParagraph: e.wrapStandAloneImageWithinParagraph}, 300),
-               ),
-       )
-}
-
 type Transformer struct {
        wrapStandAloneImageWithinParagraph bool
 }
@@ -67,7 +53,5 @@ func (t *Transformer) Transform(doc *ast.Document, reader text.Reader, pctx pars
                }
 
                return ast.WalkContinue, nil
-
        })
-
 }
index c70659a09a38cfae9241891e315aa358cc17c32a..85ea74124b4d260748b1843004b58aeaa52f44f6 100644 (file)
@@ -232,7 +232,6 @@ func highlight(fw hugio.FlexiWriter, code, lang string, attributes []attributes.
                                return ``
                        },
                }
-
        } else {
                wrapper = getPreWrapper(lang, w)
        }
@@ -314,10 +313,6 @@ func (s startEnd) End(code bool) string {
        return s.end(code)
 }
 
-func WritePreEnd(w io.Writer) {
-       fmt.Fprint(w, preEnd)
-}
-
 func writeDivStart(w hugio.FlexiWriter, attrs []attributes.Attribute) {
        w.WriteString(`<div class="highlight`)
        if attrs != nil {
index 72583f26724a617f86f559944017403e2703df73..b356132beb972f6cfa5121fe122818a8d398c2b7 100644 (file)
@@ -31,7 +31,6 @@ import (
 var DefaultTypes Types
 
 func init() {
-
        ns, err := DecodeTypes(nil)
        if err != nil {
                panic(err)
@@ -61,7 +60,6 @@ type MediaTypeConfig struct {
 
 // DecodeTypes decodes the given map of media types.
 func DecodeTypes(in map[string]any) (*config.ConfigNamespace[map[string]MediaTypeConfig, Types], error) {
-
        buildConfig := func(v any) (Types, any, error) {
                m, err := maps.ToStringMapE(v)
                if err != nil {
@@ -106,34 +104,4 @@ func DecodeTypes(in map[string]any) (*config.ConfigNamespace[map[string]MediaTyp
                return nil, fmt.Errorf("failed to decode media types: %w", err)
        }
        return ns, nil
-
-}
-
-func suffixIsRemoved() error {
-       return errors.New(`MediaType.Suffix is removed. Before Hugo 0.44 this was used both to set a custom file suffix and as way
-to augment the mediatype definition (what you see after the "+", e.g. "image/svg+xml").
-
-This had its limitations. For one, it was only possible with one file extension per MIME type.
-
-Now you can specify multiple file suffixes using "suffixes", but you need to specify the full MIME type
-identifier:
-
-[mediaTypes]
-[mediaTypes."image/svg+xml"]
-suffixes = ["svg", "abc" ]
-
-In most cases, it will be enough to just change:
-
-[mediaTypes]
-[mediaTypes."my/custom-mediatype"]
-suffix = "txt"
-
-To:
-
-[mediaTypes]
-[mediaTypes."my/custom-mediatype"]
-suffixes = ["txt"]
-
-Note that you can still get the Media Type's suffix from a template: {{ $mediaType.Suffix }}. But this will now map to the MIME type filename.
-`)
 }
index 5b5418bcd0362b145655fdf62a9c7ac3b8bb47c9..6c47bde5c401d80e09eda24cc0d5051b5e48cbe3 100644 (file)
@@ -15,6 +15,7 @@ package modules
 
 import (
        "bufio"
+       "errors"
        "fmt"
        "os"
        "path/filepath"
@@ -37,8 +38,6 @@ import (
 
        "github.com/rogpeppe/go-internal/module"
 
-       "errors"
-
        "github.com/gohugoio/hugo/config"
        "github.com/spf13/afero"
 )
@@ -47,11 +46,6 @@ var ErrNotExist = errors.New("module does not exist")
 
 const vendorModulesFilename = "modules.txt"
 
-// IsNotExist returns whether an error means that a module could not be found.
-func IsNotExist(err error) bool {
-       return errors.Is(err, os.ErrNotExist)
-}
-
 func (h *Client) Collect() (ModulesConfig, error) {
        mc, coll := h.collect(true)
        if coll.err != nil {
@@ -124,7 +118,6 @@ func (m ModulesConfig) HasConfigFile() bool {
                if len(mod.ConfigFilenames()) > 0 {
                        return true
                }
-
        }
        return false
 }
@@ -220,7 +213,6 @@ func (c *collector) getVendoredDir(path string) (vendoredModule, bool) {
 }
 
 func (c *collector) add(owner *moduleAdapter, moduleImport Import) (*moduleAdapter, error) {
-
        var (
                mod       *goModule
                moduleDir string
@@ -669,7 +661,6 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
                        } else {
                                continue
                        }
-
                }
 
                // Verify that target points to one of the predefined component dirs
index 9a24fd21c206abfc0d227d251b030525cc541eb6..cb0181a5ff283406676ff869591ee118a0f90cea 100644 (file)
@@ -424,16 +424,6 @@ func (i *imageResource) doWithImageConfig(conf images.ImageConfig, f func(src im
        return img, nil
 }
 
-func (i *imageResource) decodeImageConfig(action, spec string) (images.ImageConfig, error) {
-       options := strings.Fields(spec)
-       conf, err := images.DecodeImageConfig(action, options, i.Proc.Cfg, i.Format)
-       if err != nil {
-               return conf, err
-       }
-
-       return conf, nil
-}
-
 type giphy struct {
        image.Image
        gif *gif.GIF
index 237bee0c8a1f40e1cdf1af2dab4ed30b6de49604..9e550e252733ab548d3ca42cce2bf022598f6f41 100644 (file)
@@ -66,7 +66,6 @@ type ResourceError interface {
 
 // ErrProvider provides an Err.
 type ErrProvider interface {
-
        // Err returns an error if this resource is in an error state.
        // This will currently only be set for resources obtained from resources.GetRemote.
        Err() ResourceError
@@ -215,15 +214,3 @@ func (r resourceTypesHolder) ResourceType() string {
 func NewResourceTypesProvider(mediaType media.Type, resourceType string) ResourceTypesProvider {
        return resourceTypesHolder{mediaType: mediaType, resourceType: resourceType}
 }
-
-type languageHolder struct {
-       lang *langs.Language
-}
-
-func (l languageHolder) Language() *langs.Language {
-       return l.lang
-}
-
-func NewLanguageProvider(lang *langs.Language) LanguageProvider {
-       return languageHolder{lang: lang}
-}
index 488e8e70a8bb2c45aa17280ea9297b0e8a60b137..d1fd2481dc38ac5d555ea4d139dbde0320db7704 100644 (file)
@@ -65,7 +65,6 @@ func responseToData(res *http.Response, readBody bool) map[string]any {
        }
 
        return m
-
 }
 
 func toHTTPError(err error, res *http.Response, readBody bool) *HTTPError {
@@ -141,7 +140,6 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
                                if res.StatusCode != http.StatusNotFound {
                                        if res.StatusCode < 200 || res.StatusCode > 299 {
                                                return nil, temporaryHTTPStatusCodes[res.StatusCode], toHTTPError(fmt.Errorf("failed to fetch remote resource: %s", http.StatusText(res.StatusCode)), res, !isHeadMethod)
-
                                        }
                                }
 
@@ -151,9 +149,7 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
                                }
 
                                return b, false, nil
-
                        }()
-
                        if err != nil {
                                if retry {
                                        if start.IsZero() {
@@ -174,7 +170,6 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
                        return hugio.ToReadCloser(bytes.NewReader(b)), nil
 
                }
-
        })
        if err != nil {
                return nil, err
@@ -307,22 +302,6 @@ func addUserProvidedHeaders(headers map[string]any, req *http.Request) {
        }
 }
 
-func hasHeaderValue(m http.Header, key, value string) bool {
-       var s []string
-       var ok bool
-
-       if s, ok = m[key]; !ok {
-               return false
-       }
-
-       for _, v := range s {
-               if v == value {
-                       return true
-               }
-       }
-       return false
-}
-
 func hasHeaderKey(m http.Header, key string) bool {
        _, ok := m[key]
        return ok
index 61aaa993f056c0e1d67c7708ad6991a6dc8f3099..1f0127c66c5b5e10332de5a386cc712faf244e55 100644 (file)
@@ -129,21 +129,6 @@ type TemplatesProvider interface {
        TextTmpl() TemplateParseFinder
 }
 
-// WithInfo wraps the info in a template.
-func WithInfo(templ Template, info Info) Template {
-       if manager, ok := info.(InfoManager); ok {
-               return &templateInfoManager{
-                       Template:    templ,
-                       InfoManager: manager,
-               }
-       }
-
-       return &templateInfo{
-               Template: templ,
-               Info:     info,
-       }
-}
-
 var baseOfRe = regexp.MustCompile("template: (.*?):")
 
 func extractBaseOf(err string) string {
@@ -173,17 +158,6 @@ type page interface {
        IsNode() bool
 }
 
-func GetHasLockFromContext(ctx context.Context) bool {
-       if v := ctx.Value(texttemplate.HasLockContextKey); v != nil {
-               return v.(bool)
-       }
-       return false
-}
-
-func SetHasLockInContext(ctx context.Context, hasLock bool) context.Context {
-       return context.WithValue(ctx, texttemplate.HasLockContextKey, hasLock)
-}
-
 func GetCallbackFunctionFromContext(ctx context.Context) any {
        return ctx.Value(texttemplate.CallbackContextKey)
 }
index c21c0ae7d5f797bc185ab0761b50416065b999b2..5f748d68228420e48103503157120f6e04f1f7fe 100644 (file)
@@ -39,22 +39,6 @@ type InfoManager interface {
        identity.Manager
 }
 
-type defaultInfo struct {
-       identity.Manager
-       parseInfo ParseInfo
-}
-
-func NewInfo(id identity.Manager, parseInfo ParseInfo) Info {
-       return &defaultInfo{
-               Manager:   id,
-               parseInfo: parseInfo,
-       }
-}
-
-func (info *defaultInfo) ParseInfo() ParseInfo {
-       return info.parseInfo
-}
-
 type ParseInfo struct {
        // Set for shortcode templates with any {{ .Inner }}
        IsInner bool
diff --git a/unused.sh b/unused.sh
new file mode 100755 (executable)
index 0000000..3518923
--- /dev/null
+++ b/unused.sh
@@ -0,0 +1 @@
+deadcode -test ./... | grep -v go_templ
\ No newline at end of file