Skip to content

Commit

Permalink
chore: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Oct 22, 2023
1 parent ff16756 commit e9d7605
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions strings/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/google/cel-go/common/types"
)

const InvalidDuration = "time: invalid duration "

// Duration is a standard unit of time.
type Duration time.Duration

Expand Down Expand Up @@ -316,7 +318,7 @@ func parseDuration(s string) (Duration, error) {
return 0, nil
}
if s == "" {
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}
for s != "" {
var (
Expand All @@ -328,13 +330,13 @@ func parseDuration(s string) (Duration, error) {

// The next character must be [0-9.]
if !(s[0] == '.' || '0' <= s[0] && s[0] <= '9') {
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}
// Consume [0-9]*
pl := len(s)
v, s, err = leadingInt(s)
if err != nil {
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}
pre := pl != len(s) // whether we consumed anything before a period
// Consume (\.[0-9]*)?
Expand All @@ -344,7 +346,7 @@ func parseDuration(s string) (Duration, error) {
pl := len(s)
f, s, err = leadingInt(s)
if err != nil {
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(+orig)

Check failure on line 349 in strings/duration.go

View workflow job for this annotation

GitHub Actions / test

invalid operation: operator + not defined on orig (variable of type string)

Check failure on line 349 in strings/duration.go

View workflow job for this annotation

GitHub Actions / lint

invalid operation: operator + not defined on orig (variable of type string)) (typecheck)

Check failure on line 349 in strings/duration.go

View workflow job for this annotation

GitHub Actions / lint

invalid operation: operator + not defined on orig (variable of type string)) (typecheck)

Check failure on line 349 in strings/duration.go

View workflow job for this annotation

GitHub Actions / lint

invalid operation: operator + not defined on orig (variable of type string) (typecheck)
}
for n := pl - len(s); n > 0; n-- {
scale *= 10
Expand All @@ -353,7 +355,7 @@ func parseDuration(s string) (Duration, error) {
}
if !pre && !post {
// no digits (e.g. ".s" or "-.s")
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}

// Consume unit.
Expand All @@ -375,7 +377,7 @@ func parseDuration(s string) (Duration, error) {
}
if v > (1<<63-1)/unit {
// overflow
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}
v *= unit
if f > 0 {
Expand All @@ -384,13 +386,13 @@ func parseDuration(s string) (Duration, error) {
v += int64(float64(f) * (float64(unit) / scale))
if v < 0 {
// overflow
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}
}
d += v
if d < 0 {
// overflow
return 0, errors.New("time: invalid duration " + orig)
return 0, errors.New(InvalidDuration + orig)
}
}

Expand Down

0 comments on commit e9d7605

Please sign in to comment.