Skip to content

Commit

Permalink
chore: update go and tools
Browse files Browse the repository at this point in the history
Update to the oldest supported release of go v1.22 as this time.

Update golangci-lint to 1.61.0 and address all issues.

Update actions to the latest versions.
  • Loading branch information
stevenh committed Nov 3, 2024
1 parent a81d9a5 commit 2a2320b
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 68 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version: 1.23
cache: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
go-test-lint:
strategy:
matrix:
go: [1.21, 1.22]
golangcli: [v1.57.2]
go: [1.22, 1.23]
golangcli: [v1.61.0]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
25 changes: 11 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ linters-settings:
rules:
- name: var-naming
disabled: true
gosec:
excludes:
- G115 # Too many false positives.

linters:
enable-all: true
Expand All @@ -23,14 +26,13 @@ linters:
- lll
- gochecknoglobals
- gochecknoinits
- scopelint
- funlen
- godox
- exhaustivestruct
- goerr113
- err113
- wsl
- nlreturn
- gomnd
- mnd
- paralleltest
- wrapcheck
- testpackage
Expand All @@ -44,20 +46,13 @@ linters:
- maintidx
- ireturn
- exhaustruct
- nosnakecase
- dupword
- structcheck
- deadcode
- golint
- varcheck
- ifshort
- interfacer
- maligned
# Just causes noise
- depguard
# Go 1.22+ only
- copyloopvar
- intrange
# Deprecated
- execinquery
# Not needed in go 1.22+
- exportloopref

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

24 changes: 12 additions & 12 deletions builtin_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func builtinArrayToLocaleString(call FunctionCall) Value {
return stringValue("")
}
stringList := make([]string, 0, length)
for index := int64(0); index < length; index++ {
for index := range length {
value := thisObject.get(arrayIndexToString(index))
stringValue := ""
switch value.kind {
Expand Down Expand Up @@ -71,7 +71,7 @@ func builtinArrayConcat(call FunctionCall) Value {
obj := item.object()
if isArray(obj) {
length := obj.get(propertyLength).number().int64
for index := int64(0); index < length; index++ {
for index := range length {
name := strconv.FormatInt(index, 10)
if obj.hasProperty(name) {
valueArray = append(valueArray, obj.get(name))
Expand Down Expand Up @@ -151,7 +151,7 @@ func builtinArrayJoin(call FunctionCall) Value {
return stringValue("")
}
stringList := make([]string, 0, length)
for index := int64(0); index < length; index++ {
for index := range length {
value := thisObject.get(arrayIndexToString(index))
stringValue := ""
switch value.kind {
Expand All @@ -175,7 +175,7 @@ func builtinArraySplice(call FunctionCall) Value {
}
valueArray := make([]Value, deleteCount)

for index := int64(0); index < deleteCount; index++ {
for index := range deleteCount {
indexString := arrayIndexToString(start + index)
if thisObject.hasProperty(indexString) {
valueArray[index] = thisObject.get(indexString)
Expand Down Expand Up @@ -236,7 +236,7 @@ func builtinArraySplice(call FunctionCall) Value {
}
}

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

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

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

Expand Down Expand Up @@ -531,7 +531,7 @@ func builtinArrayEvery(call FunctionCall) Value {
if iterator := call.Argument(0); iterator.isCallable() {
length := int64(toUint32(thisObject.get(propertyLength)))
callThis := call.Argument(1)
for index := int64(0); index < length; index++ {
for index := range length {
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
if value := thisObject.get(key); iterator.call(call.runtime, callThis, value, int64Value(index), this).bool() {
continue
Expand All @@ -550,7 +550,7 @@ func builtinArraySome(call FunctionCall) Value {
if iterator := call.Argument(0); iterator.isCallable() {
length := int64(toUint32(thisObject.get(propertyLength)))
callThis := call.Argument(1)
for index := int64(0); index < length; index++ {
for index := range length {
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
if value := thisObject.get(key); iterator.call(call.runtime, callThis, value, int64Value(index), this).bool() {
return trueValue
Expand All @@ -568,7 +568,7 @@ func builtinArrayForEach(call FunctionCall) Value {
if iterator := call.Argument(0); iterator.isCallable() {
length := int64(toUint32(thisObject.get(propertyLength)))
callThis := call.Argument(1)
for index := int64(0); index < length; index++ {
for index := range length {
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
iterator.call(call.runtime, callThis, thisObject.get(key), int64Value(index), this)
}
Expand All @@ -585,7 +585,7 @@ func builtinArrayMap(call FunctionCall) Value {
length := int64(toUint32(thisObject.get(propertyLength)))
callThis := call.Argument(1)
values := make([]Value, length)
for index := int64(0); index < length; index++ {
for index := range length {
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
values[index] = iterator.call(call.runtime, callThis, thisObject.get(key), index, this)
} else {
Expand All @@ -604,7 +604,7 @@ func builtinArrayFilter(call FunctionCall) Value {
length := int64(toUint32(thisObject.get(propertyLength)))
callThis := call.Argument(1)
values := make([]Value, 0)
for index := int64(0); index < length; index++ {
for index := range length {
if key := arrayIndexToString(index); thisObject.hasProperty(key) {
value := thisObject.get(key)
if iterator.call(call.runtime, callThis, value, index, this).bool() {
Expand Down
2 changes: 1 addition & 1 deletion builtin_date.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func builtinDateBeforeSet(call FunctionCall, argumentLimit int, timeLocal bool)
}

valueList := make([]int, argumentLimit)
for index := 0; index < argumentLimit; index++ {
for index := range argumentLimit {
value := call.ArgumentList[index]
nm := value.number()
switch nm.kind {
Expand Down
2 changes: 1 addition & 1 deletion builtin_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func builtinFunctionApply(call FunctionCall) Value {
thisObject := call.thisObject()
length := int64(toUint32(arrayObject.get(propertyLength)))
valueArray := make([]Value, length)
for index := int64(0); index < length; index++ {
for index := range length {
valueArray[index] = arrayObject.get(arrayIndexToString(index))
}
return thisObject.call(this, valueArray, false, nativeFrame)
Expand Down
2 changes: 1 addition & 1 deletion builtin_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func builtinJSONReviveWalk(ctx builtinJSONParseContext, holder *object, name str
if obj := value.object(); obj != nil {
if isArray(obj) {
length := int64(objectLength(obj))
for index := int64(0); index < length; index++ {
for index := range length {
idxName := arrayIndexToString(index)
idxValue := builtinJSONReviveWalk(ctx, obj, idxName)
if idxValue.IsUndefined() {
Expand Down
4 changes: 2 additions & 2 deletions builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func builtinStringMatch(call FunctionCall) Value {
}
matchCount := len(result)
valueArray := make([]Value, matchCount)
for index := 0; index < matchCount; index++ {
for index := range matchCount {
valueArray[index] = stringValue(target[result[index][0]:result[index][1]])
}
matcher.put("lastIndex", intValue(result[matchCount-1][1]), true)
Expand Down Expand Up @@ -246,7 +246,7 @@ func builtinStringReplace(call FunctionCall) Value {
}
matchCount := len(match) / 2
argumentList := make([]Value, matchCount+2)
for index := 0; index < matchCount; index++ {
for index := range matchCount {
offset := 2 * index
if match[offset] != -1 {
argumentList[index] = stringValue(target[match[offset]:match[offset+1]])
Expand Down
4 changes: 2 additions & 2 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func formatForConsole(argumentList []Value) string {
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func newError(rt *runtime, name string, stackFramesToPop int, in ...interface{})
if rt != nil && rt.scope != nil {
curScope := rt.scope

for i := 0; i < stackFramesToPop; i++ {
for range stackFramesToPop {
if curScope.outer != nil {
curScope = curScope.outer
}
Expand Down
2 changes: 1 addition & 1 deletion functional_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func benchmarkGoSliceSort(b *testing.B, size int, sortFuncCall string, sortCode
b.Helper()
// generate arbitrary slice of 'size'
testSlice := make([]int, size)
for i := 0; i < size; i++ {
for i := range size {
testSlice[i] = rand.Int() //nolint:gosec
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/robertkrimen/otto

go 1.18
go 1.22

require (
github.com/stretchr/testify v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (p *parser) scanIdentifier() (string, error) {
}
parse = true
var value rune
for j := 0; j < 4; j++ {
for range 4 {
p.read()
decimal, ok := hex2decimal(byte(p.chr))
if !ok {
Expand Down Expand Up @@ -764,7 +764,7 @@ func parseStringLiteral(literal string) (string, error) {
if len(str) < size {
return "", fmt.Errorf("invalid escape: \\%s: len(%q) != %d", string(chr), str, size)
}
for j := 0; j < size; j++ {
for j := range size {
decimal, ok := hex2decimal(str[j])
if !ok {
return "", fmt.Errorf("invalid escape: \\%s: %q", string(chr), str[:size])
Expand Down
4 changes: 2 additions & 2 deletions parser/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func marshal(name string, children ...interface{}) interface{} {
}
ret := map[string]interface{}{}
length := len(children) / 2
for i := 0; i < length; i++ {
for i := range length {
name := children[i*2].(string)
value := children[i*2+1]
ret[name] = value
Expand Down Expand Up @@ -168,7 +168,7 @@ func testMarshalNode(node interface{}) interface{} {
value := reflect.ValueOf(node)
if value.Kind() == reflect.Slice {
tmp0 := []interface{}{}
for index := 0; index < value.Len(); index++ {
for index := range value.Len() {
tmp0 = append(tmp0, testMarshalNode(value.Index(index).Interface()))
}
return tmp0
Expand Down
8 changes: 4 additions & 4 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func fieldIndexByName(t reflect.Type, name string) []int {
t = t.Elem()
}

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

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

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

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

if reflect.PtrTo(t).Implements(reflect.TypeOf(&s).Elem()) {
if reflect.PointerTo(t).Implements(reflect.TypeOf(&s).Elem()) {
r := reflect.New(t)

if err := r.Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(v.string())); err != nil {
Expand Down
11 changes: 2 additions & 9 deletions tools/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ var broken = map[string]string{
"sendbird-calls.js": "runtime: out of memory",
}

func min(a, b int) int {
if a > b {
return b
}
return a
}

// libraries represents fetch all libraries response.
type libraries struct {
Results []library `json:"results"`
Expand Down Expand Up @@ -203,7 +196,7 @@ func fetchAll(src string) error {
work := make(chan library, downloadWorkers)
errs := make(chan error, len(libs.Results))
wg.Add(downloadWorkers)
for i := 0; i < downloadWorkers; i++ {
for range downloadWorkers {
go func() {
defer wg.Done()
for lib := range work {
Expand Down Expand Up @@ -261,7 +254,7 @@ func report(files []string) error {
work := make(chan string, workers)
results := make(chan result, len(files))
wg.Add(workers)
for i := 0; i < workers; i++ {
for range workers {
go func() {
defer wg.Done()
for f := range work {
Expand Down
Loading

0 comments on commit 2a2320b

Please sign in to comment.