Skip to content

Commit

Permalink
all: Remove unused code
Browse files Browse the repository at this point in the history
Using x/tools/cmd/deadcode
  • Loading branch information
bep committed Dec 18, 2023
1 parent 6f13430 commit 8adba64
Show file tree
Hide file tree
Showing 30 changed files with 32 additions and 405 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-dart-sass-v1.yml
Expand Up @@ -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 #
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -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 #
Expand Down
12 changes: 0 additions & 12 deletions common/herrors/errors.go
Expand Up @@ -15,14 +15,12 @@
package herrors

import (
"bytes"
"errors"
"fmt"
"io"
"os"
"runtime"
"runtime/debug"
"strconv"
)

// PrintStackTrace prints the current stacktrace to w.
Expand All @@ -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{})
Expand Down
6 changes: 0 additions & 6 deletions config/configProvider.go
Expand Up @@ -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)
}
}
21 changes: 0 additions & 21 deletions helpers/content.go
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions helpers/emoji.go
Expand Up @@ -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/
Expand Down
13 changes: 0 additions & 13 deletions helpers/general.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
59 changes: 0 additions & 59 deletions htesting/testdata_builder.go

This file was deleted.

13 changes: 3 additions & 10 deletions hugofs/fileinfo.go
Expand Up @@ -15,6 +15,7 @@
package hugofs

import (
"errors"
"os"
"path/filepath"
"reflect"
Expand All @@ -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"

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions hugofs/filename_filter_fs.go
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down
13 changes: 2 additions & 11 deletions hugofs/fs.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions hugofs/fs_test.go
Expand Up @@ -30,15 +30,14 @@ 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) {
c := qt.New(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))
Expand Down
14 changes: 2 additions & 12 deletions hugolib/filesystems/basefs.go
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -301,7 +299,6 @@ func (s SourceFilesystems) ContentStaticAssetFs(lang string) afero.Fs {
},
},
)

}

// StaticFs returns the static filesystem for the given language.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8adba64

Please sign in to comment.