Skip to content

Commit cfe32c8

Browse files
committed
fix linting errors
1 parent 3345274 commit cfe32c8

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

build.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func Build(w io.Writer, config Config, options *BuildOptions) error {
108108
return err
109109
}
110110

111+
//nolint:funlen,gocognit
111112
func buildBlock(sb io.StringWriter, parent *Directive, block Directives, depth int, lastLine int, options *BuildOptions) {
112113
for i, stmt := range block {
113114
// if the this statement is a comment on the same line as the preview, do not emit EOL for this stmt
@@ -131,19 +132,21 @@ func buildBlock(sb io.StringWriter, parent *Directive, block Directives, depth i
131132
directive := Enquote(stmt.Directive)
132133
_, _ = sb.WriteString(directive)
133134

135+
switch {
134136
// special handling for'set_by_lua_block' directive
135-
if directive == "set_by_lua_block" {
137+
case directive == "set_by_lua_block":
136138
_, _ = sb.WriteString(" ")
137139
_, _ = sb.WriteString(stmt.Args[0]) // argument for return value
138140
_, _ = sb.WriteString(" {")
139141
_, _ = sb.WriteString(stmt.Args[1]) // argument containing block content
140142
_, _ = sb.WriteString("}")
141143
// handling other lua block directives
142-
} else if strings.Contains(directive, "_by_lua_block") {
144+
case strings.Contains(directive, "_by_lua_block"):
143145
_, _ = sb.WriteString(" {")
144146
_, _ = sb.WriteString(stmt.Args[0])
145147
_, _ = sb.WriteString("}")
146-
} else {
148+
149+
default:
147150
// special handling for if statements
148151
if directive == "if" {
149152
_, _ = sb.WriteString(" (")

build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type compareFixture struct {
3535
options ParseOptions
3636
}
3737

38-
//nolint:gochecknoglobals, goconst
38+
//nolint:gochecknoglobals
3939
var buildFixtures = []buildFixture{
4040
{
4141
name: "nested-and-multiple-args",

lex.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type LexScanner interface {
5252
}
5353

5454
type ExtLexer interface {
55-
Register(LexScanner) []string
55+
Register(scanner LexScanner) []string
5656
Lex(matchedToken string) <-chan NgxToken
5757
}
5858

@@ -93,7 +93,7 @@ type tokenInfo struct {
9393
LineNumberExists bool
9494
}
9595

96-
//nolint:gocyclo,funlen,gocognit
96+
//nolint:gocyclo,funlen,gocognit,maintidx
9797
func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
9898
token := strings.Builder{}
9999
tokenLine := 1
@@ -164,6 +164,7 @@ func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
164164
la = "\\" + la
165165
}
166166

167+
// special handling for *_by_lua_block directives
167168
if token.Len() > 0 {
168169
tokenStr := token.String()
169170
if ext, ok := externalLexers[tokenStr]; ok {
@@ -187,7 +188,6 @@ func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
187188
if lastLexState == inQuote && la == quote {
188189
continue
189190
}
190-
191191
}
192192
}
193193
}
@@ -345,7 +345,7 @@ func (ll *LuaLexer) Register(s LexScanner) []string {
345345
}
346346
}
347347

348-
//nolint:funlen
348+
//nolint:funlen,gocognit,gocyclo
349349
func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
350350
tokenCh := make(chan NgxToken)
351351

@@ -356,6 +356,7 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
356356
var tok strings.Builder
357357
var inQuotes bool
358358

359+
// special handling for'set_by_lua_block' directive
359360
if matchedToken == "set_by_lua_block" {
360361
arg := ""
361362
for {
@@ -407,7 +408,6 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
407408
if err := ll.s.Err(); err != nil {
408409
lineno := ll.s.Line()
409410
tokenCh <- NgxToken{Error: &ParseError{File: &lexerFile, What: err.Error(), Line: &lineno}}
410-
411411
}
412412

413413
switch {
@@ -431,7 +431,7 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
431431

432432
if tokenDepth == 0 {
433433
tokenCh <- NgxToken{Value: tok.String(), Line: ll.s.Line(), IsQuoted: true}
434-
tokenCh <- NgxToken{Value: ";", Line: ll.s.Line(), IsQuoted: false} // For an end to the Lua string, seems hacky.
434+
tokenCh <- NgxToken{Value: ";", Line: ll.s.Line(), IsQuoted: false} // For an end to the Lua string based on the nginx bahavior
435435
// See: https://github.com/nginxinc/crossplane/blob/master/crossplane/ext/lua.py#L122C25-L122C41
436436
return
437437
}
@@ -442,8 +442,7 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
442442

443443
default:
444444
// Expected first token encountered to be a "{" to open a Lua block. Handle any other non-whitespace
445-
// character to mean we are not about to tokenize Lua.
446-
445+
// character to mean we are not about to tokenize Lua
447446
// ignoring everything until first open brace where tokenDepth > 0
448447
if isSpace(next) && tokenDepth == 0 {
449448
continue

0 commit comments

Comments
 (0)