chore: fix linting

This commit is contained in:
Maas Lalani 2022-07-30 17:40:33 -04:00
parent 61a9219d0a
commit cb590e324e
10 changed files with 22 additions and 20 deletions

View file

@ -55,7 +55,7 @@ const (
ShellCompDirectiveFilterDirs
// ===========================================================================
//
// All directives using iota should be above this one.
// For internal use.
shellCompDirectiveMaxValue //nolint:deadcode,unused,varcheck

View file

@ -39,8 +39,7 @@ func isArgument(cmd *kong.Node) bool {
// writeString writes a string into a buffer, and checks if the error is not nil.
func writeString(b io.StringWriter, s string) {
_, err := b.WriteString(s)
if err != nil {
if _, err := b.WriteString(s); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}

View file

@ -24,9 +24,8 @@ func (o Options) Run() error {
i.Placeholder = o.Placeholder
i.Width = o.Width
input, _ := stdin.Read()
var choices []string
if input != "" {
if input, _ := stdin.Read(); input != "" {
choices = strings.Split(strings.TrimSpace(input), "\n")
} else {
choices = files.List()

View file

@ -18,7 +18,7 @@ import (
"github.com/charmbracelet/gum/internal/stdin"
)
// Func is a function that formats some text
// Func is a function that formats some text.
type Func func(string) (string, error)
var formatType = map[string]Func{
@ -28,7 +28,7 @@ var formatType = map[string]Func{
"template": template,
}
// Run runs the format command
// Run runs the format command.
func (o Options) Run() error {
var input string
if len(o.Template) > 0 {

View file

@ -1,6 +1,6 @@
package format
// Options is customization options for the format command
// Options is customization options for the format command.
type Options struct {
Template []string `arg:"" optional:"" help:"Template string to format (can also be provided via stdin)"`

View file

@ -14,11 +14,8 @@ import (
// Run provides a shell script interface for the text input bubble.
// https://github.com/charmbracelet/bubbles/textinput
func (o Options) Run() error {
in, _ := stdin.Read()
i := textinput.New()
if in != "" && o.Value == "" {
if in, _ := stdin.Read(); in != "" && o.Value == "" {
i.SetValue(in)
} else {
i.SetValue(o.Value)

View file

@ -2,7 +2,7 @@ package decode
import "github.com/charmbracelet/lipgloss"
// Align maps strings to `lipgloss.Position`s
// Align maps strings to `lipgloss.Position`s.
var Align = map[string]lipgloss.Position{
"center": lipgloss.Center,
"left": lipgloss.Left,

View file

@ -2,6 +2,7 @@ package stdin
import (
"bufio"
"errors"
"io"
"os"
"strings"
@ -11,7 +12,7 @@ import (
func Read() (string, error) {
stat, err := os.Stdin.Stat()
if err != nil {
return "", err
return "", errors.New("failed to get stdin stat")
}
if stat.Mode()&os.ModeNamedPipe == 0 && stat.Size() == 0 {

View file

@ -2,7 +2,7 @@ package style
import "github.com/charmbracelet/lipgloss"
// border maps strings to `lipgloss.Border`s
// border maps strings to `lipgloss.Border`s.
var border map[string]lipgloss.Border = map[string]lipgloss.Border{
"double": lipgloss.DoubleBorder(),
"hidden": lipgloss.HiddenBorder(),

View file

@ -5,20 +5,26 @@ import (
"strings"
)
const maxTokens = 4
// parsePadding parses 1 - 4 integers from a string and returns them in a top,
// right, bottom, left order for use in the lipgloss.Padding() method
// right, bottom, left order for use in the lipgloss.Padding() method.
func parsePadding(s string) (int, int, int, int) {
var ints []int
var ints [maxTokens]int
tokens := strings.Split(s, " ")
if len(tokens) > maxTokens {
return 0, 0, 0, 0
}
// All tokens must be an integer
for _, token := range tokens {
for i, token := range tokens {
parsed, err := strconv.Atoi(token)
if err != nil {
return 0, 0, 0, 0
}
ints = append(ints, parsed)
ints[i] = parsed
}
if len(tokens) == 1 {
@ -29,7 +35,7 @@ func parsePadding(s string) (int, int, int, int) {
return ints[0], ints[1], ints[0], ints[1]
}
if len(tokens) == 4 {
if len(tokens) == maxTokens {
return ints[0], ints[1], ints[2], ints[3]
}