@@ -7,19 +7,22 @@ def match(tokens)
77 :RBRACE => :LBRACE ,
88 :RBRACK => :LBRACK ,
99 :RPAREN => :LPAREN ,
10+ :HEREDOC => :HEREDOC_OPEN ,
11+ :HEREDOC_POST => :HEREDOC_OPEN ,
1012 }
1113 open = {
1214 :LBRACE => [ ] ,
1315 :LBRACK => [ ] ,
1416 :LPAREN => [ ] ,
17+ :HEREDOC_OPEN => [ ] ,
1518 }
1619
1720 matches = { }
1821
1922 tokens . each do |token |
20- if [ :LBRACE , :LBRACK , :LPAREN ] . include? ( token . type )
23+ if [ :LBRACE , :LBRACK , :LPAREN , :HEREDOC_OPEN ] . include? ( token . type )
2124 open [ token . type ] << token
22- elsif [ :RBRACE , :RBRACK , :RPAREN ] . include? ( token . type )
25+ elsif [ :RBRACE , :RBRACK , :RPAREN , :HEREDOC , :HEREDOC_POST ] . include? ( token . type )
2326 match = open [ opening_token [ token . type ] ] . pop
2427 if not match . nil?
2528 matches [ token ] = match
@@ -50,6 +53,9 @@ def check
5053 open_groups = 0
5154 prev_token = token . prev_token
5255 while not prev_token . nil? and prev_token . type != :NEWLINE
56+ if prev_token . type == :HEREDOC_OPEN
57+ temp_indent += 1
58+ end
5359 if [ :LBRACE , :LBRACK , :LPAREN ] . include? ( prev_token . type )
5460 if matches [ prev_token ] . nil? or matches [ prev_token ] . line > prev_token . line
5561 # left braces not matched in the same line increase indent
@@ -125,6 +131,10 @@ def check
125131 actual = 0
126132 if token . next_token . type == :INDENT
127133 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
128138 else
129139 actual = 0
130140 end
0 commit comments