Skip to content

Commit bf5b473

Browse files
committed
chore: lint
1 parent 574e2a1 commit bf5b473

5 files changed

Lines changed: 38 additions & 28 deletions

File tree

attachments.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements Pop, a tool for sending emails from your terminal.
12
package main
23

34
import (

email.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ func (m Model) sendEmailCmd() tea.Cmd {
5959
}
6060
}
6161

62-
const gmailSuffix = "@gmail.com"
63-
const gmailSMTPHost = "smtp.gmail.com"
64-
const gmailSMTPPort = 587
62+
const (
63+
gmailSuffix = "@gmail.com"
64+
gmailSMTPHost = "smtp.gmail.com"
65+
gmailSMTPPort = 587
66+
)
6567

6668
func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments []string) error {
6769
server := mail.NewSMTPClient()
@@ -100,9 +102,8 @@ func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments
100102
}
101103

102104
smtpClient, err := server.Connect()
103-
104105
if err != nil {
105-
return err
106+
return fmt.Errorf("connecting to SMTP server: %w", err)
106107
}
107108

108109
email := mail.NewMSG()
@@ -128,10 +129,10 @@ func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments
128129
})
129130
}
130131

131-
return email.Send(smtpClient)
132+
return fmt.Errorf("sending email: %w", email.Send(smtpClient))
132133
}
133134

134-
func sendResendEmail(to, _, _ []string, from, subject, body string, attachments []string) error {
135+
func sendResendEmail(to, cc, bcc []string, from, subject, body string, attachments []string) error {
135136
client := resend.NewClient(resendAPIKey)
136137

137138
html := bytes.NewBufferString("")
@@ -165,7 +166,7 @@ func sendResendEmail(to, _, _ []string, from, subject, body string, attachments
165166

166167
_, err := client.Emails.Send(request)
167168
if err != nil {
168-
return err
169+
return fmt.Errorf("sending email via Resend: %w", err)
169170
}
170171

171172
return nil
@@ -198,7 +199,7 @@ func saveTmp(s string) (string, error) {
198199
if err != nil {
199200
return "", fmt.Errorf("creating temp file: %w", err)
200201
}
201-
defer f.Close()
202+
defer func() { _ = f.Close() }()
202203

203204
_, err = f.WriteString(s)
204205
if err != nil {

main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const PopSMTPUsername = "POP_SMTP_USERNAME"
4343
const PopSMTPPassword = "POP_SMTP_PASSWORD" //nolint:gosec
4444

4545
// PopSMTPEncryption is the encryption type for the SMTP server if the user is using the SMTP delivery method.
46-
const PopSMTPEncryption = "POP_SMTP_ENCRYPTION" //nolint:gosec
46+
const PopSMTPEncryption = "POP_SMTP_ENCRYPTION"
4747

4848
// PopSMTPInsecureSkipVerify is whether or not to skip TLS verification for the
4949
// SMTP server if the user is using the SMTP delivery method.
@@ -73,7 +73,7 @@ var rootCmd = &cobra.Command{
7373
Use: "pop",
7474
Short: "Send emails from your terminal",
7575
Long: `Pop is a tool for sending emails from your terminal.`,
76-
RunE: func(cmd *cobra.Command, args []string) error {
76+
RunE: func(cmd *cobra.Command, _ []string) error {
7777
var deliveryMethod DeliveryMethod
7878
switch {
7979
case resendAPIKey != "" && smtpUsername != "" && smtpPassword != "":
@@ -101,12 +101,13 @@ var rootCmd = &cobra.Command{
101101
cmd.SilenceUsage = true
102102
cmd.SilenceErrors = true
103103
return errors.New("unknown delivery method")
104+
case Resend, SMTP:
104105
}
105106

106107
if body == "" && hasStdin() {
107108
b, err := io.ReadAll(os.Stdin)
108109
if err != nil {
109-
return err
110+
return fmt.Errorf("reading stdin: %w", err)
110111
}
111112
body = string(b)
112113
}
@@ -147,7 +148,7 @@ var rootCmd = &cobra.Command{
147148

148149
m, err := p.Run()
149150
if err != nil {
150-
return err
151+
return fmt.Errorf("running program: %w", err)
151152
}
152153
mm := m.(Model)
153154
if !mm.abort {
@@ -167,7 +168,7 @@ var (
167168
// Version stores the build version of VHS at the time of package through
168169
// -ldflags.
169170
//
170-
// go build -ldflags "-s -w -X=main.Version=$(VERSION)"
171+
// go build -ldflags "-s -w -X=main.Version=$(VERSION)".
171172
Version string
172173

173174
// CommitSHA stores the git commit SHA at the time of package through -ldflags.
@@ -182,9 +183,9 @@ var ManCmd = &cobra.Command{
182183
Args: cobra.NoArgs,
183184
Hidden: true,
184185
RunE: func(_ *cobra.Command, _ []string) error {
185-
page, err := mcobra.NewManPage(1, rootCmd) // .
186+
page, err := mcobra.NewManPage(1, rootCmd)
186187
if err != nil {
187-
return err
188+
return fmt.Errorf("generating man page: %w", err)
188189
}
189190

190191
page = page.WithSection("Copyright", "© 2023 Charmbracelet, Inc.\n"+"Released under MIT License.")

model.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M
8989
from := textinput.New()
9090
from.Prompt = "From "
9191
from.Placeholder = "me@example.com"
92-
from.PromptStyle = labelStyle.Copy()
9392
from.PromptStyle = labelStyle
9493
from.TextStyle = textStyle
9594
from.Cursor.Style = cursorStyle
@@ -98,7 +97,7 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M
9897

9998
to := textinput.New()
10099
to.Prompt = "To "
101-
to.PromptStyle = labelStyle.Copy()
100+
to.PromptStyle = labelStyle
102101
to.Cursor.Style = cursorStyle
103102
to.PlaceholderStyle = placeholderStyle
104103
to.TextStyle = textStyle
@@ -107,7 +106,7 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M
107106

108107
cc := textinput.New()
109108
cc.Prompt = "Cc "
110-
cc.PromptStyle = labelStyle.Copy()
109+
cc.PromptStyle = labelStyle
111110
cc.Cursor.Style = cursorStyle
112111
cc.PlaceholderStyle = placeholderStyle
113112
cc.TextStyle = textStyle
@@ -116,7 +115,7 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M
116115

117116
bcc := textinput.New()
118117
bcc.Prompt = "Bcc "
119-
bcc.PromptStyle = labelStyle.Copy()
118+
bcc.PromptStyle = labelStyle
120119
bcc.Cursor.Style = cursorStyle
121120
bcc.PlaceholderStyle = placeholderStyle
122121
bcc.TextStyle = textStyle
@@ -125,7 +124,7 @@ func NewModel(defaults resend.SendEmailRequest, deliveryMethod DeliveryMethod) M
125124

126125
subject := textinput.New()
127126
subject.Prompt = "Subject "
128-
subject.PromptStyle = labelStyle.Copy()
127+
subject.PromptStyle = labelStyle
129128
subject.Cursor.Style = cursorStyle
130129
subject.PlaceholderStyle = placeholderStyle
131130
subject.TextStyle = textStyle
@@ -221,7 +220,7 @@ func (m Model) Init() tea.Cmd {
221220
type clearErrMsg struct{}
222221

223222
func clearErrAfter(d time.Duration) tea.Cmd {
224-
return tea.Tick(d, func(t time.Time) tea.Msg {
223+
return tea.Tick(d, func(_ time.Time) tea.Msg {
225224
return clearErrMsg{}
226225
})
227226
}
@@ -266,6 +265,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
266265
m.state = hoveringSendButton
267266
case hoveringSendButton:
268267
m.state = editingFrom
268+
case pickingFile, sendingEmail:
269269
}
270270
m.focusActiveInput()
271271

@@ -292,6 +292,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
292292
m.state = editingBody
293293
case hoveringSendButton:
294294
m.state = editingAttachments
295+
case pickingFile, sendingEmail:
295296
}
296297
m.focusActiveInput()
297298

@@ -353,6 +354,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
353354
case sendingEmail:
354355
m.loadingSpinner, cmd = m.loadingSpinner.Update(msg)
355356
cmds = append(cmds, cmd)
357+
case editingFrom, editingTo, editingCc, editingBcc, editingSubject, editingBody, hoveringSendButton:
356358
}
357359

358360
m.help, cmd = m.help.Update(msg)
@@ -419,6 +421,7 @@ func (m *Model) focusActiveInput() {
419421
case editingAttachments:
420422
m.Attachments.Styles.Title = activeLabelStyle
421423
m.Attachments.SetDelegate(attachmentDelegate{true})
424+
case hoveringSendButton, pickingFile, sendingEmail:
422425
}
423426
}
424427

@@ -434,6 +437,7 @@ func (m Model) View() string {
434437
"\n\n" + m.filepicker.View()
435438
case sendingEmail:
436439
return "\n " + m.loadingSpinner.View() + "Sending email"
440+
case editingFrom, editingTo, editingCc, editingBcc, editingSubject, editingBody, editingAttachments, hoveringSendButton:
437441
}
438442

439443
var s strings.Builder

style.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements Pop, a tool for sending emails from your terminal.
12
package main
23

34
import (
@@ -6,12 +7,14 @@ import (
67
"github.com/charmbracelet/lipgloss"
78
)
89

9-
const accentColor = lipgloss.Color("99")
10-
const yellowColor = lipgloss.Color("#ECFD66")
11-
const whiteColor = lipgloss.Color("255")
12-
const grayColor = lipgloss.Color("241")
13-
const darkGrayColor = lipgloss.Color("236")
14-
const lightGrayColor = lipgloss.Color("247")
10+
const (
11+
accentColor = lipgloss.Color("99")
12+
yellowColor = lipgloss.Color("#ECFD66")
13+
whiteColor = lipgloss.Color("255")
14+
grayColor = lipgloss.Color("241")
15+
darkGrayColor = lipgloss.Color("236")
16+
lightGrayColor = lipgloss.Color("247")
17+
)
1518

1619
var (
1720
activeTextStyle = lipgloss.NewStyle().Foreground(whiteColor)

0 commit comments

Comments
 (0)