Skip to content

Commit

Permalink
feat: go 1.21, lint fixes (#391)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 authored Sep 6, 2024
1 parent b963c39 commit 44b1cdc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ issues:
linters:
enable:
- bodyclose
- exportloopref
- goimports
- gosec
- nilerr
Expand Down
4 changes: 2 additions & 2 deletions accessibility/accessibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
// Given invalid input (non-integers, integers outside of the range), the user
// will continue to be reprompted until a valid input is given, ensuring that
// the return value is always valid.
func PromptInt(prompt string, min, max int) int {
func PromptInt(prompt string, low, high int) int {
var (
input string
choice int
)

validInt := func(s string) error {
i, err := strconv.Atoi(s)
if err != nil || i < min || i > max {
if err != nil || i < low || i > high {
return errors.New("invalid input. please try again")
}
return nil
Expand Down
14 changes: 0 additions & 14 deletions clamp.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package huh

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

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

func clamp(n, low, high int) int {
if low > high {
low, high = high, low
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/charmbracelet/huh

go 1.20
go 1.21

require (
github.com/catppuccin/go v0.2.0
Expand Down
18 changes: 9 additions & 9 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ func ValidateNotEmpty() func(s string) error {
}

// ValidateMinLength checks if the length of the input is at least min.
func ValidateMinLength(min int) func(s string) error {
func ValidateMinLength(v int) func(s string) error {
return func(s string) error {
if utf8.RuneCountInString(s) < min {
return fmt.Errorf("input must be at least %d characters long", min)
if utf8.RuneCountInString(s) < v {
return fmt.Errorf("input must be at least %d characters long", v)
}
return nil
}
}

// ValidateMaxLength checks if the length of the input is at most max.
func ValidateMaxLength(max int) func(s string) error {
func ValidateMaxLength(v int) func(s string) error {
return func(s string) error {
if utf8.RuneCountInString(s) > max {
return fmt.Errorf("input must be at most %d characters long", max)
if utf8.RuneCountInString(s) > v {
return fmt.Errorf("input must be at most %d characters long", v)
}
return nil
}
}

// ValidateLength checks if the length of the input is within the specified range.
func ValidateLength(min, max int) func(s string) error {
func ValidateLength(minl, maxl int) func(s string) error {
return func(s string) error {
if err := ValidateMinLength(min)(s); err != nil {
if err := ValidateMinLength(minl)(s); err != nil {
return err
}
return ValidateMaxLength(max)(s)
return ValidateMaxLength(maxl)(s)
}
}

Expand Down

0 comments on commit 44b1cdc

Please sign in to comment.