Skip to content

Commit 4f9b43f

Browse files
committed
fix: ineffassign
linter errors
1 parent dc5fa5e commit 4f9b43f

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,7 @@ func (t *ParsedTokenConfig) Metadata() string {
239239
func (t *ParsedTokenConfig) Prefix() ImplementationPrefix {
240240
return t.prefix
241241
}
242+
243+
func (t *ParsedTokenConfig) TokenSeparator() string {
244+
return t.tokenSeparator
245+
}

internal/parser/parser.go

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/DevLabFoundry/configmanager/v3/internal/log"
1111
)
1212

13-
func wrapErr(incompleteToken string, line, position int, etyp error) error {
14-
return fmt.Errorf("\n- token: (%s) on line: %d column: %d] %w", incompleteToken, line, position, etyp)
13+
func wrapErr(incompleteToken *config.ParsedTokenConfig, sanitized string, line, position int, etyp error) error {
14+
return fmt.Errorf("\n- token: (%s%s%s) on line: %d column: %d] %w", incompleteToken.Prefix(), incompleteToken.TokenSeparator(), sanitized, line, position, etyp)
1515
}
1616

1717
var (
@@ -26,13 +26,13 @@ type ConfigManagerTokenBlock struct {
2626
}
2727

2828
type Parser struct {
29-
l *lexer.Lexer
30-
errors []error
31-
log log.ILogger
32-
curToken config.Token
33-
peekToken config.Token
34-
config *config.GenVarsConfig
35-
environ []string
29+
l *lexer.Lexer
30+
errors []error
31+
log log.ILogger
32+
currentToken config.Token
33+
peekToken config.Token
34+
config *config.GenVarsConfig
35+
environ []string
3636
}
3737

3838
func New(l *lexer.Lexer, c *config.GenVarsConfig) *Parser {
@@ -71,7 +71,7 @@ func (p *Parser) Parse() ([]ConfigManagerTokenBlock, []error) {
7171
for !p.currentTokenIs(config.EOF) {
7272
if p.currentTokenIs(config.BEGIN_CONFIGMANAGER_TOKEN) {
7373
// continues to read the tokens until it hits an end token or errors
74-
configManagerToken, err := config.NewToken(p.curToken.ImpPrefix, *p.config)
74+
configManagerToken, err := config.NewToken(p.currentToken.ImpPrefix, *p.config)
7575
if err != nil {
7676
return nil, []error{err}
7777
}
@@ -86,12 +86,12 @@ func (p *Parser) Parse() ([]ConfigManagerTokenBlock, []error) {
8686
}
8787

8888
func (p *Parser) nextToken() {
89-
p.curToken = p.peekToken
89+
p.currentToken = p.peekToken
9090
p.peekToken = p.l.NextToken()
9191
}
9292

9393
func (p *Parser) currentTokenIs(t config.TokenType) bool {
94-
return p.curToken.Type == t
94+
return p.currentToken.Type == t
9595
}
9696

9797
func (p *Parser) peekTokenIs(t config.TokenType) bool {
@@ -111,13 +111,12 @@ func (p *Parser) peekTokenIsEnd() bool {
111111

112112
// buildConfigManagerTokenFromBlocks
113113
func (p *Parser) buildConfigManagerTokenFromBlocks(configManagerToken *config.ParsedTokenConfig) *ConfigManagerTokenBlock {
114-
currentToken := p.curToken
114+
currentToken := p.currentToken
115115
stmt := &ConfigManagerTokenBlock{BeginToken: currentToken}
116116

117117
// move past current token
118118
p.nextToken()
119119

120-
fullToken := currentToken.Literal
121120
// built as part of the below parser
122121
sanitizedToken := ""
123122

@@ -137,19 +136,15 @@ func (p *Parser) buildConfigManagerTokenFromBlocks(configManagerToken *config.Pa
137136
// when next token is another token
138137
// i.e. the tokens are adjacent
139138
if p.peekTokenIs(config.BEGIN_CONFIGMANAGER_TOKEN) {
140-
fullToken += p.curToken.Literal
141-
sanitizedToken += p.curToken.Literal
142-
stmt.EndToken = p.curToken
139+
sanitizedToken += p.currentToken.Literal
140+
stmt.EndToken = p.currentToken
143141
break
144142
}
145143

146144
// reached the end of token
147145
if p.peekTokenIsEnd() {
148-
// we want set the current token as both the full and sanitized
149-
// the current lexer token is the entire configmanager token
150-
fullToken += p.curToken.Literal
151-
sanitizedToken += p.curToken.Literal
152-
stmt.EndToken = p.curToken
146+
sanitizedToken += p.currentToken.Literal
147+
stmt.EndToken = p.currentToken
153148
break
154149
}
155150

@@ -162,7 +157,7 @@ func (p *Parser) buildConfigManagerTokenFromBlocks(configManagerToken *config.Pa
162157
// keyLookup and Metadata are optional - is always specified in that order
163158
if p.currentTokenIs(config.CONFIGMANAGER_TOKEN_KEY_PATH_SEPARATOR) {
164159
if err := p.buildKeyPathSeparator(configManagerToken); err != nil {
165-
p.errors = append(p.errors, wrapErr(fullToken, currentToken.Line, currentToken.Column, err))
160+
p.errors = append(p.errors, wrapErr(configManagerToken, sanitizedToken, currentToken.Line, currentToken.Column, err))
166161
return nil
167162
}
168163
// keyPath would have built the keyPath and metadata if any
@@ -173,32 +168,25 @@ func (p *Parser) buildConfigManagerTokenFromBlocks(configManagerToken *config.Pa
173168
// check metadata there can be a metadata bracket `[key=val,k1=v2]`
174169
if p.currentTokenIs(config.BEGIN_META_CONFIGMANAGER_TOKEN) {
175170
if err := p.buildMetadata(configManagerToken); err != nil {
176-
p.errors = append(p.errors, wrapErr(fullToken, currentToken.Line, currentToken.Column, err))
171+
p.errors = append(p.errors, wrapErr(configManagerToken, sanitizedToken, currentToken.Line, currentToken.Column, err))
177172
return nil
178173
}
179174
break
180175
}
181176

182-
sanitizedToken += p.curToken.Literal
183-
fullToken += p.curToken.Literal
177+
sanitizedToken += p.currentToken.Literal
184178

185179
// when the next token is EOF
186180
// we want set the current token
187181
// else it would be lost once the parser is advanced below
188182
p.nextToken()
189183
if p.peekTokenIs(config.EOF) {
190-
fullToken += p.curToken.Literal
191-
sanitizedToken += p.curToken.Literal
192-
stmt.EndToken = p.curToken
184+
sanitizedToken += p.currentToken.Literal
185+
stmt.EndToken = p.currentToken
193186
break
194187
}
195188
}
196189

197-
// if notFoundEnd {
198-
// p.errors = append(p.errors, wrapErr(fullToken, currentToken.Line, currentToken.Column, ErrNoEndTagFound))
199-
// return nil
200-
// }
201-
202190
configManagerToken.WithSanitizedToken(sanitizedToken)
203191
stmt.ParsedToken = *configManagerToken
204192

@@ -213,13 +201,13 @@ func (p *Parser) buildKeyPathSeparator(configManagerToken *config.ParsedTokenCon
213201
if p.peekTokenIs(config.EOF) {
214202
// if the next token EOF we set the path as current token and exit
215203
// otherwise we would never hit the below loop
216-
configManagerToken.WithKeyPath(p.curToken.Literal)
204+
configManagerToken.WithKeyPath(p.currentToken.Literal)
217205
return nil
218206
}
219207
for !p.peekTokenIs(config.EOF) {
220208
if p.peekTokenIs(config.BEGIN_META_CONFIGMANAGER_TOKEN) {
221209
// add current token to the keysPath and move onto the metadata
222-
keyPath += p.curToken.Literal
210+
keyPath += p.currentToken.Literal
223211
p.nextToken()
224212
if err := p.buildMetadata(configManagerToken); err != nil {
225213
return err
@@ -228,15 +216,15 @@ func (p *Parser) buildKeyPathSeparator(configManagerToken *config.ParsedTokenCon
228216
}
229217
// touching another token or end of token
230218
if p.peekTokenIs(config.BEGIN_CONFIGMANAGER_TOKEN) || p.peekTokenIsEnd() {
231-
keyPath += p.curToken.Literal
219+
keyPath += p.currentToken.Literal
232220
break
233221
}
234-
keyPath += p.curToken.Literal
222+
keyPath += p.currentToken.Literal
235223
p.nextToken()
236224
if p.peekTokenIs(config.EOF) {
237225
// check if the next token is EOF once advanced
238226
// if it is we want to consume current token else it will be skipped
239-
keyPath += p.curToken.Literal
227+
keyPath += p.currentToken.Literal
240228
break
241229
}
242230
}
@@ -260,12 +248,12 @@ func (p *Parser) buildMetadata(configManagerToken *config.ParsedTokenConfig) err
260248
return fmt.Errorf("%w, metadata (%s) string has no closing", ErrNoEndTagFound, metadata)
261249
}
262250
if p.peekTokenIs(config.END_META_CONFIGMANAGER_TOKEN) {
263-
metadata += p.curToken.Literal
251+
metadata += p.currentToken.Literal
264252
found = true
265253
p.nextToken()
266254
break
267255
}
268-
metadata += p.curToken.Literal
256+
metadata += p.currentToken.Literal
269257
p.nextToken()
270258
}
271259
configManagerToken.WithMetadata(metadata)

0 commit comments

Comments
 (0)