mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
fix: lint issues (#909)
* fix: some of the lint issues * fix: staticcheck
This commit is contained in:
parent
a539127432
commit
817c4bd446
23 changed files with 44 additions and 74 deletions
|
|
@ -38,7 +38,7 @@ func (o Options) Run() error {
|
|||
// normalize options into a map
|
||||
options := map[string]string{}
|
||||
// keep the labels in the user-provided order
|
||||
var labels []string
|
||||
var labels []string //nolint:prealloc
|
||||
for _, opt := range o.Options {
|
||||
if o.LabelDelimiter == "" {
|
||||
options[opt] = opt
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// Package completion provides a bash completion generator for Kong
|
||||
// applications.
|
||||
package completion
|
||||
|
||||
import (
|
||||
|
|
@ -628,6 +630,7 @@ func writeCmdAliases(buf io.StringWriter, cmd *kong.Node) {
|
|||
writeString(buf, ` fi`)
|
||||
writeString(buf, "\n")
|
||||
}
|
||||
|
||||
func writeArgAliases(buf io.StringWriter, cmd *kong.Node) {
|
||||
writeString(buf, " noun_aliases=()\n")
|
||||
sort.Strings(cmd.Aliases)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package cursor provides cursor modes.
|
||||
package cursor
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func (o Options) Run() error {
|
|||
fp := filepicker.New()
|
||||
fp.CurrentDirectory = path
|
||||
fp.Path = path
|
||||
fp.Height = o.Height
|
||||
fp.SetHeight(o.Height)
|
||||
fp.AutoHeight = o.Height == 0
|
||||
fp.Cursor = o.Cursor
|
||||
fp.DirAllowed = o.Directory
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
if m.showHelp {
|
||||
m.filepicker.Height -= lipgloss.Height(m.helpView())
|
||||
m.filepicker.Height -= lipgloss.Height(m.helpView()) //nolint:staticcheck
|
||||
}
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ func (m *model) CursorUp() {
|
|||
if m.reverse { //nolint:nestif
|
||||
m.cursor = (m.cursor + 1) % len(m.matches)
|
||||
if len(m.matches)-m.cursor <= m.viewport.YOffset {
|
||||
m.viewport.LineUp(1)
|
||||
m.viewport.ScrollUp(1)
|
||||
}
|
||||
if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset {
|
||||
m.viewport.SetYOffset(len(m.matches) - m.viewport.Height)
|
||||
|
|
@ -406,7 +406,7 @@ func (m *model) CursorUp() {
|
|||
} else {
|
||||
m.cursor = (m.cursor - 1 + len(m.matches)) % len(m.matches)
|
||||
if m.cursor < m.viewport.YOffset {
|
||||
m.viewport.LineUp(1)
|
||||
m.viewport.ScrollUp(1)
|
||||
}
|
||||
if m.cursor >= m.viewport.YOffset+m.viewport.Height {
|
||||
m.viewport.SetYOffset(len(m.matches) - m.viewport.Height)
|
||||
|
|
@ -421,7 +421,7 @@ func (m *model) CursorDown() {
|
|||
if m.reverse { //nolint:nestif
|
||||
m.cursor = (m.cursor - 1 + len(m.matches)) % len(m.matches)
|
||||
if len(m.matches)-m.cursor > m.viewport.Height+m.viewport.YOffset {
|
||||
m.viewport.LineDown(1)
|
||||
m.viewport.ScrollDown(1)
|
||||
}
|
||||
if len(m.matches)-m.cursor <= m.viewport.YOffset {
|
||||
m.viewport.GotoTop()
|
||||
|
|
@ -429,7 +429,7 @@ func (m *model) CursorDown() {
|
|||
} else {
|
||||
m.cursor = (m.cursor + 1) % len(m.matches)
|
||||
if m.cursor >= m.viewport.YOffset+m.viewport.Height {
|
||||
m.viewport.LineDown(1)
|
||||
m.viewport.ScrollDown(1)
|
||||
}
|
||||
if m.cursor < m.viewport.YOffset {
|
||||
m.viewport.GotoTop()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package decode position strings to lipgloss.
|
||||
package decode
|
||||
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
// Package exit code implementation.
|
||||
package exit
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
import "strconv"
|
||||
|
||||
// StatusTimeout is the exit code for timed out commands.
|
||||
const StatusTimeout = 124
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package files handles files.
|
||||
package files
|
||||
|
||||
import (
|
||||
|
|
@ -18,7 +19,6 @@ func List() []string {
|
|||
files = append(files, path)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return []string{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
package log
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Error prints an error message to the user.
|
||||
func Error(message string) {
|
||||
fmt.Println("Error:", message)
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package stack
|
||||
|
||||
// Stack is a stack interface for integers.
|
||||
type Stack struct {
|
||||
Push func(int)
|
||||
Pop func() int
|
||||
Length func() int
|
||||
}
|
||||
|
||||
// NewStack returns a new stack of integers.
|
||||
func NewStack() Stack {
|
||||
slice := make([]int, 0)
|
||||
return Stack{
|
||||
Push: func(i int) {
|
||||
slice = append(slice, i)
|
||||
},
|
||||
Pop: func() int {
|
||||
res := slice[len(slice)-1]
|
||||
slice = slice[:len(slice)-1]
|
||||
return res
|
||||
},
|
||||
Length: func() int {
|
||||
return len(slice)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// Package stdin handles processing input from stdin.
|
||||
package stdin
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package timeout handles context timeouts.
|
||||
package timeout
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
// LipglossPadding calculates how much padding a string is given by a style.
|
||||
func LipglossPadding(style lipgloss.Style) (int, int) {
|
||||
render := style.Render(" ")
|
||||
before := strings.Index(render, " ")
|
||||
after := len(render) - len(" ") - before
|
||||
return before, after
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// Package log the log command.
|
||||
package log
|
||||
|
||||
import (
|
||||
|
|
@ -16,7 +17,7 @@ func (o Options) Run() error {
|
|||
l := log.New(os.Stderr)
|
||||
|
||||
if o.File != "" {
|
||||
f, err := os.OpenFile(o.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm)
|
||||
f, err := os.OpenFile(o.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm) //nolint:gosec
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening file: %w", err)
|
||||
}
|
||||
|
|
@ -31,7 +32,7 @@ func (o Options) Run() error {
|
|||
if o.MinLevel != "" {
|
||||
lvl, err := log.ParseLevel(o.MinLevel)
|
||||
if err != nil {
|
||||
return err
|
||||
return err //nolint:wrapcheck
|
||||
}
|
||||
l.SetLevel(lvl)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ type Options struct {
|
|||
|
||||
MinLevel string `help:"Minimal level to show" default:"" env:"GUM_LOG_LEVEL"`
|
||||
|
||||
LevelStyle style.Styles `embed:"" prefix:"level." help:"The style of the level being used" set:"defaultBold=true" envprefix:"GUM_LOG_LEVEL_"` //nolint:staticcheck
|
||||
LevelStyle style.Styles `embed:"" prefix:"level." help:"The style of the level being used" set:"defaultBold=true" envprefix:"GUM_LOG_LEVEL_"`
|
||||
TimeStyle style.Styles `embed:"" prefix:"time." help:"The style of the time" envprefix:"GUM_LOG_TIME_"`
|
||||
PrefixStyle style.Styles `embed:"" prefix:"prefix." help:"The style of the prefix" set:"defaultBold=true" set:"defaultFaint=true" envprefix:"GUM_LOG_PREFIX_"` //nolint:staticcheck
|
||||
MessageStyle style.Styles `embed:"" prefix:"message." help:"The style of the message" envprefix:"GUM_LOG_MESSAGE_"`
|
||||
|
|
|
|||
1
main.go
1
main.go
|
|
@ -1,3 +1,4 @@
|
|||
// Package main is Gum: a tool for glamorous shell scripts.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package man the man command.
|
||||
package man
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ func (m *model) processText(msg tea.WindowSizeMsg) {
|
|||
text.WriteString("\n")
|
||||
}
|
||||
} else {
|
||||
text.WriteString(textStyle.Render(line)) //nolint: gosec
|
||||
text.WriteString(textStyle.Render(line))
|
||||
text.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"github.com/charmbracelet/gum/internal/utils"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
)
|
||||
|
|
@ -52,7 +51,7 @@ func (s *search) Execute(m *model) {
|
|||
m.content = query.ReplaceAllString(m.content, m.matchStyle.Render("$1"))
|
||||
|
||||
// Recompile the regex to match the an replace the highlights.
|
||||
leftPad, _ := utils.LipglossPadding(m.matchStyle)
|
||||
leftPad, _ := lipglossPadding(m.matchStyle)
|
||||
matchingString := regexp.QuoteMeta(m.matchStyle.Render()[:leftPad]) + s.query.String() + regexp.QuoteMeta(m.matchStyle.Render()[leftPad:])
|
||||
s.query, err = regexp.Compile(matchingString)
|
||||
if err != nil {
|
||||
|
|
@ -82,7 +81,7 @@ func (s *search) NextMatch(m *model) {
|
|||
return
|
||||
}
|
||||
|
||||
leftPad, rightPad := utils.LipglossPadding(m.matchStyle)
|
||||
leftPad, rightPad := lipglossPadding(m.matchStyle)
|
||||
s.matchIndex = (s.matchIndex + 1) % len(allMatches)
|
||||
match := allMatches[s.matchIndex]
|
||||
lhs := m.content[:match[0]]
|
||||
|
|
@ -125,7 +124,7 @@ func (s *search) PrevMatch(m *model) {
|
|||
s.matchIndex = len(allMatches) - 1
|
||||
}
|
||||
|
||||
leftPad, rightPad := utils.LipglossPadding(m.matchStyle)
|
||||
leftPad, rightPad := lipglossPadding(m.matchStyle)
|
||||
match := allMatches[s.matchIndex]
|
||||
lhs := m.content[:match[0]]
|
||||
rhs := m.content[match[0]:]
|
||||
|
|
@ -159,10 +158,18 @@ func softWrapEm(str string, maxWidth int, softWrap bool) string {
|
|||
text.WriteString("\n")
|
||||
}
|
||||
} else {
|
||||
text.WriteString(line) //nolint: gosec
|
||||
text.WriteString(line)
|
||||
text.WriteString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
return text.String()
|
||||
}
|
||||
|
||||
// lipglossPadding calculates how much padding a string is given by a style.
|
||||
func lipglossPadding(style lipgloss.Style) (int, int) {
|
||||
render := style.Render(" ")
|
||||
before := strings.Index(render, " ")
|
||||
after := len(render) - len(" ") - before
|
||||
return before, after
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import (
|
|||
func openPty(f *os.File) (pty xpty.Pty, err error) {
|
||||
width, height, err := term.GetSize(f.Fd())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, err //nolint:wrapcheck
|
||||
}
|
||||
|
||||
pty, err = xpty.NewPty(width, height)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, err //nolint:wrapcheck
|
||||
}
|
||||
|
||||
return pty, nil
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const minTokens = 1
|
||||
const halfTokens = 2
|
||||
const maxTokens = 4
|
||||
const (
|
||||
minTokens = 1
|
||||
halfTokens = 2
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Package version the version command.
|
||||
package version
|
||||
|
||||
import (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue