Skip to content

Commit 34533d9

Browse files
authored
chore: fix lint issues and enhance code quality (#245)
1 parent 3011889 commit 34533d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+185
-170
lines changed

.golangci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ linters:
1717
- gocritic
1818
- godot
1919
- gofumpt
20-
- revive
2120
- gosimple
2221
- govet
2322
- grouper
2423
- ineffassign
2524
- misspell
2625
- nakedret
2726
- nolintlint
28-
- staticcheck
2927
- reassign
28+
- revive
29+
- staticcheck
3030
- stylecheck
31+
- thelper
3132
- typecheck
3233
- unconvert
33-
- tenv
34-
- thelper
35-
- unused
3634
- unparam
37-
- misspell
35+
- unused
36+
- usetesting
3837

3938
linters-settings:
4039
forbidigo:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ lint:
6969
@for dir in $$(find $$(pwd -P) -mindepth 1 -maxdepth 4 -type d); do \
7070
if [ -e "$$dir/go.mod" ]; then \
7171
echo "Running golangci-lint in $$dir"; \
72-
cd "$$dir" && golangci-lint run; \
72+
cd "$$dir" && golangci-lint run --fix; \
7373
fi \
7474
done
7575

appregistry/strcase/strcase.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ import (
88
)
99

1010
// ToKebab converts a string to kebab case (lowercase with hyphens).
11-
// Example: "camelCase" -> "camel-case"
11+
// Example: "camelCase" -> "camel-case".
1212
func ToKebab(s string) string {
1313
return strcase.ToKebab(s)
1414
}
1515

1616
// ToSnake converts a string to snake case (lowercase with underscores).
17-
// Example: "camelCase" -> "camel_case"
17+
// Example: "camelCase" -> "camel_case".
1818
func ToSnake(s string) string {
1919
return strcase.ToSnake(s)
2020
}
2121

2222
// ToLower converts a string to all lowercase.
23-
// Example: "HELLO" -> "hello"
23+
// Example: "HELLO" -> "hello".
2424
func ToLower(s string) string {
2525
return strings.ToLower(s)
2626
}
2727

2828
// ToUpper converts a string to all uppercase.
29-
// Example: "hello" -> "HELLO"
29+
// Example: "hello" -> "HELLO".
3030
func ToUpper(s string) string {
3131
return strings.ToUpper(s)
3232
}
3333

3434
// ToUpperCamel converts a string into upper camel case with spaces preserved between logical words.
3535
// It only modifies the first rune of each word, keeping the rest intact (case-preserving).
36-
// Example: "hello-world" -> "Hello World"
37-
// Example: "snAke_caSe" -> "SnAke CaSe"
36+
// Example: "hello-world" -> "Hello World".
37+
// Example: "snAke_caSe" -> "SnAke CaSe".
3838
func ToUpperCamel(s string) string {
3939
s = strings.TrimSpace(s)
4040
s = strings.ReplaceAll(s, "-", " ")
@@ -53,8 +53,8 @@ func ToUpperCamel(s string) string {
5353

5454
// ToLowerCamel converts a string into lower camel case with spaces between words.
5555
// All characters are converted to lowercase. Hyphens and underscores are replaced with spaces.
56-
// Example: "Hello-World" -> "hello world"
57-
// Example: "UPPER_CASE" -> "upper case"
56+
// Example: "Hello-World" -> "hello world".
57+
// Example: "UPPER_CASE" -> "upper case".
5858
func ToLowerCamel(s string) string {
5959
s = strings.TrimSpace(s)
6060
s = strings.ReplaceAll(s, "-", " ")

connect/chains/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
var (
1414
configName = "connect.yaml"
1515

16-
// ErrConfigNotFound is returned when the config file is not found
16+
// ErrConfigNotFound is returned when the config file is not found.
1717
ErrConfigNotFound = fmt.Errorf("config file not found")
1818
)
1919

connect/chains/registry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func NewChainRegistry() *ChainRegistry {
2828
}
2929
}
3030

31-
// FetchChains fetches the list of chains from the cosmos.directory API
32-
// Note, the output chainregistry.Chain doesn't contain the full list of fields
31+
// FetchChains fetches the list of chains from the cosmos.directory API.
32+
// Note, the output chainregistry.Chain doesn't contain the full list of fields.
3333
func (r *ChainRegistry) FetchChains() error {
3434
client := &http.Client{
3535
Timeout: 5 * time.Second,
@@ -73,7 +73,7 @@ func (r *ChainRegistry) FetchChains() error {
7373
return nil
7474
}
7575

76-
// EnrichChain fetches the full chain information from the cosmos.directory API
76+
// EnrichChain fetches the full chain information from the cosmos.directory API.
7777
func EnrichChain(chain *chainregistry.Chain) error {
7878
baseURL := fmt.Sprintf("%s/%s", cosmosDirectoryAPIURL, chain.ChainName)
7979

connect/cmd/add.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package cmd
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
7-
"strings"
86

97
authv1betav1 "cosmossdk.io/api/cosmos/auth/v1beta1"
108
"github.com/charmbracelet/bubbles/spinner"
119
tea "github.com/charmbracelet/bubbletea"
10+
"golang.org/x/text/cases"
11+
"golang.org/x/text/language"
1212
"google.golang.org/grpc"
1313

1414
"github.com/ignite/cli/v29/ignite/pkg/chainregistry"
15+
"github.com/ignite/cli/v29/ignite/pkg/errors"
1516
"github.com/ignite/cli/v29/ignite/services/plugin"
1617

1718
"github.com/ignite/apps/connect/chains"
@@ -28,7 +29,7 @@ type addCmdModel struct {
2829
}
2930

3031
func newAddCmdModel(chain chainregistry.Chain) *addCmdModel {
31-
s := spinner.NewModel()
32+
s := spinner.New()
3233
s.Spinner = spinner.Dot
3334

3435
c := &chain
@@ -119,18 +120,18 @@ func (m *addCmdModel) View() string {
119120
end = totalSize
120121
}
121122

122-
out := "\033[K" // clear current line before printing
123+
out := outLine
123124
out += "Select endpoint:\n"
124125
for i, item := range items[start:end] {
125-
out += "\033[K" // clear current line before printing
126+
out += outLine
126127
if i == m.selectedIndex {
127128
out += "\033[32m✓ \033[1m" + item + "\033[0m\n"
128129
} else {
129130
out += fmt.Sprintf(" %s\n", item)
130131
}
131132
}
132133

133-
out += "\033[K" // clear current line before printing
134+
out += outLine
134135
out += "(press 'n'/'right' for next, 'p'/'left' for prev, 'enter' to add chain, 'q'/'ctrl+c' to quit)\n"
135136

136137
return out
@@ -204,7 +205,8 @@ func initChain(ctx context.Context, chain chainregistry.Chain, endpoint string)
204205
return err
205206
}
206207

207-
fmt.Printf("%s is ready to Connect!\n", strings.Title(chain.ChainName)) //nolintlint:staticcheck // strings.Title has a better API.
208+
c := cases.Title(language.English, cases.NoLower)
209+
fmt.Printf("%s is ready to Connect!\n", c.String(chain.ChainName))
208210
return nil
209211
}
210212

connect/cmd/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args
5151
ValidatorAddressCodec: addresscodec.NewBech32Codec(fmt.Sprintf("%svaloper", cfg.Bech32Prefix)),
5252
ConsensusAddressCodec: addresscodec.NewBech32Codec(fmt.Sprintf("%svalcons", cfg.Bech32Prefix)),
5353
},
54-
GetClientConn: func(command *cobra.Command) (grpc.ClientConnInterface, error) {
54+
GetClientConn: func(*cobra.Command) (grpc.ClientConnInterface, error) {
5555
return conn.Connect()
5656
},
5757
AddQueryConnFlags: func(command *cobra.Command) {

connect/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/ignite/cli/v29/ignite/services/plugin"
77
)
88

9+
const outLine = "\033[K" // current line before printing
10+
911
// GetCommands returns the list of app commands.
1012
func GetCommands(availableChains []string) []*plugin.Command {
1113
cmd := []*plugin.Command{

connect/cmd/discover.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
const pageSize = 10
1818

19-
// model holds the state of the UI
19+
// model holds the state of the UI.
2020
type discoverCmdModel struct {
2121
spinner spinner.Model
2222
fetching bool
@@ -28,7 +28,7 @@ type discoverCmdModel struct {
2828
chainRegistry *chains.ChainRegistry
2929
}
3030

31-
// Messages
31+
// Messages.
3232
type fetchDoneMsg struct {
3333
reg *chains.ChainRegistry
3434
}
@@ -37,12 +37,12 @@ type fetchErrMsg struct {
3737
err error
3838
}
3939

40-
// Init initialize Bubble Tea program
40+
// Init initialize Bubble Tea program.
4141
func (m *discoverCmdModel) Init() tea.Cmd {
4242
return tea.Batch(fetchChainsCmd)
4343
}
4444

45-
// fetchChainsCmd fetch the chains in the background
45+
// fetchChainsCmd fetch the chains in the background.
4646
func fetchChainsCmd() tea.Msg {
4747
cr := chains.NewChainRegistry()
4848
if err := cr.FetchChains(); err != nil {
@@ -51,7 +51,7 @@ func fetchChainsCmd() tea.Msg {
5151
return fetchDoneMsg{cr}
5252
}
5353

54-
// Update handles messages and updates the model accordingly
54+
// Update handles messages and updates the model accordingly.
5555
func (m *discoverCmdModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5656
var cmd tea.Cmd
5757
var totalSize int
@@ -114,7 +114,7 @@ func (m *discoverCmdModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
114114
return m, cmd
115115
}
116116

117-
// View returns the UI as a string
117+
// View returns the UI as a string.
118118
func (m *discoverCmdModel) View() string {
119119
if m.fetching && m.err == nil {
120120
return fmt.Sprintf("%s Discovering chains... (press 'q' to quit)\n", m.spinner.View())
@@ -139,7 +139,7 @@ func (m *discoverCmdModel) View() string {
139139
end = totalSize
140140
}
141141

142-
out := "\033[K" // clear current line before printing
142+
out := outLine
143143
out += fmt.Sprintf("Fetched %d chains. Showing %d-%d:\n", totalSize, start+1, end)
144144

145145
// ANSI escape codes for highlighting
@@ -149,7 +149,7 @@ func (m *discoverCmdModel) View() string {
149149
for i, k := range chainsNames[start:end] {
150150
chain := m.chainRegistry.Chains[k]
151151

152-
out += "\033[K" // clear current line before printing
152+
out += outLine
153153

154154
// Check if the input corresponds to this line number
155155
if i == m.selectedIndex {
@@ -159,13 +159,13 @@ func (m *discoverCmdModel) View() string {
159159
}
160160
}
161161

162-
out += "\033[K" // clear current line before printing
162+
out += outLine
163163
out += "(press 'n'/'right' for next, 'p'/'left' for prev, 'enter' to init chain, 'q'/'ctrl+c' to quit)\n"
164164
return out
165165
}
166166

167-
func DiscoverHandler(ctx context.Context, cmd *plugin.ExecutedCommand) error {
168-
s := spinner.NewModel()
167+
func DiscoverHandler(context.Context, *plugin.ExecutedCommand) error {
168+
s := spinner.New()
169169
s.Spinner = spinner.Dot
170170
model := &discoverCmdModel{
171171
spinner: s,
@@ -177,7 +177,7 @@ func DiscoverHandler(ctx context.Context, cmd *plugin.ExecutedCommand) error {
177177
return err
178178
}
179179

180-
// if the user selected a chain, execute the add command
180+
// if the user selected a chain, execute the add command.
181181
if len(model.selectedChain.ChainName) > 0 {
182182
selectedChain := model.chainRegistry.Chains[model.selectedChain.ChainName]
183183

connect/cmd/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package cmd
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"os"
87
"path"
98

9+
"github.com/ignite/cli/v29/ignite/pkg/errors"
1010
"github.com/ignite/cli/v29/ignite/services/plugin"
1111

1212
"github.com/ignite/apps/connect/chains"
1313
)
1414

15-
func RemoveHandler(ctx context.Context, cmd *plugin.ExecutedCommand) error {
15+
func RemoveHandler(_ context.Context, cmd *plugin.ExecutedCommand) error {
1616
if len(cmd.Args) < 1 {
1717
return errors.New("usage: connect remove <chain>")
1818
}

0 commit comments

Comments
 (0)