|
3 | 3 |
|
4 | 4 | PuppetLint.new_check(:'strict_indent') do |
5 | 5 | def match(tokens) |
| 6 | + opening_token = { |
| 7 | + :RBRACE => :LBRACE, |
| 8 | + :RBRACK => :LBRACK, |
| 9 | + :RPAREN => :LPAREN, |
| 10 | + :HEREDOC => :HEREDOC_OPEN, |
| 11 | + :HEREDOC_POST => :HEREDOC_OPEN, |
| 12 | + } |
6 | 13 | open = { |
7 | 14 | :LBRACE => [], |
8 | 15 | :LBRACK => [], |
9 | 16 | :LPAREN => [], |
| 17 | + :HEREDOC_OPEN => [], |
10 | 18 | } |
11 | 19 |
|
12 | 20 | matches = {} |
13 | 21 |
|
14 | 22 | tokens.each do |token| |
15 | | - if [:LBRACE, :LBRACK, :LPAREN].include?(token.type) |
| 23 | + if [:LBRACE, :LBRACK, :LPAREN, :HEREDOC_OPEN].include?(token.type) |
16 | 24 | open[token.type] << token |
17 | | - elsif [:RBRACE, :RBRACK, :RPAREN].include?(token.type) |
18 | | - match = open[("L" + token.type.to_s[1..-1]).to_sym].pop |
| 25 | + elsif [:RBRACE, :RBRACK, :RPAREN, :HEREDOC, :HEREDOC_POST].include?(token.type) |
| 26 | + match = open[opening_token[token.type]].pop |
19 | 27 | if not match.nil? |
20 | 28 | matches[token] = match |
21 | 29 | matches[match] = token |
@@ -45,6 +53,9 @@ def check |
45 | 53 | open_groups = 0 |
46 | 54 | prev_token = token.prev_token |
47 | 55 | while not prev_token.nil? and prev_token.type != :NEWLINE |
| 56 | + if prev_token.type == :HEREDOC_OPEN |
| 57 | + temp_indent += 1 |
| 58 | + end |
48 | 59 | if [:LBRACE, :LBRACK, :LPAREN].include?(prev_token.type) |
49 | 60 | if matches[prev_token].nil? or matches[prev_token].line > prev_token.line |
50 | 61 | # left braces not matched in the same line increase indent |
@@ -120,6 +131,10 @@ def check |
120 | 131 | actual = 0 |
121 | 132 | if token.next_token.type == :INDENT |
122 | 133 | actual = token.next_token.value.length |
| 134 | + elsif token.prev_token.type == :HEREDOC |
| 135 | + actual = token.prev_token.value.split("\n").last.length |
| 136 | + elsif token.prev_token.type == :HEREDOC_OPEN |
| 137 | + actual = next_token.prev_token.value.split("\n").last.length |
123 | 138 | else |
124 | 139 | actual = 0 |
125 | 140 | end |
|
0 commit comments