puppet-lint
puppet-lint copied to clipboard
Lexer wrongly detects FUNCTION_NAME instead of NAME
When I provide the lexer with this code, it will detect myclass
as type FUNCTION_NAME
, due to the missing space between myclass
and the LPAREN
:
class myclass(
$param1,
) {
}
I expect this to be type NAME
, same as when I would provide this:
class myclass (
$param1,
) {
}
Something like the following would probably help:
diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb
index e9d1696..7cf3fbe 100644
--- a/lib/puppet-lint/lexer.rb
+++ b/lib/puppet-lint/lexer.rb
@@ -211,6 +211,8 @@ class PuppetLint
value = chunk[regex, 1]
next if value.nil?
+ next if type == :FUNCTION_NAME && tokens.size > 1 && ['class', 'define'].include?(tokens[-2].value)
+
i += value.size
tokens << if type == :NAME && KEYWORDS.include?(value)
new_token(value.upcase.to_sym, value)
But IMHO even if the added check for 'does this token follow a class
or define
keyword?' is cleaned up (by moving it to a separate function and making it less ad hoc) it would still stick out as a strange special case from the tokenizing procedure.
OOC, do you have a case at hand where this misparsing leads to a specific error?
No errors per se, but i was writing a linter that adds or removes whitespace at certain locations, eg. in front of a parenthesis. Consensus seems to be that a space should not be put between a function call and its opening parenthesis, but should be put after a class name (as in the example).
Example for the function call: $x = sum($y)
(no space)