Skip to content

Commit d0d06ea

Browse files
committed
Add a hash of matching opening / closing tokens
Instead of using substring, substitutions and conversion from/to symbols for finding the opening token name of a given closing token, introduce a hash of matching names. This is not that useful for the existing tokens which have very similar opening / closing names, but will make the code simpler for supporting heredoc strings. No functional change.
1 parent 926a7ae commit d0d06ea

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/puppet-lint/plugins/check_strict_indent.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
PuppetLint.new_check(:'strict_indent') do
55
def match(tokens)
6+
opening_token = {
7+
:RBRACE => :LBRACE,
8+
:RBRACK => :LBRACK,
9+
:RPAREN => :LPAREN,
10+
}
611
open = {
712
:LBRACE => [],
813
:LBRACK => [],
@@ -15,7 +20,7 @@ def match(tokens)
1520
if [:LBRACE, :LBRACK, :LPAREN].include?(token.type)
1621
open[token.type] << token
1722
elsif [:RBRACE, :RBRACK, :RPAREN].include?(token.type)
18-
match = open[("L" + token.type.to_s[1..-1]).to_sym].pop
23+
match = open[opening_token[token.type]].pop
1924
if not match.nil?
2025
matches[token] = match
2126
matches[match] = token

0 commit comments

Comments
 (0)