Merge pull request #14107 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rails-2.17.2
build(deps): bump rubocop-rails from 2.16.1 to 2.17.2 in /Library/Homebrew
This commit is contained in:
commit
4f22527fc7
@ -147,7 +147,7 @@ GEM
|
||||
rubocop-performance (1.15.0)
|
||||
rubocop (>= 1.7.0, < 2.0)
|
||||
rubocop-ast (>= 0.4.0)
|
||||
rubocop-rails (2.16.1)
|
||||
rubocop-rails (2.17.2)
|
||||
activesupport (>= 4.2.0)
|
||||
rack (>= 1.1)
|
||||
rubocop (>= 1.33.0, < 2.0)
|
||||
@ -215,7 +215,7 @@ GEM
|
||||
yard-sorbet (0.6.1)
|
||||
sorbet-runtime (>= 0.5)
|
||||
yard (>= 0.9)
|
||||
zeitwerk (2.6.1)
|
||||
zeitwerk (2.6.4)
|
||||
|
||||
PLATFORMS
|
||||
aarch64-linux
|
||||
|
||||
@ -175,6 +175,24 @@ RuboCop::Cop::Rails::ActionFilter::FILTER_METHODS = T.let(T.unsafe(nil), Array)
|
||||
RuboCop::Cop::Rails::ActionFilter::MSG = T.let(T.unsafe(nil), String)
|
||||
RuboCop::Cop::Rails::ActionFilter::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
|
||||
|
||||
class RuboCop::Cop::Rails::ActionOrder < ::RuboCop::Cop::Base
|
||||
include ::RuboCop::Cop::VisibilityHelp
|
||||
include ::RuboCop::Cop::DefNode
|
||||
extend ::RuboCop::Cop::AutoCorrector
|
||||
|
||||
def action_declarations(param0, param1); end
|
||||
def on_class(node); end
|
||||
|
||||
private
|
||||
|
||||
def actions; end
|
||||
def expected_order; end
|
||||
def find_index(node); end
|
||||
def register_offense(previous, current); end
|
||||
end
|
||||
|
||||
RuboCop::Cop::Rails::ActionOrder::MSG = T.let(T.unsafe(nil), String)
|
||||
|
||||
class RuboCop::Cop::Rails::ActiveRecordAliases < ::RuboCop::Cop::Base
|
||||
extend ::RuboCop::Cop::AutoCorrector
|
||||
|
||||
@ -695,6 +713,10 @@ class RuboCop::Cop::Rails::EagerEvaluationLogMessage < ::RuboCop::Cop::Base
|
||||
|
||||
def replacement_range(node); end
|
||||
def replacement_source(node, arguments); end
|
||||
|
||||
class << self
|
||||
def autocorrect_incompatible_with; end
|
||||
end
|
||||
end
|
||||
|
||||
RuboCop::Cop::Rails::EagerEvaluationLogMessage::MSG = T.let(T.unsafe(nil), String)
|
||||
@ -1059,6 +1081,15 @@ end
|
||||
RuboCop::Cop::Rails::I18nLocaleTexts::MSG = T.let(T.unsafe(nil), String)
|
||||
RuboCop::Cop::Rails::I18nLocaleTexts::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
|
||||
|
||||
class RuboCop::Cop::Rails::IgnoredColumnsAssignment < ::RuboCop::Cop::Base
|
||||
extend ::RuboCop::Cop::AutoCorrector
|
||||
|
||||
def on_send(node); end
|
||||
end
|
||||
|
||||
RuboCop::Cop::Rails::IgnoredColumnsAssignment::MSG = T.let(T.unsafe(nil), String)
|
||||
RuboCop::Cop::Rails::IgnoredColumnsAssignment::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
|
||||
|
||||
class RuboCop::Cop::Rails::IgnoredSkipActionFilterOption < ::RuboCop::Cop::Base
|
||||
def filter_options(param0 = T.unsafe(nil)); end
|
||||
def on_send(node); end
|
||||
@ -1325,8 +1356,11 @@ class RuboCop::Cop::Rails::Pluck < ::RuboCop::Cop::Base
|
||||
|
||||
private
|
||||
|
||||
def message(value, node); end
|
||||
def message(replacement, node); end
|
||||
def offense_range(node); end
|
||||
def register_offense(node, key); end
|
||||
def use_block_argument_in_key?(block_argument, key); end
|
||||
def use_one_block_argument?(argument); end
|
||||
end
|
||||
|
||||
RuboCop::Cop::Rails::Pluck::MSG = T.let(T.unsafe(nil), String)
|
||||
@ -1398,11 +1432,13 @@ class RuboCop::Cop::Rails::Presence < ::RuboCop::Cop::Base
|
||||
private
|
||||
|
||||
def build_source_for_or_method(other); end
|
||||
def current(node); end
|
||||
def ignore_if_node?(node); end
|
||||
def ignore_other_node?(node); end
|
||||
def message(node, receiver, other); end
|
||||
def method_range(node); end
|
||||
def register_offense(node, receiver, other); end
|
||||
def replacement(receiver, other); end
|
||||
def replacement(receiver, other, left_sibling); end
|
||||
end
|
||||
|
||||
RuboCop::Cop::Rails::Presence::MSG = T.let(T.unsafe(nil), String)
|
||||
@ -2236,6 +2272,18 @@ RuboCop::Cop::Rails::WhereNot::NOT_IN_ANONYMOUS_RE = T.let(T.unsafe(nil), Regexp
|
||||
RuboCop::Cop::Rails::WhereNot::NOT_IN_NAMED_RE = T.let(T.unsafe(nil), Regexp)
|
||||
RuboCop::Cop::Rails::WhereNot::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
|
||||
|
||||
class RuboCop::Cop::Rails::WhereNotWithMultipleConditions < ::RuboCop::Cop::Base
|
||||
def on_send(node); end
|
||||
def where_not_call?(param0 = T.unsafe(nil)); end
|
||||
|
||||
private
|
||||
|
||||
def multiple_arguments_hash?(hash); end
|
||||
end
|
||||
|
||||
RuboCop::Cop::Rails::WhereNotWithMultipleConditions::MSG = T.let(T.unsafe(nil), String)
|
||||
RuboCop::Cop::Rails::WhereNotWithMultipleConditions::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
|
||||
|
||||
module RuboCop::Cop::TargetRailsVersion
|
||||
def minimum_target_rails_version(version); end
|
||||
def support_target_rails_version?(version); end
|
||||
@ -70,22 +70,28 @@ class Zeitwerk::Inflector
|
||||
def overrides; end
|
||||
end
|
||||
|
||||
module Zeitwerk::Internal
|
||||
def internal(method_name); end
|
||||
end
|
||||
|
||||
class Zeitwerk::Loader
|
||||
include ::Zeitwerk::RealModName
|
||||
include ::Zeitwerk::Loader::Callbacks
|
||||
include ::Zeitwerk::Loader::Helpers
|
||||
include ::Zeitwerk::Loader::Config
|
||||
include ::Zeitwerk::Loader::EagerLoad
|
||||
|
||||
def initialize; end
|
||||
|
||||
def autoloaded_dirs; end
|
||||
def autoloads; end
|
||||
def eager_load(force: T.unsafe(nil)); end
|
||||
def lazy_subdirs; end
|
||||
def mutex; end
|
||||
def mutex2; end
|
||||
def namespace_dirs; end
|
||||
def reload; end
|
||||
def setup; end
|
||||
def shadowed_file?(file); end
|
||||
def shadowed_files; end
|
||||
def to_unload; end
|
||||
def unload; end
|
||||
def unloadable_cpath?(cpath); end
|
||||
@ -111,6 +117,7 @@ class Zeitwerk::Loader
|
||||
def default_logger; end
|
||||
def default_logger=(_arg0); end
|
||||
def eager_load_all; end
|
||||
def eager_load_namespace(mod); end
|
||||
def for_gem(warn_on_extra_files: T.unsafe(nil)); end
|
||||
end
|
||||
end
|
||||
@ -128,46 +135,62 @@ module Zeitwerk::Loader::Callbacks
|
||||
end
|
||||
|
||||
module Zeitwerk::Loader::Config
|
||||
extend ::Zeitwerk::Internal
|
||||
|
||||
def initialize; end
|
||||
|
||||
def __ignores?(abspath); end
|
||||
def __roots; end
|
||||
def collapse(*glob_patterns); end
|
||||
def collapse_dirs; end
|
||||
def collapse_glob_patterns; end
|
||||
def dirs(namespaces: T.unsafe(nil)); end
|
||||
def do_not_eager_load(*paths); end
|
||||
def eager_load_exclusions; end
|
||||
def enable_reloading; end
|
||||
def ignore(*glob_patterns); end
|
||||
def ignored_glob_patterns; end
|
||||
def ignored_paths; end
|
||||
def ignores?(abspath); end
|
||||
def inflector; end
|
||||
def inflector=(_arg0); end
|
||||
def log!; end
|
||||
def logger; end
|
||||
def logger=(_arg0); end
|
||||
def on_load(cpath = T.unsafe(nil), &block); end
|
||||
def on_load_callbacks; end
|
||||
def on_setup(&block); end
|
||||
def on_setup_callbacks; end
|
||||
def on_unload(cpath = T.unsafe(nil), &block); end
|
||||
def on_unload_callbacks; end
|
||||
def push_dir(path, namespace: T.unsafe(nil)); end
|
||||
def reloading_enabled?; end
|
||||
def root_dirs; end
|
||||
def tag; end
|
||||
def tag=(tag); end
|
||||
|
||||
private
|
||||
|
||||
def actual_root_dirs; end
|
||||
def actual_roots; end
|
||||
def collapse?(dir); end
|
||||
def collapse_dirs; end
|
||||
def collapse_glob_patterns; end
|
||||
def eager_load_exclusions; end
|
||||
def excluded_from_eager_load?(abspath); end
|
||||
def expand_glob_patterns(glob_patterns); end
|
||||
def expand_paths(paths); end
|
||||
def ignored_glob_patterns; end
|
||||
def ignored_paths; end
|
||||
def ignores?(abspath); end
|
||||
def on_load_callbacks; end
|
||||
def on_setup_callbacks; end
|
||||
def on_unload_callbacks; end
|
||||
def recompute_collapse_dirs; end
|
||||
def recompute_ignored_paths; end
|
||||
def root_dir?(dir); end
|
||||
def roots; end
|
||||
end
|
||||
|
||||
module Zeitwerk::Loader::EagerLoad
|
||||
def eager_load(force: T.unsafe(nil)); end
|
||||
def eager_load_dir(path); end
|
||||
def eager_load_namespace(mod); end
|
||||
def load_file(path); end
|
||||
|
||||
private
|
||||
|
||||
def actual_eager_load_dir(dir, namespace, force: T.unsafe(nil)); end
|
||||
def eager_load_child_namespace(child, child_name, root_dir, root_namespace); end
|
||||
end
|
||||
|
||||
module Zeitwerk::Loader::Helpers
|
||||
@ -183,6 +206,7 @@ module Zeitwerk::Loader::Helpers
|
||||
def ls(dir); end
|
||||
def ruby?(path); end
|
||||
def strict_autoload_path(parent, cname); end
|
||||
def walk_up(abspath); end
|
||||
end
|
||||
|
||||
Zeitwerk::Loader::MUTEX = T.let(T.unsafe(nil), Thread::Mutex)
|
||||
@ -27,7 +27,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/i18n-1.12.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/minitest-5.16.3/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tzinfo-2.0.5/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.1/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.4/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/activesupport-6.1.7/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/public_suffix-5.0.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.1/lib")
|
||||
@ -106,7 +106,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-2.3.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.35.1/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.15.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.16.1/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.2/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.15.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.6.11/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib")
|
||||
|
||||
@ -10,6 +10,9 @@ AllCops:
|
||||
# Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
|
||||
# See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
|
||||
- db/*schema.rb
|
||||
- log/**/*
|
||||
- public/**/*
|
||||
- storage/**/*
|
||||
# Enable checking Active Support extensions.
|
||||
# See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
|
||||
ActiveSupportExtensionsEnabled: true
|
||||
@ -70,7 +73,7 @@ Rails/ActionControllerFlashBeforeRender:
|
||||
StyleGuide: 'https://rails.rubystyle.guide/#flash-before-render'
|
||||
Reference: 'https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html'
|
||||
Enabled: 'pending'
|
||||
SafeAutocorrect: false
|
||||
SafeAutoCorrect: false
|
||||
VersionAdded: '2.16'
|
||||
|
||||
Rails/ActionControllerTestCase:
|
||||
@ -78,7 +81,7 @@ Rails/ActionControllerTestCase:
|
||||
StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
|
||||
Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
|
||||
Enabled: 'pending'
|
||||
SafeAutocorrect: false
|
||||
SafeAutoCorrect: false
|
||||
VersionAdded: '2.14'
|
||||
Include:
|
||||
- '**/test/**/*.rb'
|
||||
@ -95,6 +98,21 @@ Rails/ActionFilter:
|
||||
- app/controllers/**/*.rb
|
||||
- app/mailers/**/*.rb
|
||||
|
||||
Rails/ActionOrder:
|
||||
Description: 'Enforce consistent ordering of controller actions.'
|
||||
Enabled: pending
|
||||
VersionAdded: '2.17'
|
||||
ExpectedOrder:
|
||||
- index
|
||||
- show
|
||||
- new
|
||||
- edit
|
||||
- create
|
||||
- update
|
||||
- destroy
|
||||
Include:
|
||||
- app/controllers/**/*.rb
|
||||
|
||||
Rails/ActiveRecordAliases:
|
||||
Description: >-
|
||||
Avoid Active Record aliases:
|
||||
@ -348,10 +366,13 @@ Rails/DynamicFindBy:
|
||||
# The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
|
||||
Whitelist:
|
||||
- find_by_sql
|
||||
- find_by_token_for
|
||||
AllowedMethods:
|
||||
- find_by_sql
|
||||
- find_by_token_for
|
||||
AllowedReceivers:
|
||||
- Gem::Specification
|
||||
- page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
|
||||
|
||||
Rails/EagerEvaluationLogMessage:
|
||||
Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
|
||||
@ -535,6 +556,13 @@ Rails/I18nLocaleTexts:
|
||||
Enabled: pending
|
||||
VersionAdded: '2.14'
|
||||
|
||||
Rails/IgnoredColumnsAssignment:
|
||||
Description: 'Looks for assignments of `ignored_columns` that override previous assignments.'
|
||||
StyleGuide: 'https://rails.rubystyle.guide/#append-ignored-columns'
|
||||
Enabled: pending
|
||||
SafeAutoCorrect: false
|
||||
VersionAdded: '2.17'
|
||||
|
||||
Rails/IgnoredSkipActionFilterOption:
|
||||
Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.'
|
||||
Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options'
|
||||
@ -845,7 +873,7 @@ Rails/RootJoinChain:
|
||||
Rails/RootPathnameMethods:
|
||||
Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
|
||||
Enabled: pending
|
||||
SafeAutocorrect: false
|
||||
SafeAutoCorrect: false
|
||||
VersionAdded: '2.16'
|
||||
|
||||
Rails/RootPublicPath:
|
||||
@ -1090,6 +1118,17 @@ Rails/WhereNot:
|
||||
Enabled: 'pending'
|
||||
VersionAdded: '2.8'
|
||||
|
||||
Rails/WhereNotWithMultipleConditions:
|
||||
Description: 'Do not use `where.not(...)` with multiple conditions.'
|
||||
Enabled: 'pending'
|
||||
VersionAdded: '2.17'
|
||||
|
||||
# Accept `redirect_to(...) and return` and similar cases.
|
||||
Style/AndOr:
|
||||
EnforcedStyle: conditionals
|
||||
|
||||
Style/SymbolProc:
|
||||
AllowedMethods:
|
||||
- define_method
|
||||
- mail
|
||||
- respond_to
|
||||
@ -14,6 +14,16 @@ RuboCop::Rails::Inject.defaults!
|
||||
|
||||
require_relative 'rubocop/cop/rails_cops'
|
||||
|
||||
RuboCop::Cop::Style::HashExcept.minimum_target_ruby_version(2.0)
|
||||
|
||||
RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
|
||||
Module.new do
|
||||
def autocorrect_incompatible_with
|
||||
super.push(RuboCop::Cop::Rails::EagerEvaluationLogMessage)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
RuboCop::Cop::Style::RedundantSelf.singleton_class.prepend(
|
||||
Module.new do
|
||||
def autocorrect_incompatible_with
|
||||
@ -68,9 +68,12 @@ module RuboCop
|
||||
|
||||
def followed_by_render?(flash_node)
|
||||
flash_assigment_node = find_ancestor(flash_node, type: :send)
|
||||
context = flash_assigment_node.parent
|
||||
context = flash_assigment_node
|
||||
context = context.parent if context.parent.if_type?
|
||||
context = context.right_siblings
|
||||
return true if context.empty?
|
||||
|
||||
context.each_child_node.any? do |node|
|
||||
context.compact.any? do |node|
|
||||
render?(node)
|
||||
end
|
||||
end
|
||||
@ -31,7 +31,7 @@ module RuboCop
|
||||
def_node_matcher :action_controller_test_case?, <<~PATTERN
|
||||
(class
|
||||
(const nil? _)
|
||||
(const (const {nil? cbase} :ActionController) :TestCase) nil?)
|
||||
(const (const {nil? cbase} :ActionController) :TestCase) _)
|
||||
PATTERN
|
||||
|
||||
def on_class(node)
|
||||
@ -0,0 +1,81 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# Enforces consistent ordering of the standard Rails RESTful controller actions.
|
||||
#
|
||||
# The cop is configurable and can enforce any ordering of the standard actions.
|
||||
# All other methods are ignored.
|
||||
#
|
||||
# [source,yaml]
|
||||
# ----
|
||||
# Rails/ActionOrder:
|
||||
# ExpectedOrder:
|
||||
# - index
|
||||
# - show
|
||||
# - new
|
||||
# - edit
|
||||
# - create
|
||||
# - update
|
||||
# - destroy
|
||||
# ----
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# def index; end
|
||||
# def destroy; end
|
||||
# def show; end
|
||||
#
|
||||
# # good
|
||||
# def index; end
|
||||
# def show; end
|
||||
# def destroy; end
|
||||
class ActionOrder < Base
|
||||
extend AutoCorrector
|
||||
include VisibilityHelp
|
||||
include DefNode
|
||||
|
||||
MSG = 'Action `%<current>s` should appear before `%<previous>s`.'
|
||||
|
||||
def_node_search :action_declarations, '(def {%1} ...)'
|
||||
|
||||
def on_class(node)
|
||||
action_declarations(node, actions).each_cons(2) do |previous, current|
|
||||
next if node_visibility(current) != :public || non_public?(current)
|
||||
next if find_index(current) >= find_index(previous)
|
||||
|
||||
register_offense(previous, current)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expected_order
|
||||
cop_config['ExpectedOrder'].map(&:to_sym)
|
||||
end
|
||||
|
||||
def actions
|
||||
@actions ||= Set.new(expected_order)
|
||||
end
|
||||
|
||||
def find_index(node)
|
||||
expected_order.find_index(node.method_name)
|
||||
end
|
||||
|
||||
def register_offense(previous, current)
|
||||
message = format(
|
||||
MSG,
|
||||
expected_order: expected_order.join(', '),
|
||||
previous: previous.method_name,
|
||||
current: current.method_name
|
||||
)
|
||||
add_offense(current, message: message) do |corrector|
|
||||
corrector.replace(current, previous.source)
|
||||
corrector.replace(previous, current.source)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -56,7 +56,8 @@ module RuboCop
|
||||
argument.send_type? ||
|
||||
argument.const_type? ||
|
||||
argument.splat_type? ||
|
||||
allowed_name?(argument)
|
||||
allowed_name?(argument) ||
|
||||
!argument.respond_to?(:value)
|
||||
end
|
||||
|
||||
def register_offense(node, message, preferred_method)
|
||||
@ -22,19 +22,23 @@ module RuboCop
|
||||
# User.find_by(name: name, email: email)
|
||||
# User.find_by!(email: email)
|
||||
#
|
||||
# @example AllowedMethods: find_by_sql
|
||||
# @example AllowedMethods: ['find_by_sql', 'find_by_token_for'] (default)
|
||||
# # bad
|
||||
# User.find_by_query(users_query)
|
||||
# User.find_by_token_for(:password_reset, token)
|
||||
#
|
||||
# # good
|
||||
# User.find_by_sql(users_sql)
|
||||
# User.find_by_token_for(:password_reset, token)
|
||||
#
|
||||
# @example AllowedReceivers: Gem::Specification
|
||||
# @example AllowedReceivers: ['Gem::Specification', 'page'] (default)
|
||||
# # bad
|
||||
# Specification.find_by_name('backend').gem_dir
|
||||
# page.find_by_id('a_dom_id').click
|
||||
#
|
||||
# # good
|
||||
# Gem::Specification.find_by_name('backend').gem_dir
|
||||
# page.find_by_id('a_dom_id').click
|
||||
class DynamicFindBy < Base
|
||||
include ActiveRecordHelper
|
||||
extend AutoCorrector
|
||||
@ -37,6 +37,10 @@ module RuboCop
|
||||
)
|
||||
PATTERN
|
||||
|
||||
def self.autocorrect_incompatible_with
|
||||
[Style::MethodCallWithArgsParentheses]
|
||||
end
|
||||
|
||||
def on_send(node)
|
||||
return if node.parent&.block_type?
|
||||
|
||||
@ -17,7 +17,7 @@ module RuboCop
|
||||
# # good
|
||||
# User.order(:foo).each
|
||||
#
|
||||
# @example AllowedPattern: [/order/]
|
||||
# @example AllowedPattern: ['order']
|
||||
# # good
|
||||
# User.order(:foo).each
|
||||
class FindEach < Base
|
||||
@ -43,7 +43,7 @@ module RuboCop
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
child_node, method_name, time_argument = *node.first_argument.children
|
||||
child_node, method_name, time_argument = *node.first_argument&.children
|
||||
return if time_argument || !child_node
|
||||
return unless current_time?(child_node, method_name) || current_time_with_convert?(child_node, method_name)
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# Looks for assignments of `ignored_columns` that may override previous
|
||||
# assignments.
|
||||
#
|
||||
# Overwriting previous assignments is usually a mistake, since it will
|
||||
# un-ignore the first set of columns. Since duplicate column names is not
|
||||
# a problem, it is better to simply append to the list.
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# # bad
|
||||
# class User < ActiveRecord::Base
|
||||
# self.ignored_columns = [:one]
|
||||
# end
|
||||
#
|
||||
# # bad
|
||||
# class User < ActiveRecord::Base
|
||||
# self.ignored_columns = [:one, :two]
|
||||
# end
|
||||
#
|
||||
# # good
|
||||
# class User < ActiveRecord::Base
|
||||
# self.ignored_columns += [:one, :two]
|
||||
# end
|
||||
#
|
||||
# # good
|
||||
# class User < ActiveRecord::Base
|
||||
# self.ignored_columns += [:one]
|
||||
# self.ignored_columns += [:two]
|
||||
# end
|
||||
#
|
||||
class IgnoredColumnsAssignment < Base
|
||||
extend AutoCorrector
|
||||
|
||||
MSG = 'Use `+=` instead of `=`.'
|
||||
RESTRICT_ON_SEND = %i[ignored_columns=].freeze
|
||||
|
||||
def on_send(node)
|
||||
add_offense(node.loc.operator) do |corrector|
|
||||
corrector.replace(node.loc.operator, '+=')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -21,42 +21,62 @@ module RuboCop
|
||||
extend AutoCorrector
|
||||
extend TargetRailsVersion
|
||||
|
||||
MSG = 'Prefer `pluck(:%<value>s)` over `%<current>s`.'
|
||||
MSG = 'Prefer `%<replacement>s` over `%<current>s`.'
|
||||
|
||||
minimum_target_rails_version 5.0
|
||||
|
||||
def_node_matcher :pluck_candidate?, <<~PATTERN
|
||||
({block numblock} (send _ {:map :collect}) $_argument (send (lvar $_element) :[] (sym $_value)))
|
||||
({block numblock} (send _ {:map :collect}) $_argument (send lvar :[] $_key))
|
||||
PATTERN
|
||||
|
||||
def on_block(node)
|
||||
pluck_candidate?(node) do |argument, element, value|
|
||||
pluck_candidate?(node) do |argument, key|
|
||||
next unless use_one_block_argument?(argument)
|
||||
|
||||
match = if node.block_type?
|
||||
argument.children.first.source.to_sym == element
|
||||
block_argument = argument.children.first.source
|
||||
use_block_argument_in_key?(block_argument, key)
|
||||
else # numblock
|
||||
argument == 1 && element == :_1
|
||||
argument == 1 && use_block_argument_in_key?('_1', key)
|
||||
end
|
||||
next unless match
|
||||
|
||||
message = message(value, node)
|
||||
|
||||
add_offense(offense_range(node), message: message) do |corrector|
|
||||
corrector.replace(offense_range(node), "pluck(:#{value})")
|
||||
end
|
||||
register_offense(node, key)
|
||||
end
|
||||
end
|
||||
alias on_numblock on_block
|
||||
|
||||
private
|
||||
|
||||
def use_one_block_argument?(argument)
|
||||
return true if argument == 1 # Checks for numbered argument `_1`.
|
||||
|
||||
argument.respond_to?(:one?) && argument.one?
|
||||
end
|
||||
|
||||
def use_block_argument_in_key?(block_argument, key)
|
||||
return false if block_argument == key.source
|
||||
|
||||
key.each_descendant(:lvar).none? { |lvar| block_argument == lvar.source }
|
||||
end
|
||||
|
||||
def offense_range(node)
|
||||
node.send_node.loc.selector.join(node.loc.end)
|
||||
end
|
||||
|
||||
def message(value, node)
|
||||
def register_offense(node, key)
|
||||
replacement = "pluck(#{key.source})"
|
||||
message = message(replacement, node)
|
||||
|
||||
add_offense(offense_range(node), message: message) do |corrector|
|
||||
corrector.replace(offense_range(node), replacement)
|
||||
end
|
||||
end
|
||||
|
||||
def message(replacement, node)
|
||||
current = offense_range(node).source
|
||||
|
||||
format(MSG, value: value, current: current)
|
||||
format(MSG, replacement: replacement, current: current)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -93,7 +93,7 @@ module RuboCop
|
||||
|
||||
def register_offense(node, receiver, other)
|
||||
add_offense(node, message: message(node, receiver, other)) do |corrector|
|
||||
corrector.replace(node.source_range, replacement(receiver, other))
|
||||
corrector.replace(node.source_range, replacement(receiver, other, node.left_sibling))
|
||||
end
|
||||
end
|
||||
|
||||
@ -106,10 +106,20 @@ module RuboCop
|
||||
end
|
||||
|
||||
def message(node, receiver, other)
|
||||
format(MSG, prefer: replacement(receiver, other), current: node.source)
|
||||
prefer = replacement(receiver, other, node.left_sibling).gsub(/^\s*|\n/, '')
|
||||
current = current(node).gsub(/^\s*|\n/, '')
|
||||
format(MSG, prefer: prefer, current: current)
|
||||
end
|
||||
|
||||
def replacement(receiver, other)
|
||||
def current(node)
|
||||
if node.source.include?("\n")
|
||||
"#{node.loc.keyword.with(end_pos: node.condition.loc.selector.end_pos).source} ... end"
|
||||
else
|
||||
node.source
|
||||
end
|
||||
end
|
||||
|
||||
def replacement(receiver, other, left_sibling)
|
||||
or_source = if other&.send_type?
|
||||
build_source_for_or_method(other)
|
||||
elsif other.nil? || other.nil_type?
|
||||
@ -118,23 +128,24 @@ module RuboCop
|
||||
" || #{other.source}"
|
||||
end
|
||||
|
||||
"#{receiver.source}.presence" + or_source
|
||||
replaced = "#{receiver.source}.presence#{or_source}"
|
||||
left_sibling ? "(#{replaced})" : replaced
|
||||
end
|
||||
|
||||
def build_source_for_or_method(other)
|
||||
if other.parenthesized? || other.method?('[]') || !other.arguments?
|
||||
if other.parenthesized? || other.method?('[]') || other.arithmetic_operation? || !other.arguments?
|
||||
" || #{other.source}"
|
||||
else
|
||||
method = range_between(
|
||||
other.source_range.begin_pos,
|
||||
other.first_argument.source_range.begin_pos - 1
|
||||
).source
|
||||
|
||||
method = method_range(other).source
|
||||
arguments = other.arguments.map(&:source).join(', ')
|
||||
|
||||
" || #{method}(#{arguments})"
|
||||
end
|
||||
end
|
||||
|
||||
def method_range(node)
|
||||
range_between(node.source_range.begin_pos, node.first_argument.source_range.begin_pos - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -143,7 +143,7 @@ module RuboCop
|
||||
def_node_matcher :belongs_to_without_fk?, <<~PATTERN
|
||||
{
|
||||
(send nil? :belongs_to (sym %1)) # belongs_to :user
|
||||
(send nil? :belongs_to (sym %1) !hash) # belongs_to :user, -> { not_deleted }
|
||||
(send nil? :belongs_to (sym %1) !hash ...) # belongs_to :user, -> { not_deleted }
|
||||
(send nil? :belongs_to (sym %1) !(hash <(pair (sym :foreign_key) _) ...>))
|
||||
}
|
||||
PATTERN
|
||||
@ -98,6 +98,8 @@ module RuboCop
|
||||
proc = if node.numblock_type?
|
||||
->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
|
||||
else
|
||||
return false if node.arguments.empty?
|
||||
|
||||
arg = node.arguments.first
|
||||
->(n) { same_value?(arg, n.receiver) }
|
||||
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