| 
									
										
										
										
											2024-07-14 00:24:16 +00:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-20 10:22:39 -08:00
										 |  |  | require "rubocops/extend/formula_cop" | 
					
						
							| 
									
										
										
										
											2017-05-22 13:09:49 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | module RuboCop | 
					
						
							|  |  |  |   module Cop | 
					
						
							|  |  |  |     module FormulaAudit | 
					
						
							| 
									
										
										
										
											2024-04-26 20:55:51 +02:00
										 |  |  |       # This cop ensures that caveats don't recommend unsupported or unsafe operations. | 
					
						
							| 
									
										
										
										
											2020-08-26 02:21:58 +02:00
										 |  |  |       # | 
					
						
							| 
									
										
										
										
											2024-04-26 20:55:51 +02:00
										 |  |  |       # ### Example | 
					
						
							| 
									
										
										
										
											2020-08-26 02:21:58 +02:00
										 |  |  |       # | 
					
						
							| 
									
										
										
										
											2024-04-26 20:55:51 +02:00
										 |  |  |       # ```ruby | 
					
						
							|  |  |  |       # # bad | 
					
						
							|  |  |  |       # def caveats | 
					
						
							|  |  |  |       #   <<~EOS | 
					
						
							| 
									
										
										
										
											2024-12-28 15:52:04 -05:00
										 |  |  |       #     Use `setuid` to allow running the executable by non-root users. | 
					
						
							| 
									
										
										
										
											2024-04-26 20:55:51 +02:00
										 |  |  |       #   EOS | 
					
						
							|  |  |  |       # end | 
					
						
							|  |  |  |       # | 
					
						
							|  |  |  |       # # good | 
					
						
							|  |  |  |       # def caveats | 
					
						
							|  |  |  |       #   <<~EOS | 
					
						
							|  |  |  |       #     Use `sudo` to run the executable. | 
					
						
							|  |  |  |       #   EOS | 
					
						
							|  |  |  |       # end | 
					
						
							|  |  |  |       # ``` | 
					
						
							| 
									
										
										
										
											2023-02-20 18:10:59 -08:00
										 |  |  |       class Caveats < FormulaCop | 
					
						
							| 
									
										
										
										
											2024-07-07 15:18:29 -04:00
										 |  |  |         sig { override.params(_formula_nodes: FormulaNodes).void } | 
					
						
							|  |  |  |         def audit_formula(_formula_nodes) | 
					
						
							| 
									
										
										
										
											2017-05-22 13:09:49 +05:30
										 |  |  |           caveats_strings.each do |n| | 
					
						
							| 
									
										
										
										
											2023-01-16 01:24:23 -05:00
										 |  |  |             if regex_match_group(n, /\bsetuid\b/i) | 
					
						
							| 
									
										
										
										
											2025-05-30 16:42:32 -04:00
										 |  |  |               problem "Instead of recommending `setuid` in the caveats, suggest `sudo`." | 
					
						
							| 
									
										
										
										
											2023-01-16 01:24:23 -05:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-16 01:24:23 -05:00
										 |  |  |             problem "Don't use ANSI escape codes in the caveats." if regex_match_group(n, /\e/) | 
					
						
							| 
									
										
										
										
											2017-05-22 13:09:49 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |