Remove deprecations <= v0.122.0 (note)

These have, once we release this, been logging ERROR for 6 minor versions.
This commit is contained in:
Bjørn Erik Pedersen
2024-11-16 17:58:06 +01:00
parent f7fc6ccd59
commit ad43d137d5
16 changed files with 7 additions and 287 deletions

View File

@@ -26,7 +26,6 @@ import (
"time"
"github.com/gohugoio/hugo/common/collections"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/deps"
@@ -189,54 +188,6 @@ func (ns *Namespace) Dictionary(values ...any) (map[string]any, error) {
return root, nil
}
// EchoParam returns the value in the collection c with key k if is set; otherwise, it returns an
// empty string.
// Deprecated: Use the index function instead.
func (ns *Namespace) EchoParam(c, k any) any {
hugo.Deprecate("collections.EchoParam", "Use the index function instead.", "v0.120.0")
av, isNil := indirect(reflect.ValueOf(c))
if isNil {
return ""
}
var avv reflect.Value
switch av.Kind() {
case reflect.Array, reflect.Slice:
index, ok := k.(int)
if ok && av.Len() > index {
avv = av.Index(index)
}
case reflect.Map:
kv := reflect.ValueOf(k)
if kv.Type().AssignableTo(av.Type().Key()) {
avv = av.MapIndex(kv)
}
}
avv, isNil = indirect(avv)
if isNil {
return ""
}
if avv.IsValid() {
switch avv.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return avv.Int()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return avv.Uint()
case reflect.Float32, reflect.Float64:
return avv.Float()
case reflect.String:
return avv.String()
case reflect.Bool:
return avv.Bool()
}
}
return ""
}
// First returns the first limit items in list l.
func (ns *Namespace) First(limit any, l any) (any, error) {
if limit == nil || l == nil {

View File

@@ -232,39 +232,6 @@ func TestReverse(t *testing.T) {
c.Assert(err, qt.Not(qt.IsNil))
}
func TestEchoParam(t *testing.T) {
t.Skip("deprecated, will be removed in Hugo 0.133.0")
t.Parallel()
c := qt.New(t)
ns := newNs()
for i, test := range []struct {
a any
key any
expect any
}{
{[]int{1, 2, 3}, 1, int64(2)},
{[]uint{1, 2, 3}, 1, uint64(2)},
{[]float64{1.1, 2.2, 3.3}, 1, float64(2.2)},
{[]string{"foo", "bar", "baz"}, 1, "bar"},
{[]TstX{{A: "a", B: "b"}, {A: "c", B: "d"}, {A: "e", B: "f"}}, 1, ""},
{map[string]int{"foo": 1, "bar": 2, "baz": 3}, "bar", int64(2)},
{map[string]uint{"foo": 1, "bar": 2, "baz": 3}, "bar", uint64(2)},
{map[string]float64{"foo": 1.1, "bar": 2.2, "baz": 3.3}, "bar", float64(2.2)},
{map[string]string{"foo": "FOO", "bar": "BAR", "baz": "BAZ"}, "bar", "BAR"},
{map[string]TstX{"foo": {A: "a", B: "b"}, "bar": {A: "c", B: "d"}, "baz": {A: "e", B: "f"}}, "bar", ""},
{map[string]any{"foo": nil}, "foo", ""},
{(*[]string)(nil), "bar", ""},
} {
errMsg := qt.Commentf("[%d] %v", i, test)
result := ns.EchoParam(test.a, test.key)
c.Assert(result, qt.Equals, test.expect, errMsg)
}
}
func TestFirst(t *testing.T) {
t.Parallel()
c := qt.New(t)

View File

@@ -67,11 +67,6 @@ func init() {
[][2]string{},
)
ns.AddMethodMapping(ctx.EchoParam,
[]string{"echoParam"},
[][2]string{},
)
ns.AddMethodMapping(ctx.First,
[]string{"first"},
[][2]string{},

View File

@@ -26,7 +26,6 @@ import (
translators "github.com/gohugoio/localescompressed"
"github.com/gohugoio/hugo/common/hreflect"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/deps"
"github.com/spf13/cast"
)
@@ -240,12 +239,6 @@ func (ns *Namespace) FormatNumberCustom(precision, number any, options ...any) (
return string(b), nil
}
// Deprecated: Use lang.FormatNumberCustom instead.
func (ns *Namespace) NumFmt(precision, number any, options ...any) (string, error) {
hugo.Deprecate("lang.NumFmt", "Use lang.FormatNumberCustom instead.", "v0.120.0")
return ns.FormatNumberCustom(precision, number, options...)
}
type pagesLanguageMerger interface {
MergeByLanguageInterface(other any) (any, error)
}