Skip to content

Commit 8adba64

Browse files
committed
all: Remove unused code
Using x/tools/cmd/deadcode
1 parent 6f13430 commit 8adba64

30 files changed

+32
-405
lines changed

.github/workflows/test-dart-sass-v1.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
**/go.sum
3131
**/go.mod
3232
- name: Install Ruby
33-
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
33+
uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b
3434
with:
3535
ruby-version: '2.7'
3636
bundler-cache: true #

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
**/go.sum
3333
**/go.mod
3434
- name: Install Ruby
35-
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
35+
uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b
3636
with:
3737
ruby-version: '2.7'
3838
bundler-cache: true #

common/herrors/errors.go

-12
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
package herrors
1616

1717
import (
18-
"bytes"
1918
"errors"
2019
"fmt"
2120
"io"
2221
"os"
2322
"runtime"
2423
"runtime/debug"
25-
"strconv"
2624
)
2725

2826
// PrintStackTrace prints the current stacktrace to w.
@@ -49,16 +47,6 @@ func Recover(args ...any) {
4947
}
5048
}
5149

52-
// GetGID the current goroutine id. Used only for debugging.
53-
func GetGID() uint64 {
54-
b := make([]byte, 64)
55-
b = b[:runtime.Stack(b, false)]
56-
b = bytes.TrimPrefix(b, []byte("goroutine "))
57-
b = b[:bytes.IndexByte(b, ' ')]
58-
n, _ := strconv.ParseUint(string(b), 10, 64)
59-
return n
60-
}
61-
6250
// IsFeatureNotAvailableError returns true if the given error is or contains a FeatureNotAvailableError.
6351
func IsFeatureNotAvailableError(err error) bool {
6452
return errors.Is(err, &FeatureNotAvailableError{})

config/configProvider.go

-6
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,3 @@ func GetStringSlicePreserveString(cfg Provider, key string) []string {
9595
sd := cfg.Get(key)
9696
return types.ToStringSlicePreserveString(sd)
9797
}
98-
99-
func setIfNotSet(cfg Provider, key string, value any) {
100-
if !cfg.IsSet(key) {
101-
cfg.Set(key, value)
102-
}
103-
}

helpers/content.go

-21
Original file line numberDiff line numberDiff line change
@@ -266,24 +266,3 @@ func (c *ContentSpec) TrimShortHTML(input []byte) []byte {
266266
func isEndOfSentence(r rune) bool {
267267
return r == '.' || r == '?' || r == '!' || r == '"' || r == '\n'
268268
}
269-
270-
// Kept only for benchmark.
271-
func (c *ContentSpec) truncateWordsToWholeSentenceOld(content string) (string, bool) {
272-
words := strings.Fields(content)
273-
274-
if c.Cfg.SummaryLength() >= len(words) {
275-
return strings.Join(words, " "), false
276-
}
277-
278-
for counter, word := range words[c.Cfg.SummaryLength():] {
279-
if strings.HasSuffix(word, ".") ||
280-
strings.HasSuffix(word, "?") ||
281-
strings.HasSuffix(word, ".\"") ||
282-
strings.HasSuffix(word, "!") {
283-
upper := c.Cfg.SummaryLength() + counter + 1
284-
return strings.Join(words[:upper], " "), (upper < len(words))
285-
}
286-
}
287-
288-
return strings.Join(words[:c.Cfg.SummaryLength()], " "), true
289-
}

helpers/emoji.go

-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ var (
3030
emojiMaxSize int
3131
)
3232

33-
// Emoji returns the emoji given a key, e.g. ":smile:", nil if not found.
34-
func Emoji(key string) []byte {
35-
emojiInit.Do(initEmoji)
36-
return emojis[key]
37-
}
38-
3933
// Emojify "emojifies" the input source.
4034
// Note that the input byte slice will be modified if needed.
4135
// See http://www.emoji-cheat-sheet.com/

helpers/general.go

-13
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/jdkato/prose/transform"
3333

3434
bp "github.com/gohugoio/hugo/bufferpool"
35-
"github.com/spf13/pflag"
3635
)
3736

3837
// FilePathSeparator as defined by os.Separator.
@@ -317,18 +316,6 @@ func IsWhitespace(r rune) bool {
317316
return r == ' ' || r == '\t' || r == '\n' || r == '\r'
318317
}
319318

320-
// NormalizeHugoFlags facilitates transitions of Hugo command-line flags,
321-
// e.g. --baseUrl to --baseURL, --uglyUrls to --uglyURLs
322-
func NormalizeHugoFlags(f *pflag.FlagSet, name string) pflag.NormalizedName {
323-
switch name {
324-
case "baseUrl":
325-
name = "baseURL"
326-
case "uglyUrls":
327-
name = "uglyURLs"
328-
}
329-
return pflag.NormalizedName(name)
330-
}
331-
332319
// PrintFs prints the given filesystem to the given writer starting from the given path.
333320
// This is useful for debugging.
334321
func PrintFs(fs afero.Fs, path string, w io.Writer) {

htesting/testdata_builder.go

-59
This file was deleted.

hugofs/fileinfo.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package hugofs
1616

1717
import (
18+
"errors"
1819
"os"
1920
"path/filepath"
2021
"reflect"
@@ -28,8 +29,6 @@ import (
2829
"github.com/gohugoio/hugo/hugofs/files"
2930
"golang.org/x/text/unicode/norm"
3031

31-
"errors"
32-
3332
"github.com/gohugoio/hugo/common/hreflect"
3433
"github.com/gohugoio/hugo/common/htime"
3534

@@ -224,7 +223,8 @@ func newDirNameOnlyFileInfo(name string, meta *FileMeta, fileOpener func() (afer
224223
func decorateFileInfo(
225224
fi os.FileInfo,
226225
fs afero.Fs, opener func() (afero.File, error),
227-
filename, filepath string, inMeta *FileMeta) FileMetaInfo {
226+
filename, filepath string, inMeta *FileMeta,
227+
) FileMetaInfo {
228228
var meta *FileMeta
229229
var fim FileMetaInfo
230230

@@ -289,13 +289,6 @@ func fileInfosToNames(fis []os.FileInfo) []string {
289289
return names
290290
}
291291

292-
func fromSlash(filenames []string) []string {
293-
for i, name := range filenames {
294-
filenames[i] = filepath.FromSlash(name)
295-
}
296-
return filenames
297-
}
298-
299292
func sortFileInfos(fis []os.FileInfo) {
300293
sort.Slice(fis, func(i, j int) bool {
301294
fimi, fimj := fis[i].(FileMetaInfo), fis[j].(FileMetaInfo)

hugofs/filename_filter_fs.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import (
2323
"github.com/spf13/afero"
2424
)
2525

26-
var (
27-
_ FilesystemUnwrapper = (*filenameFilterFs)(nil)
28-
)
26+
var _ FilesystemUnwrapper = (*filenameFilterFs)(nil)
2927

3028
func newFilenameFilterFs(fs afero.Fs, base string, filter *glob.FilenameFilter) afero.Fs {
3129
return &filenameFilterFs{
@@ -93,12 +91,6 @@ func (fs *filenameFilterFs) Stat(name string) (os.FileInfo, error) {
9391
return fi, err
9492
}
9593

96-
func (fs *filenameFilterFs) getOpener(name string) func() (afero.File, error) {
97-
return func() (afero.File, error) {
98-
return fs.Open(name)
99-
}
100-
}
101-
10294
type filenameFilterDir struct {
10395
afero.File
10496
base string
@@ -162,9 +154,11 @@ func (fs *filenameFilterFs) RemoveAll(p string) error {
162154
func (fs *filenameFilterFs) Rename(o, n string) error {
163155
return syscall.EPERM
164156
}
157+
165158
func (fs *filenameFilterFs) Create(n string) (afero.File, error) {
166159
return nil, syscall.EPERM
167160
}
161+
168162
func (fs *filenameFilterFs) Name() string {
169163
return "FinameFilterFS"
170164
}

hugofs/fs.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,7 @@ type Fs struct {
6060
WorkingDirWritable afero.Fs
6161
}
6262

63-
// NewDefault creates a new Fs with the OS file system
64-
// as source and destination file systems.
65-
func NewDefault(conf config.BaseConfig) *Fs {
66-
fs := Os
67-
return NewFrom(fs, conf)
68-
}
69-
70-
func NewDefaultOld(cfg config.Provider) *Fs {
63+
func NewDefault(cfg config.Provider) *Fs {
7164
workingDir, publishDir := getWorkingPublishDir(cfg)
7265
fs := Os
7366
return newFs(fs, fs, workingDir, publishDir)
@@ -99,7 +92,6 @@ func getWorkingPublishDir(cfg config.Provider) (string, string) {
9992
publishDir = cfg.GetString("publishDir")
10093
}
10194
return workingDir, publishDir
102-
10395
}
10496

10597
func newFs(source, destination afero.Fs, workingDir, publishDir string) *Fs {
@@ -166,7 +158,7 @@ func MakeReadableAndRemoveAllModulePkgDir(fs afero.Fs, dir string) (int, error)
166158
}
167159
if info.IsDir() {
168160
counter++
169-
fs.Chmod(path, 0777)
161+
fs.Chmod(path, 0o777)
170162
}
171163
return nil
172164
})
@@ -217,7 +209,6 @@ func WalkFilesystems(fs afero.Fs, fn WalkFn) bool {
217209
if WalkFilesystems(afs.UnwrapFilesystem(), fn) {
218210
return true
219211
}
220-
221212
} else if bfs, ok := fs.(FilesystemsUnwrapper); ok {
222213
for _, sf := range bfs.UnwrapFilesystems() {
223214
if WalkFilesystems(sf, fn) {

hugofs/fs_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ func TestIsOsFs(t *testing.T) {
3030
c.Assert(IsOsFs(&afero.MemMapFs{}), qt.Equals, false)
3131
c.Assert(IsOsFs(afero.NewBasePathFs(&afero.MemMapFs{}, "/public")), qt.Equals, false)
3232
c.Assert(IsOsFs(afero.NewBasePathFs(Os, t.TempDir())), qt.Equals, true)
33-
3433
}
3534

3635
func TestNewDefault(t *testing.T) {
3736
c := qt.New(t)
3837
v := config.New()
3938
v.Set("workingDir", t.TempDir())
4039
v.Set("publishDir", "public")
41-
f := NewDefaultOld(v)
40+
f := NewDefault(v)
4241

4342
c.Assert(f.Source, qt.IsNotNil)
4443
c.Assert(f.Source, hqt.IsSameType, new(afero.OsFs))

hugolib/filesystems/basefs.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ var filePathSeparator = string(filepath.Separator)
5757
// to underline that even if they can be composites, they all have a base path set to a specific
5858
// resource folder, e.g "/my-project/content". So, no absolute filenames needed.
5959
type BaseFs struct {
60-
6160
// SourceFilesystems contains the different source file systems.
6261
*SourceFilesystems
6362

@@ -180,7 +179,6 @@ func (b *BaseFs) AbsProjectContentDir(filename string) (string, string, error) {
180179
return filename, filepath.Join(meta.Filename, filename), nil
181180
}
182181
}
183-
184182
}
185183

186184
return "", "", fmt.Errorf("could not determine content directory for %q", filename)
@@ -301,7 +299,6 @@ func (s SourceFilesystems) ContentStaticAssetFs(lang string) afero.Fs {
301299
},
302300
},
303301
)
304-
305302
}
306303

307304
// StaticFs returns the static filesystem for the given language.
@@ -666,8 +663,8 @@ func (b *sourceFilesystemsBuilder) isStaticMount(mnt modules.Mount) bool {
666663

667664
func (b *sourceFilesystemsBuilder) createOverlayFs(
668665
collector *filesystemsCollector,
669-
mounts []mountsDescriptor) error {
670-
666+
mounts []mountsDescriptor,
667+
) error {
671668
if len(mounts) == 0 {
672669
appendNopIfEmpty := func(ofs *overlayfs.OverlayFs) *overlayfs.OverlayFs {
673670
if ofs.NumFilesystems() > 0 {
@@ -857,13 +854,6 @@ func (c *filesystemsCollector) addDir(rfs *hugofs.RootMappingFs, componentFolder
857854
}
858855
}
859856

860-
func (c *filesystemsCollector) reverseFis(fis []hugofs.FileMetaInfo) {
861-
for i := len(fis)/2 - 1; i >= 0; i-- {
862-
opp := len(fis) - 1 - i
863-
fis[i], fis[opp] = fis[opp], fis[i]
864-
}
865-
}
866-
867857
type mountsDescriptor struct {
868858
modules.Module
869859
dir string

0 commit comments

Comments
 (0)