Skip to content

Commit

Permalink
support indent in multi-line collector operators
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-makandra committed Nov 7, 2024
1 parent 1c7fb2b commit 8353c21
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/puppet-lint/plugins/check_strict_indent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ def match(tokens)
RPAREN: :LPAREN,
HEREDOC: :HEREDOC_OPEN,
HEREDOC_POST: :HEREDOC_OPEN,
RCOLLECT: :LCOLLECT,
RRCOLLECT: :LLCOLLECT,
}
open = {
LBRACE: [],
LBRACK: [],
LPAREN: [],
HEREDOC_OPEN: [],
LCOLLECT: [],
LLCOLLECT: [],
}

matches = {}

tokens.each do |token|
if %i[LBRACE LBRACK LPAREN HEREDOC_OPEN].include?(token.type)
if %i[LBRACE LBRACK LPAREN HEREDOC_OPEN LCOLLECT LLCOLLECT].include?(token.type)
open[token.type] << token
elsif %i[RBRACE RBRACK RPAREN HEREDOC HEREDOC_POST].include?(token.type)
elsif %i[RBRACE RBRACK RPAREN HEREDOC HEREDOC_POST RCOLLECT RRCOLLECT].include?(token.type)
match = open[opening_token[token.type]].pop
unless match.nil?
matches[token] = match
Expand Down Expand Up @@ -54,7 +58,7 @@ def check
prev_token = token.prev_token
while !prev_token.nil? and prev_token.type != :NEWLINE
temp_indent += 1 if prev_token.type == :HEREDOC_OPEN
if %i[LBRACE LBRACK
if %i[LBRACE LBRACK LCOLLECT LLCOLLECT
LPAREN].include?(prev_token.type) && (matches[prev_token].nil? or matches[prev_token].line > prev_token.line)
# left braces not matched in the same line increase indent
open_groups += 1
Expand Down Expand Up @@ -97,7 +101,7 @@ def check
# unindent for closing brackets in the current line
next_token = token.next_token
while !next_token.nil? and next_token.type != :NEWLINE
if %i[RBRACE RBRACK RPAREN].include?(next_token.type)
if %i[RBRACE RBRACK RPAREN RCOLLECT RRCOLLECT].include?(next_token.type)
if !matches[next_token].nil? and matches[next_token].line < next_token.line
# right braces matched in a previous line decrease indent
indent -= 1
Expand Down

0 comments on commit 8353c21

Please sign in to comment.