| 
									
										
										
										
											2018-10-26 19:41:14 +01:00
										 |  |  | require "rubocops/extend/formula" | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | module RuboCop | 
					
						
							|  |  |  |   module Cop | 
					
						
							| 
									
										
										
										
											2018-04-25 07:58:01 +10:00
										 |  |  |     module FormulaAudit | 
					
						
							| 
									
										
										
										
											2018-10-18 21:42:43 -04:00
										 |  |  |       # This cop checks if redundant components are present and other component errors. | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |       # | 
					
						
							|  |  |  |       # - `url|checksum|mirror` should be inside `stable` block | 
					
						
							|  |  |  |       # - `head` and `head do` should not be simultaneously present | 
					
						
							| 
									
										
										
										
											2018-10-18 21:42:43 -04:00
										 |  |  |       # - `bottle :unneeded`/`:disable` and `bottle do` should not be simultaneously present | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  |       # - `stable do` should not be present without a `head` or `devel` spec | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |       class ComponentsRedundancy < FormulaCop | 
					
						
							|  |  |  |         HEAD_MSG = "`head` and `head do` should not be simultaneously present".freeze | 
					
						
							|  |  |  |         BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present".freeze | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  |         STABLE_MSG = "`stable do` should not be present without a `head` or `devel` spec".freeze | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 00:36:18 -04:00
										 |  |  |         def audit_formula(_node, _class_node, _parent_class_node, body_node) | 
					
						
							|  |  |  |           stable_block = find_block(body_node, :stable) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |           if stable_block | 
					
						
							|  |  |  |             [:url, :sha256, :mirror].each do |method_name| | 
					
						
							| 
									
										
										
										
											2017-06-19 00:36:18 -04:00
										 |  |  |               problem "`#{method_name}` should be put inside `stable` block" if method_called?(body_node, method_name) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 00:36:18 -04:00
										 |  |  |           problem HEAD_MSG if method_called?(body_node, :head) && | 
					
						
							|  |  |  |                               find_block(body_node, :head) | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 00:36:18 -04:00
										 |  |  |           problem BOTTLE_MSG if method_called?(body_node, :bottle) && | 
					
						
							|  |  |  |                                 find_block(body_node, :bottle) | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |           return if method_called?(body_node, :head) || | 
					
						
							|  |  |  |                     find_block(body_node, :head) || | 
					
						
							|  |  |  |                     find_block(body_node, :devel) | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 11:46:39 +10:00
										 |  |  |           problem STABLE_MSG if stable_block | 
					
						
							| 
									
										
										
										
											2017-04-08 15:10:44 +05:30
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |