From 11a9fccd58e9544d336ba8aa74ad866122a410df Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 31 May 2024 13:48:29 -0700 Subject: [PATCH] chore: fix lint issues (#534) --- help/help.go | 11 +++++------ list/defaultitem.go | 14 +++++++------- list/list.go | 4 ++-- table/table.go | 4 ++-- textarea/textarea.go | 9 +++++---- textinput/textinput.go | 6 ++++-- viewport/viewport.go | 2 +- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/help/help.go b/help/help.go index edb5a47..f4e1c97 100644 --- a/help/help.go +++ b/help/help.go @@ -15,7 +15,6 @@ import ( // Note that if a key is disabled (via key.Binding.SetEnabled) it will not be // rendered in the help view, so in theory generated help should self-manage. type KeyMap interface { - // ShortHelp returns a slice of bindings to be displayed in the short // version of the help. The help bubble will render help in the order in // which the help items are returned here. @@ -82,10 +81,10 @@ func New() Model { ShortKey: keyStyle, ShortDesc: descStyle, ShortSeparator: sepStyle, - Ellipsis: sepStyle.Copy(), - FullKey: keyStyle.Copy(), - FullDesc: descStyle.Copy(), - FullSeparator: sepStyle.Copy(), + Ellipsis: sepStyle, + FullKey: keyStyle, + FullDesc: descStyle, + FullSeparator: sepStyle, }, } } @@ -118,7 +117,7 @@ func (m Model) ShortHelpView(bindings []key.Binding) string { var b strings.Builder var totalWidth int - var separator = m.Styles.ShortSeparator.Inline(true).Render(m.ShortSeparator) + separator := m.Styles.ShortSeparator.Inline(true).Render(m.ShortSeparator) for i, kb := range bindings { if !kb.Enabled() { diff --git a/list/defaultitem.go b/list/defaultitem.go index ce98dd3..3f07cef 100644 --- a/list/defaultitem.go +++ b/list/defaultitem.go @@ -37,7 +37,7 @@ func NewDefaultItemStyles() (s DefaultItemStyles) { Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}). Padding(0, 0, 0, 2) - s.NormalDesc = s.NormalTitle.Copy(). + s.NormalDesc = s.NormalTitle. Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}) s.SelectedTitle = lipgloss.NewStyle(). @@ -46,14 +46,14 @@ func NewDefaultItemStyles() (s DefaultItemStyles) { Foreground(lipgloss.AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"}). Padding(0, 0, 0, 1) - s.SelectedDesc = s.SelectedTitle.Copy(). + s.SelectedDesc = s.SelectedTitle. Foreground(lipgloss.AdaptiveColor{Light: "#F793FF", Dark: "#AD58B4"}) s.DimmedTitle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#A49FA5", Dark: "#777777"}). Padding(0, 0, 0, 2) - s.DimmedDesc = s.DimmedTitle.Copy(). + s.DimmedDesc = s.DimmedTitle. Foreground(lipgloss.AdaptiveColor{Light: "#C2B8C2", Dark: "#4D4D4D"}) s.FilterMatch = lipgloss.NewStyle().Underline(true) @@ -187,7 +187,7 @@ func (d DefaultDelegate) Render(w io.Writer, m Model, index int, item Item) { if isFiltered { // Highlight matches unmatched := s.SelectedTitle.Inline(true) - matched := unmatched.Copy().Inherit(s.FilterMatch) + matched := unmatched.Inherit(s.FilterMatch) title = lipgloss.StyleRunes(title, matchedRunes, matched, unmatched) } title = s.SelectedTitle.Render(title) @@ -196,7 +196,7 @@ func (d DefaultDelegate) Render(w io.Writer, m Model, index int, item Item) { if isFiltered { // Highlight matches unmatched := s.NormalTitle.Inline(true) - matched := unmatched.Copy().Inherit(s.FilterMatch) + matched := unmatched.Inherit(s.FilterMatch) title = lipgloss.StyleRunes(title, matchedRunes, matched, unmatched) } title = s.NormalTitle.Render(title) @@ -204,10 +204,10 @@ func (d DefaultDelegate) Render(w io.Writer, m Model, index int, item Item) { } if d.ShowDescription { - fmt.Fprintf(w, "%s\n%s", title, desc) + fmt.Fprintf(w, "%s\n%s", title, desc) //nolint: errcheck return } - fmt.Fprintf(w, "%s", title) + fmt.Fprintf(w, "%s", title) //nolint: errcheck } // ShortHelp returns the delegate's short help. diff --git a/list/list.go b/list/list.go index 573e76a..17e6e15 100644 --- a/list/list.go +++ b/list/list.go @@ -1049,7 +1049,7 @@ func (m Model) View() string { func (m Model) titleView() string { var ( view string - titleBarStyle = m.Styles.TitleBar.Copy() + titleBarStyle = m.Styles.TitleBar // We need to account for the size of the spinner, even if we don't // render it, to reserve some space for it should we turn it on later. @@ -1157,7 +1157,7 @@ func (m Model) paginationView() string { style := m.Styles.PaginationStyle if m.delegate.Spacing() == 0 && style.GetMarginTop() == 0 { - style = style.Copy().MarginTop(1) + style = style.MarginTop(1) } return style.Render(s) diff --git a/table/table.go b/table/table.go index e355b23..0bdd6d7 100644 --- a/table/table.go +++ b/table/table.go @@ -409,7 +409,7 @@ func (m *Model) FromValues(value, separator string) { type StyleFunc func(row, col int, value string) lipgloss.Style func (m Model) headersView() string { - var s = make([]string, 0, len(m.cols)) + s := make([]string, 0, len(m.cols)) for _, col := range m.cols { if col.Width <= 0 { continue @@ -422,7 +422,7 @@ func (m Model) headersView() string { } func (m *Model) renderRow(r int) string { - var s = make([]string, 0, len(m.cols)) + s := make([]string, 0, len(m.cols)) for i, value := range m.rows[r] { if m.cols[i].Width <= 0 { continue diff --git a/textarea/textarea.go b/textarea/textarea.go index 1e99437..0e868e0 100644 --- a/textarea/textarea.go +++ b/textarea/textarea.go @@ -30,8 +30,10 @@ const ( ) // Internal messages for clipboard operations. -type pasteMsg string -type pasteErrMsg struct{ error } +type ( + pasteMsg string + pasteErrMsg struct{ error } +) // KeyMap is the key bindings for different actions within the textarea. type KeyMap struct { @@ -606,8 +608,7 @@ func (m *Model) transposeLeft() { if m.col >= len(m.value[m.row]) { m.SetCursor(m.col - 1) } - m.value[m.row][m.col-1], m.value[m.row][m.col] = - m.value[m.row][m.col], m.value[m.row][m.col-1] + m.value[m.row][m.col-1], m.value[m.row][m.col] = m.value[m.row][m.col], m.value[m.row][m.col-1] if m.col < len(m.value[m.row]) { m.SetCursor(m.col + 1) } diff --git a/textinput/textinput.go b/textinput/textinput.go index 310ee30..93bc150 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -17,8 +17,10 @@ import ( ) // Internal messages for clipboard operations. -type pasteMsg string -type pasteErrMsg struct{ error } +type ( + pasteMsg string + pasteErrMsg struct{ error } +) // EchoMode sets the input behavior of the text input field. type EchoMode int diff --git a/viewport/viewport.go b/viewport/viewport.go index 960bfa4..e0a4cc3 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -378,7 +378,7 @@ func (m Model) View() string { MaxHeight(contentHeight). // truncate height if taller. MaxWidth(contentWidth). // truncate width if wider. Render(strings.Join(m.visibleLines(), "\n")) - return m.Style.Copy(). + return m.Style. UnsetWidth().UnsetHeight(). // Style size already applied in contents. Render(contents) }