Skip to content

Commit

Permalink
Merge pull request #16510 from dduugg/inverse-include-exclude-cop
Browse files Browse the repository at this point in the history
Vendor remaining Rails cops, remove ActiveSupport
  • Loading branch information
dduugg authored Jan 30, 2024
2 parents a17f62e + bec27d4 commit 3a27cac
Show file tree
Hide file tree
Showing 55 changed files with 1,648 additions and 54,206 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,20 @@
**/vendor/gems/mechanize-*/test/

# Ignore dependencies we don't wish to vendor
**/vendor/bundle/ruby/*/gems/activesupport-*/
**/vendor/bundle/ruby/*/gems/ast-*/
**/vendor/bundle/ruby/*/gems/bootsnap-*/
**/vendor/bundle/ruby/*/gems/bundler-*/
**/vendor/bundle/ruby/*/gems/byebug-*/
**/vendor/bundle/ruby/*/gems/coderay-*/
**/vendor/bundle/ruby/*/gems/colorize-*/
**/vendor/bundle/ruby/*/gems/commander-*/
**/vendor/bundle/ruby/*/gems/concurrent-ruby-*/
**/vendor/bundle/ruby/*/gems/diff-lcs-*/
**/vendor/bundle/ruby/*/gems/docile-*/
**/vendor/bundle/ruby/*/gems/ecma-re-validator-*/
**/vendor/bundle/ruby/*/gems/erubi-*/
**/vendor/bundle/ruby/*/gems/hana-*/
**/vendor/bundle/ruby/*/gems/highline-*/
**/vendor/bundle/ruby/*/gems/hpricot-*/
**/vendor/bundle/ruby/*/gems/i18n-*/
**/vendor/bundle/ruby/*/gems/jaro_winkler-*/
**/vendor/bundle/ruby/*/gems/json-*/
**/vendor/bundle/ruby/*/gems/json_schemer-*/
Expand All @@ -108,7 +105,6 @@
**/vendor/bundle/ruby/*/gems/psych-*/
**/vendor/bundle/ruby/*/gems/pry-*/
**/vendor/bundle/ruby/*/gems/racc-*/
**/vendor/bundle/ruby/*/gems/rack-*/
**/vendor/bundle/ruby/*/gems/rainbow-*/
**/vendor/bundle/ruby/*/gems/rbi-*/
**/vendor/bundle/ruby/*/gems/rdiscount-*/
Expand Down Expand Up @@ -140,7 +136,6 @@
**/vendor/bundle/ruby/*/gems/syntax_tree-*/
**/vendor/bundle/ruby/*/gems/tapioca-*/
**/vendor/bundle/ruby/*/gems/thor-*/
**/vendor/bundle/ruby/*/gems/tzinfo-*/
**/vendor/bundle/ruby/*/gems/unf-*/
**/vendor/bundle/ruby/*/gems/unf_ext-*/
**/vendor/bundle/ruby/*/gems/unicode-display_width-*/
Expand All @@ -149,7 +144,6 @@
**/vendor/bundle/ruby/*/gems/webrobots-*/
**/vendor/bundle/ruby/*/gems/yard-*/
**/vendor/bundle/ruby/*/gems/yard-sorbet-*/
**/vendor/bundle/ruby/*/gems/zeitwerk-*/
**/vendor/cache/
**/vendor/specifications/

Expand Down
51 changes: 21 additions & 30 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require:
- ./Homebrew/rubocops.rb
- rubocop-performance
- rubocop-rails
- rubocop-rspec
- rubocop-sorbet

Expand All @@ -13,7 +12,6 @@ inherit_mode:

AllCops:
TargetRubyVersion: 3.1
ActiveSupportExtensionsEnabled: true
NewCops: enable
Include:
- "**/*.rbi"
Expand Down Expand Up @@ -51,10 +49,26 @@ FormulaAuditStrict:
Homebrew:
Enabled: true

Homebrew/Blank:
Exclude:
# Core extensions are not available here:
- "Homebrew/startup/bootsnap.rb"

Homebrew/CompactBlank:
Exclude:
# `blank?` is not necessarily available here:
- "Homebrew/extend/enumerable.rb"

# only used internally
Homebrew/MoveToExtendOS:
Enabled: false

Homebrew/NegateInclude:
Exclude:
# `exclude?` is not available here:
- "Homebrew/standalone/init.rb"
- "Homebrew/rubocops/**/*"

# `system` is a special case and aligns on second argument, so allow this for formulae.
Layout/ArgumentAlignment:
Exclude:
Expand Down Expand Up @@ -200,32 +214,6 @@ Performance/CaseWhenSplat:
Performance/MethodObjectAsBlock:
Enabled: false

Rails:
# Selectively enable what we want.
Enabled: false
Exclude:
# This file is loaded before any extra methods are defined.
- "Homebrew/standalone/init.rb"
# Do not use ActiveSupport in RuboCops.
- "Homebrew/rubocops/**/*"

# These relate to ActiveSupport and not other parts of Rails.
Rails/Blank:
Enabled: true
Rails/CompactBlank:
Enabled: true
Rails/NegateInclude:
Enabled: true
Rails/Presence:
Enabled: true
Rails/Present:
Enabled: true
Exclude:
# `present?` is defined as `!blank?` wihin this file
- "Homebrew/extend/blank.rb"
Rails/SafeNavigationWithBlank:
Enabled: true

# Intentionally disabled as it doesn't fit with our code style.
RSpec/AnyInstance:
Enabled: false
Expand Down Expand Up @@ -355,15 +343,18 @@ Style/HashAsLastArrayItem:
- "/**/Formula/**/*.rb"
- "**/Formula/**/*.rb"

Style/InverseMethods:
InverseMethods:
:blank?: :present?

Style/InvertibleUnlessCondition:
Enabled: true
InverseMethods:
# Favor `if a != b` over `unless a == b`
:==: :!=
# Unset this (prefer `unless a.zero?` over `if a.nonzero?`)
:zero?:
# Don't require non-standard `exclude?` (for now at least) - it's not available in every file
:include?:
:blank?: :present?

Style/MutableConstant:
# would rather freeze too much than too little
Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ end
group :style, optional: true do
gem "rubocop", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
gem "rubocop-rspec", require: false
gem "rubocop-sorbet", require: false
end
Expand Down Expand Up @@ -72,7 +71,6 @@ group :audit, :bump_unversioned_casks, :livecheck, optional: true do
end

# vendored gems (no group)
gem "activesupport", "<7" # we're actively working to remove this: https://github.com/Homebrew/brew/issues/16190
gem "addressable"
gem "patchelf"
gem "plist"
Expand Down
20 changes: 0 additions & 20 deletions Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.7.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
Expand All @@ -17,7 +11,6 @@ GEM
coderay (1.1.3)
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.2.3)
diff-lcs (1.5.0)
docile (1.4.0)
elftools (1.2.0)
Expand All @@ -26,8 +19,6 @@ GEM
hana (1.3.7)
highline (2.0.3)
hpricot (0.8.6)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1)
json_schemer (2.1.1)
hana (~> 1.3)
Expand Down Expand Up @@ -60,7 +51,6 @@ GEM
method_source (~> 1.0)
public_suffix (5.0.4)
racc (1.7.3)
rack (3.0.8)
rainbow (3.1.1)
rbi (0.1.6)
prism (>= 0.18.0, < 0.20)
Expand Down Expand Up @@ -116,11 +106,6 @@ GEM
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rails (2.23.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rspec (2.26.1)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
Expand Down Expand Up @@ -167,8 +152,6 @@ GEM
thor (>= 1.2.0)
yard-sorbet
thor (1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.9.1)
Expand All @@ -178,7 +161,6 @@ GEM
yard-sorbet (0.8.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)
zeitwerk (2.6.12)

PLATFORMS
aarch64-linux
Expand All @@ -188,7 +170,6 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
activesupport (< 7)
addressable
bootsnap
byebug
Expand All @@ -210,7 +191,6 @@ DEPENDENCIES
rubocop
rubocop-ast
rubocop-performance
rubocop-rails
rubocop-rspec
rubocop-sorbet
ruby-macho
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/abstract_artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def to_s
end

def to_args
@dsl_args.reject(&:blank?)
@dsl_args.compact_blank
end
end
end
Expand Down
60 changes: 15 additions & 45 deletions Library/Homebrew/extend/blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def blank?

# An object is present if it's not blank.
sig { returns(T::Boolean) }
def present?
!blank?
end
def present? = !blank?

# Returns the receiver if it's present otherwise returns +nil+.
# <tt>object.presence</tt> is equivalent to
Expand All @@ -48,44 +46,32 @@ class NilClass
#
# nil.blank? # => true
sig { returns(TrueClass) }
def blank?
true
end
def blank? = true

sig { returns(FalseClass) }
def present? # :nodoc:
false
end
def present? = false # :nodoc:
end

class FalseClass
# +false+ is blank:
#
# false.blank? # => true
sig { returns(TrueClass) }
def blank?
true
end
def blank? = true

sig { returns(FalseClass) }
def present? # :nodoc:
false
end
def present? = false # :nodoc:
end

class TrueClass
# +true+ is not blank:
#
# true.blank? # => false
sig { returns(FalseClass) }
def blank?
false
end
def blank? = false

sig { returns(TrueClass) }
def present? # :nodoc:
true
end
def present? = true # :nodoc:
end

class Array
Expand All @@ -98,9 +84,7 @@ class Array
alias blank? empty?

sig { returns(T::Boolean) }
def present? # :nodoc:
!empty?
end
def present? = !empty? # :nodoc:
end

class Hash
Expand All @@ -113,9 +97,7 @@ class Hash
alias blank? empty?

sig { returns(T::Boolean) }
def present? # :nodoc:
!empty?
end
def present? = !empty? # :nodoc:
end

class Symbol
Expand All @@ -126,9 +108,7 @@ class Symbol
alias blank? empty?

sig { returns(T::Boolean) }
def present? # :nodoc:
!empty?
end
def present? = !empty? # :nodoc:
end

class String
Expand Down Expand Up @@ -164,9 +144,7 @@ def blank?
end

sig { returns(T::Boolean) }
def present? # :nodoc:
!blank?
end
def present? = !blank? # :nodoc:
end

class Numeric # :nodoc:
Expand All @@ -175,27 +153,19 @@ class Numeric # :nodoc:
# 1.blank? # => false
# 0.blank? # => false
sig { returns(FalseClass) }
def blank?
false
end
def blank? = false

sig { returns(TrueClass) }
def present?
true
end
def present? = true
end

class Time # :nodoc:
# No Time is blank:
#
# Time.now.blank? # => false
sig { returns(FalseClass) }
def blank?
false
end
def blank? = false

sig { returns(TrueClass) }
def present?
true
end
def present? = true
end
Loading

0 comments on commit 3a27cac

Please sign in to comment.