Skip to content

Commit

Permalink
ci: fix lint failures (#502)
Browse files Browse the repository at this point in the history
Fix lint failures introduced by new 1.53 linters
* Remove naked returns
* Accept times using local time where intended
* Allow unused parameter for now on call method
* Disable depguard which just seems to be noise

Also:
* Correct typo so we use the specified golangci-lint version in CI.
  • Loading branch information
stevenh authored Jul 16, 2023
1 parent fc4074c commit ea8bcc3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
go: [1.19, 1.18]
golangcli: [v1.50.1]
golangcli: [v1.53.3]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Go Lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ matrix.golangci }}
version: ${{ matrix.golangcli }}
args: "--out-${NO_FUTURE}format colored-line-number"
skip-pkg-cache: true
skip-build-cache: true
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ linters:
- ifshort
- interfacer
- maligned
# Just causes noise
- depguard

issues:
exclude-use-default: false
Expand Down
50 changes: 25 additions & 25 deletions builtin_date.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,56 @@ package otto

import (
"math"
Time "time"
"time"
)

// Date

const (
// TODO Be like V8?
// builtinDateDateTimeLayout = "Mon Jan 2 2006 15:04:05 GMT-0700 (MST)".
builtinDateDateTimeLayout = Time.RFC1123 // "Mon, 02 Jan 2006 15:04:05 MST"
builtinDateDateTimeLayout = time.RFC1123 // "Mon, 02 Jan 2006 15:04:05 MST"
builtinDateDateLayout = "Mon, 02 Jan 2006"
builtinDateTimeLayout = "15:04:05 MST"
)

// utcTimeZone is the time zone used for UTC calculations.
// It is GMT not UTC as that's what Javascript does because toUTCString is
// actually an alias to toGMTString.
var utcTimeZone = Time.FixedZone("GMT", 0)
var utcTimeZone = time.FixedZone("GMT", 0)

func builtinDate(call FunctionCall) Value {
date := &dateObject{}
date.Set(newDateTime([]Value{}, Time.Local))
date.Set(newDateTime([]Value{}, time.Local)) //nolint: gosmopolitan
return stringValue(date.Time().Format(builtinDateDateTimeLayout))
}

func builtinNewDate(obj *object, argumentList []Value) Value {
return objectValue(obj.runtime.newDate(newDateTime(argumentList, Time.Local)))
return objectValue(obj.runtime.newDate(newDateTime(argumentList, time.Local))) //nolint: gosmopolitan
}

func builtinDateToString(call FunctionCall) Value {
date := dateObjectOf(call.runtime, call.thisObject())
if date.isNaN {
return stringValue("Invalid Date")
}
return stringValue(date.Time().Local().Format(builtinDateDateTimeLayout))
return stringValue(date.Time().Local().Format(builtinDateDateTimeLayout)) //nolint: gosmopolitan
}

func builtinDateToDateString(call FunctionCall) Value {
date := dateObjectOf(call.runtime, call.thisObject())
if date.isNaN {
return stringValue("Invalid Date")
}
return stringValue(date.Time().Local().Format(builtinDateDateLayout))
return stringValue(date.Time().Local().Format(builtinDateDateLayout)) //nolint: gosmopolitan
}

func builtinDateToTimeString(call FunctionCall) Value {
date := dateObjectOf(call.runtime, call.thisObject())
if date.isNaN {
return stringValue("Invalid Date")
}
return stringValue(date.Time().Local().Format(builtinDateTimeLayout))
return stringValue(date.Time().Local().Format(builtinDateTimeLayout)) //nolint: gosmopolitan
}

func builtinDateToUTCString(call FunctionCall) Value {
Expand Down Expand Up @@ -142,7 +142,7 @@ func builtinDateBeforeSet(call FunctionCall, argumentLimit int, timeLocal bool)
}
baseTime := date.Time()
if timeLocal {
baseTime = baseTime.Local()
baseTime = baseTime.Local() //nolint: gosmopolitan
}
ecmaTime := newEcmaTime(baseTime)
return obj, &date, &ecmaTime, valueList
Expand All @@ -154,7 +154,7 @@ func builtinDateParse(call FunctionCall) Value {
}

func builtinDateUTC(call FunctionCall) Value {
return float64Value(newDateTime(call.ArgumentList, Time.UTC))
return float64Value(newDateTime(call.ArgumentList, time.UTC))
}

func builtinDateNow(call FunctionCall) Value {
Expand All @@ -168,7 +168,7 @@ func builtinDateToLocaleString(call FunctionCall) Value {
if date.isNaN {
return stringValue("Invalid Date")
}
return stringValue(date.Time().Local().Format("2006-01-02 15:04:05"))
return stringValue(date.Time().Local().Format("2006-01-02 15:04:05")) //nolint: gosmopolitan
}

// This is a placeholder.
Expand All @@ -177,7 +177,7 @@ func builtinDateToLocaleDateString(call FunctionCall) Value {
if date.isNaN {
return stringValue("Invalid Date")
}
return stringValue(date.Time().Local().Format("2006-01-02"))
return stringValue(date.Time().Local().Format("2006-01-02")) //nolint: gosmopolitan
}

// This is a placeholder.
Expand All @@ -186,7 +186,7 @@ func builtinDateToLocaleTimeString(call FunctionCall) Value {
if date.isNaN {
return stringValue("Invalid Date")
}
return stringValue(date.Time().Local().Format("15:04:05"))
return stringValue(date.Time().Local().Format("15:04:05")) //nolint: gosmopolitan
}

func builtinDateValueOf(call FunctionCall) Value {
Expand All @@ -204,7 +204,7 @@ func builtinDateGetYear(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Year() - 1900)
return intValue(date.Time().Local().Year() - 1900) //nolint: gosmopolitan
}

func builtinDateGetFullYear(call FunctionCall) Value {
Expand All @@ -214,7 +214,7 @@ func builtinDateGetFullYear(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Year())
return intValue(date.Time().Local().Year()) //nolint: gosmopolitan
}

func builtinDateGetUTCFullYear(call FunctionCall) Value {
Expand All @@ -230,7 +230,7 @@ func builtinDateGetMonth(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(dateFromGoMonth(date.Time().Local().Month()))
return intValue(dateFromGoMonth(date.Time().Local().Month())) //nolint: gosmopolitan
}

func builtinDateGetUTCMonth(call FunctionCall) Value {
Expand All @@ -246,7 +246,7 @@ func builtinDateGetDate(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Day())
return intValue(date.Time().Local().Day()) //nolint: gosmopolitan
}

func builtinDateGetUTCDate(call FunctionCall) Value {
Expand All @@ -263,7 +263,7 @@ func builtinDateGetDay(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(dateFromGoDay(date.Time().Local().Weekday()))
return intValue(dateFromGoDay(date.Time().Local().Weekday())) //nolint: gosmopolitan
}

func builtinDateGetUTCDay(call FunctionCall) Value {
Expand All @@ -279,7 +279,7 @@ func builtinDateGetHours(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Hour())
return intValue(date.Time().Local().Hour()) //nolint: gosmopolitan
}

func builtinDateGetUTCHours(call FunctionCall) Value {
Expand All @@ -295,7 +295,7 @@ func builtinDateGetMinutes(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Minute())
return intValue(date.Time().Local().Minute()) //nolint: gosmopolitan
}

func builtinDateGetUTCMinutes(call FunctionCall) Value {
Expand All @@ -311,7 +311,7 @@ func builtinDateGetSeconds(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Second())
return intValue(date.Time().Local().Second()) //nolint: gosmopolitan
}

func builtinDateGetUTCSeconds(call FunctionCall) Value {
Expand All @@ -327,7 +327,7 @@ func builtinDateGetMilliseconds(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
return intValue(date.Time().Local().Nanosecond() / (100 * 100 * 100))
return intValue(date.Time().Local().Nanosecond() / (100 * 100 * 100)) //nolint: gosmopolitan
}

func builtinDateGetUTCMilliseconds(call FunctionCall) Value {
Expand All @@ -343,17 +343,17 @@ func builtinDateGetTimezoneOffset(call FunctionCall) Value {
if date.isNaN {
return NaNValue()
}
timeLocal := date.Time().Local()
timeLocal := date.Time().Local() //nolint: gosmopolitan
// Is this kosher?
timeLocalAsUTC := Time.Date(
timeLocalAsUTC := time.Date(
timeLocal.Year(),
timeLocal.Month(),
timeLocal.Day(),
timeLocal.Hour(),
timeLocal.Minute(),
timeLocal.Second(),
timeLocal.Nanosecond(),
Time.UTC,
time.UTC,
)
return float64Value(date.Time().Sub(timeLocalAsUTC).Seconds() / 60)
}
Expand Down
9 changes: 3 additions & 6 deletions object_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,10 @@ func objectCanPutDetails(obj *object, name string) (canPut bool, prop *property,
if prop != nil {
switch propertyValue := prop.value.(type) {
case Value:
canPut = prop.writable()
return
return prop.writable(), prop, nil
case propertyGetSet:
setter = propertyValue[1]
canPut = setter != nil
return
return setter != nil, prop, setter
default:
panic(obj.runtime.panicTypeError("unexpected type %T to Object.CanPutDetails", prop.value))
}
Expand All @@ -231,8 +229,7 @@ func objectCanPutDetails(obj *object, name string) (canPut bool, prop *property,
return prop.writable(), nil, nil
case propertyGetSet:
setter = propertyValue[1]
canPut = setter != nil
return
return setter != nil, prop, setter
default:
panic(obj.runtime.panicTypeError("unexpected type %T to Object.CanPutDetails", prop.value))
}
Expand Down
26 changes: 11 additions & 15 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,20 @@ func (p *parser) scan() (tkn token.Token, literal string, idx file.Idx) { //noli

switch tkn {
case 0: // Not a keyword
if literal == "true" || literal == "false" {
switch literal {
case "true", "false":
p.insertSemicolon = true
tkn = token.BOOLEAN
return
} else if literal == "null" {
return token.BOOLEAN, literal, idx
case "null":
p.insertSemicolon = true
tkn = token.NULL
return
return token.NULL, literal, idx
}

case token.KEYWORD:
tkn = token.KEYWORD
if strict {
// TODO If strict and in strict mode, then this is not a break
break
}
return
return token.KEYWORD, literal, idx

case
token.THIS,
Expand All @@ -169,19 +166,18 @@ func (p *parser) scan() (tkn token.Token, literal string, idx file.Idx) { //noli
token.CONTINUE,
token.DEBUGGER:
p.insertSemicolon = true
return
return tkn, literal, idx

default:
return
return tkn, literal, idx
}
}
p.insertSemicolon = true
tkn = token.IDENTIFIER
return
return token.IDENTIFIER, literal, idx
case '0' <= chr && chr <= '9':
p.insertSemicolon = true
tkn, literal = p.scanNumericLiteral(false)
return
return tkn, literal, idx
default:
p.read()
switch chr {
Expand Down Expand Up @@ -306,7 +302,7 @@ func (p *parser) scan() (tkn token.Token, literal string, idx file.Idx) { //noli
}
}
p.insertSemicolon = insertSemicolon
return
return tkn, literal, idx
}
}

Expand Down
2 changes: 1 addition & 1 deletion type_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (o *object) isCall() bool {
}
}

func (o *object) call(this Value, argumentList []Value, eval bool, frm frame) Value {
func (o *object) call(this Value, argumentList []Value, eval bool, frm frame) Value { //nolint: unparam // Isn't currently used except in recursive self.
switch fn := o.value.(type) {
case nativeFunctionObject:
// Since eval is a native function, we only have to check for it here
Expand Down

0 comments on commit ea8bcc3

Please sign in to comment.