| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  | module RuboCop | 
					
						
							|  |  |  |   module AST | 
					
						
							| 
									
										
										
										
											2020-11-05 17:17:03 -05:00
										 |  |  |     # Extensions for RuboCop's AST Node class. | 
					
						
							| 
									
										
										
										
											2018-10-26 19:49:21 +01:00
										 |  |  |     class Node | 
					
						
							|  |  |  |       include RuboCop::Cask::Constants | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def_node_matcher :method_node, "{$(send ...) (block $(send ...) ...)}" | 
					
						
							|  |  |  |       def_node_matcher :block_args,  "(block _ $_ _)" | 
					
						
							|  |  |  |       def_node_matcher :block_body,  "(block _ _ $_)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def_node_matcher :key_node,    "{(pair $_ _) (hash (pair $_ _) ...)}" | 
					
						
							|  |  |  |       def_node_matcher :val_node,    "{(pair _ $_) (hash (pair _ $_) ...)}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def_node_matcher :cask_block?, "(block (send nil? :cask _) args ...)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def stanza? | 
					
						
							|  |  |  |         (send_type? || block_type?) && STANZA_ORDER.include?(method_name) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def heredoc? | 
					
						
							|  |  |  |         loc.is_a?(Parser::Source::Map::Heredoc) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def expression | 
					
						
							|  |  |  |         base_expression = loc.expression | 
					
						
							|  |  |  |         descendants.select(&:heredoc?).reduce(base_expression) do |expr, node| | 
					
						
							|  |  |  |           expr.join(node.loc.heredoc_end) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |