| 
									
										
										
										
											2024-02-04 14:13:06 +01:00
										 |  |  | # typed: true | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module RuboCop | 
					
						
							|  |  |  |   module Cop | 
					
						
							|  |  |  |     module Cask | 
					
						
							|  |  |  |       class SharedFilelistGlob < Base | 
					
						
							|  |  |  |         extend AutoCorrector | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         def on_send(node) | 
					
						
							| 
									
										
										
										
											2024-02-04 14:34:30 +01:00
										 |  |  |           return if node.method_name != :zap | 
					
						
							| 
									
										
										
										
											2024-02-04 14:13:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |           node.each_descendant(:pair).each do |pair| | 
					
						
							|  |  |  |             symbols = pair.children.select(&:sym_type?).map(&:value) | 
					
						
							|  |  |  |             next unless symbols.include?(:trash) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             pair.each_descendant(:array).each do |array| | 
					
						
							| 
									
										
										
										
											2024-02-08 07:03:51 +00:00
										 |  |  |               regex = /\.sfl\d"$/ | 
					
						
							| 
									
										
										
										
											2024-02-04 14:34:30 +01:00
										 |  |  |               message = "Use a glob (*) instead of a specific version (ie. sfl2) for trashing Shared File List paths" | 
					
						
							| 
									
										
										
										
											2024-02-04 14:13:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |               array.children.each do |item| | 
					
						
							| 
									
										
										
										
											2024-02-04 14:34:30 +01:00
										 |  |  |                 next unless item.source.match?(regex) | 
					
						
							| 
									
										
										
										
											2024-02-04 14:13:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 14:34:30 +01:00
										 |  |  |                 corrected_item = item.source.sub(/sfl\d"$/, "sfl*\"") | 
					
						
							| 
									
										
										
										
											2024-02-04 14:13:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 14:34:30 +01:00
										 |  |  |                 add_offense(item, | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |                             message:) do |corrector| | 
					
						
							| 
									
										
										
										
											2024-02-04 14:13:06 +01:00
										 |  |  |                   corrector.replace(item, corrected_item) | 
					
						
							|  |  |  |                 end | 
					
						
							|  |  |  |               end | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |