Merge pull request #12741 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rails-2.13.2

build(deps): bump rubocop-rails from 2.13.1 to 2.13.2 in /Library/Homebrew
This commit is contained in:
Nanda H Krishna 2022-01-17 18:41:54 -05:00 committed by GitHub
commit d5b9206905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
118 changed files with 127 additions and 52 deletions

View File

@ -138,7 +138,7 @@ GEM
rubocop-performance (1.13.2) rubocop-performance (1.13.2)
rubocop (>= 1.7.0, < 2.0) rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0) rubocop-ast (>= 0.4.0)
rubocop-rails (2.13.1) rubocop-rails (2.13.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0) rubocop (>= 1.7.0, < 2.0)

View File

@ -109,6 +109,14 @@ class RuboCop::Cop::IndexMethod::Captures < ::Struct
end end
RuboCop::Cop::IndexMethod::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array) RuboCop::Cop::IndexMethod::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
module RuboCop::Cop::MigrationsHelper
extend ::RuboCop::AST::NodePattern::Macros
def in_migration?(node); end
def migration_class?(param0 = T.unsafe(nil)); end
end
module RuboCop::Cop::Rails; end module RuboCop::Cop::Rails; end
class RuboCop::Cop::Rails::ActionFilter < ::RuboCop::Cop::Base class RuboCop::Cop::Rails::ActionFilter < ::RuboCop::Cop::Base
@ -398,6 +406,7 @@ class RuboCop::Cop::Rails::CompactBlank < ::RuboCop::Cop::Base
def offense_range(node); end def offense_range(node); end
def preferred_method(node); end def preferred_method(node); end
def use_hash_value_block_argument?(arguments, receiver_in_block); end def use_hash_value_block_argument?(arguments, receiver_in_block); end
def use_single_value_block_argument?(arguments, receiver_in_block); end
end end
RuboCop::Cop::Rails::CompactBlank::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::CompactBlank::MSG = T.let(T.unsafe(nil), String)
@ -947,6 +956,7 @@ class RuboCop::Cop::Rails::InverseOf < ::RuboCop::Cop::Base
private private
def ignore_scopes?; end
def message(options); end def message(options); end
end end
@ -1254,8 +1264,11 @@ class RuboCop::Cop::Rails::ReadWriteAttribute < ::RuboCop::Cop::Base
private private
def message(node); end def build_message(node); end
def multi_line_message(node); end
def node_replacement(node); end
def read_attribute_replacement(node); end def read_attribute_replacement(node); end
def single_line_message(node); end
def within_shadowing_method?(node); end def within_shadowing_method?(node); end
def write_attribute_replacement(node); end def write_attribute_replacement(node); end
end end
@ -1464,6 +1477,8 @@ RuboCop::Cop::Rails::RequireDependency::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::RequireDependency::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array) RuboCop::Cop::Rails::RequireDependency::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::Rails::ReversibleMigration < ::RuboCop::Cop::Base class RuboCop::Cop::Rails::ReversibleMigration < ::RuboCop::Cop::Base
include ::RuboCop::Cop::MigrationsHelper
def change_table_call(param0 = T.unsafe(nil)); end def change_table_call(param0 = T.unsafe(nil)); end
def drop_table_call(param0 = T.unsafe(nil)); end def drop_table_call(param0 = T.unsafe(nil)); end
def irreversible_schema_statement_call(param0 = T.unsafe(nil)); end def irreversible_schema_statement_call(param0 = T.unsafe(nil)); end
@ -1494,8 +1509,9 @@ end
RuboCop::Cop::Rails::ReversibleMigration::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::ReversibleMigration::MSG = T.let(T.unsafe(nil), String)
class RuboCop::Cop::Rails::ReversibleMigrationMethodDefinition < ::RuboCop::Cop::Base class RuboCop::Cop::Rails::ReversibleMigrationMethodDefinition < ::RuboCop::Cop::Base
include ::RuboCop::Cop::MigrationsHelper
def change_method?(param0 = T.unsafe(nil)); end def change_method?(param0 = T.unsafe(nil)); end
def migration_class?(param0 = T.unsafe(nil)); end
def on_class(node); end def on_class(node); end
def up_and_down_methods?(param0 = T.unsafe(nil)); end def up_and_down_methods?(param0 = T.unsafe(nil)); end
end end

View File

@ -5099,7 +5099,6 @@ class RuboCop::AST::NodePattern::Parser
end end
module RuboCop::AST::NodePattern::Sets module RuboCop::AST::NodePattern::Sets
SET_BLANK_EMPTY = ::T.let(nil, ::T.untyped)
SET_BUILD_RECOMMENDED_TEST_OPTIONAL = ::T.let(nil, ::T.untyped) SET_BUILD_RECOMMENDED_TEST_OPTIONAL = ::T.let(nil, ::T.untyped)
SET_CHANGE_COLUMN_EXECUTE = ::T.let(nil, ::T.untyped) SET_CHANGE_COLUMN_EXECUTE = ::T.let(nil, ::T.untyped)
SET_DEPENDS_ON_USES_FROM_MACOS = ::T.let(nil, ::T.untyped) SET_DEPENDS_ON_USES_FROM_MACOS = ::T.let(nil, ::T.untyped)

View File

@ -88,7 +88,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.1.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.1.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.24.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.24.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.13.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.13.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.13.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.13.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.7.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.5/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-3.0.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-3.0.0/lib"

View File

@ -453,6 +453,7 @@ Rails/InverseOf:
Description: 'Checks for associations where the inverse cannot be determined automatically.' Description: 'Checks for associations where the inverse cannot be determined automatically.'
Enabled: true Enabled: true
VersionAdded: '0.52' VersionAdded: '0.52'
IgnoreScopes: false
Include: Include:
- app/models/**/*.rb - app/models/**/*.rb
@ -627,6 +628,7 @@ Rails/RedundantForeignKey:
Rails/RedundantPresenceValidationOnBelongsTo: Rails/RedundantPresenceValidationOnBelongsTo:
Description: 'Checks for redundant presence validation on belongs_to association.' Description: 'Checks for redundant presence validation on belongs_to association.'
Enabled: pending Enabled: pending
SafeAutoCorrect: false
VersionAdded: '2.13' VersionAdded: '2.13'
Rails/RedundantReceiverInWithOptions: Rails/RedundantReceiverInWithOptions:
@ -702,15 +704,17 @@ Rails/ReversibleMigration:
Reference: 'https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html' Reference: 'https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html'
Enabled: true Enabled: true
VersionAdded: '0.47' VersionAdded: '0.47'
VersionChanged: '2.13'
Include: Include:
- db/migrate/*.rb - db/**/*.rb
Rails/ReversibleMigrationMethodDefinition: Rails/ReversibleMigrationMethodDefinition:
Description: 'Checks whether the migration implements either a `change` method or both an `up` and a `down` method.' Description: 'Checks whether the migration implements either a `change` method or both an `up` and a `down` method.'
Enabled: false Enabled: false
VersionAdded: '2.10' VersionAdded: '2.10'
VersionChanged: '2.13'
Include: Include:
- db/migrate/*.rb - db/**/*.rb
Rails/RootJoinChain: Rails/RootJoinChain:
Description: 'Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.' Description: 'Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.'

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
module RuboCop
module Cop
# Common functionality for cops working with migrations
module MigrationsHelper
extend NodePattern::Macros
def_node_matcher :migration_class?, <<~PATTERN
(class
(const nil? _)
(send
(const (const {nil? cbase} :ActiveRecord) :Migration)
:[]
(float _))
_)
PATTERN
def in_migration?(node)
node.each_ancestor(:class).any? do |class_node|
migration_class?(class_node)
end
end
end
end
end

View File

@ -10,25 +10,21 @@ module RuboCop
# blank check of block arguments to the receiver object. # blank check of block arguments to the receiver object.
# #
# For example, `[[1, 2], [3, nil]].reject { |first, second| second.blank? }` and # For example, `[[1, 2], [3, nil]].reject { |first, second| second.blank? }` and
# `[[1, 2], [3, nil]].compact_blank` are not compatible. The same is true for `empty?`. # `[[1, 2], [3, nil]].compact_blank` are not compatible. The same is true for `blank?`.
# This will work fine when the receiver is a hash object. # This will work fine when the receiver is a hash object.
# #
# @example # @example
# #
# # bad # # bad
# collection.reject(&:blank?) # collection.reject(&:blank?)
# collection.reject(&:empty?)
# collection.reject { |_k, v| v.blank? } # collection.reject { |_k, v| v.blank? }
# collection.reject { |_k, v| v.empty? }
# #
# # good # # good
# collection.compact_blank # collection.compact_blank
# #
# # bad # # bad
# collection.reject!(&:blank?) # collection.reject!(&:blank?)
# collection.reject!(&:empty?)
# collection.reject! { |_k, v| v.blank? } # collection.reject! { |_k, v| v.blank? }
# collection.reject! { |_k, v| v.empty? }
# #
# # good # # good
# collection.compact_blank! # collection.compact_blank!
@ -48,13 +44,13 @@ module RuboCop
(send _ {:reject :reject!}) (send _ {:reject :reject!})
$(args ...) $(args ...)
(send (send
$(lvar _) {:blank? :empty?})) $(lvar _) :blank?))
PATTERN PATTERN
def_node_matcher :reject_with_block_pass?, <<~PATTERN def_node_matcher :reject_with_block_pass?, <<~PATTERN
(send _ {:reject :reject!} (send _ {:reject :reject!}
(block_pass (block_pass
(sym {:blank? :empty?}))) (sym :blank?)))
PATTERN PATTERN
def on_send(node) def on_send(node)
@ -73,12 +69,17 @@ module RuboCop
return true if reject_with_block_pass?(node) return true if reject_with_block_pass?(node)
if (arguments, receiver_in_block = reject_with_block?(node.parent)) if (arguments, receiver_in_block = reject_with_block?(node.parent))
return arguments.length == 1 || use_hash_value_block_argument?(arguments, receiver_in_block) return use_single_value_block_argument?(arguments, receiver_in_block) ||
use_hash_value_block_argument?(arguments, receiver_in_block)
end end
false false
end end
def use_single_value_block_argument?(arguments, receiver_in_block)
arguments.length == 1 && arguments[0].source == receiver_in_block.source
end
def use_hash_value_block_argument?(arguments, receiver_in_block) def use_hash_value_block_argument?(arguments, receiver_in_block)
arguments.length == 2 && arguments[1].source == receiver_in_block.source arguments.length == 2 && arguments[1].source == receiver_in_block.source
end end

View File

@ -26,7 +26,8 @@ module RuboCop
RESTRICT_ON_SEND = %i[+ -].freeze RESTRICT_ON_SEND = %i[+ -].freeze
DURATIONS = Set[:second, :seconds, :minute, :minutes, :hour, :hours, DURATIONS = Set[:second, :seconds, :minute, :minutes, :hour, :hours,
:day, :days, :week, :weeks, :fortnight, :fortnights] :day, :days, :week, :weeks, :fortnight, :fortnights,
:month, :months, :year, :years]
# @!method duration_arithmetic_argument?(node) # @!method duration_arithmetic_argument?(node)
# Match duration subtraction or addition with current time. # Match duration subtraction or addition with current time.

View File

@ -126,6 +126,18 @@ module RuboCop
# has_many :physicians, through: :appointments # has_many :physicians, through: :appointments
# end # end
# #
# @example IgnoreScopes: false (default)
# # bad
# class Blog < ApplicationRecord
# has_many :posts, -> { order(published_at: :desc) }
# end
#
# @example IgnoreScopes: true
# # good
# class Blog < ApplicationRecord
# has_many :posts, -> { order(published_at: :desc) }
# end
#
# @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations # @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations
# @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses # @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses
class InverseOf < Base class InverseOf < Base
@ -189,7 +201,7 @@ module RuboCop
end end
def scope?(arguments) def scope?(arguments)
arguments.any?(&:block_type?) !ignore_scopes? && arguments.any?(&:block_type?)
end end
def options_requiring_inverse_of?(options) def options_requiring_inverse_of?(options)
@ -236,6 +248,10 @@ module RuboCop
SPECIFY_MSG SPECIFY_MSG
end end
end end
def ignore_scopes?
cop_config['IgnoreScopes'] == true
end
end end
end end
end end

View File

@ -37,7 +37,7 @@ module RuboCop
class ReadWriteAttribute < Base class ReadWriteAttribute < Base
extend AutoCorrector extend AutoCorrector
MSG = 'Prefer `%<prefer>s` over `%<current>s`.' MSG = 'Prefer `%<prefer>s`.'
RESTRICT_ON_SEND = %i[read_attribute write_attribute].freeze RESTRICT_ON_SEND = %i[read_attribute write_attribute].freeze
def_node_matcher :read_write_attribute?, <<~PATTERN def_node_matcher :read_write_attribute?, <<~PATTERN
@ -51,35 +51,51 @@ module RuboCop
return unless read_write_attribute?(node) return unless read_write_attribute?(node)
return if within_shadowing_method?(node) return if within_shadowing_method?(node)
add_offense(node.loc.selector, message: message(node)) do |corrector| add_offense(node, message: build_message(node)) do |corrector|
case node.method_name corrector.replace(node.source_range, node_replacement(node))
when :read_attribute
replacement = read_attribute_replacement(node)
when :write_attribute
replacement = write_attribute_replacement(node)
end
corrector.replace(node.source_range, replacement)
end end
end end
private private
def within_shadowing_method?(node) def within_shadowing_method?(node)
node.each_ancestor(:def).any? do |enclosing_method| first_arg = node.first_argument
shadowing_method_name = node.first_argument.value.to_s return false unless first_arg.respond_to?(:value)
shadowing_method_name << '=' if node.method?(:write_attribute)
enclosing_method.method_name.to_s == shadowing_method_name enclosing_method = node.each_ancestor(:def).first
return false unless enclosing_method
shadowing_method_name = first_arg.value.to_s
shadowing_method_name << '=' if node.method?(:write_attribute)
enclosing_method.method?(shadowing_method_name)
end
def build_message(node)
if node.single_line?
single_line_message(node)
else
multi_line_message(node)
end end
end end
def message(node) def single_line_message(node)
format(MSG, prefer: node_replacement(node))
end
def multi_line_message(node)
if node.method?(:read_attribute) if node.method?(:read_attribute)
format(MSG, prefer: 'self[:attr]', current: 'read_attribute(:attr)') format(MSG, prefer: 'self[:attr]')
else else
format(MSG, prefer: 'self[:attr] = val', format(MSG, prefer: 'self[:attr] = val')
current: 'write_attribute(:attr, val)') end
end
def node_replacement(node)
case node.method_name
when :read_attribute
read_attribute_replacement(node)
when :write_attribute
write_attribute_replacement(node)
end end
end end

View File

@ -8,6 +8,10 @@ module RuboCop
# explicitly set to `false`. The presence validator is added # explicitly set to `false`. The presence validator is added
# automatically, and explicit presence validation is redundant. # automatically, and explicit presence validation is redundant.
# #
# @safety
# This cop's autocorrection is unsafe because it changes the default error message
# from "can't be blank" to "must exist".
#
# @example # @example
# # bad # # bad
# belongs_to :user # belongs_to :user
@ -46,9 +50,6 @@ module RuboCop
# @example source that matches - by association # @example source that matches - by association
# validates :name, :user, presence: true # validates :name, :user, presence: true
# #
# @example source that matches - with presence options
# validates :user, presence: { message: 'duplicate' }
#
# @example source that matches - by a foreign key # @example source that matches - by a foreign key
# validates :user_id, presence: true # validates :user_id, presence: true
# #
@ -62,7 +63,7 @@ module RuboCop
send nil? :validates send nil? :validates
(sym $_)+ (sym $_)+
$[ $[
(hash <$(pair (sym :presence) {true hash}) ...>) # presence: true (hash <$(pair (sym :presence) true) ...>) # presence: true
!(hash <$(pair (sym :strict) {true const}) ...>) # strict: true !(hash <$(pair (sym :strict) {true const}) ...>) # strict: true
] ]
) )

View File

@ -176,6 +176,8 @@ module RuboCop
# #
# @see https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html # @see https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html
class ReversibleMigration < Base class ReversibleMigration < Base
include MigrationsHelper
MSG = '%<action>s is not reversible.' MSG = '%<action>s is not reversible.'
def_node_matcher :irreversible_schema_statement_call, <<~PATTERN def_node_matcher :irreversible_schema_statement_call, <<~PATTERN
@ -207,7 +209,7 @@ module RuboCop
PATTERN PATTERN
def on_send(node) def on_send(node)
return unless within_change_method?(node) return unless in_migration?(node) && within_change_method?(node)
return if within_reversible_or_up_only_block?(node) return if within_reversible_or_up_only_block?(node)
check_irreversible_schema_statement_node(node) check_irreversible_schema_statement_node(node)
@ -220,7 +222,7 @@ module RuboCop
end end
def on_block(node) def on_block(node)
return unless within_change_method?(node) return unless in_migration?(node) && within_change_method?(node)
return if within_reversible_or_up_only_block?(node) return if within_reversible_or_up_only_block?(node)
return if node.body.nil? return if node.body.nil?

View File

@ -43,19 +43,11 @@ module RuboCop
# end # end
# end # end
class ReversibleMigrationMethodDefinition < Base class ReversibleMigrationMethodDefinition < Base
include MigrationsHelper
MSG = 'Migrations must contain either a `change` method, or ' \ MSG = 'Migrations must contain either a `change` method, or ' \
'both an `up` and a `down` method.' 'both an `up` and a `down` method.'
def_node_matcher :migration_class?, <<~PATTERN
(class
(const nil? _)
(send
(const (const {nil? cbase} :ActiveRecord) :Migration)
:[]
(float _))
_)
PATTERN
def_node_matcher :change_method?, <<~PATTERN def_node_matcher :change_method?, <<~PATTERN
[ #migration_class? `(def :change (args) _) ] [ #migration_class? `(def :change (args) _) ]
PATTERN PATTERN

Some files were not shown because too many files have changed in this diff Show More