Skip to content

Commit cc7bda4

Browse files
authored
Merge pull request #95 from osteele/modernize
Modernize
2 parents 0f5b61d + eabfe53 commit cc7bda4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+532
-455
lines changed

.golangci.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,46 @@ issues:
66

77
# go generate introduces these
88
- path: expressions/scanner.go
9-
linters: [deadcode, unused, varcheck]
9+
linters: [deadcode, unused, varcheck, revive, stylecheck, gocritic, unconvert, gofumpt]
1010
linters:
11-
enable:
12-
- gofmt
11+
enable-all: true
12+
disable:
13+
- depguard
14+
- exhaustruct
15+
- varnamelen
16+
- godox
17+
- wsl
18+
- wrapcheck
19+
- gomnd
20+
- gochecknoglobals
21+
- exhaustive
22+
- testpackage
23+
- ireturn
24+
- godot
25+
- mnd
26+
- nonamedreturns
27+
- funlen
28+
- gci
29+
- nlreturn
30+
- inamedparam
31+
- lll
32+
- paralleltest
33+
- gocognit
34+
- goconst
35+
- cyclop
36+
- dupword
37+
- whitespace
38+
- nolintlint
39+
- nestif
40+
- forcetypeassert
41+
- interfacebloat
42+
- revive
43+
- gocyclo
44+
- errname
45+
- gosmopolitan
46+
- maintidx
47+
48+
# Todo: re-add
49+
- err113
50+
- errorlint
51+
fix: true

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Contributions:
115115

116116
* Fix array[nil] ([e39a1fe](https://github.com/osteele/liquid/commit/e39a1fe))
117117
* Fix file not found tests for Windows ([068afef](https://github.com/osteele/liquid/commit/068afef))
118-
* Restore m['str'] where m map[interface{}]interface{}
118+
* Restore m['str'] where m map[any]any
119119
([9852226](https://github.com/osteele/liquid/commit/9852226))
120120

121121
### Docs

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ generator.
4343
```go
4444
engine := liquid.NewEngine()
4545
template := `<h1>{{ page.title }}</h1>`
46-
bindings := map[string]interface{}{
46+
bindings := map[string]any{
4747
"page": map[string]string{
4848
"title": "Introduction",
4949
},
@@ -84,15 +84,15 @@ These features of Shopify Liquid aren't implemented:
8484

8585
Drops have a different design from the Shopify (Ruby) implementation. A Ruby
8686
drop sets `liquid_attributes` to a list of attributes that are exposed to
87-
Liquid. A Go drop implements `ToLiquid() interface{}`, that returns a proxy
87+
Liquid. A Go drop implements `ToLiquid() any`, that returns a proxy
8888
object. Conventionally, the proxy is a `map` or `struct` that defines the
8989
exposed properties. See <http://godoc.org/github.com/osteele/liquid#Drop> for
9090
additional information.
9191

9292
### Value Types
9393

9494
`Render` and friends take a `Bindings` parameter. This is a map of `string` to
95-
`interface{}`, that associates template variable names with Go values.
95+
`any`, that associates template variable names with Go values.
9696

9797
Any Go value can be used as a variable value. These values have special meaning:
9898

cmd/liquid/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121

2222
// for testing
2323
var (
24-
stderr io.Writer = os.Stderr
25-
stdout io.Writer = os.Stdout
26-
stdin io.Reader = os.Stdin
27-
exit func(int) = os.Exit
28-
env func() []string = os.Environ
29-
bindings map[string]interface{} = map[string]interface{}{}
24+
stderr io.Writer = os.Stderr
25+
stdout io.Writer = os.Stdout
26+
stdin io.Reader = os.Stdin
27+
exit func(int) = os.Exit
28+
env func() []string = os.Environ
29+
bindings map[string]any = map[string]any{}
3030
strictVars bool
3131
)
3232

cmd/liquid/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestMain(t *testing.T) {
1818
stdin = os.Stdin
1919
exit = os.Exit
2020
env = os.Environ
21-
bindings = map[string]interface{}{}
21+
bindings = map[string]any{}
2222
}()
2323

2424
exit = func(n int) {
@@ -58,7 +58,7 @@ func TestMain(t *testing.T) {
5858
main()
5959
require.True(t, envCalled)
6060
require.Equal(t, "Hello, World!", buf.String())
61-
bindings = make(map[string]interface{})
61+
bindings = make(map[string]any)
6262

6363
// filename
6464
stdin = os.Stdin

drops.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package liquid
22

33
// Drop indicates that the object will present to templates as its ToLiquid value.
44
type Drop interface {
5-
ToLiquid() interface{}
5+
ToLiquid() any
66
}
77

88
// FromDrop returns returns object.ToLiquid() if object's type implement this function;
99
// else the object itself.
10-
func FromDrop(object interface{}) interface{} {
10+
func FromDrop(object any) any {
1111
switch object := object.(type) {
1212
case Drop:
1313
return object.ToLiquid()

drops_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
type dropTest struct{}
1212

13-
func (d dropTest) ToLiquid() interface{} { return "drop" }
13+
func (d dropTest) ToLiquid() any { return "drop" }
1414

1515
func TestDrops(t *testing.T) {
1616
require.Equal(t, "drop", FromDrop(dropTest{}))
@@ -20,22 +20,22 @@ func TestDrops(t *testing.T) {
2020

2121
type redConvertible struct{}
2222

23-
func (c redConvertible) ToLiquid() interface{} {
24-
return map[string]interface{}{
23+
func (c redConvertible) ToLiquid() any {
24+
return map[string]any{
2525
"color": "red",
2626
}
2727
}
2828

2929
func ExampleDrop_map() {
3030
// type redConvertible struct{}
3131
//
32-
// func (c redConvertible) ToLiquid() interface{} {
33-
// return map[string]interface{}{
32+
// func (c redConvertible) ToLiquid() any {
33+
// return map[string]any{
3434
// "color": "red",
3535
// }
3636
// }
3737
engine := NewEngine()
38-
bindings := map[string]interface{}{
38+
bindings := map[string]any{
3939
"car": redConvertible{},
4040
}
4141
template := `{{ car.color }}`
@@ -49,7 +49,7 @@ func ExampleDrop_map() {
4949

5050
type car struct{ color, model string }
5151

52-
func (c car) ToLiquid() interface{} {
52+
func (c car) ToLiquid() any {
5353
return carDrop{c.model, c.color}
5454
}
5555

@@ -65,7 +65,7 @@ func (c carDrop) Drive() string {
6565
func ExampleDrop_struct() {
6666
// type car struct{ color, model string }
6767
//
68-
// func (c car) ToLiquid() interface{} {
68+
// func (c car) ToLiquid() any {
6969
// return carDrop{c.model, c.color}
7070
// }
7171
//
@@ -79,7 +79,7 @@ func ExampleDrop_struct() {
7979
// }
8080

8181
engine := NewEngine()
82-
bindings := map[string]interface{}{
82+
bindings := map[string]any{
8383
"car": car{"blue", "S85"},
8484
}
8585
template := `{{ car.color }} {{ car.Drive }} Model {{ car.Model }}`

engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (e *Engine) RegisterBlock(name string, td Renderer) {
4343
// * https://github.com/osteele/liquid/blob/main/filters/standard_filters.go
4444
//
4545
// * https://github.com/osteele/gojekyll/blob/master/filters/filters.go
46-
func (e *Engine) RegisterFilter(name string, fn interface{}) {
46+
func (e *Engine) RegisterFilter(name string, fn any) {
4747
e.cfg.AddFilter(name, fn)
4848
}
4949

engine_examples_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package liquid
33
import (
44
"fmt"
55
"log"
6+
"strconv"
67
"strings"
78

89
"github.com/osteele/liquid/render"
@@ -11,7 +12,7 @@ import (
1112
func Example() {
1213
engine := NewEngine()
1314
source := `<h1>{{ page.title }}</h1>`
14-
bindings := map[string]interface{}{
15+
bindings := map[string]any{
1516
"page": map[string]string{
1617
"title": "Introduction",
1718
},
@@ -27,18 +28,19 @@ func Example() {
2728
func ExampleEngine_ParseAndRenderString() {
2829
engine := NewEngine()
2930
source := `{{ hello | capitalize | append: " Mundo" }}`
30-
bindings := map[string]interface{}{"hello": "hola"}
31+
bindings := map[string]any{"hello": "hola"}
3132
out, err := engine.ParseAndRenderString(source, bindings)
3233
if err != nil {
3334
log.Fatalln(err)
3435
}
3536
fmt.Println(out)
3637
// Output: Hola Mundo
3738
}
39+
3840
func ExampleEngine_ParseTemplate() {
3941
engine := NewEngine()
4042
source := `{{ hello | capitalize | append: " Mundo" }}`
41-
bindings := map[string]interface{}{"hello": "hola"}
43+
bindings := map[string]any{"hello": "hola"}
4244
tpl, err := engine.ParseString(source)
4345
if err != nil {
4446
log.Fatalln(err)
@@ -50,11 +52,12 @@ func ExampleEngine_ParseTemplate() {
5052
fmt.Println(out)
5153
// Output: Hola Mundo
5254
}
55+
5356
func ExampleEngine_RegisterFilter() {
5457
engine := NewEngine()
5558
engine.RegisterFilter("has_prefix", strings.HasPrefix)
5659
template := `{{ title | has_prefix: "Intro" }}`
57-
bindings := map[string]interface{}{
60+
bindings := map[string]any{
5861
"title": "Introduction",
5962
}
6063
out, err := engine.ParseAndRenderString(template, bindings)
@@ -64,6 +67,7 @@ func ExampleEngine_RegisterFilter() {
6467
fmt.Println(out)
6568
// Output: true
6669
}
70+
6771
func ExampleEngine_RegisterFilter_optional_argument() {
6872
engine := NewEngine()
6973
// func(a, b int) int) would default the second argument to zero.
@@ -74,7 +78,7 @@ func ExampleEngine_RegisterFilter_optional_argument() {
7478
return a + b(1)
7579
})
7680
template := `10 + 1 = {{ m | inc }}; 20 + 5 = {{ n | inc: 5 }}`
77-
bindings := map[string]interface{}{
81+
bindings := map[string]any{
7882
"m": 10,
7983
"n": "20",
8084
}
@@ -108,7 +112,7 @@ func ExampleEngine_RegisterBlock() {
108112
return "", err
109113
}
110114
n := len(s)
111-
return fmt.Sprint(n), nil
115+
return strconv.Itoa(n), nil
112116
})
113117

114118
template := `{% length %}abc{% endlength %}`

engine_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package liquid
33
import (
44
"bytes"
55
"encoding/json"
6-
"fmt"
76
"io"
7+
"strconv"
88
"strings"
99
"testing"
1010

1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
var emptyBindings = map[string]interface{}{}
14+
var emptyBindings = map[string]any{}
1515

1616
// There's a lot more tests in the filters and tags sub-packages.
1717
// This collects a minimal set for testing end-to-end.
@@ -21,18 +21,18 @@ var liquidTests = []struct{ in, expected string }{
2121
{`{{ "upper" | upcase }}`, "UPPER"},
2222
}
2323

24-
var testBindings = map[string]interface{}{
24+
var testBindings = map[string]any{
2525
"x": 123,
2626
"ar": []string{"first", "second", "third"},
27-
"page": map[string]interface{}{
27+
"page": map[string]any{
2828
"title": "Introduction",
2929
},
3030
}
3131

3232
func TestEngine_ParseAndRenderString(t *testing.T) {
3333
engine := NewEngine()
3434
for i, test := range liquidTests {
35-
t.Run(fmt.Sprint(i+1), func(t *testing.T) {
35+
t.Run(strconv.Itoa(i+1), func(t *testing.T) {
3636
out, err := engine.ParseAndRenderString(test.in, testBindings)
3737
require.NoErrorf(t, err, test.in)
3838
require.Equalf(t, test.expected, out, test.in)
@@ -51,7 +51,7 @@ func (c *capWriter) Write(bs []byte) (int, error) {
5151
func TestEngine_ParseAndFRender(t *testing.T) {
5252
engine := NewEngine()
5353
for i, test := range liquidTests {
54-
t.Run(fmt.Sprint(i+1), func(t *testing.T) {
54+
t.Run(strconv.Itoa(i+1), func(t *testing.T) {
5555
wr := capWriter{}
5656
err := engine.ParseAndFRender(&wr, []byte(test.in), testBindings)
5757
require.NoErrorf(t, err, test.in)
@@ -61,8 +61,8 @@ func TestEngine_ParseAndFRender(t *testing.T) {
6161
}
6262

6363
func TestEngine_ParseAndRenderString_ptr_to_hash(t *testing.T) {
64-
params := map[string]interface{}{
65-
"message": &map[string]interface{}{
64+
params := map[string]any{
65+
"message": &map[string]any{
6666
"Text": "hello",
6767
"jsonNumber": json.Number("123"),
6868
},
@@ -77,7 +77,7 @@ func TestEngine_ParseAndRenderString_ptr_to_hash(t *testing.T) {
7777
type testStruct struct{ Text string }
7878

7979
func TestEngine_ParseAndRenderString_struct(t *testing.T) {
80-
params := map[string]interface{}{
80+
params := map[string]any{
8181
"message": testStruct{
8282
Text: "hello",
8383
},
@@ -103,7 +103,7 @@ func TestEngine_ParseAndRender_errors(t *testing.T) {
103103
func BenchmarkEngine_Parse(b *testing.B) {
104104
engine := NewEngine()
105105
buf := new(bytes.Buffer)
106-
for i := 0; i < 1000; i++ {
106+
for range 1000 {
107107
_, err := io.WriteString(buf, `if{% if true %}true{% elsif %}elsif{% else %}else{% endif %}`)
108108
require.NoError(b, err)
109109
_, err = io.WriteString(buf, `loop{% for item in array %}loop{% break %}{% endfor %}`)
@@ -115,7 +115,7 @@ func BenchmarkEngine_Parse(b *testing.B) {
115115
}
116116
s := buf.Bytes()
117117
b.ResetTimer()
118-
for i := 0; i < b.N; i++ {
118+
for range b.N {
119119
_, err := engine.ParseTemplate(s)
120120
require.NoError(b, err)
121121
}
@@ -134,5 +134,5 @@ func TestEngine_ParseTemplateAndCache(t *testing.T) {
134134
// ...and execute the second.
135135
result, err := eng.ParseAndRender(templateB, Bindings{})
136136
require.NoError(t, err)
137-
require.Equal(t, string(result), "Foo, Bar")
137+
require.Equal(t, "Foo, Bar", string(result))
138138
}

0 commit comments

Comments
 (0)