Merge pull request #14842 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rails-2.18.0

build(deps): bump rubocop-rails from 2.17.4 to 2.18.0 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2023-03-02 20:16:34 +00:00 committed by GitHub
commit fe89c0ce41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
149 changed files with 306 additions and 107 deletions

View File

@ -147,7 +147,7 @@ GEM
rubocop-performance (1.16.0) rubocop-performance (1.16.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.17.4) rubocop-rails (2.18.0)
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)

View File

@ -29,7 +29,7 @@ class BuildOptions
if option_defined? "with-#{name}" if option_defined? "with-#{name}"
include? "with-#{name}" include? "with-#{name}"
elsif option_defined? "without-#{name}" elsif option_defined? "without-#{name}"
!include? "without-#{name}" # rubocop:disable Rails/NegateInclude !include? "without-#{name}"
else else
false false
end end

View File

@ -112,7 +112,7 @@ module RuboCop
end end
def check_on_system_block_content(component_precedence_list, on_system_block) def check_on_system_block_content(component_precedence_list, on_system_block)
if on_system_block.body.block_type? && !on_system_methods.include?(on_system_block.body.method_name) if on_system_block.body.block_type? && !on_system_methods.include?(on_system_block.body.method_name) # rubocop:disable Style/InverseMethods (false positive)
offending_node(on_system_block) offending_node(on_system_block)
problem "Nest `#{on_system_block.method_name}` blocks inside `#{on_system_block.body.method_name}` " \ problem "Nest `#{on_system_block.method_name}` blocks inside `#{on_system_block.body.method_name}` " \
"blocks when there is only one inner block." do |corrector| "blocks when there is only one inner block." do |corrector|

View File

@ -53,7 +53,7 @@ module RuboCop
desc_problem "Description shouldn't start with an article." if regex_match_group(desc, /^(the|an?)(?=\s)/i) desc_problem "Description shouldn't start with an article." if regex_match_group(desc, /^(the|an?)(?=\s)/i)
# Check if invalid lowercase words are at the start of a desc. # Check if invalid lowercase words are at the start of a desc.
if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) && if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) && # rubocop:disable Style/InverseMethods (false positive)
regex_match_group(desc, /^[a-z]/) regex_match_group(desc, /^[a-z]/)
desc_problem "Description should start with a capital letter." desc_problem "Description should start with a capital letter."
end end

View File

@ -140,6 +140,7 @@ class RuboCop::Cop::Rails::ActionControllerFlashBeforeRender < ::RuboCop::Cop::B
def followed_by_render?(flash_node); end def followed_by_render?(flash_node); end
def inherit_action_controller_base?(node); end def inherit_action_controller_base?(node); end
def instance_method_or_block?(node); end def instance_method_or_block?(node); end
def use_redirect_to?(context); end
end end
RuboCop::Cop::Rails::ActionControllerFlashBeforeRender::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::ActionControllerFlashBeforeRender::MSG = T.let(T.unsafe(nil), String)
@ -919,6 +920,7 @@ RuboCop::Cop::Rails::FindEach::SCOPE_METHODS = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::Rails::FreezeTime < ::RuboCop::Cop::Base class RuboCop::Cop::Rails::FreezeTime < ::RuboCop::Cop::Base
extend ::RuboCop::Cop::AutoCorrector extend ::RuboCop::Cop::AutoCorrector
extend ::RuboCop::Cop::TargetRailsVersion
def on_send(node); end def on_send(node); end
def time_now?(param0 = T.unsafe(nil)); end def time_now?(param0 = T.unsafe(nil)); end
@ -1185,6 +1187,7 @@ class RuboCop::Cop::Rails::LexicallyScopedActionFilter < ::RuboCop::Cop::Base
private private
def alias_methods(node); end
def aliased_action_methods(node, defined_methods); end def aliased_action_methods(node, defined_methods); end
def array_values(node); end def array_values(node); end
def defined_action_methods(block); end def defined_action_methods(block); end
@ -1714,6 +1717,21 @@ end
RuboCop::Cop::Rails::RequireDependency::MSG = T.let(T.unsafe(nil), String) 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::ResponseParsedBody < ::RuboCop::Cop::Base
extend ::RuboCop::Cop::AutoCorrector
extend ::RuboCop::Cop::TargetRailsVersion
def json_parse_response_body?(param0 = T.unsafe(nil)); end
def on_send(node); end
private
def autocorrect(corrector, node); end
end
RuboCop::Cop::Rails::ResponseParsedBody::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::ResponseParsedBody::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 include ::RuboCop::Cop::MigrationsHelper
@ -1967,12 +1985,14 @@ class RuboCop::Cop::Rails::SquishedSQLHeredocs < ::RuboCop::Cop::Base
def message(node); end def message(node); end
def offense_detected?(node); end def offense_detected?(node); end
def singleline_comments_present?(node); end
def sql_heredoc?(node); end def sql_heredoc?(node); end
def using_squish?(node); end def using_squish?(node); end
end end
RuboCop::Cop::Rails::SquishedSQLHeredocs::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::SquishedSQLHeredocs::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::SquishedSQLHeredocs::SQL = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::SquishedSQLHeredocs::SQL = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::SquishedSQLHeredocs::SQL_IDENTIFIER_MARKERS = T.let(T.unsafe(nil), Regexp)
RuboCop::Cop::Rails::SquishedSQLHeredocs::SQUISH = T.let(T.unsafe(nil), String) RuboCop::Cop::Rails::SquishedSQLHeredocs::SQUISH = T.let(T.unsafe(nil), String)
class RuboCop::Cop::Rails::StripHeredoc < ::RuboCop::Cop::Base class RuboCop::Cop::Rails::StripHeredoc < ::RuboCop::Cop::Base
@ -2164,8 +2184,10 @@ RuboCop::Cop::Rails::UnknownEnv::MSG_SIMILAR = T.let(T.unsafe(nil), String)
class RuboCop::Cop::Rails::UnusedIgnoredColumns < ::RuboCop::Cop::Base class RuboCop::Cop::Rails::UnusedIgnoredColumns < ::RuboCop::Cop::Base
include ::RuboCop::Cop::ActiveRecordHelper include ::RuboCop::Cop::ActiveRecordHelper
def appended_ignored_columns(param0 = T.unsafe(nil)); end
def column_name(param0 = T.unsafe(nil)); end def column_name(param0 = T.unsafe(nil)); end
def ignored_columns(param0 = T.unsafe(nil)); end def ignored_columns(param0 = T.unsafe(nil)); end
def on_op_asgn(node); end
def on_send(node); end def on_send(node); end
private private

View File

@ -8298,18 +8298,80 @@ module Stdenv
end end
class String class String
def acts_like_string?(); end
def at(position); end
def camelcase(first_letter=T.unsafe(nil)); end
def camelize(first_letter=T.unsafe(nil)); end
def classify(); end
def constantize(); end
def dasherize(); end
def deconstantize(); end
def demodulize(); end
def exclude?(string); end def exclude?(string); end
def fast_xs(); end def fast_xs(); end
def first(limit=T.unsafe(nil)); end
def foreign_key(separate_class_name_and_id_with_underscore=T.unsafe(nil)); end
def from(position); end
def html_safe(); end
def humanize(capitalize: T.unsafe(nil), keep_id_suffix: T.unsafe(nil)); end
def indent(amount, indent_string=T.unsafe(nil), indent_empty_lines=T.unsafe(nil)); end def indent(amount, indent_string=T.unsafe(nil), indent_empty_lines=T.unsafe(nil)); end
def indent!(amount, indent_string=T.unsafe(nil), indent_empty_lines=T.unsafe(nil)); end def indent!(amount, indent_string=T.unsafe(nil), indent_empty_lines=T.unsafe(nil)); end
def is_utf8?(); end
def last(limit=T.unsafe(nil)); end
def mb_chars(); end
def parameterize(separator: T.unsafe(nil), preserve_case: T.unsafe(nil), locale: T.unsafe(nil)); end
def pluralize(count=T.unsafe(nil), locale=T.unsafe(nil)); end
def remove(*patterns); end
def remove!(*patterns); end
def safe_constantize(); end
def shellescape(); end def shellescape(); end
def shellsplit(); end def shellsplit(); end
def singularize(locale=T.unsafe(nil)); end
def squish(); end
def squish!(); end
def tableize(); end
def titlecase(keep_id_suffix: T.unsafe(nil)); end
def titleize(keep_id_suffix: T.unsafe(nil)); end
def to(position); end
def to_date(); end
def to_datetime(); end
def to_nfc(); end def to_nfc(); end
def to_nfd(); end def to_nfd(); end
@ -8317,6 +8379,18 @@ class String
def to_nfkc(); end def to_nfkc(); end
def to_nfkd(); end def to_nfkd(); end
def to_time(form=T.unsafe(nil)); end
def truncate(truncate_at, options=T.unsafe(nil)); end
def truncate_bytes(truncate_at, omission: T.unsafe(nil)); end
def truncate_words(words_count, options=T.unsafe(nil)); end
def underscore(); end
def upcase_first(); end
end end
class StringScanner class StringScanner

View File

@ -138,6 +138,11 @@ module Cask
def token_conflicts?; end def token_conflicts?; end
end end
class Cask
sig { returns(T::Boolean) }
def loaded_from_api?; end
end
class Installer class Installer
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def binaries?; end def binaries?; end

View File

@ -1,11 +1,13 @@
# typed: false # typed: false
# frozen_string_literal: true # frozen_string_literal: true
# Disable Rails cops, as we haven't required active_support yet.
# rubocop:disable Rails
homebrew_bootsnap_enabled = ENV["HOMEBREW_NO_BOOTSNAP"].nil? && !ENV["HOMEBREW_BOOTSNAP"].nil? homebrew_bootsnap_enabled = ENV["HOMEBREW_NO_BOOTSNAP"].nil? && !ENV["HOMEBREW_BOOTSNAP"].nil?
# portable ruby doesn't play nice with bootsnap # portable ruby doesn't play nice with bootsnap
# Can't use .exclude? here because we haven't required active_support yet.
homebrew_bootsnap_enabled &&= !RUBY_PATH.to_s.include?("/vendor/portable-ruby/") # rubocop:disable Rails/NegateInclude homebrew_bootsnap_enabled &&= !RUBY_PATH.to_s.include?("/vendor/portable-ruby/") # rubocop:disable Style/InverseMethods
homebrew_bootsnap_enabled &&= if ENV["HOMEBREW_MACOS_VERSION"] homebrew_bootsnap_enabled &&= if ENV["HOMEBREW_MACOS_VERSION"]
# Apple Silicon doesn't play nice with bootsnap # Apple Silicon doesn't play nice with bootsnap
@ -32,8 +34,7 @@ if homebrew_bootsnap_enabled
if defined?(Bootsnap) if defined?(Bootsnap)
cache = ENV.fetch("HOMEBREW_CACHE", nil) || ENV.fetch("HOMEBREW_DEFAULT_CACHE", nil) cache = ENV.fetch("HOMEBREW_CACHE", nil) || ENV.fetch("HOMEBREW_DEFAULT_CACHE", nil)
# Can't use .blank? here because we haven't required active_support yet. raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty?
raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty? # rubocop:disable Rails/Blank
Bootsnap.setup( Bootsnap.setup(
cache_dir: cache, cache_dir: cache,
@ -45,3 +46,4 @@ if homebrew_bootsnap_enabled
$stderr.puts "Error: HOMEBREW_BOOTSNAP could not `require \"bootsnap\"`!\n\n" $stderr.puts "Error: HOMEBREW_BOOTSNAP could not `require \"bootsnap\"`!\n\n"
end end
end end
# rubocop:enable Rails

View File

@ -132,7 +132,7 @@ module Utils
timeout: end_time&.remaining, timeout: end_time&.remaining,
**command_options **command_options
return result if result.success? || !args.exclude?("--http1.1") return result if result.success? || args.include?("--http1.1")
raise Timeout::Error, result.stderr.lines.last.chomp if timeout && result.status.exitstatus == 28 raise Timeout::Error, result.stderr.lines.last.chomp if timeout && result.status.exitstatus == 28

View File

@ -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/rubocop-1.46.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.46.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-capybara-2.17.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-capybara-2.17.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.16.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.16.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.4/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.18.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.18.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.18.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.7.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.7.0/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

@ -46,23 +46,6 @@ Lint/NumberConversion:
- fortnights - fortnights
- in_milliseconds - in_milliseconds
AllowedPatterns: [] AllowedPatterns: []
# Deprecated.
IgnoredMethods:
- ago
- from_now
- second
- seconds
- minute
- minutes
- hour
- hours
- day
- days
- week
- weeks
- fortnight
- fortnights
- in_milliseconds
Rails: Rails:
Enabled: true Enabled: true
@ -135,7 +118,9 @@ Rails/ActiveRecordOverride:
Check for overriding Active Record methods instead of using Check for overriding Active Record methods instead of using
callbacks. callbacks.
Enabled: true Enabled: true
Severity: warning
VersionAdded: '0.67' VersionAdded: '0.67'
VersionChanged: '2.18'
Include: Include:
- app/models/**/*.rb - app/models/**/*.rb
@ -226,6 +211,9 @@ Rails/BelongsTo:
Description: >- Description: >-
Use `optional: true` instead of `required: false` for Use `optional: true` instead of `required: false` for
`belongs_to` relations. `belongs_to` relations.
Reference:
- https://guides.rubyonrails.org/5_0_release_notes.html
- https://github.com/rails/rails/pull/18937
Enabled: true Enabled: true
VersionAdded: '0.62' VersionAdded: '0.62'
@ -244,6 +232,9 @@ Rails/Blank:
Rails/BulkChangeTable: Rails/BulkChangeTable:
Description: 'Check whether alter queries are combinable.' Description: 'Check whether alter queries are combinable.'
Reference:
- https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-change_table
- https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html
Enabled: true Enabled: true
VersionAdded: '0.57' VersionAdded: '0.57'
Database: null Database: null
@ -330,9 +321,10 @@ Rails/DelegateAllowBlank:
Rails/DeprecatedActiveModelErrorsMethods: Rails/DeprecatedActiveModelErrorsMethods:
Description: 'Avoid manipulating ActiveModel errors hash directly.' Description: 'Avoid manipulating ActiveModel errors hash directly.'
Enabled: pending Enabled: pending
Severity: warning
Safe: false Safe: false
VersionAdded: '2.14' VersionAdded: '2.14'
VersionChanged: '2.15' VersionChanged: '2.18'
Rails/DotSeparatedKeys: Rails/DotSeparatedKeys:
Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.' Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.'
@ -343,12 +335,16 @@ Rails/DotSeparatedKeys:
Rails/DuplicateAssociation: Rails/DuplicateAssociation:
Description: "Don't repeat associations in a model." Description: "Don't repeat associations in a model."
Enabled: pending Enabled: pending
Severity: warning
VersionAdded: '2.14' VersionAdded: '2.14'
VersionChanged: '2.18'
Rails/DuplicateScope: Rails/DuplicateScope:
Description: 'Multiple scopes share this same where clause.' Description: 'Multiple scopes share this same where clause.'
Enabled: pending Enabled: pending
Severity: warning
VersionAdded: '2.14' VersionAdded: '2.14'
VersionChanged: '2.18'
Rails/DurationArithmetic: Rails/DurationArithmetic:
Description: 'Do not use duration as arithmetic operand with `Time.current`.' Description: 'Do not use duration as arithmetic operand with `Time.current`.'
@ -463,7 +459,7 @@ Rails/FindById:
VersionAdded: '2.7' VersionAdded: '2.7'
Rails/FindEach: Rails/FindEach:
Description: 'Prefer all.find_each over all.find.' Description: 'Prefer all.find_each over all.each.'
StyleGuide: 'https://rails.rubystyle.guide#find-each' StyleGuide: 'https://rails.rubystyle.guide#find-each'
Enabled: true Enabled: true
VersionAdded: '0.30' VersionAdded: '0.30'
@ -477,13 +473,6 @@ Rails/FindEach:
- select - select
- lock - lock
AllowedPatterns: [] AllowedPatterns: []
# Deprecated.
IgnoredMethods:
# Methods that don't work well with `find_each`.
- order
- limit
- select
- lock
Rails/FreezeTime: Rails/FreezeTime:
Description: 'Prefer `freeze_time` over `travel_to` with an argument of the current time.' Description: 'Prefer `freeze_time` over `travel_to` with an argument of the current time.'
@ -592,6 +581,9 @@ Rails/Inquiry:
Rails/InverseOf: Rails/InverseOf:
Description: 'Checks for associations where the inverse cannot be determined automatically.' Description: 'Checks for associations where the inverse cannot be determined automatically.'
Reference:
- https://guides.rubyonrails.org/association_basics.html#bi-directional-associations
- https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses
Enabled: true Enabled: true
VersionAdded: '0.52' VersionAdded: '0.52'
IgnoreScopes: false IgnoreScopes: false
@ -695,7 +687,9 @@ Rails/Pluck:
Description: 'Prefer `pluck` over `map { ... }`.' Description: 'Prefer `pluck` over `map { ... }`.'
StyleGuide: 'https://rails.rubystyle.guide#pluck' StyleGuide: 'https://rails.rubystyle.guide#pluck'
Enabled: 'pending' Enabled: 'pending'
Safe: false
VersionAdded: '2.7' VersionAdded: '2.7'
VersionChanged: '2.18'
Rails/PluckId: Rails/PluckId:
Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.' Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.'
@ -847,6 +841,17 @@ Rails/RequireDependency:
Enabled: false Enabled: false
VersionAdded: '2.10' VersionAdded: '2.10'
Rails/ResponseParsedBody:
Description: Prefer `response.parsed_body` to `JSON.parse(response.body)`.
Enabled: pending
SafeAutoCorrect: false
VersionAdded: '2.18'
Include:
- spec/controllers/**/*.rb
- spec/requests/**/*.rb
- test/controllers/**/*.rb
- test/integration/**/*.rb
Rails/ReversibleMigration: Rails/ReversibleMigration:
Description: 'Checks whether the change method of the migration file is reversible.' Description: 'Checks whether the change method of the migration file is reversible.'
StyleGuide: 'https://rails.rubystyle.guide#reversible-migration' StyleGuide: 'https://rails.rubystyle.guide#reversible-migration'
@ -1038,10 +1043,14 @@ Rails/TopLevelHashWithIndifferentAccess:
Description: 'Identifies top-level `HashWithIndifferentAccess`.' Description: 'Identifies top-level `HashWithIndifferentAccess`.'
Reference: 'https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#top-level-hashwithindifferentaccess-is-soft-deprecated' Reference: 'https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#top-level-hashwithindifferentaccess-is-soft-deprecated'
Enabled: pending Enabled: pending
Severity: warning
VersionAdded: '2.16' VersionAdded: '2.16'
VersionChanged: '2.18'
Rails/TransactionExitStatement: Rails/TransactionExitStatement:
Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.' Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
Reference:
- https://github.com/rails/rails/commit/15aa4200e083
Enabled: pending Enabled: pending
VersionAdded: '2.14' VersionAdded: '2.14'
@ -1066,7 +1075,9 @@ Rails/UniqueValidationWithoutIndex:
Rails/UnknownEnv: Rails/UnknownEnv:
Description: 'Use correct environment name.' Description: 'Use correct environment name.'
Enabled: true Enabled: true
Severity: warning
VersionAdded: '0.51' VersionAdded: '0.51'
VersionChanged: '2.18'
Environments: Environments:
- development - development
- test - test
@ -1121,12 +1132,27 @@ Rails/WhereNot:
Rails/WhereNotWithMultipleConditions: Rails/WhereNotWithMultipleConditions:
Description: 'Do not use `where.not(...)` with multiple conditions.' Description: 'Do not use `where.not(...)` with multiple conditions.'
Enabled: 'pending' Enabled: 'pending'
Severity: warning
VersionAdded: '2.17' VersionAdded: '2.17'
VersionChanged: '2.18'
# 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/FormatStringToken:
AllowedMethods:
- redirect
Style/InverseMethods:
# `InverseMethods` are methods that can be inverted by a not (`not` or `!`)
# The relationship of inverse methods only needs to be defined in one direction.
# Keys and values both need to be defined as symbols.
InverseMethods:
:present?: :blank?
:include?: :exclude?
:valid?: :invalid?
Style/SymbolProc: Style/SymbolProc:
AllowedMethods: AllowedMethods:
- define_method - define_method

View File

@ -67,9 +67,11 @@ module RuboCop
private private
def followed_by_render?(flash_node) def followed_by_render?(flash_node)
flash_assigment_node = find_ancestor(flash_node, type: :send) flash_assignment_node = find_ancestor(flash_node, type: :send)
context = flash_assigment_node context = flash_assignment_node
if (node = context.each_ancestor(:if, :rescue).first) if (node = context.each_ancestor(:if, :rescue).first)
return false if use_redirect_to?(context)
context = node context = node
elsif context.right_siblings.empty? elsif context.right_siblings.empty?
return true return true
@ -95,6 +97,12 @@ module RuboCop
def_node || block_node def_node || block_node
end end
def use_redirect_to?(context)
context.right_siblings.compact.any? do |sibling|
sibling.send_type? && sibling.method?(:redirect_to)
end
end
def find_ancestor(node, type:) def find_ancestor(node, type:)
node.each_ancestor(type).first node.each_ancestor(type).first
end end

View File

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

View File

@ -26,6 +26,8 @@ module RuboCop
RESTRICT_ON_SEND = ALIASES.keys.freeze RESTRICT_ON_SEND = ALIASES.keys.freeze
def on_send(node) def on_send(node)
return if node.arguments.empty?
method_name = node.method_name method_name = node.method_name
alias_method = ALIASES[method_name] alias_method = ALIASES[method_name]

View File

@ -47,9 +47,6 @@ module RuboCop
# class Post < ApplicationRecord # class Post < ApplicationRecord
# belongs_to :blog, optional: false # belongs_to :blog, optional: false
# end # end
#
# @see https://guides.rubyonrails.org/5_0_release_notes.html
# @see https://github.com/rails/rails/pull/18937
class BelongsTo < Base class BelongsTo < Base
extend AutoCorrector extend AutoCorrector
extend TargetRailsVersion extend TargetRailsVersion

View File

@ -8,7 +8,7 @@ module RuboCop
# #
# Interaction with `Style/UnlessElse`: # Interaction with `Style/UnlessElse`:
# The configuration of `NotPresent` will not produce an offense in the # The configuration of `NotPresent` will not produce an offense in the
# context of `unless else` if `Style/UnlessElse` is inabled. This is # context of `unless else` if `Style/UnlessElse` is enabled. This is
# to prevent interference between the autocorrection of the two cops. # to prevent interference between the autocorrection of the two cops.
# #
# @safety # @safety

View File

@ -62,9 +62,6 @@ module RuboCop
# t.string :nickname # t.string :nickname
# end # end
# end # end
#
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-change_table
# @see https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html
class BulkChangeTable < Base class BulkChangeTable < Base
MSG_FOR_CHANGE_TABLE = <<~MSG.chomp MSG_FOR_CHANGE_TABLE = <<~MSG.chomp
You can combine alter queries using `bulk: true` options. You can combine alter queries using `bulk: true` options.
@ -216,7 +213,7 @@ module RuboCop
true true
when POSTGRESQL when POSTGRESQL
# Add bulk alter support for PostgreSQL in 5.2.0 # Add bulk alter support for PostgreSQL in 5.2.0
# @see https://github.com/rails/rails/pull/31331 # See: https://github.com/rails/rails/pull/31331
target_rails_version >= 5.2 target_rails_version >= 5.2
else else
false false

View File

@ -160,7 +160,7 @@ module RuboCop
end end
def model_file? def model_file?
processed_source.buffer.name.include?('/models/') processed_source.file_path.include?('/models/')
end end
end end
end end

View File

@ -26,6 +26,9 @@ module RuboCop
# #
class FreezeTime < Base class FreezeTime < Base
extend AutoCorrector extend AutoCorrector
extend TargetRailsVersion
minimum_target_rails_version 5.2
MSG = 'Use `freeze_time` instead of `travel_to`.' MSG = 'Use `freeze_time` instead of `travel_to`.'
NOW_METHODS = %i[now new current].freeze NOW_METHODS = %i[now new current].freeze

View File

@ -41,11 +41,11 @@ module RuboCop
PATTERN PATTERN
def_node_matcher :association_without_options?, <<~PATTERN def_node_matcher :association_without_options?, <<~PATTERN
(send nil? {:has_many :has_one} _) (send _ {:has_many :has_one} _)
PATTERN PATTERN
def_node_matcher :association_with_options?, <<~PATTERN def_node_matcher :association_with_options?, <<~PATTERN
(send nil? {:has_many :has_one} ... (hash $...)) (send _ {:has_many :has_one} ... (hash $...))
PATTERN PATTERN
def_node_matcher :dependent_option?, <<~PATTERN def_node_matcher :dependent_option?, <<~PATTERN

View File

@ -35,8 +35,6 @@ module RuboCop
# skip_before_action :login_required, # skip_before_action :login_required,
# if: -> { trusted_origin? && action_name != "admin" } # if: -> { trusted_origin? && action_name != "admin" }
# end # end
#
# @see https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options
class IgnoredSkipActionFilterOption < Base class IgnoredSkipActionFilterOption < Base
MSG = <<~MSG.chomp.freeze MSG = <<~MSG.chomp.freeze
`%<ignore>s` option will be ignored when `%<prefer>s` and `%<ignore>s` are used together. `%<ignore>s` option will be ignored when `%<prefer>s` and `%<ignore>s` are used together.

View File

@ -137,9 +137,6 @@ module RuboCop
# class Blog < ApplicationRecord # class Blog < ApplicationRecord
# has_many :posts, -> { order(published_at: :desc) } # has_many :posts, -> { order(published_at: :desc) }
# end # end
#
# @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
class InverseOf < Base class InverseOf < Base
SPECIFY_MSG = 'Specify an `:inverse_of` option.' SPECIFY_MSG = 'Specify an `:inverse_of` option.'
NIL_MSG = 'You specified `inverse_of: nil`, you probably meant to use `inverse_of: false`.' NIL_MSG = 'You specified `inverse_of: nil`, you probably meant to use `inverse_of: false`.'

View File

@ -144,19 +144,29 @@ module RuboCop
end end
def aliased_action_methods(node, defined_methods) def aliased_action_methods(node, defined_methods)
alias_methods = node.each_child_node(:send).select { |send_node| send_node.method?(:alias_method) } alias_methods = alias_methods(node)
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| defined_methods.each_with_object([]) do |defined_method, aliased_method|
if (new_method_name = hash_of_alias_methods[defined_method]) if (new_method_name = alias_methods[defined_method])
aliased_method << new_method_name aliased_method << new_method_name
end end
end end
end end
def alias_methods(node)
result = {}
node.each_child_node(:send, :alias) do |child_node|
case child_node.type
when :send
if child_node.method?(:alias_method)
result[child_node.last_argument.value] = child_node.first_argument.value
end
when :alias
result[child_node.old_identifier.value] = child_node.new_identifier.value
end
end
result
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

View File

@ -26,7 +26,7 @@ module RuboCop
RESTRICT_ON_SEND = %i[!].freeze RESTRICT_ON_SEND = %i[!].freeze
def_node_matcher :negate_include_call?, <<~PATTERN def_node_matcher :negate_include_call?, <<~PATTERN
(send (send $_ :include? $_) :!) (send (send $!nil? :include? $_) :!)
PATTERN PATTERN
def on_send(node) def on_send(node)

View File

@ -21,7 +21,7 @@ module RuboCop
RESTRICT_ON_SEND = %i[add_column add_reference].freeze RESTRICT_ON_SEND = %i[add_column add_reference].freeze
def_node_matcher :add_not_null_column?, <<~PATTERN def_node_matcher :add_not_null_column?, <<~PATTERN
(send nil? :add_column _ _ _ (hash $...)) (send nil? :add_column _ _ $_ (hash $...))
PATTERN PATTERN
def_node_matcher :add_not_null_reference?, <<~PATTERN def_node_matcher :add_not_null_reference?, <<~PATTERN
@ -44,17 +44,20 @@ module RuboCop
private private
def check_add_column(node) def check_add_column(node)
pairs = add_not_null_column?(node) add_not_null_column?(node) do |type, pairs|
check_pairs(pairs) return if type.value == :virtual || type.value == 'virtual'
check_pairs(pairs)
end
end end
def check_add_reference(node) def check_add_reference(node)
pairs = add_not_null_reference?(node) add_not_null_reference?(node) do |pairs|
check_pairs(pairs) check_pairs(pairs)
end
end end
def check_pairs(pairs) def check_pairs(pairs)
return unless pairs
return if pairs.any? { |pair| default_option?(pair) } return if pairs.any? { |pair| default_option?(pair) }
null_false = pairs.find { |pair| null_false?(pair) } null_false = pairs.find { |pair| null_false?(pair) }

View File

@ -9,6 +9,18 @@ module RuboCop
# element in an enumerable. When called on an Active Record relation, it # element in an enumerable. When called on an Active Record relation, it
# results in a more efficient query that only selects the necessary key. # results in a more efficient query that only selects the necessary key.
# #
# @safety
# This cop is unsafe because model can use column aliases.
#
# [source,ruby]
# ----
# # Original code
# User.select('name AS nickname').map { |user| user[:nickname] } # => array of nicknames
#
# # After autocorrection
# User.select('name AS nickname').pluck(:nickname) # => raises ActiveRecord::StatementInvalid
# ----
#
# @example # @example
# # bad # # bad
# Post.published.map { |post| post[:title] } # Post.published.map { |post| post[:title] }

View File

@ -112,10 +112,10 @@ module RuboCop
end end
def current(node) def current(node)
if node.source.include?("\n") if !node.ternary? && node.source.include?("\n")
"#{node.loc.keyword.with(end_pos: node.condition.loc.selector.end_pos).source} ... end" "#{node.loc.keyword.with(end_pos: node.condition.loc.selector.end_pos).source} ... end"
else else
node.source node.source.gsub(/\n\s*/, ' ')
end end
end end

View File

@ -8,7 +8,7 @@ module RuboCop
# #
# Interaction with `Style/UnlessElse`: # Interaction with `Style/UnlessElse`:
# The configuration of `NotBlank` will not produce an offense in the # The configuration of `NotBlank` will not produce an offense in the
# context of `unless else` if `Style/UnlessElse` is inabled. This is # context of `unless else` if `Style/UnlessElse` is enabled. This is
# to prevent interference between the autocorrection of the two cops. # to prevent interference between the autocorrection of the two cops.
# #
# @example NotNilAndNotEmpty: true (default) # @example NotNilAndNotEmpty: true (default)

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