Skip to content

Commit 20fd13d

Browse files
committed
Fix golint-cli -fast warnings
1 parent 269b041 commit 20fd13d

8 files changed

+7
-40
lines changed

buffer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (b *Buffer) setText(v string) {
7171
b.workingLines[b.workingIndex] = v
7272

7373
if o != v {
74+
dummyExecutor("")
7475
// Text is changed.
7576
// TODO: Call callback function triggered by text changed. And also history search text should reset.
7677
// https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/buffer.py#L380-L384
@@ -86,6 +87,7 @@ func (b *Buffer) setCursorPosition(p int) {
8687
b.cursorPosition = 0
8788
}
8889
if p != o {
90+
dummyExecutor("")
8991
// Cursor position is changed.
9092
// TODO: Call a onCursorPositionChanged function.
9193
}
@@ -101,14 +103,12 @@ func (b *Buffer) setDocument(d *Document) {
101103
func (b *Buffer) CursorLeft(count int) {
102104
l := b.Document().GetCursorLeftPosition(count)
103105
b.cursorPosition += l
104-
return
105106
}
106107

107108
// CursorRight move to right on the current line.
108109
func (b *Buffer) CursorRight(count int) {
109110
l := b.Document().GetCursorRightPosition(count)
110111
b.cursorPosition += l
111-
return
112112
}
113113

114114
// CursorUp move cursor to the previous line.

completion.go

-4
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ func (c *CompletionManager) Reset() {
6161
c.selected = -1
6262
c.verticalScroll = 0
6363
c.Update(*NewDocument())
64-
return
6564
}
6665

6766
// Update to update the suggestions.
6867
func (c *CompletionManager) Update(in Document) {
6968
c.tmp = c.completer(in)
70-
return
7169
}
7270

7371
// Previous to select the previous suggestion item.
@@ -77,7 +75,6 @@ func (c *CompletionManager) Previous() {
7775
}
7876
c.selected--
7977
c.update()
80-
return
8178
}
8279

8380
// Next to select the next suggestion item.
@@ -87,7 +84,6 @@ func (c *CompletionManager) Next() {
8784
}
8885
c.selected++
8986
c.update()
90-
return
9187
}
9288

9389
// Completing returns whether the CompletionManager selects something one.

filter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func FilterFuzzy(completions []Suggest, sub string, ignoreCase bool) []Suggest {
3030

3131
func fuzzyMatch(s, sub string) bool {
3232
sChars := []rune(s)
33-
subChars := []rune(sub)
3433
sIdx := 0
3534

36-
for _, c := range subChars {
35+
// https://staticcheck.io/docs/checks#S1029
36+
for _, c := range sub {
3737
found := false
3838
for ; sIdx < len(sChars); sIdx++ {
3939
if sChars[sIdx] == c {

output_vt100.go

-25
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,53 @@ type VT100Writer struct {
1313
// WriteRaw to write raw byte array
1414
func (w *VT100Writer) WriteRaw(data []byte) {
1515
w.buffer = append(w.buffer, data...)
16-
return
1716
}
1817

1918
// Write to write safety byte array by removing control sequences.
2019
func (w *VT100Writer) Write(data []byte) {
2120
w.WriteRaw(bytes.Replace(data, []byte{0x1b}, []byte{'?'}, -1))
22-
return
2321
}
2422

2523
// WriteRawStr to write raw string
2624
func (w *VT100Writer) WriteRawStr(data string) {
2725
w.WriteRaw([]byte(data))
28-
return
2926
}
3027

3128
// WriteStr to write safety string by removing control sequences.
3229
func (w *VT100Writer) WriteStr(data string) {
3330
w.Write([]byte(data))
34-
return
3531
}
3632

3733
/* Erase */
3834

3935
// EraseScreen erases the screen with the background colour and moves the cursor to home.
4036
func (w *VT100Writer) EraseScreen() {
4137
w.WriteRaw([]byte{0x1b, '[', '2', 'J'})
42-
return
4338
}
4439

4540
// EraseUp erases the screen from the current line up to the top of the screen.
4641
func (w *VT100Writer) EraseUp() {
4742
w.WriteRaw([]byte{0x1b, '[', '1', 'J'})
48-
return
4943
}
5044

5145
// EraseDown erases the screen from the current line down to the bottom of the screen.
5246
func (w *VT100Writer) EraseDown() {
5347
w.WriteRaw([]byte{0x1b, '[', 'J'})
54-
return
5548
}
5649

5750
// EraseStartOfLine erases from the current cursor position to the start of the current line.
5851
func (w *VT100Writer) EraseStartOfLine() {
5952
w.WriteRaw([]byte{0x1b, '[', '1', 'K'})
60-
return
6153
}
6254

6355
// EraseEndOfLine erases from the current cursor position to the end of the current line.
6456
func (w *VT100Writer) EraseEndOfLine() {
6557
w.WriteRaw([]byte{0x1b, '[', 'K'})
66-
return
6758
}
6859

6960
// EraseLine erases the entire current line.
7061
func (w *VT100Writer) EraseLine() {
7162
w.WriteRaw([]byte{0x1b, '[', '2', 'K'})
72-
return
7363
}
7464

7565
/* Cursor */
@@ -82,7 +72,6 @@ func (w *VT100Writer) ShowCursor() {
8272
// HideCursor hides cursor.
8373
func (w *VT100Writer) HideCursor() {
8474
w.WriteRaw([]byte{0x1b, '[', '?', '2', '5', 'l'})
85-
return
8675
}
8776

8877
// CursorGoTo sets the cursor position where subsequent text will begin.
@@ -99,7 +88,6 @@ func (w *VT100Writer) CursorGoTo(row, col int) {
9988
w.WriteRaw([]byte{';'})
10089
w.WriteRaw([]byte(c))
10190
w.WriteRaw([]byte{'H'})
102-
return
10391
}
10492

10593
// CursorUp moves the cursor up by 'n' rows; the default count is 1.
@@ -114,7 +102,6 @@ func (w *VT100Writer) CursorUp(n int) {
114102
w.WriteRaw([]byte{0x1b, '['})
115103
w.WriteRaw([]byte(s))
116104
w.WriteRaw([]byte{'A'})
117-
return
118105
}
119106

120107
// CursorDown moves the cursor down by 'n' rows; the default count is 1.
@@ -129,7 +116,6 @@ func (w *VT100Writer) CursorDown(n int) {
129116
w.WriteRaw([]byte{0x1b, '['})
130117
w.WriteRaw([]byte(s))
131118
w.WriteRaw([]byte{'B'})
132-
return
133119
}
134120

135121
// CursorForward moves the cursor forward by 'n' columns; the default count is 1.
@@ -144,7 +130,6 @@ func (w *VT100Writer) CursorForward(n int) {
144130
w.WriteRaw([]byte{0x1b, '['})
145131
w.WriteRaw([]byte(s))
146132
w.WriteRaw([]byte{'C'})
147-
return
148133
}
149134

150135
// CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
@@ -159,40 +144,34 @@ func (w *VT100Writer) CursorBackward(n int) {
159144
w.WriteRaw([]byte{0x1b, '['})
160145
w.WriteRaw([]byte(s))
161146
w.WriteRaw([]byte{'D'})
162-
return
163147
}
164148

165149
// AskForCPR asks for a cursor position report (CPR).
166150
func (w *VT100Writer) AskForCPR() {
167151
// CPR: Cursor Position Request.
168152
w.WriteRaw([]byte{0x1b, '[', '6', 'n'})
169-
return
170153
}
171154

172155
// SaveCursor saves current cursor position.
173156
func (w *VT100Writer) SaveCursor() {
174157
w.WriteRaw([]byte{0x1b, '[', 's'})
175-
return
176158
}
177159

178160
// UnSaveCursor restores cursor position after a Save Cursor.
179161
func (w *VT100Writer) UnSaveCursor() {
180162
w.WriteRaw([]byte{0x1b, '[', 'u'})
181-
return
182163
}
183164

184165
/* Scrolling */
185166

186167
// ScrollDown scrolls display down one line.
187168
func (w *VT100Writer) ScrollDown() {
188169
w.WriteRaw([]byte{0x1b, 'D'})
189-
return
190170
}
191171

192172
// ScrollUp scroll display up one line.
193173
func (w *VT100Writer) ScrollUp() {
194174
w.WriteRaw([]byte{0x1b, 'M'})
195-
return
196175
}
197176

198177
/* Title */
@@ -220,13 +199,11 @@ func (w *VT100Writer) SetTitle(title string) {
220199
w.WriteRaw([]byte{0x1b, ']', '2', ';'})
221200
w.WriteRaw(titleBytes)
222201
w.WriteRaw([]byte{0x07})
223-
return
224202
}
225203

226204
// ClearTitle clears a title of terminal window.
227205
func (w *VT100Writer) ClearTitle() {
228206
w.WriteRaw([]byte{0x1b, ']', '2', ';', 0x07})
229-
return
230207
}
231208

232209
/* Font */
@@ -240,7 +217,6 @@ func (w *VT100Writer) SetColor(fg, bg Color, bold bool) {
240217
// Details are https://github.com/c-bata/go-prompt/pull/85
241218
w.SetDisplayAttributes(fg, bg, DisplayReset)
242219
}
243-
return
244220
}
245221

246222
// SetDisplayAttributes to set VT100 display attributes.
@@ -269,7 +245,6 @@ func (w *VT100Writer) SetDisplayAttributes(fg, bg Color, attrs ...DisplayAttribu
269245
b = backgroundANSIColors[DefaultColor]
270246
}
271247
w.WriteRaw(b)
272-
return
273248
}
274249

275250
var displayAttributeParameters = map[DisplayAttribute][]byte{

output_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (w *WindowsWriter) Flush() error {
2828
var _ ConsoleWriter = &WindowsWriter{}
2929

3030
var (
31-
// Deprecated: Please use NewStdoutWriter
31+
// NewStandardOutputWriter is Deprecated: Please use NewStdoutWriter
3232
NewStandardOutputWriter = NewStdoutWriter
3333
)
3434

prompt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (p *Prompt) handleKeyBinding(key Key) bool {
221221
func (p *Prompt) handleASCIICodeBinding(b []byte) bool {
222222
checked := false
223223
for _, kb := range p.ASCIICodeBindings {
224-
if bytes.Compare(kb.ASCIICode, b) == 0 {
224+
if bytes.Equal(kb.ASCIICode, b) {
225225
kb.Fn(p.buf)
226226
checked = true
227227
}

render.go

-4
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,19 @@ func (r *Render) prepareArea(lines int) {
7575
for i := 0; i < lines; i++ {
7676
r.out.ScrollUp()
7777
}
78-
return
7978
}
8079

8180
// UpdateWinSize called when window size is changed.
8281
func (r *Render) UpdateWinSize(ws *WinSize) {
8382
r.row = ws.Row
8483
r.col = ws.Col
85-
return
8684
}
8785

8886
func (r *Render) renderWindowTooSmall() {
8987
r.out.CursorGoTo(0, 0)
9088
r.out.EraseScreen()
9189
r.out.SetColor(DarkRed, White, false)
9290
r.out.WriteStr("Your console window is too small...")
93-
return
9491
}
9592

9693
func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
@@ -167,7 +164,6 @@ func (r *Render) renderCompletion(buf *Buffer, completions *CompletionManager) {
167164

168165
r.out.CursorUp(windowHeight)
169166
r.out.SetColor(DefaultColor, DefaultColor, false)
170-
return
171167
}
172168

173169
// Render renders to the console.

shortcut.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package prompt
22

3-
func dummyExecutor(in string) { return }
3+
func dummyExecutor(in string) {}
44

55
// Input get the input data from the user and return it.
66
func Input(prefix string, completer Completer, opts ...Option) string {

0 commit comments

Comments
 (0)