Skip to content
Myr

Improvements to code quality and readability (#1737)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Remove 1 unused field and 3 unused functions unused elements fount by running golangci-lint run --disable-all --enable unused src/result.go:19:2: field `index` is unused (unused) index int32 ^ src/tui/light.go:716:23: func `(*LightWindow).stderr` is unused (unused) func (w *LightWindow) stderr(str string) { ^ src/terminal.go:1015:6: func `numLinesMax` is unused (unused) func numLinesMax(str string, max int) int { ^ src/tui/tui.go:167:20: func `ColorPair.is24` is unused (unused) func (p ColorPair) is24() bool { ^ * Address warnings from "gosimple" linter src/options.go:389:83: S1003: should use strings.Contains(str, ",,,") instead (gosimple) if str == "," || strings.HasPrefix(str, ",,") || strings.HasSuffix(str, ",,") || strings.Index(str, ",,,") >= 0 { ^ src/options.go:630:18: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple) executeRegexp = regexp.MustCompile( ^ src/terminal.go:29:16: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple) placeholder = regexp.MustCompile("\\\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\\+?f?nf?})") ^ src/terminal_test.go:92:10: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple) regex = regexp.MustCompile("\\w+") ^ * Address warnings from "staticcheck" linter src/algo/algo.go:374:2: SA4006: this value of `offset32` is never used (staticcheck) offset32, T := alloc32(offset32, slab, N) ^ src/algo/algo.go:456:2: SA4006: this value of `offset16` is never used (staticcheck) offset16, C := alloc16(offset16, slab, width*M) ^ src/tui/tui.go:119:2: SA9004: only the first constant in this group has an explicit type (staticcheck) colUndefined Color = -2 ^

authored by Alexandr · committed by Junegunn Choi · parent b911af2 · Browse files · 7 files+7 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+7 added−29 removed

  • other:+7 added−29 removed

7 files+7 added−29 removed

modified:src/algo/algo.go+2 added-2 removed
369 unmodified lines
370 offset16, B := alloc16(offset16, slab, N)371 // The first occurrence of each character in the pattern372 offset32, F := alloc32(offset32, slab, M)373 // Rune array374 offset32, T := alloc32(offset32, slab, N)374 _, T := alloc32(offset32, slab, N)375 input.CopyRunes(T)376377 // Phase 2. Calculate bonus for each point378 maxScore, maxScorePos := int16(0), 0
73 unmodified lines
452 offset16, H := alloc16(offset16, slab, width*M)453 copy(H, H0[f0:lastIdx+1])454455 // Possible length of consecutive chunk at each position.456 offset16, C := alloc16(offset16, slab, width*M)456 _, C := alloc16(offset16, slab, width*M)457 copy(C, C0[f0:lastIdx+1])458459 Fsub := F[1:]460 Psub := pattern[1:][:len(Fsub)]
399 unmodified lines
modified:src/tui/light.go-4 removed
711 unmodified lines
712func (w *LightWindow) csi(code string) {713 w.renderer.csi(code)714}715716func (w *LightWindow) stderr(str string) {717 w.renderer.stderr(str)718}719716func (w *LightWindow) stderrInternal(str string, allowNLCR bool) {717 w.renderer.stderrInternal(str, allowNLCR)718}719
224 unmodified lines
modified:src/tui/tui.go+1 added-5 removed
115 unmodified lines
116}117118const (119 colUndefined Color = -2120 colDefault = -1120 colDefault Color = -1121)122123const (124 colBlack Color = iota
38 unmodified lines
163func (p ColorPair) Bg() Color {164 return p.bg165}166167func (p ColorPair) is24() bool {168 return p.fg.is24() || p.bg.is24()169}170167type ColorTheme struct {168 Fg Color169 Bg Color170 DarkBg Color
302 unmodified lines
modified:src/options.go+2 added-2 removed
384 unmodified lines
385 errorExit(message)386 }387388 tokens := strings.Split(str, ",")389 if str == "," || strings.HasPrefix(str, ",,") || strings.HasSuffix(str, ",,") || strings.Index(str, ",,,") >= 0 {389 if str == "," || strings.HasPrefix(str, ",,") || strings.HasSuffix(str, ",,") || strings.Contains(str, ",,,") {390 tokens = append(tokens, ",")391 }392393 chords := make(map[int]string)
233 unmodified lines
627func init() {628 // Backreferences are not supported.629 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')630 executeRegexp = regexp.MustCompile(631 "(?si):(execute(?:-multi|-silent)?):.+|:(execute(?:-multi|-silent)?)(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")631 `(?si):(execute(?:-multi|-silent)?):.+|:(execute(?:-multi|-silent)?)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)632}633634func parseKeymap(keymap map[int][]action, str string) {635 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
683 unmodified lines
modified:src/result.go-1 removed
14 unmodified lines
15type colorOffset struct {16 offset [2]int3217 color tui.ColorPair18 attr tui.Attr19 index int3219}2021type Result struct {22 item *Item
203 unmodified lines
modified:src/terminal_test.go+1 added-1 removed
87 unmodified lines
88 result = replacePlaceholder("echo {s..}", true, Delimiter{str: &delim}, printsep, false, "query", items1)89 check("echo ' foo'\\''bar baz'")9091 // Whitespace preserving flag with regex delimiter92 regex = regexp.MustCompile("\\w+")92 regex = regexp.MustCompile(`\w+`)9394 result = replacePlaceholder("echo {s1}", true, Delimiter{regex: regex}, printsep, false, "query", items1)95 check("echo ' '")96
43 unmodified lines
modified:src/terminal.go+1 added-14 removed
24 unmodified lines
25var placeholder *regexp.Regexp26var activeTempFiles []string2728func init() {29 placeholder = regexp.MustCompile("\\\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\\+?f?nf?})")29 placeholder = regexp.MustCompile(`\\?(?:{[+sf]*[0-9,-.]*}|{q}|{\+?f?nf?})`)30 activeTempFiles = []string{}31}3233type jumpMode int
977 unmodified lines
1011 }1012 return displayWidth1013}10141015func numLinesMax(str string, max int) int {1016 lines := 01017 for lines < max {1018 idx := strings.Index(str, "\n")1019 if idx < 0 {1020 break1021 }1022 str = str[idx+1:]1023 lines++1024 }1025 return lines1026}10271015func (t *Terminal) printPreview() {1016 if !t.hasPreviewWindow() {1017 return1018 }
1116 unmodified lines