brew vendor-gems: commit updates.
This commit is contained in:
parent
ab5f32a901
commit
c4ac617a86
@ -83,7 +83,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.0.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.0.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.20.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.20.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.11.3/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.12.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.4.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.4.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"
|
||||||
|
|||||||
@ -1,84 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module RuboCop
|
|
||||||
module Cop
|
|
||||||
module Rails
|
|
||||||
# This cop checks that `tag` is used instead of `content_tag`
|
|
||||||
# because `content_tag` is legacy syntax.
|
|
||||||
#
|
|
||||||
# NOTE: Allow `content_tag` when the first argument is a variable because
|
|
||||||
# `content_tag(name)` is simpler rather than `tag.public_send(name)`.
|
|
||||||
#
|
|
||||||
# @example
|
|
||||||
# # bad
|
|
||||||
# content_tag(:p, 'Hello world!')
|
|
||||||
# content_tag(:br)
|
|
||||||
#
|
|
||||||
# # good
|
|
||||||
# tag.p('Hello world!')
|
|
||||||
# tag.br
|
|
||||||
# content_tag(name, 'Hello world!')
|
|
||||||
class ContentTag < Base
|
|
||||||
include RangeHelp
|
|
||||||
extend AutoCorrector
|
|
||||||
extend TargetRailsVersion
|
|
||||||
|
|
||||||
minimum_target_rails_version 5.1
|
|
||||||
|
|
||||||
MSG = 'Use `tag` instead of `content_tag`.'
|
|
||||||
RESTRICT_ON_SEND = %i[content_tag].freeze
|
|
||||||
|
|
||||||
def on_new_investigation
|
|
||||||
@corrected_nodes = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def on_send(node)
|
|
||||||
first_argument = node.first_argument
|
|
||||||
return if !first_argument ||
|
|
||||||
allowed_argument?(first_argument) ||
|
|
||||||
corrected_ancestor?(node)
|
|
||||||
|
|
||||||
add_offense(node) do |corrector|
|
|
||||||
autocorrect(corrector, node)
|
|
||||||
|
|
||||||
@corrected_nodes ||= Set.new.compare_by_identity
|
|
||||||
@corrected_nodes.add(node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def corrected_ancestor?(node)
|
|
||||||
node.each_ancestor(:send).any? { |ancestor| @corrected_nodes&.include?(ancestor) }
|
|
||||||
end
|
|
||||||
|
|
||||||
def allowed_argument?(argument)
|
|
||||||
argument.variable? || argument.send_type? || argument.const_type? || argument.splat_type?
|
|
||||||
end
|
|
||||||
|
|
||||||
def autocorrect(corrector, node)
|
|
||||||
if method_name?(node.first_argument)
|
|
||||||
range = correction_range(node)
|
|
||||||
|
|
||||||
rest_args = node.arguments.drop(1)
|
|
||||||
replacement = "tag.#{node.first_argument.value.to_s.underscore}(#{rest_args.map(&:source).join(', ')})"
|
|
||||||
|
|
||||||
corrector.replace(range, replacement)
|
|
||||||
else
|
|
||||||
corrector.replace(node.loc.selector, 'tag')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def method_name?(node)
|
|
||||||
return false unless node.str_type? || node.sym_type?
|
|
||||||
|
|
||||||
/^[a-zA-Z_][a-zA-Z_\-0-9]*$/.match?(node.value)
|
|
||||||
end
|
|
||||||
|
|
||||||
def correction_range(node)
|
|
||||||
range_between(node.loc.selector.begin_pos, node.loc.expression.end_pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -181,12 +181,14 @@ Rails/BulkChangeTable:
|
|||||||
- db/migrate/*.rb
|
- db/migrate/*.rb
|
||||||
|
|
||||||
Rails/ContentTag:
|
Rails/ContentTag:
|
||||||
Description: 'Use `tag` instead of `content_tag`.'
|
Description: 'Use `tag.something` instead of `tag(:something)`.'
|
||||||
Reference:
|
Reference:
|
||||||
|
- 'https://github.com/rubocop/rubocop-rails/issues/260'
|
||||||
- 'https://github.com/rails/rails/issues/25195'
|
- 'https://github.com/rails/rails/issues/25195'
|
||||||
- 'https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag'
|
- 'https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag'
|
||||||
Enabled: true
|
Enabled: true
|
||||||
VersionAdded: '2.6'
|
VersionAdded: '2.6'
|
||||||
|
VersionChanged: '2.12'
|
||||||
|
|
||||||
Rails/CreateTableWithTimestamps:
|
Rails/CreateTableWithTimestamps:
|
||||||
Description: >-
|
Description: >-
|
||||||
@ -499,6 +501,7 @@ Rails/OrderById:
|
|||||||
Rails/Output:
|
Rails/Output:
|
||||||
Description: 'Checks for calls to puts, print, etc.'
|
Description: 'Checks for calls to puts, print, etc.'
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
SafeAutoCorrect: false
|
||||||
VersionAdded: '0.15'
|
VersionAdded: '0.15'
|
||||||
VersionChanged: '0.19'
|
VersionChanged: '0.19'
|
||||||
Include:
|
Include:
|
||||||
@ -607,6 +610,14 @@ Rails/RedundantReceiverInWithOptions:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
VersionAdded: '0.52'
|
VersionAdded: '0.52'
|
||||||
|
|
||||||
|
Rails/RedundantTravelBack:
|
||||||
|
Description: This cop checks for redundant `travel_back` calls.
|
||||||
|
Enabled: pending
|
||||||
|
VersionAdded: '2.12'
|
||||||
|
Include:
|
||||||
|
- spec/**/*.rb
|
||||||
|
- test/**/*.rb
|
||||||
|
|
||||||
Rails/ReflectionClassName:
|
Rails/ReflectionClassName:
|
||||||
Description: 'Use a string for `class_name` option value in the definition of a reflection.'
|
Description: 'Use a string for `class_name` option value in the definition of a reflection.'
|
||||||
Enabled: true
|
Enabled: true
|
||||||
@ -713,6 +724,7 @@ Rails/ScopeArgs:
|
|||||||
Description: 'Checks the arguments of ActiveRecord scopes.'
|
Description: 'Checks the arguments of ActiveRecord scopes.'
|
||||||
Enabled: true
|
Enabled: true
|
||||||
VersionAdded: '0.19'
|
VersionAdded: '0.19'
|
||||||
|
VersionChanged: '2.12'
|
||||||
Include:
|
Include:
|
||||||
- app/models/**/*.rb
|
- app/models/**/*.rb
|
||||||
|
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Rails
|
||||||
|
# This cop checks legacy syntax usage of `tag`
|
||||||
|
#
|
||||||
|
# NOTE: Allow `tag` when the first argument is a variable because
|
||||||
|
# `tag(name)` is simpler rather than `tag.public_send(name)`.
|
||||||
|
# And this cop will be renamed to something like `LegacyTag` in the future. (e.g. RuboCop Rails 2.0)
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# # bad
|
||||||
|
# tag(:p)
|
||||||
|
# tag(:br, class: 'classname')
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# tag.p
|
||||||
|
# tag.br(class: 'classname')
|
||||||
|
# tag(name, class: 'classname')
|
||||||
|
class ContentTag < Base
|
||||||
|
include RangeHelp
|
||||||
|
extend AutoCorrector
|
||||||
|
extend TargetRailsVersion
|
||||||
|
|
||||||
|
minimum_target_rails_version 5.1
|
||||||
|
|
||||||
|
MSG = 'Use `tag.%<preferred_method>s` instead of `tag(%<current_argument>s)`.'
|
||||||
|
RESTRICT_ON_SEND = %i[tag].freeze
|
||||||
|
|
||||||
|
def on_new_investigation
|
||||||
|
@corrected_nodes = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
first_argument = node.first_argument
|
||||||
|
return if !first_argument ||
|
||||||
|
allowed_argument?(first_argument) ||
|
||||||
|
corrected_ancestor?(node)
|
||||||
|
|
||||||
|
preferred_method = node.first_argument.value.to_s.underscore
|
||||||
|
message = format(MSG, preferred_method: preferred_method, current_argument: first_argument.source)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def corrected_ancestor?(node)
|
||||||
|
node.each_ancestor(:send).any? { |ancestor| @corrected_nodes&.include?(ancestor) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def allowed_argument?(argument)
|
||||||
|
argument.variable? ||
|
||||||
|
argument.send_type? ||
|
||||||
|
argument.const_type? ||
|
||||||
|
argument.splat_type? ||
|
||||||
|
allowed_name?(argument)
|
||||||
|
end
|
||||||
|
|
||||||
|
def autocorrect(corrector, node, preferred_method)
|
||||||
|
range = correction_range(node)
|
||||||
|
|
||||||
|
rest_args = node.arguments.drop(1)
|
||||||
|
replacement = "tag.#{preferred_method}(#{rest_args.map(&:source).join(', ')})"
|
||||||
|
|
||||||
|
corrector.replace(range, replacement)
|
||||||
|
end
|
||||||
|
|
||||||
|
def allowed_name?(argument)
|
||||||
|
return false unless argument.str_type? || argument.sym_type?
|
||||||
|
|
||||||
|
!/^[a-zA-Z\-][a-zA-Z\-0-9]*$/.match?(argument.value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def correction_range(node)
|
||||||
|
range_between(node.loc.selector.begin_pos, node.loc.expression.end_pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -100,7 +100,7 @@ module RuboCop
|
|||||||
|
|
||||||
def method_name_matches?(method_name, body)
|
def method_name_matches?(method_name, body)
|
||||||
method_name == body.method_name ||
|
method_name == body.method_name ||
|
||||||
include_prefix_case? && method_name == prefixed_method_name(body)
|
(include_prefix_case? && method_name == prefixed_method_name(body))
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_prefix_case?
|
def include_prefix_case?
|
||||||
@ -40,7 +40,7 @@ module RuboCop
|
|||||||
IGNORED_ARGUMENT_TYPES = %i[hash splat].freeze
|
IGNORED_ARGUMENT_TYPES = %i[hash splat].freeze
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
return if node.receiver.nil? && !inherit_active_record_base?(node) || allowed_invocation?(node)
|
return if (node.receiver.nil? && !inherit_active_record_base?(node)) || allowed_invocation?(node)
|
||||||
|
|
||||||
method_name = node.method_name
|
method_name = node.method_name
|
||||||
static_name = static_method_name(method_name)
|
static_name = static_method_name(method_name)
|
||||||
@ -114,6 +114,8 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def valid_options?(options)
|
def valid_options?(options)
|
||||||
|
options = options.first.children.first.pairs if options.first.kwsplat_type?
|
||||||
|
|
||||||
return true unless options
|
return true unless options
|
||||||
return true if options.any? do |o|
|
return true if options.any? do |o|
|
||||||
dependent_option?(o) || present_option?(o)
|
dependent_option?(o) || present_option?(o)
|
||||||
@ -27,6 +27,7 @@ module RuboCop
|
|||||||
KEYWORD_ARGS = %i[
|
KEYWORD_ARGS = %i[
|
||||||
method params session body flash xhr as headers env to
|
method params session body flash xhr as headers env to
|
||||||
].freeze
|
].freeze
|
||||||
|
ROUTING_METHODS = %i[draw routes].freeze
|
||||||
RESTRICT_ON_SEND = %i[get post put patch delete head].freeze
|
RESTRICT_ON_SEND = %i[get post put patch delete head].freeze
|
||||||
|
|
||||||
minimum_target_rails_version 5.0
|
minimum_target_rails_version 5.0
|
||||||
@ -40,6 +41,8 @@ module RuboCop
|
|||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
|
return if in_routing_block?(node)
|
||||||
|
|
||||||
http_request?(node) do |data|
|
http_request?(node) do |data|
|
||||||
return unless needs_conversion?(data)
|
return unless needs_conversion?(data)
|
||||||
|
|
||||||
@ -63,13 +66,17 @@ module RuboCop
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def in_routing_block?(node)
|
||||||
|
!!node.each_ancestor(:block).detect { |block| ROUTING_METHODS.include?(block.send_node.method_name) }
|
||||||
|
end
|
||||||
|
|
||||||
def needs_conversion?(data)
|
def needs_conversion?(data)
|
||||||
return true unless data.hash_type?
|
return true unless data.hash_type?
|
||||||
return false if kwsplat_hash?(data)
|
return false if kwsplat_hash?(data)
|
||||||
|
|
||||||
data.each_pair.none? do |pair|
|
data.each_pair.none? do |pair|
|
||||||
special_keyword_arg?(pair.key) ||
|
special_keyword_arg?(pair.key) ||
|
||||||
format_arg?(pair.key) && data.pairs.one?
|
(format_arg?(pair.key) && data.pairs.one?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -124,9 +124,10 @@ module RuboCop
|
|||||||
block = parent.each_child_node(:begin).first
|
block = parent.each_child_node(:begin).first
|
||||||
return unless block
|
return unless block
|
||||||
|
|
||||||
defined_methods = block.each_child_node(:def).map(&:method_name)
|
defined_action_methods = defined_action_methods(block)
|
||||||
|
|
||||||
methods = array_values(methods_node).reject do |method|
|
methods = array_values(methods_node).reject do |method|
|
||||||
defined_methods.include?(method)
|
defined_action_methods.include?(method)
|
||||||
end
|
end
|
||||||
|
|
||||||
message = message(methods, parent)
|
message = message(methods, parent)
|
||||||
@ -135,6 +136,26 @@ module RuboCop
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def defined_action_methods(block)
|
||||||
|
defined_methods = block.each_child_node(:def).map(&:method_name)
|
||||||
|
|
||||||
|
defined_methods + aliased_action_methods(block, defined_methods)
|
||||||
|
end
|
||||||
|
|
||||||
|
def aliased_action_methods(node, defined_methods)
|
||||||
|
alias_methods = node.each_child_node(:send).select { |send_node| send_node.method?(:alias_method) }
|
||||||
|
|
||||||
|
hash_of_alias_methods = alias_methods.each_with_object({}) do |alias_method, result|
|
||||||
|
result[alias_method.last_argument.value] = alias_method.first_argument.value
|
||||||
|
end
|
||||||
|
|
||||||
|
defined_methods.each_with_object([]) do |defined_method, aliased_method|
|
||||||
|
if (new_method_name = hash_of_alias_methods[defined_method])
|
||||||
|
aliased_method << new_method_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# @param node [RuboCop::AST::Node]
|
# @param node [RuboCop::AST::Node]
|
||||||
# @return [Array<Symbol>]
|
# @return [Array<Symbol>]
|
||||||
def array_values(node) # rubocop:disable Metrics/MethodLength
|
def array_values(node) # rubocop:disable Metrics/MethodLength
|
||||||
@ -75,8 +75,8 @@ module RuboCop
|
|||||||
corrector.replace(str_range, "#{existing_rel} noopener")
|
corrector.replace(str_range, "#{existing_rel} noopener")
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_rel(send_node, offence_node, corrector)
|
def add_rel(send_node, offense_node, corrector)
|
||||||
opening_quote = offence_node.children.last.source[0]
|
opening_quote = offense_node.children.last.source[0]
|
||||||
closing_quote = opening_quote == ':' ? '' : opening_quote
|
closing_quote = opening_quote == ':' ? '' : opening_quote
|
||||||
new_rel_exp = ", rel: #{opening_quote}noopener#{closing_quote}"
|
new_rel_exp = ", rel: #{opening_quote}noopener#{closing_quote}"
|
||||||
range = if (last_argument = send_node.last_argument).hash_type?
|
range = if (last_argument = send_node.last_argument).hash_type?
|
||||||
@ -14,6 +14,9 @@ module RuboCop
|
|||||||
# # good
|
# # good
|
||||||
# Rails.logger.debug 'A debug message'
|
# Rails.logger.debug 'A debug message'
|
||||||
class Output < Base
|
class Output < Base
|
||||||
|
include RangeHelp
|
||||||
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Do not write to stdout. ' \
|
MSG = 'Do not write to stdout. ' \
|
||||||
"Use Rails's logger if you want to log."
|
"Use Rails's logger if you want to log."
|
||||||
RESTRICT_ON_SEND = %i[
|
RESTRICT_ON_SEND = %i[
|
||||||
@ -35,10 +38,13 @@ module RuboCop
|
|||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
return unless (output?(node) || io_output?(node)) &&
|
return unless (output?(node) || io_output?(node)) && node.arguments?
|
||||||
node.arguments?
|
|
||||||
|
|
||||||
add_offense(node.loc.selector)
|
range = offense_range(node)
|
||||||
|
|
||||||
|
add_offense(range) do |corrector|
|
||||||
|
corrector.replace(range, 'Rails.logger.debug')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -46,6 +52,14 @@ module RuboCop
|
|||||||
def match_gvar?(sym)
|
def match_gvar?(sym)
|
||||||
%i[$stdout $stderr].include?(sym)
|
%i[$stdout $stderr].include?(sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def offense_range(node)
|
||||||
|
if node.receiver
|
||||||
|
range_between(node.loc.expression.begin_pos, node.loc.selector.end_pos)
|
||||||
|
else
|
||||||
|
node.loc.selector
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -61,8 +61,8 @@ module RuboCop
|
|||||||
def offense?(node)
|
def offense?(node)
|
||||||
number, = *node.receiver
|
number, = *node.receiver
|
||||||
|
|
||||||
singular_receiver?(number) && plural_method?(node.method_name) ||
|
(singular_receiver?(number) && plural_method?(node.method_name)) ||
|
||||||
plural_receiver?(number) && singular_method?(node.method_name)
|
(plural_receiver?(number) && singular_method?(node.method_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
def plural_method?(method_name)
|
def plural_method?(method_name)
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Rails
|
||||||
|
# This cop checks for redundant `travel_back` calls.
|
||||||
|
# Since Rails 5.2, `travel_back` is automatically called at the end of the test.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# def teardown
|
||||||
|
# do_something
|
||||||
|
# travel_back
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# def teardown
|
||||||
|
# do_something
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # bad
|
||||||
|
# after do
|
||||||
|
# do_something
|
||||||
|
# travel_back
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# after do
|
||||||
|
# do_something
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
class RedundantTravelBack < Base
|
||||||
|
include RangeHelp
|
||||||
|
extend AutoCorrector
|
||||||
|
extend TargetRailsVersion
|
||||||
|
|
||||||
|
minimum_target_rails_version 5.2
|
||||||
|
|
||||||
|
MSG = 'Redundant `travel_back` detected.'
|
||||||
|
RESTRICT_ON_SEND = %i[travel_back].freeze
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
return unless node.each_ancestor(:def, :block).any? do |ancestor|
|
||||||
|
method_name = ancestor.def_type? ? :teardown : :after
|
||||||
|
|
||||||
|
ancestor.method?(method_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
add_offense(node) do |corrector|
|
||||||
|
corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -343,8 +343,8 @@ module RuboCop
|
|||||||
|
|
||||||
def within_reversible_or_up_only_block?(node)
|
def within_reversible_or_up_only_block?(node)
|
||||||
node.each_ancestor(:block).any? do |ancestor|
|
node.each_ancestor(:block).any? do |ancestor|
|
||||||
ancestor.block_type? &&
|
(ancestor.block_type? &&
|
||||||
ancestor.send_node.method?(:reversible) ||
|
ancestor.send_node.method?(:reversible)) ||
|
||||||
ancestor.send_node.method?(:up_only)
|
ancestor.send_node.method?(:up_only)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -14,6 +14,8 @@ module RuboCop
|
|||||||
# # good
|
# # good
|
||||||
# scope :something, -> { where(something: true) }
|
# scope :something, -> { where(something: true) }
|
||||||
class ScopeArgs < Base
|
class ScopeArgs < Base
|
||||||
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG = 'Use `lambda`/`proc` instead of a plain method call.'
|
MSG = 'Use `lambda`/`proc` instead of a plain method call.'
|
||||||
RESTRICT_ON_SEND = %i[scope].freeze
|
RESTRICT_ON_SEND = %i[scope].freeze
|
||||||
|
|
||||||
@ -21,7 +23,9 @@ module RuboCop
|
|||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
scope?(node) do |second_arg|
|
scope?(node) do |second_arg|
|
||||||
add_offense(second_arg)
|
add_offense(second_arg) do |corrector|
|
||||||
|
corrector.replace(second_arg, "-> { #{second_arg.source} }")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user