| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  | require "abstract_command" | 
					
						
							| 
									
										
										
										
											2016-11-20 13:00:01 -05:00
										 |  |  | require "json" | 
					
						
							| 
									
										
										
										
											2017-05-29 01:21:36 +02:00
										 |  |  | require "open3" | 
					
						
							| 
									
										
										
										
											2018-06-05 23:19:18 -04:00
										 |  |  | require "style" | 
					
						
							| 
									
										
										
										
											2016-04-18 17:39:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 13:36:26 +00:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |   module DevCmd | 
					
						
							|  |  |  |     class StyleCmd < AbstractCommand | 
					
						
							|  |  |  |       cmd_args do | 
					
						
							|  |  |  |         description <<~EOS | 
					
						
							|  |  |  |           Check formulae or files for conformance to Homebrew style guidelines. | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |           Lists of <file>, <tap> and <formula> may not be combined. If none are | 
					
						
							|  |  |  |           provided, `style` will run style checks on the whole Homebrew library, | 
					
						
							|  |  |  |           including core code and all formulae. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |         switch "--fix", | 
					
						
							|  |  |  |                description: "Fix style violations automatically using RuboCop's auto-correct feature." | 
					
						
							|  |  |  |         switch "--display-cop-names", | 
					
						
							|  |  |  |                description: "Include the RuboCop cop name for each violation in the output.", | 
					
						
							|  |  |  |                hidden:      true | 
					
						
							|  |  |  |         switch "--reset-cache", | 
					
						
							|  |  |  |                description: "Reset the RuboCop cache." | 
					
						
							|  |  |  |         switch "--formula", "--formulae", | 
					
						
							|  |  |  |                description: "Treat all named arguments as formulae." | 
					
						
							|  |  |  |         switch "--cask", "--casks", | 
					
						
							|  |  |  |                description: "Treat all named arguments as casks." | 
					
						
							|  |  |  |         comma_array "--only-cops", | 
					
						
							|  |  |  |                     description: "Specify a comma-separated <cops> list to check for violations of only the " \ | 
					
						
							|  |  |  |                                  "listed RuboCop cops." | 
					
						
							|  |  |  |         comma_array "--except-cops", | 
					
						
							|  |  |  |                     description: "Specify a comma-separated <cops> list to skip checking for violations of the " \ | 
					
						
							|  |  |  |                                  "listed RuboCop cops." | 
					
						
							| 
									
										
										
										
											2018-11-07 23:44:34 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |         conflicts "--formula", "--cask" | 
					
						
							|  |  |  |         conflicts "--only-cops", "--except-cops" | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |         named_args [:file, :tap, :formula, :cask], without_api: true | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |       sig { override.void } | 
					
						
							|  |  |  |       def run | 
					
						
							|  |  |  |         target = if args.no_named? | 
					
						
							|  |  |  |           nil | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           args.named.to_paths | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-11-07 23:44:34 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |         only_cops = args.only_cops | 
					
						
							|  |  |  |         except_cops = args.except_cops | 
					
						
							| 
									
										
										
										
											2018-11-07 23:44:34 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |         options = { | 
					
						
							|  |  |  |           fix:         args.fix?, | 
					
						
							|  |  |  |           reset_cache: args.reset_cache?, | 
					
						
							|  |  |  |           debug:       args.debug?, | 
					
						
							|  |  |  |           verbose:     args.verbose?, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if only_cops | 
					
						
							|  |  |  |           options[:only_cops] = only_cops | 
					
						
							|  |  |  |         elsif except_cops | 
					
						
							|  |  |  |           options[:except_cops] = except_cops | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           options[:except_cops] = %w[FormulaAuditStrict] | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2015-01-02 13:36:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 21:44:06 -07:00
										 |  |  |         Homebrew.failed = !Style.check_style_and_print(target, **options) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-05-03 11:33:00 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-01-02 13:36:26 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | end |