 45978435e7
			
		
	
	
		45978435e7
		
			
		
	
	
	
	
		
			
			- Previously I thought that comments were fine to discourage people from wasting their time trying to bump things that used `undef` that Sorbet didn't support. But RuboCop is better at this since it'll complain if the comments are unnecessary. - Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501. - I've gone for a mixture of `rubocop:disable` for the files that can't be `typed: strict` (use of undef, required before everything else, etc) and `rubocop:todo` for everything else that should be tried to make strictly typed. There's no functional difference between the two as `rubocop:todo` is `rubocop:disable` with a different name. - And I entirely disabled the cop for the docs/ directory since `typed: strict` isn't going to gain us anything for some Markdown linting config files. - This means that now it's easier to track what needs to be done rather than relying on checklists of files in our big Sorbet issue: ```shell $ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l 268 ``` - And this is confirmed working for new files: ```shell $ git status On branch use-rubocop-for-sorbet-strict-sigils Untracked files: (use "git add <file>..." to include in what will be committed) Library/Homebrew/bad.rb Library/Homebrew/good.rb nothing added to commit but untracked files present (use "git add" to track) $ brew style Offenses: bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true. ^^^^^^^^^^^^^ 1340 files inspected, 1 offense detected ```
		
			
				
	
	
		
			55 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # typed: true # rubocop:disable Sorbet/StrictSigil
 | |
| # frozen_string_literal: true
 | |
| 
 | |
| # This file is included before any other files. It intentionally has typing disabled and has minimal use of `require`.
 | |
| 
 | |
| required_ruby_major, required_ruby_minor, = ENV.fetch("HOMEBREW_REQUIRED_RUBY_VERSION", "").split(".").map(&:to_i)
 | |
| gems_vendored = if required_ruby_minor.nil?
 | |
|   # We're likely here if running RuboCop etc, so just assume we don't need to install gems as we likely already have
 | |
|   true
 | |
| else
 | |
|   ruby_major, ruby_minor, = RUBY_VERSION.split(".").map(&:to_i)
 | |
|   raise "Could not parse Ruby requirements" if !ruby_major || !ruby_minor || !required_ruby_major
 | |
| 
 | |
|   if ruby_major < required_ruby_major || (ruby_major == required_ruby_major && ruby_minor < required_ruby_minor)
 | |
|     raise "Homebrew must be run under Ruby #{required_ruby_major}.#{required_ruby_minor}! " \
 | |
|           "You're running #{RUBY_VERSION}."
 | |
|   end
 | |
| 
 | |
|   # This list should match .gitignore
 | |
|   vendored_versions = ["3.3"].freeze
 | |
|   vendored_versions.include?("#{ruby_major}.#{ruby_minor}")
 | |
| end.freeze
 | |
| 
 | |
| # We trust base Ruby to provide what we need.
 | |
| # Don't look into the user-installed sitedir, which may contain older versions of RubyGems.
 | |
| require "rbconfig"
 | |
| $LOAD_PATH.reject! { |path| path.start_with?(RbConfig::CONFIG["sitedir"]) }
 | |
| 
 | |
| require "pathname"
 | |
| dir = __dir__ || raise("__dir__ is not defined")
 | |
| HOMEBREW_LIBRARY_PATH = Pathname(dir).parent.realpath.freeze
 | |
| HOMEBREW_USING_PORTABLE_RUBY = RbConfig.ruby.include?("/vendor/portable-ruby/").freeze
 | |
| 
 | |
| require_relative "../utils/gems"
 | |
| Homebrew.setup_gem_environment!(setup_path: false)
 | |
| 
 | |
| # Install gems for Rubies we don't vendor for.
 | |
| if !gems_vendored && !ENV["HOMEBREW_SKIP_INITIAL_GEM_INSTALL"]
 | |
|   Homebrew.install_bundler_gems!(setup_path: false)
 | |
|   ENV["HOMEBREW_SKIP_INITIAL_GEM_INSTALL"] = "1"
 | |
| end
 | |
| 
 | |
| unless $LOAD_PATH.include?(HOMEBREW_LIBRARY_PATH.to_s)
 | |
|   # Insert the path after any existing Homebrew paths (e.g. those inserted by tests and parent processes)
 | |
|   last_homebrew_path_idx = $LOAD_PATH.rindex do |path|
 | |
|     path.start_with?(HOMEBREW_LIBRARY_PATH.to_s) && !path.include?("vendor/portable-ruby")
 | |
|   end || -1
 | |
|   $LOAD_PATH.insert(last_homebrew_path_idx + 1, HOMEBREW_LIBRARY_PATH.to_s)
 | |
| end
 | |
| require_relative "../vendor/bundle/bundler/setup"
 | |
| require "portable_ruby_gems" if HOMEBREW_USING_PORTABLE_RUBY
 | |
| $LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \
 | |
|                    "bundler-#{Homebrew::HOMEBREW_BUNDLER_VERSION}/lib"
 | |
| $LOAD_PATH.uniq!
 |