-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vendor remaining Rails cops, remove ActiveSupport #16510
Changes from all commits
9d081a6
686264f
6472aca
f99d39f
665bda0
0caaa1f
ae249ec
2e90749
8f52b6f
8db86f7
4b59101
bec27d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
require: | ||
- ./Homebrew/rubocops.rb | ||
- rubocop-performance | ||
- rubocop-rails | ||
- rubocop-rspec | ||
- rubocop-sorbet | ||
|
||
|
@@ -13,7 +12,6 @@ inherit_mode: | |
|
||
AllCops: | ||
TargetRubyVersion: 3.1 | ||
ActiveSupportExtensionsEnabled: true | ||
NewCops: enable | ||
Include: | ||
- "**/*.rbi" | ||
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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?: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was introduced by the rubocop-rails config, and is no longer necessary to unset. |
||
:blank?: :present? | ||
|
||
Style/MutableConstant: | ||
# would rather freeze too much than too little | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,7 @@ def to_s | |
end | ||
|
||
def to_args | ||
@dsl_args.reject(&:blank?) | ||
@dsl_args.compact_blank | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused why these violations were not caught before 😕 |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -48,44 +46,32 @@ class NilClass | |
# | ||
# nil.blank? # => true | ||
sig { returns(TrueClass) } | ||
def blank? | ||
true | ||
end | ||
def blank? = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit of Ruby 3 cleanup while were dealing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good to me! |
||
|
||
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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -164,9 +144,7 @@ def blank? | |
end | ||
|
||
sig { returns(T::Boolean) } | ||
def present? # :nodoc: | ||
!blank? | ||
end | ||
def present? = !blank? # :nodoc: | ||
end | ||
|
||
class Numeric # :nodoc: | ||
|
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, and the
InvertibleUnlessCondition
entry below it, allow us to remove some redundant contents of theBlank
andPresent
cops (specificallye, theNotPresent
,UnlessPresent
,NotBlank
, andUnlessBlank
config option handling.