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:
Bo Anderson 2022-11-05 18:40:49 +00:00 committed by GitHub
commit 4f22527fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
158 changed files with 784 additions and 189 deletions

View File

@ -147,7 +147,7 @@ GEM
rubocop-performance (1.15.0) rubocop-performance (1.15.0)
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.16.1) rubocop-rails (2.17.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0) rubocop (>= 1.33.0, < 2.0)
@ -215,7 +215,7 @@ GEM
yard-sorbet (0.6.1) yard-sorbet (0.6.1)
sorbet-runtime (>= 0.5) sorbet-runtime (>= 0.5)
yard (>= 0.9) yard (>= 0.9)
zeitwerk (2.6.1) zeitwerk (2.6.4)
PLATFORMS PLATFORMS
aarch64-linux aarch64-linux

View File

@ -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::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::ActionFilter::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array) 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 class RuboCop::Cop::Rails::ActiveRecordAliases < ::RuboCop::Cop::Base
extend ::RuboCop::Cop::AutoCorrector extend ::RuboCop::Cop::AutoCorrector
@ -695,6 +713,10 @@ class RuboCop::Cop::Rails::EagerEvaluationLogMessage < ::RuboCop::Cop::Base
def replacement_range(node); end def replacement_range(node); end
def replacement_source(node, arguments); end def replacement_source(node, arguments); end
class << self
def autocorrect_incompatible_with; end
end
end end
RuboCop::Cop::Rails::EagerEvaluationLogMessage::MSG = T.let(T.unsafe(nil), String) 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::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::I18nLocaleTexts::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array) 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 class RuboCop::Cop::Rails::IgnoredSkipActionFilterOption < ::RuboCop::Cop::Base
def filter_options(param0 = T.unsafe(nil)); end def filter_options(param0 = T.unsafe(nil)); end
def on_send(node); end def on_send(node); end
@ -1325,8 +1356,11 @@ class RuboCop::Cop::Rails::Pluck < ::RuboCop::Cop::Base
private private
def message(value, node); end def message(replacement, node); end
def offense_range(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 end
RuboCop::Cop::Rails::Pluck::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::Pluck::MSG = T.let(T.unsafe(nil), String)
@ -1398,11 +1432,13 @@ class RuboCop::Cop::Rails::Presence < ::RuboCop::Cop::Base
private private
def build_source_for_or_method(other); end def build_source_for_or_method(other); end
def current(node); end
def ignore_if_node?(node); end def ignore_if_node?(node); end
def ignore_other_node?(node); end def ignore_other_node?(node); end
def message(node, receiver, other); end def message(node, receiver, other); end
def method_range(node); end
def register_offense(node, receiver, other); end def register_offense(node, receiver, other); end
def replacement(receiver, other); end def replacement(receiver, other, left_sibling); end
end end
RuboCop::Cop::Rails::Presence::MSG = T.let(T.unsafe(nil), String) 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::NOT_IN_NAMED_RE = T.let(T.unsafe(nil), Regexp)
RuboCop::Cop::Rails::WhereNot::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array) 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 module RuboCop::Cop::TargetRailsVersion
def minimum_target_rails_version(version); end def minimum_target_rails_version(version); end
def support_target_rails_version?(version); end def support_target_rails_version?(version); end

View File

@ -70,22 +70,28 @@ class Zeitwerk::Inflector
def overrides; end def overrides; end
end end
module Zeitwerk::Internal
def internal(method_name); end
end
class Zeitwerk::Loader class Zeitwerk::Loader
include ::Zeitwerk::RealModName include ::Zeitwerk::RealModName
include ::Zeitwerk::Loader::Callbacks include ::Zeitwerk::Loader::Callbacks
include ::Zeitwerk::Loader::Helpers include ::Zeitwerk::Loader::Helpers
include ::Zeitwerk::Loader::Config include ::Zeitwerk::Loader::Config
include ::Zeitwerk::Loader::EagerLoad
def initialize; end def initialize; end
def autoloaded_dirs; end def autoloaded_dirs; end
def autoloads; end def autoloads; end
def eager_load(force: T.unsafe(nil)); end
def lazy_subdirs; end
def mutex; end def mutex; end
def mutex2; end def mutex2; end
def namespace_dirs; end
def reload; end def reload; end
def setup; end def setup; end
def shadowed_file?(file); end
def shadowed_files; end
def to_unload; end def to_unload; end
def unload; end def unload; end
def unloadable_cpath?(cpath); end def unloadable_cpath?(cpath); end
@ -111,6 +117,7 @@ class Zeitwerk::Loader
def default_logger; end def default_logger; end
def default_logger=(_arg0); end def default_logger=(_arg0); end
def eager_load_all; end def eager_load_all; end
def eager_load_namespace(mod); end
def for_gem(warn_on_extra_files: T.unsafe(nil)); end def for_gem(warn_on_extra_files: T.unsafe(nil)); end
end end
end end
@ -128,46 +135,62 @@ module Zeitwerk::Loader::Callbacks
end end
module Zeitwerk::Loader::Config module Zeitwerk::Loader::Config
extend ::Zeitwerk::Internal
def initialize; end def initialize; end
def __ignores?(abspath); end
def __roots; end
def collapse(*glob_patterns); end def collapse(*glob_patterns); end
def collapse_dirs; end
def collapse_glob_patterns; end
def dirs(namespaces: T.unsafe(nil)); end def dirs(namespaces: T.unsafe(nil)); end
def do_not_eager_load(*paths); end def do_not_eager_load(*paths); end
def eager_load_exclusions; end
def enable_reloading; end def enable_reloading; end
def ignore(*glob_patterns); end def ignore(*glob_patterns); end
def ignored_glob_patterns; end
def ignored_paths; end
def ignores?(abspath); end
def inflector; end def inflector; end
def inflector=(_arg0); end def inflector=(_arg0); end
def log!; end def log!; end
def logger; end def logger; end
def logger=(_arg0); end def logger=(_arg0); end
def on_load(cpath = T.unsafe(nil), &block); end def on_load(cpath = T.unsafe(nil), &block); end
def on_load_callbacks; end
def on_setup(&block); end def on_setup(&block); end
def on_setup_callbacks; end
def on_unload(cpath = T.unsafe(nil), &block); 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 push_dir(path, namespace: T.unsafe(nil)); end
def reloading_enabled?; end def reloading_enabled?; end
def root_dirs; end
def tag; end def tag; end
def tag=(tag); end def tag=(tag); end
private private
def actual_root_dirs; end def actual_roots; end
def collapse?(dir); 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 excluded_from_eager_load?(abspath); end
def expand_glob_patterns(glob_patterns); end def expand_glob_patterns(glob_patterns); end
def expand_paths(paths); 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_collapse_dirs; end
def recompute_ignored_paths; end def recompute_ignored_paths; end
def root_dir?(dir); 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 end
module Zeitwerk::Loader::Helpers module Zeitwerk::Loader::Helpers
@ -183,6 +206,7 @@ module Zeitwerk::Loader::Helpers
def ls(dir); end def ls(dir); end
def ruby?(path); end def ruby?(path); end
def strict_autoload_path(parent, cname); end def strict_autoload_path(parent, cname); end
def walk_up(abspath); end
end end
Zeitwerk::Loader::MUTEX = T.let(T.unsafe(nil), Thread::Mutex) Zeitwerk::Loader::MUTEX = T.let(T.unsafe(nil), Thread::Mutex)

View File

@ -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/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/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/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/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/public_suffix-5.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.1/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/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-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-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-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/rubocop-sorbet-0.6.11/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib")

View File

@ -10,6 +10,9 @@ AllCops:
# Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default. # 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 # See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
- db/*schema.rb - db/*schema.rb
- log/**/*
- public/**/*
- storage/**/*
# Enable checking Active Support extensions. # Enable checking Active Support extensions.
# See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions # See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
ActiveSupportExtensionsEnabled: true ActiveSupportExtensionsEnabled: true
@ -70,7 +73,7 @@ Rails/ActionControllerFlashBeforeRender:
StyleGuide: 'https://rails.rubystyle.guide/#flash-before-render' StyleGuide: 'https://rails.rubystyle.guide/#flash-before-render'
Reference: 'https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html' Reference: 'https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html'
Enabled: 'pending' Enabled: 'pending'
SafeAutocorrect: false SafeAutoCorrect: false
VersionAdded: '2.16' VersionAdded: '2.16'
Rails/ActionControllerTestCase: Rails/ActionControllerTestCase:
@ -78,7 +81,7 @@ Rails/ActionControllerTestCase:
StyleGuide: 'https://rails.rubystyle.guide/#integration-testing' StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html' Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
Enabled: 'pending' Enabled: 'pending'
SafeAutocorrect: false SafeAutoCorrect: false
VersionAdded: '2.14' VersionAdded: '2.14'
Include: Include:
- '**/test/**/*.rb' - '**/test/**/*.rb'
@ -95,6 +98,21 @@ Rails/ActionFilter:
- app/controllers/**/*.rb - app/controllers/**/*.rb
- app/mailers/**/*.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: Rails/ActiveRecordAliases:
Description: >- Description: >-
Avoid Active Record aliases: Avoid Active Record aliases:
@ -348,10 +366,13 @@ Rails/DynamicFindBy:
# The `Whitelist` has been deprecated, Please use `AllowedMethods` instead. # The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
Whitelist: Whitelist:
- find_by_sql - find_by_sql
- find_by_token_for
AllowedMethods: AllowedMethods:
- find_by_sql - find_by_sql
- find_by_token_for
AllowedReceivers: AllowedReceivers:
- Gem::Specification - Gem::Specification
- page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
Rails/EagerEvaluationLogMessage: Rails/EagerEvaluationLogMessage:
Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.' Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
@ -535,6 +556,13 @@ Rails/I18nLocaleTexts:
Enabled: pending Enabled: pending
VersionAdded: '2.14' 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: Rails/IgnoredSkipActionFilterOption:
Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.' 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' Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options'
@ -845,7 +873,7 @@ Rails/RootJoinChain:
Rails/RootPathnameMethods: Rails/RootPathnameMethods:
Description: 'Use `Rails.root` IO methods instead of passing it to `File`.' Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
Enabled: pending Enabled: pending
SafeAutocorrect: false SafeAutoCorrect: false
VersionAdded: '2.16' VersionAdded: '2.16'
Rails/RootPublicPath: Rails/RootPublicPath:
@ -1090,6 +1118,17 @@ Rails/WhereNot:
Enabled: 'pending' Enabled: 'pending'
VersionAdded: '2.8' 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. # Accept `redirect_to(...) and return` and similar cases.
Style/AndOr: Style/AndOr:
EnforcedStyle: conditionals EnforcedStyle: conditionals
Style/SymbolProc:
AllowedMethods:
- define_method
- mail
- respond_to

View File

@ -14,6 +14,16 @@ RuboCop::Rails::Inject.defaults!
require_relative 'rubocop/cop/rails_cops' 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( RuboCop::Cop::Style::RedundantSelf.singleton_class.prepend(
Module.new do Module.new do
def autocorrect_incompatible_with def autocorrect_incompatible_with

View File

@ -68,9 +68,12 @@ module RuboCop
def followed_by_render?(flash_node) def followed_by_render?(flash_node)
flash_assigment_node = find_ancestor(flash_node, type: :send) 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) render?(node)
end end
end end

View File

@ -31,7 +31,7 @@ module RuboCop
def_node_matcher :action_controller_test_case?, <<~PATTERN def_node_matcher :action_controller_test_case?, <<~PATTERN
(class (class
(const nil? _) (const nil? _)
(const (const {nil? cbase} :ActionController) :TestCase) nil?) (const (const {nil? cbase} :ActionController) :TestCase) _)
PATTERN PATTERN
def on_class(node) def on_class(node)

View File

@ -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

View File

@ -56,7 +56,8 @@ module RuboCop
argument.send_type? || argument.send_type? ||
argument.const_type? || argument.const_type? ||
argument.splat_type? || argument.splat_type? ||
allowed_name?(argument) allowed_name?(argument) ||
!argument.respond_to?(:value)
end end
def register_offense(node, message, preferred_method) def register_offense(node, message, preferred_method)

View File

@ -22,19 +22,23 @@ module RuboCop
# User.find_by(name: name, email: email) # User.find_by(name: name, email: email)
# User.find_by!(email: email) # User.find_by!(email: email)
# #
# @example AllowedMethods: find_by_sql # @example AllowedMethods: ['find_by_sql', 'find_by_token_for'] (default)
# # bad # # bad
# User.find_by_query(users_query) # User.find_by_query(users_query)
# User.find_by_token_for(:password_reset, token)
# #
# # good # # good
# User.find_by_sql(users_sql) # 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 # # bad
# Specification.find_by_name('backend').gem_dir # Specification.find_by_name('backend').gem_dir
# page.find_by_id('a_dom_id').click
# #
# # good # # good
# Gem::Specification.find_by_name('backend').gem_dir # Gem::Specification.find_by_name('backend').gem_dir
# page.find_by_id('a_dom_id').click
class DynamicFindBy < Base class DynamicFindBy < Base
include ActiveRecordHelper include ActiveRecordHelper
extend AutoCorrector extend AutoCorrector

View File

@ -37,6 +37,10 @@ module RuboCop
) )
PATTERN PATTERN
def self.autocorrect_incompatible_with
[Style::MethodCallWithArgsParentheses]
end
def on_send(node) def on_send(node)
return if node.parent&.block_type? return if node.parent&.block_type?

View File

@ -17,7 +17,7 @@ module RuboCop
# # good # # good
# User.order(:foo).each # User.order(:foo).each
# #
# @example AllowedPattern: [/order/] # @example AllowedPattern: ['order']
# # good # # good
# User.order(:foo).each # User.order(:foo).each
class FindEach < Base class FindEach < Base

View File

@ -43,7 +43,7 @@ module RuboCop
PATTERN PATTERN
def on_send(node) 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 if time_argument || !child_node
return unless current_time?(child_node, method_name) || current_time_with_convert?(child_node, method_name) return unless current_time?(child_node, method_name) || current_time_with_convert?(child_node, method_name)

View File

@ -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

View File

@ -21,42 +21,62 @@ module RuboCop
extend AutoCorrector extend AutoCorrector
extend TargetRailsVersion extend TargetRailsVersion
MSG = 'Prefer `pluck(:%<value>s)` over `%<current>s`.' MSG = 'Prefer `%<replacement>s` over `%<current>s`.'
minimum_target_rails_version 5.0 minimum_target_rails_version 5.0
def_node_matcher :pluck_candidate?, <<~PATTERN 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 PATTERN
def on_block(node) 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? 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 else # numblock
argument == 1 && element == :_1 argument == 1 && use_block_argument_in_key?('_1', key)
end end
next unless match next unless match
message = message(value, node) register_offense(node, key)
add_offense(offense_range(node), message: message) do |corrector|
corrector.replace(offense_range(node), "pluck(:#{value})")
end
end end
end end
alias on_numblock on_block alias on_numblock on_block
private 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) def offense_range(node)
node.send_node.loc.selector.join(node.loc.end) node.send_node.loc.selector.join(node.loc.end)
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 current = offense_range(node).source
format(MSG, value: value, current: current) format(MSG, replacement: replacement, current: current)
end end
end end
end end

View File

@ -93,7 +93,7 @@ module RuboCop
def register_offense(node, receiver, other) def register_offense(node, receiver, other)
add_offense(node, message: message(node, receiver, other)) do |corrector| 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
end end
@ -106,10 +106,20 @@ module RuboCop
end end
def message(node, receiver, other) 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 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? or_source = if other&.send_type?
build_source_for_or_method(other) build_source_for_or_method(other)
elsif other.nil? || other.nil_type? elsif other.nil? || other.nil_type?
@ -118,23 +128,24 @@ module RuboCop
" || #{other.source}" " || #{other.source}"
end end
"#{receiver.source}.presence" + or_source replaced = "#{receiver.source}.presence#{or_source}"
left_sibling ? "(#{replaced})" : replaced
end end
def build_source_for_or_method(other) 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}" " || #{other.source}"
else else
method = range_between( method = method_range(other).source
other.source_range.begin_pos,
other.first_argument.source_range.begin_pos - 1
).source
arguments = other.arguments.map(&:source).join(', ') arguments = other.arguments.map(&:source).join(', ')
" || #{method}(#{arguments})" " || #{method}(#{arguments})"
end end
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 end
end end

View File

@ -143,7 +143,7 @@ module RuboCop
def_node_matcher :belongs_to_without_fk?, <<~PATTERN def_node_matcher :belongs_to_without_fk?, <<~PATTERN
{ {
(send nil? :belongs_to (sym %1)) # belongs_to :user (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) _) ...>)) (send nil? :belongs_to (sym %1) !(hash <(pair (sym :foreign_key) _) ...>))
} }
PATTERN PATTERN

View File

@ -98,6 +98,8 @@ module RuboCop
proc = if node.numblock_type? proc = if node.numblock_type?
->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' } ->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
else else
return false if node.arguments.empty?
arg = node.arguments.first arg = node.arguments.first
->(n) { same_value?(arg, n.receiver) } ->(n) { same_value?(arg, n.receiver) }
end end

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