Skip to content

Commit 7e66fb8

Browse files
committed
Fix some linter error
1 parent 85f5020 commit 7e66fb8

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

lex.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ func SetTokenChanCap(size int) {
4444
tokChanCap = size
4545
}
4646

47+
// LexScanner provides an interface for scanning tokens.
4748
type LexScanner interface {
49+
// Scan is used to advance the scanner to the next token.
4850
Scan() bool
51+
// Err returns any error encountered during scanning.
4952
Err() error
53+
// Text returns the most recent token generated by Scan as a string.
5054
Text() string
55+
// Line returns the line number of the most recent token generated by Scan.
5156
Line() int
5257
}
5358

@@ -164,7 +169,6 @@ func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
164169
la = "\\" + la
165170
}
166171

167-
// special handling for *_by_lua_block directives
168172
if token.Len() > 0 {
169173
tokenStr := token.String()
170174
if ext, ok := externalLexers[tokenStr]; ok {
@@ -357,8 +361,8 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
357361
var inQuotes bool
358362

359363
// special handling for'set_by_lua_block' directive
360-
// #nosec G101
361-
if matchedToken == "set_by_lua_block" { //nolint
364+
// ignore Potential hardcoded credentials linter warning for "set_by_lua_block"
365+
if matchedToken == "set_by_lua_block" /* #nosec G101 */ {
362366
arg := ""
363367
for {
364368
if !ll.s.Scan() {
@@ -380,22 +384,23 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
380384
}
381385
arg += next
382386
}
383-
// skip leading whitespace after the return value
384-
for {
385-
if !ll.s.Scan() {
386-
return
387-
}
388-
next := ll.s.Text()
387+
}
389388

390-
if !isSpace(next) {
391-
if next != "{" {
392-
lineno := ll.s.Line()
393-
tokenCh <- NgxToken{Error: &ParseError{File: &lexerFile, What: `unexpected "}"`, Line: &lineno}}
394-
return
395-
}
396-
tokenDepth++
397-
break
389+
// skip leading whitespace after the return value
390+
for {
391+
if !ll.s.Scan() {
392+
return
393+
}
394+
next := ll.s.Text()
395+
396+
if !isSpace(next) {
397+
if next != "{" {
398+
lineno := ll.s.Line()
399+
tokenCh <- NgxToken{Error: &ParseError{File: &lexerFile, What: `expected "{" to start lua block`, Line: &lineno}}
400+
return
398401
}
402+
tokenDepth++
403+
break
399404
}
400405
}
401406

0 commit comments

Comments
 (0)