Skip to content

Commit 07a9836

Browse files
committed
Fix review issues: gofmt, dead code, panics, typos, stale docs
Code fixes: - Remove dead `wordchars` field from zshFormat - Remove dead `_ = err` and `_ = cursor` in completion.go - Guard WordbreakPrefix() against empty TokenSlice panic - Fix fish comment: `not` is not a pipeline delimiter (not in KeywordOperators) - Fix comment typos: "lexographical"→"lexicographic", "classifiees"→"classifies" - Fix wordbreak.go URL: stray `)` in Lists.html link - Fix stray blank lines in wordbreak.go and tokenslice.go - Apply gofmt -s across all files Doc fixes: - Update plan.md: TokenSlice methods stay exported (not unexported) - Update plan.md risk #7: remove "become internal implementation details" Assisted-by: Crush:glm-5.2
1 parent 1c2da55 commit 07a9836

16 files changed

Lines changed: 103 additions & 108 deletions

completion.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,5 @@ func SplitForCompletionAt(s string, cursor int, format Format) *CompletionContex
8484
}
8585

8686
ctx.Prefix = pipeline.WordbreakPrefix()
87-
88-
_ = cursor // cursor position is implicitly at end (tokens already reflect full input)
89-
_ = err
9087
return ctx
9188
}

completion_test.go

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,87 @@ import "testing"
44

55
func TestSplitForCompletion(t *testing.T) {
66
tests := []struct {
7-
name string
8-
input string
9-
format Format
10-
wantWord string
11-
wantPrefix string
12-
wantState LexerState
7+
name string
8+
input string
9+
format Format
10+
wantWord string
11+
wantPrefix string
12+
wantState LexerState
1313
wantRedirect bool
14-
wantWords []string
14+
wantWords []string
1515
}{
1616
{
17-
name: "simple word",
18-
input: "echo hel",
19-
format: BashFormat(),
20-
wantWord: "hel",
17+
name: "simple word",
18+
input: "echo hel",
19+
format: BashFormat(),
20+
wantWord: "hel",
2121
wantPrefix: "",
22-
wantState: IN_WORD_STATE,
23-
wantWords: []string{"echo", "hel"},
22+
wantState: IN_WORD_STATE,
23+
wantWords: []string{"echo", "hel"},
2424
},
2525
{
26-
name: "inside double quotes",
27-
input: `echo "hel`,
28-
format: BashFormat(),
29-
wantWord: "hel",
26+
name: "inside double quotes",
27+
input: `echo "hel`,
28+
format: BashFormat(),
29+
wantWord: "hel",
3030
wantPrefix: "",
31-
wantState: QUOTING_ESCAPING_STATE,
32-
wantWords: []string{"echo", "hel"},
31+
wantState: QUOTING_ESCAPING_STATE,
32+
wantWords: []string{"echo", "hel"},
3333
},
3434
{
35-
name: "inside single quotes",
36-
input: "echo 'hel",
37-
format: BashFormat(),
38-
wantWord: "hel",
35+
name: "inside single quotes",
36+
input: "echo 'hel",
37+
format: BashFormat(),
38+
wantWord: "hel",
3939
wantPrefix: "",
40-
wantState: QUOTING_STATE,
41-
wantWords: []string{"echo", "hel"},
40+
wantState: QUOTING_STATE,
41+
wantWords: []string{"echo", "hel"},
4242
},
4343
{
44-
name: "pipeline",
45-
input: "echo foo | grep bar",
46-
format: BashFormat(),
47-
wantWord: "bar",
44+
name: "pipeline",
45+
input: "echo foo | grep bar",
46+
format: BashFormat(),
47+
wantWord: "bar",
4848
wantPrefix: "",
49-
wantState: IN_WORD_STATE,
50-
wantWords: []string{"grep", "bar"},
49+
wantState: IN_WORD_STATE,
50+
wantWords: []string{"grep", "bar"},
5151
},
5252
{
53-
name: "redirect target",
54-
input: "echo foo > bar",
55-
format: BashFormat(),
56-
wantWord: "bar",
57-
wantPrefix: "",
58-
wantState: IN_WORD_STATE,
53+
name: "redirect target",
54+
input: "echo foo > bar",
55+
format: BashFormat(),
56+
wantWord: "bar",
57+
wantPrefix: "",
58+
wantState: IN_WORD_STATE,
5959
wantRedirect: true,
60-
wantWords: []string{"echo", "foo"},
60+
wantWords: []string{"echo", "foo"},
6161
},
6262
{
63-
name: "wordbreak prefix with equals",
64-
input: "echo foo=bar",
65-
format: BashFormat(),
66-
wantWord: "foo=bar",
63+
name: "wordbreak prefix with equals",
64+
input: "echo foo=bar",
65+
format: BashFormat(),
66+
wantWord: "foo=bar",
6767
wantPrefix: "foo=",
68-
wantState: IN_WORD_STATE,
69-
wantWords: []string{"echo", "foo=bar"},
68+
wantState: IN_WORD_STATE,
69+
wantWords: []string{"echo", "foo=bar"},
7070
},
7171
{
72-
name: "empty input",
73-
input: "",
74-
format: BashFormat(),
75-
wantWord: "",
72+
name: "empty input",
73+
input: "",
74+
format: BashFormat(),
75+
wantWord: "",
7676
wantPrefix: "",
77-
wantState: START_STATE,
78-
wantWords: []string{""},
77+
wantState: START_STATE,
78+
wantWords: []string{""},
7979
},
8080
{
81-
name: "escape at end",
82-
input: `echo foo\`,
83-
format: BashFormat(),
84-
wantWord: "foo",
81+
name: "escape at end",
82+
input: `echo foo\`,
83+
format: BashFormat(),
84+
wantWord: "foo",
8585
wantPrefix: "",
86-
wantState: ESCAPING_STATE,
87-
wantWords: []string{"echo", "foo"},
86+
wantState: ESCAPING_STATE,
87+
wantWords: []string{"echo", "foo"},
8888
},
8989
}
9090

format_bash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ func (bashFormat) KeywordOperators() map[string]WordbreakType { return nil }
4242
func (bashFormat) NonEscapingQuoteEscapes() bool { return false }
4343

4444
func (bashFormat) NonEscapingQuoteBackslashEscapes() bool { return false }
45-
func (bashFormat) EscapeNotBareword() bool { return true }
45+
func (bashFormat) EscapeNotBareword() bool { return true }

format_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ func (cmdFormat) ClassifyOperator(raw string) WordbreakType {
6262

6363
func (cmdFormat) KeywordOperators() map[string]WordbreakType { return nil }
6464

65-
func (cmdFormat) NonEscapingQuoteEscapes() bool { return false }
65+
func (cmdFormat) NonEscapingQuoteEscapes() bool { return false }
6666
func (cmdFormat) NonEscapingQuoteBackslashEscapes() bool { return false }
67-
func (cmdFormat) EscapeNotBareword() bool { return true } // ^ is always an escape
67+
func (cmdFormat) EscapeNotBareword() bool { return true } // ^ is always an escape

format_elvish.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package shlex
22

33
// elvishFormat implements Format for elvish lexing.
44
// Key differences from bash:
5-
// - '' inside single quotes → literal ' (same as zsh RC_QUOTES)
5+
// - inside single quotes → literal ' (same as zsh RC_QUOTES)
66
// - \ is NOT an escape character outside quotes (it's a bareword char)
77
// - No POSIX list operators (no &&, ||, &)
88
type elvishFormat struct{}
@@ -51,6 +51,6 @@ func (elvishFormat) ClassifyOperator(raw string) WordbreakType {
5151

5252
func (elvishFormat) KeywordOperators() map[string]WordbreakType { return nil }
5353

54-
func (elvishFormat) NonEscapingQuoteEscapes() bool { return true } // '' → '
54+
func (elvishFormat) NonEscapingQuoteEscapes() bool { return true } // '' → '
5555
func (elvishFormat) NonEscapingQuoteBackslashEscapes() bool { return false }
56-
func (elvishFormat) EscapeNotBareword() bool { return false } // \ is a bareword char in elvish
56+
func (elvishFormat) EscapeNotBareword() bool { return false } // \ is a bareword char in elvish

format_fish.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package shlex
22

33
// fishFormat implements Format for fish lexing.
44
// Key differences from bash:
5-
// - \' and \\ are escapes inside single quotes (NonEscapingQuoteEscapes)
6-
// - Keyword operators: and, or, not (bare words acting as operators)
5+
// - \' and \\ are escapes inside single quotes (NonEscapingQuoteBackslashEscapes)
6+
// - Keyword operators: and, or (bare words acting as pipeline delimiters)
7+
// - `not` is a prefix keyword but not a pipeline delimiter, so not in KeywordOperators
78
// - No word splitting on variable expansion (doesn't affect lexing)
89
// - Narrower escape set in double quotes (\" \$ \\ and \+newline only)
910
type fishFormat struct{}
@@ -55,6 +56,6 @@ func (fishFormat) KeywordOperators() map[string]WordbreakType {
5556
}
5657
}
5758

58-
func (fishFormat) NonEscapingQuoteEscapes() bool { return true } // ' and \\ inside single quotes
59+
func (fishFormat) NonEscapingQuoteEscapes() bool { return true } // ' and \\ inside single quotes
5960
func (fishFormat) NonEscapingQuoteBackslashEscapes() bool { return true }
60-
func (fishFormat) EscapeNotBareword() bool { return true }
61+
func (fishFormat) EscapeNotBareword() bool { return true }

format_nushell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NushellFormat() Format { return nushellFormat{} }
1717
func (nushellFormat) Classifier() tokenClassifier {
1818
t := tokenClassifier{}
1919
t.addRuneClass(spaceRunes, spaceRuneClass)
20-
t.addRuneClass(escapingQuoteRunes, escapingQuoteRuneClass) // "
20+
t.addRuneClass(escapingQuoteRunes, escapingQuoteRuneClass) // "
2121
t.addRuneClass(nonEscapingQuoteRunes, nonEscapingQuoteRuneClass) // '
2222
// Nushell: backtick is a quote character (not an escape)
2323
t.addRuneClass("`", nonEscapingQuoteRuneClass)
@@ -54,6 +54,6 @@ func (nushellFormat) ClassifyOperator(raw string) WordbreakType {
5454

5555
func (nushellFormat) KeywordOperators() map[string]WordbreakType { return nil }
5656

57-
func (nushellFormat) NonEscapingQuoteEscapes() bool { return false }
57+
func (nushellFormat) NonEscapingQuoteEscapes() bool { return false }
5858
func (nushellFormat) NonEscapingQuoteBackslashEscapes() bool { return false }
59-
func (nushellFormat) EscapeNotBareword() bool { return true }
59+
func (nushellFormat) EscapeNotBareword() bool { return true }

format_oil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ package shlex
22

33
// OilFormat returns the Oil shell (OSH) lexical format.
44
// OSH is bash-compatible, so it uses the bash format directly.
5-
// YSH string types (r'...', '''...''') are deferred to Phase 4.
5+
// YSH string types (r'...', ”'...') are deferred to Phase 4.
66
func OilFormat() Format { return bashFormat{} }

format_powershell.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package shlex
22

33
// powershellFormat implements Format for PowerShell lexing.
44
// Key differences from bash:
5-
// - Backtick (`) is the escape character, not backslash (\)
6-
// - '' inside single quotes → literal ' (doubled quote)
7-
// - "" inside double quotes → literal " (doubled quote)
8-
// - No single-quote-as-quote for outer quote pairs in the POSIX sense;
9-
// both ' and " are quote chars
10-
// - Here-strings (@'...'@, @"..."@) and --% are deferred to Phase 4
5+
// - Backtick (`) is the escape character, not backslash (\)
6+
// - ” inside single quotes → literal ' (doubled quote)
7+
// - "" inside double quotes → literal " (doubled quote)
8+
// - No single-quote-as-quote for outer quote pairs in the POSIX sense;
9+
// both ' and " are quote chars
10+
// - Here-strings (@'...'@, @"..."@) and --% are deferred to Phase 4
1111
type powershellFormat struct{}
1212

1313
// PowershellFormat returns the PowerShell lexical format.
@@ -16,7 +16,7 @@ func PowershellFormat() Format { return powershellFormat{} }
1616
func (powershellFormat) Classifier() tokenClassifier {
1717
t := tokenClassifier{}
1818
t.addRuneClass(spaceRunes, spaceRuneClass)
19-
t.addRuneClass(escapingQuoteRunes, escapingQuoteRuneClass) // " is escaping quote
19+
t.addRuneClass(escapingQuoteRunes, escapingQuoteRuneClass) // " is escaping quote
2020
t.addRuneClass(nonEscapingQuoteRunes, nonEscapingQuoteRuneClass) // ' is non-escaping
2121
// PowerShell: backtick is the escape character, not backslash
2222
t.addRuneClass("`", escapeRuneClass)
@@ -58,6 +58,6 @@ func (powershellFormat) ClassifyOperator(raw string) WordbreakType {
5858

5959
func (powershellFormat) KeywordOperators() map[string]WordbreakType { return nil }
6060

61-
func (powershellFormat) NonEscapingQuoteEscapes() bool { return true } // '' → '
61+
func (powershellFormat) NonEscapingQuoteEscapes() bool { return true } // '' → '
6262
func (powershellFormat) NonEscapingQuoteBackslashEscapes() bool { return false }
63-
func (powershellFormat) EscapeNotBareword() bool { return true }
63+
func (powershellFormat) EscapeNotBareword() bool { return true }

format_tcsh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ func (tcshFormat) ClassifyOperator(raw string) WordbreakType {
2020

2121
func (tcshFormat) KeywordOperators() map[string]WordbreakType { return nil }
2222

23-
func (tcshFormat) NonEscapingQuoteEscapes() bool { return false }
23+
func (tcshFormat) NonEscapingQuoteEscapes() bool { return false }
2424
func (tcshFormat) NonEscapingQuoteBackslashEscapes() bool { return false }
25-
func (tcshFormat) EscapeNotBareword() bool { return true }
25+
func (tcshFormat) EscapeNotBareword() bool { return true }

0 commit comments

Comments
 (0)