Skip to content

Commit 789ee6d

Browse files
Alex Charisbramp
authored andcommitted
restore order of IndexFunc and TrimFunc->TrimLeftFunc
Signed-off-by: Alex Charis <[email protected]>
1 parent 05f384e commit 789ee6d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

analyzer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ const (
5353
func Preview(sql string) int {
5454
trimmed := StripLeadingComments(sql)
5555

56-
firstWord := strings.TrimLeftFunc(trimmed, func(r rune) bool { return !unicode.IsLetter(r) })
57-
if end := strings.IndexFunc(firstWord, unicode.IsSpace); end != -1 {
58-
firstWord = firstWord[:end]
56+
firstWord := trimmed
57+
if end := strings.IndexFunc(trimmed, unicode.IsSpace); end != -1 {
58+
firstWord = trimmed[:end]
5959
}
60+
firstWord = strings.TrimLeftFunc(firstWord, func(r rune) bool { return !unicode.IsLetter(r) })
6061
// Comparison is done in order of priority.
6162
loweredFirstWord := strings.ToLower(firstWord)
6263
switch loweredFirstWord {

analyzer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func TestPreview(t *testing.T) {
7070
{"unknown", StmtUnknown},
7171

7272
{"/* leading comment */ select ...", StmtSelect},
73+
{"/* leading comment */ (select ...", StmtSelect},
7374
{"/* leading comment */ /* leading comment 2 */ select ...", StmtSelect},
7475
{"/*! MySQL-specific comment */", StmtComment},
7576
{"/*!50708 MySQL-version comment */", StmtComment},

0 commit comments

Comments
 (0)