| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:41:14 +01:00
										 |  |  | require "rubocops/extend/formula" | 
					
						
							| 
									
										
										
										
											2018-09-02 23:30:07 +02:00
										 |  |  | require "extend/string" | 
					
						
							| 
									
										
										
										
											2017-05-24 13:04:55 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | module RuboCop | 
					
						
							|  |  |  |   module Cop | 
					
						
							|  |  |  |     module FormulaAudit | 
					
						
							| 
									
										
										
										
											2018-10-18 21:42:43 -04:00
										 |  |  |       # This cop audits versioned Formulae for `conflicts_with`. | 
					
						
							| 
									
										
										
										
											2017-05-24 13:04:55 +05:30
										 |  |  |       class Conflicts < FormulaCop | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |         MSG = "Versioned formulae should not use `conflicts_with`. " \ | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  |               "Use `keg_only :versioned_formula` instead." | 
					
						
							| 
									
										
										
										
											2017-05-24 13:04:55 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         WHITELIST = %w[
 | 
					
						
							|  |  |  |           bash-completion@ | 
					
						
							|  |  |  |         ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def audit_formula(_node, _class_node, _parent_class_node, body) | 
					
						
							|  |  |  |           return unless versioned_formula? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 15:48:41 +05:30
										 |  |  |           problem MSG if !@formula_name.start_with?(*WHITELIST) && | 
					
						
							| 
									
										
										
										
											2017-05-24 13:04:55 +05:30
										 |  |  |                          method_called_ever?(body, :conflicts_with) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |