docs: fix lint issues in examples and tutorials (#759)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Carlos Alexandro Becker · committed by GitHub · parent b2d2ac6 · Browse files · 18 files·+47 added−66 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Diff stats
18 files+47 added−66 removed
- other:+47 added−66 removed
Provenance
- Commit
b80eb83- Tree
478e2d7- Author
Carlos Alexandro Becker <caarlos0@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
b2d2ac6
18 files changed+47 added−66 removed
modified:examples/cellbuffer/main.go+13 added-17 removed
16 unmodified lines17 const (18 fps = 6019 frequency = 7.520 damping = 0.1521+ asterisk = "*"22 )23 24 func drawEllipse(cb *cellbuffer, xc, yc, rx, ry float64) {24- const c = "*"25 var (26 dx, dy, d1, d2 float6427- x float64 = 028- y = ry27+ x float6428+ y = ry29 )30 31 d1 = ry*ry - rx*rx*ry + 0.25*rx*rx32 dx = 2 * ry * ry * x33 dy = 2 * rx * rx * y34 35 for dx < dy {36- cb.set(c, int(x+xc), int(y+yc))37- cb.set(c, int(-x+xc), int(y+yc))38- cb.set(c, int(x+xc), int(-y+yc))39- cb.set(c, int(-x+xc), int(-y+yc))36+ cb.set(int(x+xc), int(y+yc))37+ cb.set(int(-x+xc), int(y+yc))38+ cb.set(int(x+xc), int(-y+yc))39+ cb.set(int(-x+xc), int(-y+yc))40 if d1 < 0 {41 x++42 dx = dx + (2 * ry * ry)43 d1 = d1 + dx + (ry * ry)8 unmodified lines52 53 d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx * ry * ry)54 55 for y >= 0 {56- cb.set(c, int(x+xc), int(y+yc))57- cb.set(c, int(-x+xc), int(y+yc))58- cb.set(c, int(x+xc), int(-y+yc))59- cb.set(c, int(-x+xc), int(-y+yc))56+ cb.set(int(x+xc), int(y+yc))57+ cb.set(int(-x+xc), int(y+yc))58+ cb.set(int(x+xc), int(-y+yc))59+ cb.set(int(-x+xc), int(-y+yc))60 if d2 > 0 {61 y--62 dy = dy - (2 * rx * rx)63 d2 = d2 + (rx * rx) - dy20 unmodified lines84 c.cells = make([]string, w*h)85 c.wipe()86 }87 88-func (c cellbuffer) set(v string, x, y int) {88+func (c cellbuffer) set(x, y int) {89 i := y*c.stride + x90 if i > len(c.cells)-1 || x < 0 || y < 0 || x >= c.width() || y >= c.height() {91 return92 }93- c.cells[i] = v93+ c.cells[i] = asterisk94 }95 96-func (c *cellbuffer) clear(x, y int) {97- c.set(" ", x, y)98-}99-96 func (c *cellbuffer) wipe() {97 for i := range c.cells {98 c.cells[i] = " "99 }96 unmodified linesmodified:examples/composable-views/main.go+1 added-1 removed
96 unmodified lines97 cmds = append(cmds, m.timer.Init())98 } else {99 m.Next()100 m.resetSpinner()101- cmds = append(cmds, spinner.Tick)101+ cmds = append(cmds, m.spinner.Tick)102 }103 }104 switch m.state {105 // update whichever model is focused57 unmodified linesmodified:examples/help/main.go+3 added-3 removed
130 unmodified lines131 }132 133 func main() {134 if os.Getenv("HELP_DEBUG") != "" {135- if f, err := tea.LogToFile("debug.log", "help"); err != nil {135+ f, err := tea.LogToFile("debug.log", "help")136+ if err != nil {137 fmt.Println("Couldn't open a file for logging:", err)138 os.Exit(1)138- } else {139- defer f.Close()139 }140+ defer f.Close() // nolint:errcheck141 }142 143 if _, err := tea.NewProgram(newModel()).Run(); err != nil {144 fmt.Printf("Could not start program :(\n%v\n", err)3 unmodified linesmodified:examples/http/main.go+1 added-1 removed
74 unmodified lines75 res, err := c.Get(url)76 if err != nil {77 return errMsg{err}78 }79- defer res.Body.Close()79+ defer res.Body.Close() // nolint:errcheck80 81 return statusMsg(res.StatusCode)82 }modified:examples/list-simple/main.go+3 added-3 removed
26 unmodified lines27 func (i item) FilterValue() string { return "" }28 29 type itemDelegate struct{}30 31-func (d itemDelegate) Height() int { return 1 }32-func (d itemDelegate) Spacing() int { return 0 }33-func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }31+func (d itemDelegate) Height() int { return 1 }32+func (d itemDelegate) Spacing() int { return 0 }33+func (d itemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil }34 func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {35 i, ok := listItem.(item)36 if !ok {37 return91 unmodified linesmodified:examples/package-manager/main.go+1 added-3 removed
113 unmodified lines114 115 func downloadAndInstall(pkg string) tea.Cmd {116 // This is where you'd do i/o stuff to download and install packages. In117 // our case we're just pausing for a moment to simulate the process.118- d := time.Millisecond * time.Duration(rand.Intn(500))118+ d := time.Millisecond * time.Duration(rand.Intn(500)) //nolint:gosec119 return tea.Tick(d, func(t time.Time) tea.Msg {120 return installedPkgMsg(pkg)121 })122 }5 unmodified lines128 return b129 }130 131 func main() {132- rand.Seed(time.Now().Unix())133-132 if _, err := tea.NewProgram(newModel()).Run(); err != nil {133 fmt.Println("Error running program:", err)134 os.Exit(1)135 }1 unmodified linemodified:examples/package-manager/packages.go+1 added-1 removed
44 unmodified lines45 pkgs[i], pkgs[j] = pkgs[j], pkgs[i]46 })47 48 for k := range pkgs {49- pkgs[k] += fmt.Sprintf("-%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10))49+ pkgs[k] += fmt.Sprintf("-%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10)) //nolint:gosec50 }51 return pkgs52 }modified:examples/pipe/main.go+1 added-1 removed
56 unmodified lines57 58 func newModel(initialValue string) (m model) {59 i := textinput.New()60 i.Prompt = ""61- i.CursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))61+ i.Cursor.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))62 i.Width = 4863 i.SetValue(initialValue)64 i.CursorEnd()65 i.Focus()28 unmodified linesmodified:examples/prevent-quit/main.go+1 added-1 removed
59 unmodified lines60 ti.Focus()61 62 return model{63 textarea: ti,64- help: help.NewModel(),64+ help: help.New(),65 keymap: keymap{66 save: key.NewBinding(67 key.WithKeys("ctrl+s"),68 key.WithHelp("ctrl+s", "save"),86 unmodified linesmodified:examples/progress-download/main.go+3 added-3 removed
38 unmodified lines39 return len(p), nil40 }41 42 func getResponse(url string) (*http.Response, error) {43- resp, err := http.Get(url)43+ resp, err := http.Get(url) // nolint:gosec44 if err != nil {45 log.Fatal(err)46 }47 if resp.StatusCode != http.StatusOK {15 unmodified lines63 if err != nil {64 fmt.Println("could not get response", err)65 os.Exit(1)66 }67- defer resp.Body.Close()67+ defer resp.Body.Close() // nolint:errcheck68 69 // Don't add TUI if the header doesn't include content size70 // it's impossible see progress without total71 if resp.ContentLength <= 0 {6 unmodified lines78 if err != nil {79 fmt.Println("could not create file:", err)80 os.Exit(1)81 }82- defer file.Close()82+ defer file.Close() // nolint:errcheck83 84 pw := &progressWriter{85 total: int(resp.ContentLength),86 file: file,21 unmodified linesmodified:examples/realtime/main.go+2 added-4 removed
22 unmodified lines23 // asynchronously.24 func listenForActivity(sub chan struct{}) tea.Cmd {25 return func() tea.Msg {26 for {27- time.Sleep(time.Millisecond * time.Duration(rand.Int63n(900)+100))27+ time.Sleep(time.Millisecond * time.Duration(rand.Int63n(900)+100)) // nolint:gosec28 sub <- struct{}{}29 }30 }31 }13 unmodified lines45 }46 47 func (m model) Init() tea.Cmd {48 return tea.Batch(49- spinner.Tick,49+ m.spinner.Tick,50 listenForActivity(m.sub), // generate activity51 waitForActivity(m.sub), // wait for activity52 )53 }23 unmodified lines77 return s78 }79 80 func main() {81- rand.Seed(time.Now().UTC().UnixNano())82-81 p := tea.NewProgram(model{82 sub: make(chan struct{}),83 spinner: spinner.New(),84 })6 unmodified linesmodified:examples/send-msg/main.go+3 added-5 removed
51 unmodified lines52 }53 }54 55 func (m model) Init() tea.Cmd {56- return spinner.Tick56+ return m.spinner.Tick57 }58 59 func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {60 switch msg := msg.(type) {38 unmodified lines99 return appStyle.Render(s)100 }101 102 func main() {103- rand.Seed(time.Now().UTC().UnixNano())104-103 p := tea.NewProgram(newModel())104 105 // Simulate activity106 go func() {107 for {110- pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond108+ pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond // nolint:gosec109 time.Sleep(pause)110 111 // Send the Bubble Tea program a message from outside the112 // tea.Program. This will block until it is ready to receive13 unmodified lines126 "an apple", "a pear", "a gherkin", "a party gherkin",127 "a kohlrabi", "some spaghetti", "tacos", "a currywurst", "some curry",128 "a sandwich", "some peanut butter", "some cashews", "some ramen",129 }132- return string(food[rand.Intn(len(food))])130+ return food[rand.Intn(len(food))] // nolint:gosec131 }modified:examples/stopwatch/main.go+1 added-1 removed
89 unmodified lines90 key.WithKeys("ctrl+c", "q"),91 key.WithHelp("q", "quit"),92 ),93 },94- help: help.NewModel(),94+ help: help.New(),95 }96 97 m.keymap.start.SetEnabled(false)98 5 unmodified linesmodified:examples/textinputs/main.go+6 added-5 removed
6 unmodified lines7 "fmt"8 "os"9 "strings"10 11+ "github.com/charmbracelet/bubbles/cursor"12 "github.com/charmbracelet/bubbles/textinput"13 tea "github.com/charmbracelet/bubbletea"14 "github.com/charmbracelet/lipgloss"15 )12 unmodified lines28 29 type model struct {30 focusIndex int31 inputs []textinput.Model31- cursorMode textinput.CursorMode32+ cursorMode cursor.Mode33 }34 35 func initialModel() model {36 m := model{2 unmodified lines39 40 var t textinput.Model41 for i := range m.inputs {42 t = textinput.New()42- t.CursorStyle = cursorStyle43+ t.Cursor.Style = cursorStyle44 t.CharLimit = 3245 46 switch i {47 case 0:29 unmodified lines77 78 // Change cursor mode79 case "ctrl+r":80 m.cursorMode++80- if m.cursorMode > textinput.CursorHide {81- m.cursorMode = textinput.CursorBlink81+ if m.cursorMode > cursor.CursorHide {82+ m.cursorMode = cursor.CursorBlink83 }84 cmds := make([]tea.Cmd, len(m.inputs))85 for i := range m.inputs {85- cmds[i] = m.inputs[i].SetCursorMode(m.cursorMode)86+ cmds[i] = m.inputs[i].Cursor.SetMode(m.cursorMode)87 }88 return m, tea.Batch(cmds...)89 90 // Set focus to next input88 unmodified linesmodified:examples/timer/main.go+1 added-1 removed
109 unmodified lines110 key.WithKeys("q", "ctrl+c"),111 key.WithHelp("q", "quit"),112 ),113 },114- help: help.NewModel(),114+ help: help.New(),115 }116 m.keymap.start.SetEnabled(false)117 118 if _, err := tea.NewProgram(m).Run(); err != nil {4 unmodified linesmodified:examples/tui-daemon-combo/main.go+3 added-5 removed
17 unmodified lines18 19 var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render20 21 func main() {22- rand.Seed(time.Now().UTC().UnixNano())23-22 var (23 daemonMode bool24 showHelp bool25 opts []tea.ProgramOption48 unmodified lines74 75 func (m model) Init() tea.Cmd {76 log.Println("Starting work...")77 return tea.Batch(80- spinner.Tick,78+ m.spinner.Tick,79 runPretendProcess,80 )81 }82 42 unmodified lines125 type processFinishedMsg time.Duration126 127 // pretendProcess simulates a long-running process.128 func runPretendProcess() tea.Msg {131- pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond129+ pause := time.Duration(rand.Int63n(899)+100) * time.Millisecond // nolint:gosec130 time.Sleep(pause)131 return processFinishedMsg(pause)132 }133 134 func randomEmoji() string {135 emojis := []rune("🍦🧋🍡🤠👾😭🦊🐯🦆🥨🎏🍔🍒🍥🎮📦🦁🐶🐸🍕🥐🧲🚒🥇🏆🌽")138- return string(emojis[rand.Intn(len(emojis))])136+ return string(emojis[rand.Intn(len(emojis))]) // nolint:gosec137 }modified:examples/views/main.go+2 added-10 removed
214 unmodified lines215 if m.Loaded {216 label = fmt.Sprintf("Downloaded. Exiting in %s seconds...", colorFg(strconv.Itoa(m.Ticks), "79"))217 }218 219- return msg + "\n\n" + label + "\n" + progressbar(80, m.Progress) + "%"219+ return msg + "\n\n" + label + "\n" + progressbar(m.Progress) + "%"220 }221 222 func checkbox(label string, checked bool) string {223 if checked {1 unmodified line225 }226 return fmt.Sprintf("[ ] %s", label)227 }228 229-func progressbar(width int, percent float64) string {229+func progressbar(percent float64) string {230 w := float64(progressBarWidth)231 232 fullSize := int(math.Round(w * percent))233 var fullCells string18 unmodified lines252 func makeFgStyle(color string) func(string) string {253 return termenv.Style{}.Foreground(term.Color(color)).Styled254 }255 256-// Color a string's foreground and background with the given value.257-func makeFgBgStyle(fg, bg string) func(string) string {258- return termenv.Style{}.259- Foreground(term.Color(fg)).260- Background(term.Color(bg)).261- Styled262-}263-256 // Generate a blend of colors.257 func makeRamp(colorA, colorB string, steps float64) (s []string) {258 cA, _ := colorful.Hex(colorA)259 cB, _ := colorful.Hex(colorB)22 unmodified linesmodified:tutorials/commands/main.go+1 added-1 removed
20 unmodified lines21 res, err := c.Get(url)22 if err != nil {23 return errMsg{err}24 }25- defer res.Body.Close()25+ defer res.Body.Close() // nolint:errcheck26 27 return statusMsg(res.StatusCode)28 }29 49 unmodified lines