Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit 82a5fab

Browse files
authored
Resolve misc. lint violations and formatting issues (#471)
* Ignore staticcheck violations about error message formatting * Avoid using `strings.Title` * Rename error type to start with "err" * Iterate over string runes directly * go fmt code comments * go fmt build directives
1 parent f0d409e commit 82a5fab

15 files changed

+35
-23
lines changed

confirm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (c *Confirm) getBool(showHelp bool, config *PromptConfig) (bool, error) {
9090
continue
9191
default:
9292
// we didnt get a valid answer, so print error and prompt again
93+
//lint:ignore ST1005 it should be fine for this error message to have punctuation
9394
if err := c.Error(config, fmt.Errorf("%q is not a valid answer, please try again.", val)); err != nil {
9495
return c.Default, err
9596
}

core/template.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ var TemplateFuncsNoColor = map[string]interface{}{
2323
},
2424
}
2525

26-
//RunTemplate returns two formatted strings given a template and
27-
//the data it requires. The first string returned is generated for
28-
//user-facing output and may or may not contain ANSI escape codes
29-
//for colored output. The second string does not contain escape codes
30-
//and can be used by the renderer for layout purposes.
26+
// RunTemplate returns two formatted strings given a template and
27+
// the data it requires. The first string returned is generated for
28+
// user-facing output and may or may not contain ANSI escape codes
29+
// for colored output. The second string does not contain escape codes
30+
// and can be used by the renderer for layout purposes.
3131
func RunTemplate(tmpl string, data interface{}) (string, string, error) {
3232
tPair, err := GetTemplatePair(tmpl)
3333
if err != nil {
@@ -52,11 +52,11 @@ var (
5252
memoMutex = &sync.RWMutex{}
5353
)
5454

55-
//GetTemplatePair returns a pair of compiled templates where the
56-
//first template is generated for user-facing output and the
57-
//second is generated for use by the renderer. The second
58-
//template does not contain any color escape codes, whereas
59-
//the first template may or may not depending on DisableColor.
55+
// GetTemplatePair returns a pair of compiled templates where the
56+
// first template is generated for user-facing output and the
57+
// second is generated for use by the renderer. The second
58+
// template does not contain any color escape codes, whereas
59+
// the first template may or may not depending on DisableColor.
6060
func GetTemplatePair(tmpl string) ([2]*template.Template, error) {
6161
memoMutex.RLock()
6262
if t, ok := memoizedGetTemplate[tmpl]; ok {

core/write.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ func (err errFieldNotMatch) Is(target error) bool { // implements the dynamic er
142142
// It returns the Question.Name that couldn't be matched with a destination field.
143143
//
144144
// Usage:
145-
// err := survey.Ask(qs, &v);
146-
// if err != nil {
147-
// if name, ok := core.IsFieldNotMatch(err); ok {
148-
// [...name is the not matched question name]
149-
// }
150-
// }
145+
//
146+
// if err := survey.Ask(qs, &v); err != nil {
147+
// if name, ok := core.IsFieldNotMatch(err); ok {
148+
// // name is the question name that did not match a field
149+
// }
150+
// }
151151
func IsFieldNotMatch(err error) (string, bool) {
152152
if err != nil {
153153
if v, ok := err.(errFieldNotMatch); ok {
@@ -301,6 +301,7 @@ func copy(t reflect.Value, v reflect.Value) (err error) {
301301
case reflect.Float64:
302302
castVal, casterr = strconv.ParseFloat(vString, 64)
303303
default:
304+
//lint:ignore ST1005 allow this error message to be capitalized
304305
return fmt.Errorf("Unable to convert from string to type %s", t.Kind())
305306
}
306307

@@ -335,6 +336,7 @@ func copy(t reflect.Value, v reflect.Value) (err error) {
335336
}
336337

337338
// we're copying an option answer to an incorrect type
339+
//lint:ignore ST1005 allow this error message to be capitalized
338340
return fmt.Errorf("Unable to convert from OptionAnswer to type %s", t.Kind())
339341
}
340342

input.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ func (i *Input) onRune(config *PromptConfig) terminal.OnRuneFn {
127127
)
128128

129129
if err == nil {
130-
err = readLineAgain
130+
err = errReadLineAgain
131131
}
132132

133133
return []rune(i.typedAnswer), true, err
134134
})
135135
}
136136

137-
var readLineAgain = errors.New("read line again")
137+
var errReadLineAgain = errors.New("read line again")
138138

139139
func (i *Input) Prompt(config *PromptConfig) (interface{}, error) {
140140
// render the template
@@ -170,7 +170,7 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) {
170170
}
171171

172172
line, err = rr.ReadLineWithDefault(0, line, i.onRune(config))
173-
if err == readLineAgain {
173+
if err == errReadLineAgain {
174174
continue
175175
}
176176

survey.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ in the documentation. For example:
278278
}
279279
280280
survey.AskOne(prompt, &name)
281-
282281
*/
283282
func AskOne(p Prompt, response interface{}, opts ...AskOpt) error {
284283
err := Ask([]*Question{{Prompt: p}}, response, opts...)

terminal/display_posix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package terminal

terminal/error.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import (
55
)
66

77
var (
8+
//lint:ignore ST1012 keeping old name for backwards compatibility
89
InterruptErr = errors.New("interrupt")
910
)

terminal/output.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package terminal

terminal/runereader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ func StringWidth(str string) int {
405405
w := 0
406406
ansi := false
407407

408-
rs := []rune(str)
409-
for _, r := range rs {
408+
for _, r := range str {
410409
// increase width only when outside of ANSI escape sequences
411410
if ansi || isAnsiMarker(r) {
412411
ansi = !isAnsiTerminator(r)

terminal/runereader_bsd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a BSD-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
67
// +build darwin dragonfly freebsd netbsd openbsd
78

89
package terminal

0 commit comments

Comments
 (0)