Skip to content

Commit c98eb2b

Browse files
committed
address linter
1 parent 3ed26c7 commit c98eb2b

5 files changed

Lines changed: 99 additions & 51 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ install:
99
#=============================================================================#
1010
# Tooling #
1111
#=============================================================================#
12-
.PHONY: tool-all license format lint vulncheck nancy
12+
.PHONY: tool-all license format lint nancy
1313

1414
# This runs all the common tools like linting, etc.
15-
tool-all : license format lint vulncheck nancy
15+
tool-all: license format lint nancy
1616

1717
FILES := $(shell find . -name "*.go" -not -path "./simapp/*" -not -name "*.pb.go" -not -name "*.pb.gw.go" -not -name "*.pulsar.go")
1818
license:
@@ -23,6 +23,7 @@ license:
2323
check-license:
2424
@echo "Checking files for license..."
2525
@go-license --config .github/license.yaml $(FILES) --verify
26+
@echo "Done!"
2627

2728
GOLANGCI_LINT_VERSION="v2.2.2"
2829
GOLANGCI_LINT_IMAGE=golangci/golangci-lint:$(GOLANGCI_LINT_VERSION)

internal/actions.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package internal
1919

2020
import (
21+
"errors"
2122
"fmt"
2223
"strconv"
2324
"strings"
@@ -99,17 +100,20 @@ func (m Model) processFeeAction() (tea.Model, tea.Cmd) {
99100
basisPointsStr := m.actionInputs[1].Value()
100101

101102
if recipientAddr == "" {
102-
m.err = fmt.Errorf("recipient address is required")
103+
m.err = errors.New("recipient address is required")
104+
103105
return m, nil
104106
}
105107
if basisPointsStr == "" {
106-
m.err = fmt.Errorf("basis points is required")
108+
m.err = errors.New("basis points is required")
109+
107110
return m, nil
108111
}
109112

110113
basisPoints, err := strconv.ParseUint(basisPointsStr, 10, 32)
111114
if err != nil {
112-
m.err = fmt.Errorf("invalid basis points: %v", err)
115+
m.err = fmt.Errorf("invalid basis points: %w", err)
116+
113117
return m, nil
114118
}
115119

@@ -123,25 +127,30 @@ func (m Model) processFeeAction() (tea.Model, tea.Cmd) {
123127
}
124128

125129
if err = feeAttr.Validate(); err != nil {
126-
m.err = fmt.Errorf("invalid fee attributes: %v", err)
130+
m.err = fmt.Errorf("invalid fee attributes: %w", err)
131+
127132
return m, nil
128133
}
129134

130135
feeAction := core.Action{
131136
Id: core.ACTION_FEE,
132137
}
138+
133139
err = feeAction.SetAttributes(&feeAttr)
134140
if err != nil {
135-
m.err = fmt.Errorf("failed to set action attributes: %v", err)
141+
m.err = fmt.Errorf("failed to set action attributes: %w", err)
142+
136143
return m, nil
137144
}
138145

139146
if err = feeAction.Validate(); err != nil {
140-
m.err = fmt.Errorf("invalid fee action: %v", err)
147+
m.err = fmt.Errorf("invalid fee action: %w", err)
148+
141149
return m, nil
142150
}
143151

144152
m.actions = append(m.actions, &feeAction)
153+
145154
return m.initActionSelection(), nil
146155
}
147156

@@ -172,14 +181,13 @@ func (m Model) updateActionInputs(msg tea.Msg) tea.Cmd {
172181
return nil
173182
}
174183

175-
switch msg := msg.(type) {
176-
case tea.KeyMsg:
184+
if msg, ok := msg.(tea.KeyMsg); ok {
177185
switch msg.String() {
178-
case "tab", "shift+tab", "up", "down":
186+
case Tab, ShiftTab, Up, Down:
179187
s := msg.String()
180188

181189
// Update focus position
182-
if s == "up" || s == "shift+tab" {
190+
if s == Up || s == ShiftTab {
183191
if focusIndex > 0 {
184192
focusIndex--
185193
}
@@ -191,7 +199,7 @@ func (m Model) updateActionInputs(msg tea.Msg) tea.Cmd {
191199

192200
// Update focus for all inputs
193201
cmds := make([]tea.Cmd, len(m.actionInputs))
194-
for i := 0; i < len(m.actionInputs); i++ {
202+
for i := range m.actionInputs {
195203
if i == focusIndex {
196204
cmds[i] = m.actionInputs[i].Focus()
197205
} else {

internal/forwarding.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,19 @@ func (m Model) processCCTPForwarding() (tea.Model, tea.Cmd) {
136136

137137
domain, err := strconv.ParseUint(domainStr, 10, 32)
138138
if err != nil {
139-
m.err = fmt.Errorf("invalid destination domain: %v", err)
139+
m.err = fmt.Errorf("invalid destination domain: %w", err)
140+
140141
return m, nil
141142
}
142143

143-
var mintRecipient []byte
144144
if mintRecipientStr == "" {
145145
m.err = errors.New("mint recipient cannot be empty")
146+
146147
return m, nil
147-
} else if mintRecipientStr == "r" {
148+
}
149+
150+
var mintRecipient []byte
151+
if mintRecipientStr == "r" {
148152
mintRecipient = testutil.RandomBytes(32)
149153
} else {
150154
mintRecipient = []byte(mintRecipientStr)
@@ -169,15 +173,17 @@ func (m Model) processCCTPForwarding() (tea.Model, tea.Cmd) {
169173
passthroughPayload,
170174
)
171175
if err != nil {
172-
m.err = fmt.Errorf("failed to create CCTP forwarding: %v", err)
176+
m.err = fmt.Errorf("failed to create CCTP forwarding: %w", err)
177+
173178
return m, nil
174179
}
175180

176181
m.forwarding = cctpForwarding
177182

178183
m.payload, err = buildFinalPayload(m.forwarding, m.actions)
179184
if err != nil {
180-
m.err = fmt.Errorf("failed to build finalPayload: %v", err)
185+
m.err = fmt.Errorf("failed to build finalPayload: %w", err)
186+
181187
return m, nil
182188
}
183189

@@ -189,22 +195,21 @@ func (m Model) updateForwardingInputs(msg tea.Msg) tea.Cmd {
189195
return nil
190196
}
191197

192-
switch msg := msg.(type) {
193-
case tea.KeyMsg:
198+
if msg, ok := msg.(tea.KeyMsg); ok {
194199
switch msg.String() {
195-
case "tab", "shift+tab", "up", "down":
200+
case Tab, ShiftTab, Up, Down:
196201
s := msg.String()
197202

198203
// Update focus position
199-
if (s == "up" || s == "shift+tab") && focusIndex > 0 {
204+
if (s == Up || s == ShiftTab) && focusIndex > 0 {
200205
focusIndex--
201206
} else if focusIndex < len(m.forwardingInputs)-1 {
202207
focusIndex++
203208
}
204209

205210
// Update focus for all inputs
206211
cmds := make([]tea.Cmd, len(m.forwardingInputs))
207-
for i := 0; i < len(m.forwardingInputs); i++ {
212+
for i := range m.forwardingInputs {
208213
if i == focusIndex {
209214
cmds[i] = m.forwardingInputs[i].Focus()
210215
} else {

internal/keys.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package internal
18+
19+
const (
20+
Up = "up"
21+
Down = "down"
22+
Tab = "tab"
23+
ShiftTab = "shift+tab"
24+
)

internal/ui_model.go

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func InitialModel() Model {
7676
}
7777

7878
l := list.New(actionItems, list.NewDefaultDelegate(), 0, 0)
79-
l.Title = "Select an action to add:"
79+
l.Title = "Select an action to add:" //nolint:goconst
8080

8181
return Model{
8282
state: actionSelection,
@@ -109,6 +109,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
109109
m.windowHeight = msg.Height
110110
m.list.SetWidth(msg.Width)
111111
m.list.SetHeight(msg.Height - 3)
112+
112113
return m, nil
113114
}
114115

@@ -127,10 +128,39 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
127128
return m, cmd
128129
}
129130

131+
func (m Model) View() string {
132+
var s strings.Builder
133+
134+
switch m.state {
135+
case actionSelection:
136+
m.writeActionSelection(&s)
137+
case forwardingSelection:
138+
m.writeForwardingSelection(&s)
139+
case feeActionInput:
140+
m.writeFeeActionSelection(&s)
141+
case cctpForwardingInput:
142+
m.writeCCTPForwardingSelection(&s)
143+
}
144+
145+
if m.err != nil {
146+
s.WriteString(
147+
lipgloss.NewStyle().
148+
Foreground(lipgloss.Color("196")).
149+
Render("\nError: " + m.err.Error()),
150+
)
151+
}
152+
153+
return s.String()
154+
}
155+
130156
func (m Model) handleEnter() (tea.Model, tea.Cmd) {
131157
switch m.state {
132158
case actionSelection:
133-
selected := m.list.SelectedItem().(item)
159+
selected, ok := m.list.SelectedItem().(item)
160+
if !ok {
161+
panic(fmt.Sprintf("failed to cast list item to item; got: %T", m.list.SelectedItem()))
162+
}
163+
134164
switch selected.title {
135165
case core.ACTION_FEE.String():
136166
return m.initFeeActionInput(), nil
@@ -142,7 +172,11 @@ func (m Model) handleEnter() (tea.Model, tea.Cmd) {
142172
case feeActionInput:
143173
return m.processFeeAction()
144174
case forwardingSelection:
145-
selected := m.list.SelectedItem().(item)
175+
selected, ok := m.list.SelectedItem().(item)
176+
if !ok {
177+
panic(fmt.Sprintf("failed to cast list item to item; got: %T", m.list.SelectedItem()))
178+
}
179+
146180
switch selected.title {
147181
case core.PROTOCOL_CCTP.String():
148182
return m.initCCTPForwardingInput(), nil
@@ -154,30 +188,6 @@ func (m Model) handleEnter() (tea.Model, tea.Cmd) {
154188
case cctpForwardingInput:
155189
return m.processCCTPForwarding()
156190
}
157-
return m, nil
158-
}
159-
160-
func (m Model) View() string {
161-
var s strings.Builder
162-
163-
switch m.state {
164-
case actionSelection:
165-
m.writeActionSelection(&s)
166-
case forwardingSelection:
167-
m.writeForwardingSelection(&s)
168-
case feeActionInput:
169-
m.writeFeeActionSelection(&s)
170-
case cctpForwardingInput:
171-
m.writeCCTPForwardingSelection(&s)
172-
}
173-
174-
if m.err != nil {
175-
s.WriteString(
176-
lipgloss.NewStyle().
177-
Foreground(lipgloss.Color("196")).
178-
Render("\nError: " + m.err.Error()),
179-
)
180-
}
181191

182-
return s.String()
192+
return m, nil
183193
}

0 commit comments

Comments
 (0)