Merge pull request #12200 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rails-2.12.3

build(deps): bump rubocop-rails from 2.12.2 to 2.12.3 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2021-10-07 12:36:42 +01:00 committed by GitHub
commit ba4d3ca94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
110 changed files with 51 additions and 15 deletions

View File

@ -139,7 +139,7 @@ GEM
rubocop-performance (1.11.5) rubocop-performance (1.11.5)
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.12.2) rubocop-rails (2.12.3)
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

@ -387,6 +387,7 @@ class RuboCop::Cop::Rails::ContentTag < ::RuboCop::Cop::Base
def autocorrect(corrector, node, preferred_method); end def autocorrect(corrector, node, preferred_method); end
def corrected_ancestor?(node); end def corrected_ancestor?(node); end
def correction_range(node); end def correction_range(node); end
def register_offense(node, message, preferred_method); end
end end
RuboCop::Cop::Rails::ContentTag::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::ContentTag::MSG = T.let(T.unsafe(nil), String)
@ -690,6 +691,8 @@ class RuboCop::Cop::Rails::FindEach < ::RuboCop::Cop::Base
private private
def active_model_error?(node); end
def active_model_error_where?(node); end
def ignored?(node); end def ignored?(node); end
end end

View File

@ -89,7 +89,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.22.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.22.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.11.5/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.11.5/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.12.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.12.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.5.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.2/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.1/lib"

View File

@ -9,7 +9,7 @@ AllCops:
- bin/* - bin/*
- db/schema.rb - db/schema.rb
# What version of Rails is the inspected code using? If a value is specified # What version of Rails is the inspected code using? If a value is specified
# for TargetRailsVersion then it is used. Acceptable values are specificed # for TargetRailsVersion then it is used. Acceptable values are specified
# as a float (i.e. 5.1); the patch version of Rails should not be included. # as a float (i.e. 5.1); the patch version of Rails should not be included.
# If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
# gems.locked file to find the version of Rails that has been bound to the # gems.locked file to find the version of Rails that has been bound to the
@ -189,6 +189,9 @@ Rails/ContentTag:
Enabled: true Enabled: true
VersionAdded: '2.6' VersionAdded: '2.6'
VersionChanged: '2.12' VersionChanged: '2.12'
# This `Exclude` config prevents false positives for `tag` calls to `has_one: tag`. No helpers are used in normal models.
Exclude:
- app/models/**/*.rb
Rails/CreateTableWithTimestamps: Rails/CreateTableWithTimestamps:
Description: >- Description: >-
@ -198,6 +201,10 @@ Rails/CreateTableWithTimestamps:
VersionAdded: '0.52' VersionAdded: '0.52'
Include: Include:
- db/migrate/*.rb - db/migrate/*.rb
Exclude:
# Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
# auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
- db/migrate/*_create_active_storage_tables.active_storage.rb
Rails/Date: Rails/Date:
Description: >- Description: >-
@ -816,7 +823,7 @@ Rails/UniqBeforePluck:
AutoCorrect: false AutoCorrect: false
Rails/UniqueValidationWithoutIndex: Rails/UniqueValidationWithoutIndex:
Description: 'Uniqueness validation should be with a unique index.' Description: 'Uniqueness validation should have a unique index on the database column.'
Enabled: true Enabled: true
VersionAdded: '2.5' VersionAdded: '2.5'
Include: Include:

View File

@ -33,6 +33,9 @@ module RuboCop
end end
def on_send(node) def on_send(node)
return unless node.receiver.nil?
return if node.arguments.count >= 3
first_argument = node.first_argument first_argument = node.first_argument
return if !first_argument || return if !first_argument ||
allowed_argument?(first_argument) || allowed_argument?(first_argument) ||
@ -41,12 +44,7 @@ module RuboCop
preferred_method = node.first_argument.value.to_s.underscore preferred_method = node.first_argument.value.to_s.underscore
message = format(MSG, preferred_method: preferred_method, current_argument: first_argument.source) message = format(MSG, preferred_method: preferred_method, current_argument: first_argument.source)
add_offense(node, message: message) do |corrector| register_offense(node, message, preferred_method)
autocorrect(corrector, node, preferred_method)
@corrected_nodes ||= Set.new.compare_by_identity
@corrected_nodes.add(node)
end
end end
private private
@ -63,6 +61,15 @@ module RuboCop
allowed_name?(argument) allowed_name?(argument)
end end
def register_offense(node, message, preferred_method)
add_offense(node, message: message) do |corrector|
autocorrect(corrector, node, preferred_method)
@corrected_nodes ||= Set.new.compare_by_identity
@corrected_nodes.add(node)
end
end
def autocorrect(corrector, node, preferred_method) def autocorrect(corrector, node, preferred_method)
range = correction_range(node) range = correction_range(node)

View File

@ -43,9 +43,20 @@ module RuboCop
private private
def ignored?(node) def ignored?(node)
return true if active_model_error_where?(node.receiver)
method_chain = node.each_node(:send).map(&:method_name) method_chain = node.each_node(:send).map(&:method_name)
(cop_config['IgnoredMethods'].map(&:to_sym) & method_chain).any? (cop_config['IgnoredMethods'].map(&:to_sym) & method_chain).any?
end end
def active_model_error_where?(node)
node.method?(:where) && active_model_error?(node.receiver)
end
def active_model_error?(node)
node.send_type? && node.method?(:errors)
end
end end
end end
end end

View File

@ -90,7 +90,7 @@ module RuboCop
end end
def nested_relative_date(node, &callback) def nested_relative_date(node, &callback)
return if node.block_type? return if node.nil? || node.block_type?
node.each_child_node do |child| node.each_child_node do |child|
nested_relative_date(child, &callback) nested_relative_date(child, &callback)

View File

@ -317,16 +317,24 @@ module RuboCop
return if receiver != node.receiver && return if receiver != node.receiver &&
reversible_change_table_call?(node) reversible_change_table_call?(node)
action = if method_name == :remove
target_rails_version >= 6.1 ? 't.remove (without type)' : 't.remove'
else
"change_table(with #{method_name})"
end
add_offense( add_offense(
node, node,
message: format(MSG, action: "change_table(with #{method_name})") message: format(MSG, action: action)
) )
end end
def reversible_change_table_call?(node) def reversible_change_table_call?(node)
case node.method_name case node.method_name
when :change, :remove when :change
false false
when :remove
target_rails_version >= 6.1 && all_hash_key?(node.arguments.last, :type)
when :change_default, :change_column_default, :change_table_comment, when :change_default, :change_column_default, :change_table_comment,
:change_column_comment :change_column_comment
all_hash_key?(node.arguments.last, :from, :to) all_hash_key?(node.arguments.last, :from, :to)

View File

@ -27,7 +27,7 @@ module RuboCop
class UniqueValidationWithoutIndex < Base class UniqueValidationWithoutIndex < Base
include ActiveRecordHelper include ActiveRecordHelper
MSG = 'Uniqueness validation should be with a unique index.' MSG = 'Uniqueness validation should have a unique index on the database column.'
RESTRICT_ON_SEND = %i[validates].freeze RESTRICT_ON_SEND = %i[validates].freeze
def on_send(node) def on_send(node)

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