Skip to content

Commit aefc75a

Browse files
authored
chore: update go and tools (#537)
Update to the oldest supported release of go v1.22 at this time. Update golangci-lint to 1.61.0 and address all issues. Update actions to the latest versions.
1 parent a81d9a5 commit aefc75a

21 files changed

+58
-68
lines changed

.github/workflows/release-build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ jobs:
1111
runs-on: [ubuntu-latest]
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 0
1717
- name: Set up Go
18-
uses: actions/setup-go@v3
18+
uses: actions/setup-go@v5
1919
with:
20-
go-version: 1.19
20+
go-version: 1.23
2121
cache: true
2222
- name: Run GoReleaser
23-
uses: goreleaser/goreleaser-action@v3
23+
uses: goreleaser/goreleaser-action@v6
2424
with:
2525
# either 'goreleaser' (default) or 'goreleaser-pro'
2626
distribution: goreleaser

.github/workflows/test-lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
go-test-lint:
99
strategy:
1010
matrix:
11-
go: [1.21, 1.22]
12-
golangcli: [v1.57.2]
11+
go: [1.22, 1.23]
12+
golangcli: [v1.61.0]
1313
os: [ubuntu-latest]
1414
runs-on: ${{ matrix.os }}
1515
steps:

.golangci.yml

+11-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ linters-settings:
1515
rules:
1616
- name: var-naming
1717
disabled: true
18+
gosec:
19+
excludes:
20+
- G115 # Too many false positives.
1821

1922
linters:
2023
enable-all: true
@@ -23,14 +26,13 @@ linters:
2326
- lll
2427
- gochecknoglobals
2528
- gochecknoinits
26-
- scopelint
2729
- funlen
2830
- godox
29-
- exhaustivestruct
30-
- goerr113
31+
- err113
3132
- wsl
3233
- nlreturn
3334
- gomnd
35+
- mnd
3436
- paralleltest
3537
- wrapcheck
3638
- testpackage
@@ -44,20 +46,13 @@ linters:
4446
- maintidx
4547
- ireturn
4648
- exhaustruct
47-
- nosnakecase
4849
- dupword
49-
- structcheck
50-
- deadcode
51-
- golint
52-
- varcheck
53-
- ifshort
54-
- interfacer
55-
- maligned
5650
# Just causes noise
5751
- depguard
58-
# Go 1.22+ only
59-
- copyloopvar
60-
- intrange
52+
# Deprecated
53+
- execinquery
54+
# Not needed in go 1.22+
55+
- exportloopref
6156

6257
issues:
6358
exclude-use-default: false
@@ -73,4 +68,6 @@ issues:
7368
# Field alignment in tests isn't a performance issue.
7469
- text: fieldalignment
7570
path: _test\.go
71+
- text: Error return value of `fmt\.Fprint.*` is not checked
72+
path: tools/tester/main.go
7673

builtin_array.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func builtinArrayToLocaleString(call FunctionCall) Value {
4343
return stringValue("")
4444
}
4545
stringList := make([]string, 0, length)
46-
for index := int64(0); index < length; index++ {
46+
for index := range length {
4747
value := thisObject.get(arrayIndexToString(index))
4848
stringValue := ""
4949
switch value.kind {
@@ -71,7 +71,7 @@ func builtinArrayConcat(call FunctionCall) Value {
7171
obj := item.object()
7272
if isArray(obj) {
7373
length := obj.get(propertyLength).number().int64
74-
for index := int64(0); index < length; index++ {
74+
for index := range length {
7575
name := strconv.FormatInt(index, 10)
7676
if obj.hasProperty(name) {
7777
valueArray = append(valueArray, obj.get(name))
@@ -151,7 +151,7 @@ func builtinArrayJoin(call FunctionCall) Value {
151151
return stringValue("")
152152
}
153153
stringList := make([]string, 0, length)
154-
for index := int64(0); index < length; index++ {
154+
for index := range length {
155155
value := thisObject.get(arrayIndexToString(index))
156156
stringValue := ""
157157
switch value.kind {
@@ -175,7 +175,7 @@ func builtinArraySplice(call FunctionCall) Value {
175175
}
176176
valueArray := make([]Value, deleteCount)
177177

178-
for index := int64(0); index < deleteCount; index++ {
178+
for index := range deleteCount {
179179
indexString := arrayIndexToString(start + index)
180180
if thisObject.hasProperty(indexString) {
181181
valueArray[index] = thisObject.get(indexString)
@@ -236,7 +236,7 @@ func builtinArraySplice(call FunctionCall) Value {
236236
}
237237
}
238238

239-
for index := int64(0); index < itemCount; index++ {
239+
for index := range itemCount {
240240
thisObject.put(arrayIndexToString(index+start), itemList[index], true)
241241
}
242242
thisObject.put(propertyLength, int64Value(length+itemCount-deleteCount), true)
@@ -257,7 +257,7 @@ func builtinArraySlice(call FunctionCall) Value {
257257
sliceLength := end - start
258258
sliceValueArray := make([]Value, sliceLength)
259259

260-
for index := int64(0); index < sliceLength; index++ {
260+
for index := range sliceLength {
261261
from := arrayIndexToString(index + start)
262262
if thisObject.hasProperty(from) {
263263
sliceValueArray[index] = thisObject.get(from)
@@ -283,7 +283,7 @@ func builtinArrayUnshift(call FunctionCall) Value {
283283
}
284284
}
285285

286-
for index := int64(0); index < itemCount; index++ {
286+
for index := range itemCount {
287287
thisObject.put(arrayIndexToString(index), itemList[index], true)
288288
}
289289

@@ -531,7 +531,7 @@ func builtinArrayEvery(call FunctionCall) Value {
531531
if iterator := call.Argument(0); iterator.isCallable() {
532532
length := int64(toUint32(thisObject.get(propertyLength)))
533533
callThis := call.Argument(1)
534-
for index := int64(0); index < length; index++ {
534+
for index := range length {
535535
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
536536
if value := thisObject.get(key); iterator.call(call.runtime, callThis, value, int64Value(index), this).bool() {
537537
continue
@@ -550,7 +550,7 @@ func builtinArraySome(call FunctionCall) Value {
550550
if iterator := call.Argument(0); iterator.isCallable() {
551551
length := int64(toUint32(thisObject.get(propertyLength)))
552552
callThis := call.Argument(1)
553-
for index := int64(0); index < length; index++ {
553+
for index := range length {
554554
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
555555
if value := thisObject.get(key); iterator.call(call.runtime, callThis, value, int64Value(index), this).bool() {
556556
return trueValue
@@ -568,7 +568,7 @@ func builtinArrayForEach(call FunctionCall) Value {
568568
if iterator := call.Argument(0); iterator.isCallable() {
569569
length := int64(toUint32(thisObject.get(propertyLength)))
570570
callThis := call.Argument(1)
571-
for index := int64(0); index < length; index++ {
571+
for index := range length {
572572
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
573573
iterator.call(call.runtime, callThis, thisObject.get(key), int64Value(index), this)
574574
}
@@ -585,7 +585,7 @@ func builtinArrayMap(call FunctionCall) Value {
585585
length := int64(toUint32(thisObject.get(propertyLength)))
586586
callThis := call.Argument(1)
587587
values := make([]Value, length)
588-
for index := int64(0); index < length; index++ {
588+
for index := range length {
589589
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
590590
values[index] = iterator.call(call.runtime, callThis, thisObject.get(key), index, this)
591591
} else {
@@ -604,7 +604,7 @@ func builtinArrayFilter(call FunctionCall) Value {
604604
length := int64(toUint32(thisObject.get(propertyLength)))
605605
callThis := call.Argument(1)
606606
values := make([]Value, 0)
607-
for index := int64(0); index < length; index++ {
607+
for index := range length {
608608
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
609609
value := thisObject.get(key)
610610
if iterator.call(call.runtime, callThis, value, index, this).bool() {

builtin_date.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func builtinDateBeforeSet(call FunctionCall, argumentLimit int, timeLocal bool)
129129
}
130130

131131
valueList := make([]int, argumentLimit)
132-
for index := 0; index < argumentLimit; index++ {
132+
for index := range argumentLimit {
133133
value := call.ArgumentList[index]
134134
nm := value.number()
135135
switch nm.kind {

builtin_function.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func builtinFunctionApply(call FunctionCall) Value {
8585
thisObject := call.thisObject()
8686
length := int64(toUint32(arrayObject.get(propertyLength)))
8787
valueArray := make([]Value, length)
88-
for index := int64(0); index < length; index++ {
88+
for index := range length {
8989
valueArray[index] = arrayObject.get(arrayIndexToString(index))
9090
}
9191
return thisObject.call(this, valueArray, false, nativeFrame)

builtin_json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func builtinJSONReviveWalk(ctx builtinJSONParseContext, holder *object, name str
4444
if obj := value.object(); obj != nil {
4545
if isArray(obj) {
4646
length := int64(objectLength(obj))
47-
for index := int64(0); index < length; index++ {
47+
for index := range length {
4848
idxName := arrayIndexToString(index)
4949
idxValue := builtinJSONReviveWalk(ctx, obj, idxName)
5050
if idxValue.IsUndefined() {

builtin_string.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func builtinStringMatch(call FunctionCall) Value {
163163
}
164164
matchCount := len(result)
165165
valueArray := make([]Value, matchCount)
166-
for index := 0; index < matchCount; index++ {
166+
for index := range matchCount {
167167
valueArray[index] = stringValue(target[result[index][0]:result[index][1]])
168168
}
169169
matcher.put("lastIndex", intValue(result[matchCount-1][1]), true)
@@ -246,7 +246,7 @@ func builtinStringReplace(call FunctionCall) Value {
246246
}
247247
matchCount := len(match) / 2
248248
argumentList := make([]Value, matchCount+2)
249-
for index := 0; index < matchCount; index++ {
249+
for index := range matchCount {
250250
offset := 2 * index
251251
if match[offset] != -1 {
252252
argumentList[index] = stringValue(target[match[offset]:match[offset+1]])

console.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ func formatForConsole(argumentList []Value) string {
1515
}
1616

1717
func builtinConsoleLog(call FunctionCall) Value {
18-
fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList))
18+
fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList)) //nolint:errcheck // Nothing we can do if this fails.
1919
return Value{}
2020
}
2121

2222
func builtinConsoleError(call FunctionCall) Value {
23-
fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList))
23+
fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList)) //nolint:errcheck // Nothing we can do if this fails.
2424
return Value{}
2525
}
2626

error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func newError(rt *runtime, name string, stackFramesToPop int, in ...interface{})
148148
if rt != nil && rt.scope != nil {
149149
curScope := rt.scope
150150

151-
for i := 0; i < stackFramesToPop; i++ {
151+
for range stackFramesToPop {
152152
if curScope.outer != nil {
153153
curScope = curScope.outer
154154
}

functional_benchmark_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func benchmarkGoSliceSort(b *testing.B, size int, sortFuncCall string, sortCode
123123
b.Helper()
124124
// generate arbitrary slice of 'size'
125125
testSlice := make([]int, size)
126-
for i := 0; i < size; i++ {
126+
for i := range size {
127127
testSlice[i] = rand.Int() //nolint:gosec
128128
}
129129

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/robertkrimen/otto
22

3-
go 1.18
3+
go 1.22
44

55
require (
66
github.com/stretchr/testify v1.8.1

parser/lexer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (p *parser) scanIdentifier() (string, error) {
114114
}
115115
parse = true
116116
var value rune
117-
for j := 0; j < 4; j++ {
117+
for range 4 {
118118
p.read()
119119
decimal, ok := hex2decimal(byte(p.chr))
120120
if !ok {
@@ -764,7 +764,7 @@ func parseStringLiteral(literal string) (string, error) {
764764
if len(str) < size {
765765
return "", fmt.Errorf("invalid escape: \\%s: len(%q) != %d", string(chr), str, size)
766766
}
767-
for j := 0; j < size; j++ {
767+
for j := range size {
768768
decimal, ok := hex2decimal(str[j])
769769
if !ok {
770770
return "", fmt.Errorf("invalid escape: \\%s: %q", string(chr), str[:size])

parser/marshal_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func marshal(name string, children ...interface{}) interface{} {
2424
}
2525
ret := map[string]interface{}{}
2626
length := len(children) / 2
27-
for i := 0; i < length; i++ {
27+
for i := range length {
2828
name := children[i*2].(string)
2929
value := children[i*2+1]
3030
ret[name] = value
@@ -168,7 +168,7 @@ func testMarshalNode(node interface{}) interface{} {
168168
value := reflect.ValueOf(node)
169169
if value.Kind() == reflect.Slice {
170170
tmp0 := []interface{}{}
171-
for index := 0; index < value.Len(); index++ {
171+
for index := range value.Len() {
172172
tmp0 = append(tmp0, testMarshalNode(value.Index(index).Interface()))
173173
}
174174
return tmp0

runtime.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func fieldIndexByName(t reflect.Type, name string) []int {
293293
t = t.Elem()
294294
}
295295

296-
for i := 0; i < t.NumField(); i++ {
296+
for i := range t.NumField() {
297297
f := t.Field(i)
298298

299299
if !validGoStructName(f.Name) {
@@ -430,7 +430,7 @@ func (rt *runtime) convertCallParameter(v Value, t reflect.Type) (reflect.Value,
430430

431431
switch o.class {
432432
case classArrayName:
433-
for i := int64(0); i < l; i++ {
433+
for i := range l {
434434
p, ok := o.property[strconv.FormatInt(i, 10)]
435435
if !ok {
436436
continue
@@ -457,7 +457,7 @@ func (rt *runtime) convertCallParameter(v Value, t reflect.Type) (reflect.Value,
457457
gslice = false
458458
}
459459

460-
for i := int64(0); i < l; i++ {
460+
for i := range l {
461461
var p *property
462462
if gslice {
463463
p = goSliceGetOwnProperty(o, strconv.FormatInt(i, 10))
@@ -601,7 +601,7 @@ func (rt *runtime) convertCallParameter(v Value, t reflect.Type) (reflect.Value,
601601
if v.kind == valueString {
602602
var s encoding.TextUnmarshaler
603603

604-
if reflect.PtrTo(t).Implements(reflect.TypeOf(&s).Elem()) {
604+
if reflect.PointerTo(t).Implements(reflect.TypeOf(&s).Elem()) {
605605
r := reflect.New(t)
606606

607607
if err := r.Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(v.string())); err != nil {

tools/tester/main.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ var broken = map[string]string{
6767
"sendbird-calls.js": "runtime: out of memory",
6868
}
6969

70-
func min(a, b int) int {
71-
if a > b {
72-
return b
73-
}
74-
return a
75-
}
76-
7770
// libraries represents fetch all libraries response.
7871
type libraries struct {
7972
Results []library `json:"results"`
@@ -203,7 +196,7 @@ func fetchAll(src string) error {
203196
work := make(chan library, downloadWorkers)
204197
errs := make(chan error, len(libs.Results))
205198
wg.Add(downloadWorkers)
206-
for i := 0; i < downloadWorkers; i++ {
199+
for range downloadWorkers {
207200
go func() {
208201
defer wg.Done()
209202
for lib := range work {
@@ -261,7 +254,7 @@ func report(files []string) error {
261254
work := make(chan string, workers)
262255
results := make(chan result, len(files))
263256
wg.Add(workers)
264-
for i := 0; i < workers; i++ {
257+
for range workers {
265258
go func() {
266259
defer wg.Done()
267260
for f := range work {

0 commit comments

Comments
 (0)