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:
commit
fe89c0ce41
@ -147,7 +147,7 @@ GEM
|
||||
rubocop-performance (1.16.0)
|
||||
rubocop (>= 1.7.0, < 2.0)
|
||||
rubocop-ast (>= 0.4.0)
|
||||
rubocop-rails (2.17.4)
|
||||
rubocop-rails (2.18.0)
|
||||
activesupport (>= 4.2.0)
|
||||
rack (>= 1.1)
|
||||
rubocop (>= 1.33.0, < 2.0)
|
||||
|
@ -29,7 +29,7 @@ class BuildOptions
|
||||
if option_defined? "with-#{name}"
|
||||
include? "with-#{name}"
|
||||
elsif option_defined? "without-#{name}"
|
||||
!include? "without-#{name}" # rubocop:disable Rails/NegateInclude
|
||||
!include? "without-#{name}"
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ module RuboCop
|
||||
end
|
||||
|
||||
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)
|
||||
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|
|
||||
|
@ -53,7 +53,7 @@ module RuboCop
|
||||
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.
|
||||
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]/)
|
||||
desc_problem "Description should start with a capital letter."
|
||||
end
|
||||
|
@ -140,6 +140,7 @@ class RuboCop::Cop::Rails::ActionControllerFlashBeforeRender < ::RuboCop::Cop::B
|
||||
def followed_by_render?(flash_node); end
|
||||
def inherit_action_controller_base?(node); end
|
||||
def instance_method_or_block?(node); end
|
||||
def use_redirect_to?(context); end
|
||||
end
|
||||
|
||||
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
|
||||
extend ::RuboCop::Cop::AutoCorrector
|
||||
extend ::RuboCop::Cop::TargetRailsVersion
|
||||
|
||||
def on_send(node); end
|
||||
def time_now?(param0 = T.unsafe(nil)); end
|
||||
@ -1185,6 +1187,7 @@ class RuboCop::Cop::Rails::LexicallyScopedActionFilter < ::RuboCop::Cop::Base
|
||||
|
||||
private
|
||||
|
||||
def alias_methods(node); end
|
||||
def aliased_action_methods(node, defined_methods); end
|
||||
def array_values(node); 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::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
|
||||
include ::RuboCop::Cop::MigrationsHelper
|
||||
|
||||
@ -1967,12 +1985,14 @@ class RuboCop::Cop::Rails::SquishedSQLHeredocs < ::RuboCop::Cop::Base
|
||||
|
||||
def message(node); end
|
||||
def offense_detected?(node); end
|
||||
def singleline_comments_present?(node); end
|
||||
def sql_heredoc?(node); end
|
||||
def using_squish?(node); end
|
||||
end
|
||||
|
||||
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_IDENTIFIER_MARKERS = T.let(T.unsafe(nil), Regexp)
|
||||
RuboCop::Cop::Rails::SquishedSQLHeredocs::SQUISH = T.let(T.unsafe(nil), String)
|
||||
|
||||
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
|
||||
include ::RuboCop::Cop::ActiveRecordHelper
|
||||
|
||||
def appended_ignored_columns(param0 = T.unsafe(nil)); end
|
||||
def column_name(param0 = T.unsafe(nil)); end
|
||||
def ignored_columns(param0 = T.unsafe(nil)); end
|
||||
def on_op_asgn(node); end
|
||||
def on_send(node); end
|
||||
|
||||
private
|
@ -8298,18 +8298,80 @@ module Stdenv
|
||||
end
|
||||
|
||||
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 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 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 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_nfd(); end
|
||||
@ -8317,6 +8379,18 @@ class String
|
||||
def to_nfkc(); 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
|
||||
|
||||
class StringScanner
|
||||
|
@ -138,6 +138,11 @@ module Cask
|
||||
def token_conflicts?; end
|
||||
end
|
||||
|
||||
class Cask
|
||||
sig { returns(T::Boolean) }
|
||||
def loaded_from_api?; end
|
||||
end
|
||||
|
||||
class Installer
|
||||
sig { returns(T::Boolean) }
|
||||
def binaries?; end
|
||||
|
@ -1,11 +1,13 @@
|
||||
# typed: false
|
||||
# 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?
|
||||
|
||||
# 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"]
|
||||
# Apple Silicon doesn't play nice with bootsnap
|
||||
@ -32,8 +34,7 @@ if homebrew_bootsnap_enabled
|
||||
|
||||
if defined?(Bootsnap)
|
||||
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? # rubocop:disable Rails/Blank
|
||||
raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty?
|
||||
|
||||
Bootsnap.setup(
|
||||
cache_dir: cache,
|
||||
@ -45,3 +46,4 @@ if homebrew_bootsnap_enabled
|
||||
$stderr.puts "Error: HOMEBREW_BOOTSNAP could not `require \"bootsnap\"`!\n\n"
|
||||
end
|
||||
end
|
||||
# rubocop:enable Rails
|
||||
|
@ -132,7 +132,7 @@ module Utils
|
||||
timeout: end_time&.remaining,
|
||||
**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
|
||||
|
||||
|
@ -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-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-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-sorbet-0.7.0/lib")
|
||||
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib")
|
||||
|
@ -46,23 +46,6 @@ Lint/NumberConversion:
|
||||
- fortnights
|
||||
- in_milliseconds
|
||||
AllowedPatterns: []
|
||||
# Deprecated.
|
||||
IgnoredMethods:
|
||||
- ago
|
||||
- from_now
|
||||
- second
|
||||
- seconds
|
||||
- minute
|
||||
- minutes
|
||||
- hour
|
||||
- hours
|
||||
- day
|
||||
- days
|
||||
- week
|
||||
- weeks
|
||||
- fortnight
|
||||
- fortnights
|
||||
- in_milliseconds
|
||||
|
||||
Rails:
|
||||
Enabled: true
|
||||
@ -135,7 +118,9 @@ Rails/ActiveRecordOverride:
|
||||
Check for overriding Active Record methods instead of using
|
||||
callbacks.
|
||||
Enabled: true
|
||||
Severity: warning
|
||||
VersionAdded: '0.67'
|
||||
VersionChanged: '2.18'
|
||||
Include:
|
||||
- app/models/**/*.rb
|
||||
|
||||
@ -226,6 +211,9 @@ Rails/BelongsTo:
|
||||
Description: >-
|
||||
Use `optional: true` instead of `required: false` for
|
||||
`belongs_to` relations.
|
||||
Reference:
|
||||
- https://guides.rubyonrails.org/5_0_release_notes.html
|
||||
- https://github.com/rails/rails/pull/18937
|
||||
Enabled: true
|
||||
VersionAdded: '0.62'
|
||||
|
||||
@ -244,6 +232,9 @@ Rails/Blank:
|
||||
|
||||
Rails/BulkChangeTable:
|
||||
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
|
||||
VersionAdded: '0.57'
|
||||
Database: null
|
||||
@ -330,9 +321,10 @@ Rails/DelegateAllowBlank:
|
||||
Rails/DeprecatedActiveModelErrorsMethods:
|
||||
Description: 'Avoid manipulating ActiveModel errors hash directly.'
|
||||
Enabled: pending
|
||||
Severity: warning
|
||||
Safe: false
|
||||
VersionAdded: '2.14'
|
||||
VersionChanged: '2.15'
|
||||
VersionChanged: '2.18'
|
||||
|
||||
Rails/DotSeparatedKeys:
|
||||
Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.'
|
||||
@ -343,12 +335,16 @@ Rails/DotSeparatedKeys:
|
||||
Rails/DuplicateAssociation:
|
||||
Description: "Don't repeat associations in a model."
|
||||
Enabled: pending
|
||||
Severity: warning
|
||||
VersionAdded: '2.14'
|
||||
VersionChanged: '2.18'
|
||||
|
||||
Rails/DuplicateScope:
|
||||
Description: 'Multiple scopes share this same where clause.'
|
||||
Enabled: pending
|
||||
Severity: warning
|
||||
VersionAdded: '2.14'
|
||||
VersionChanged: '2.18'
|
||||
|
||||
Rails/DurationArithmetic:
|
||||
Description: 'Do not use duration as arithmetic operand with `Time.current`.'
|
||||
@ -463,7 +459,7 @@ Rails/FindById:
|
||||
VersionAdded: '2.7'
|
||||
|
||||
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'
|
||||
Enabled: true
|
||||
VersionAdded: '0.30'
|
||||
@ -477,13 +473,6 @@ Rails/FindEach:
|
||||
- select
|
||||
- lock
|
||||
AllowedPatterns: []
|
||||
# Deprecated.
|
||||
IgnoredMethods:
|
||||
# Methods that don't work well with `find_each`.
|
||||
- order
|
||||
- limit
|
||||
- select
|
||||
- lock
|
||||
|
||||
Rails/FreezeTime:
|
||||
Description: 'Prefer `freeze_time` over `travel_to` with an argument of the current time.'
|
||||
@ -592,6 +581,9 @@ Rails/Inquiry:
|
||||
|
||||
Rails/InverseOf:
|
||||
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
|
||||
VersionAdded: '0.52'
|
||||
IgnoreScopes: false
|
||||
@ -695,7 +687,9 @@ Rails/Pluck:
|
||||
Description: 'Prefer `pluck` over `map { ... }`.'
|
||||
StyleGuide: 'https://rails.rubystyle.guide#pluck'
|
||||
Enabled: 'pending'
|
||||
Safe: false
|
||||
VersionAdded: '2.7'
|
||||
VersionChanged: '2.18'
|
||||
|
||||
Rails/PluckId:
|
||||
Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.'
|
||||
@ -847,6 +841,17 @@ Rails/RequireDependency:
|
||||
Enabled: false
|
||||
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:
|
||||
Description: 'Checks whether the change method of the migration file is reversible.'
|
||||
StyleGuide: 'https://rails.rubystyle.guide#reversible-migration'
|
||||
@ -1038,10 +1043,14 @@ Rails/TopLevelHashWithIndifferentAccess:
|
||||
Description: 'Identifies top-level `HashWithIndifferentAccess`.'
|
||||
Reference: 'https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#top-level-hashwithindifferentaccess-is-soft-deprecated'
|
||||
Enabled: pending
|
||||
Severity: warning
|
||||
VersionAdded: '2.16'
|
||||
VersionChanged: '2.18'
|
||||
|
||||
Rails/TransactionExitStatement:
|
||||
Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
|
||||
Reference:
|
||||
- https://github.com/rails/rails/commit/15aa4200e083
|
||||
Enabled: pending
|
||||
VersionAdded: '2.14'
|
||||
|
||||
@ -1066,7 +1075,9 @@ Rails/UniqueValidationWithoutIndex:
|
||||
Rails/UnknownEnv:
|
||||
Description: 'Use correct environment name.'
|
||||
Enabled: true
|
||||
Severity: warning
|
||||
VersionAdded: '0.51'
|
||||
VersionChanged: '2.18'
|
||||
Environments:
|
||||
- development
|
||||
- test
|
||||
@ -1121,12 +1132,27 @@ Rails/WhereNot:
|
||||
Rails/WhereNotWithMultipleConditions:
|
||||
Description: 'Do not use `where.not(...)` with multiple conditions.'
|
||||
Enabled: 'pending'
|
||||
Severity: warning
|
||||
VersionAdded: '2.17'
|
||||
VersionChanged: '2.18'
|
||||
|
||||
# Accept `redirect_to(...) and return` and similar cases.
|
||||
Style/AndOr:
|
||||
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:
|
||||
AllowedMethods:
|
||||
- define_method
|
@ -67,9 +67,11 @@ module RuboCop
|
||||
private
|
||||
|
||||
def followed_by_render?(flash_node)
|
||||
flash_assigment_node = find_ancestor(flash_node, type: :send)
|
||||
context = flash_assigment_node
|
||||
flash_assignment_node = find_ancestor(flash_node, type: :send)
|
||||
context = flash_assignment_node
|
||||
if (node = context.each_ancestor(:if, :rescue).first)
|
||||
return false if use_redirect_to?(context)
|
||||
|
||||
context = node
|
||||
elsif context.right_siblings.empty?
|
||||
return true
|
||||
@ -95,6 +97,12 @@ module RuboCop
|
||||
def_node || block_node
|
||||
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:)
|
||||
node.each_ancestor(type).first
|
||||
end
|
@ -30,7 +30,7 @@ module RuboCop
|
||||
|
||||
def_node_matcher :action_controller_test_case?, <<~PATTERN
|
||||
(class
|
||||
(const {nil? cbase} _)
|
||||
(const _ _)
|
||||
(const (const {nil? cbase} :ActionController) :TestCase) _)
|
||||
PATTERN
|
||||
|
@ -26,6 +26,8 @@ module RuboCop
|
||||
RESTRICT_ON_SEND = ALIASES.keys.freeze
|
||||
|
||||
def on_send(node)
|
||||
return if node.arguments.empty?
|
||||
|
||||
method_name = node.method_name
|
||||
alias_method = ALIASES[method_name]
|
||||
|
@ -47,9 +47,6 @@ module RuboCop
|
||||
# class Post < ApplicationRecord
|
||||
# belongs_to :blog, optional: false
|
||||
# end
|
||||
#
|
||||
# @see https://guides.rubyonrails.org/5_0_release_notes.html
|
||||
# @see https://github.com/rails/rails/pull/18937
|
||||
class BelongsTo < Base
|
||||
extend AutoCorrector
|
||||
extend TargetRailsVersion
|
@ -8,7 +8,7 @@ module RuboCop
|
||||
#
|
||||
# Interaction with `Style/UnlessElse`:
|
||||
# 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.
|
||||
#
|
||||
# @safety
|
@ -62,9 +62,6 @@ module RuboCop
|
||||
# t.string :nickname
|
||||
# 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
|
||||
MSG_FOR_CHANGE_TABLE = <<~MSG.chomp
|
||||
You can combine alter queries using `bulk: true` options.
|
||||
@ -216,7 +213,7 @@ module RuboCop
|
||||
true
|
||||
when POSTGRESQL
|
||||
# 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
|
||||
else
|
||||
false
|
@ -160,7 +160,7 @@ module RuboCop
|
||||
end
|
||||
|
||||
def model_file?
|
||||
processed_source.buffer.name.include?('/models/')
|
||||
processed_source.file_path.include?('/models/')
|
||||
end
|
||||
end
|
||||
end
|
@ -26,6 +26,9 @@ module RuboCop
|
||||
#
|
||||
class FreezeTime < Base
|
||||
extend AutoCorrector
|
||||
extend TargetRailsVersion
|
||||
|
||||
minimum_target_rails_version 5.2
|
||||
|
||||
MSG = 'Use `freeze_time` instead of `travel_to`.'
|
||||
NOW_METHODS = %i[now new current].freeze
|
@ -41,11 +41,11 @@ module RuboCop
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :association_without_options?, <<~PATTERN
|
||||
(send nil? {:has_many :has_one} _)
|
||||
(send _ {:has_many :has_one} _)
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :association_with_options?, <<~PATTERN
|
||||
(send nil? {:has_many :has_one} ... (hash $...))
|
||||
(send _ {:has_many :has_one} ... (hash $...))
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :dependent_option?, <<~PATTERN
|
@ -35,8 +35,6 @@ module RuboCop
|
||||
# skip_before_action :login_required,
|
||||
# if: -> { trusted_origin? && action_name != "admin" }
|
||||
# end
|
||||
#
|
||||
# @see https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options
|
||||
class IgnoredSkipActionFilterOption < Base
|
||||
MSG = <<~MSG.chomp.freeze
|
||||
`%<ignore>s` option will be ignored when `%<prefer>s` and `%<ignore>s` are used together.
|
@ -137,9 +137,6 @@ module RuboCop
|
||||
# class Blog < ApplicationRecord
|
||||
# has_many :posts, -> { order(published_at: :desc) }
|
||||
# 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
|
||||
SPECIFY_MSG = 'Specify an `:inverse_of` option.'
|
||||
NIL_MSG = 'You specified `inverse_of: nil`, you probably meant to use `inverse_of: false`.'
|
@ -144,19 +144,29 @@ module RuboCop
|
||||
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
|
||||
|
||||
alias_methods = alias_methods(node)
|
||||
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
|
||||
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]
|
||||
# @return [Array<Symbol>]
|
||||
def array_values(node) # rubocop:disable Metrics/MethodLength
|
@ -26,7 +26,7 @@ module RuboCop
|
||||
RESTRICT_ON_SEND = %i[!].freeze
|
||||
|
||||
def_node_matcher :negate_include_call?, <<~PATTERN
|
||||
(send (send $_ :include? $_) :!)
|
||||
(send (send $!nil? :include? $_) :!)
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
@ -21,7 +21,7 @@ module RuboCop
|
||||
RESTRICT_ON_SEND = %i[add_column add_reference].freeze
|
||||
|
||||
def_node_matcher :add_not_null_column?, <<~PATTERN
|
||||
(send nil? :add_column _ _ _ (hash $...))
|
||||
(send nil? :add_column _ _ $_ (hash $...))
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :add_not_null_reference?, <<~PATTERN
|
||||
@ -44,17 +44,20 @@ module RuboCop
|
||||
private
|
||||
|
||||
def check_add_column(node)
|
||||
pairs = add_not_null_column?(node)
|
||||
add_not_null_column?(node) do |type, pairs|
|
||||
return if type.value == :virtual || type.value == 'virtual'
|
||||
|
||||
check_pairs(pairs)
|
||||
end
|
||||
end
|
||||
|
||||
def check_add_reference(node)
|
||||
pairs = add_not_null_reference?(node)
|
||||
add_not_null_reference?(node) do |pairs|
|
||||
check_pairs(pairs)
|
||||
end
|
||||
end
|
||||
|
||||
def check_pairs(pairs)
|
||||
return unless pairs
|
||||
return if pairs.any? { |pair| default_option?(pair) }
|
||||
|
||||
null_false = pairs.find { |pair| null_false?(pair) }
|
@ -9,6 +9,18 @@ module RuboCop
|
||||
# element in an enumerable. When called on an Active Record relation, it
|
||||
# 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
|
||||
# # bad
|
||||
# Post.published.map { |post| post[:title] }
|
@ -112,10 +112,10 @@ module RuboCop
|
||||
end
|
||||
|
||||
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"
|
||||
else
|
||||
node.source
|
||||
node.source.gsub(/\n\s*/, ' ')
|
||||
end
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ module RuboCop
|
||||
#
|
||||
# Interaction with `Style/UnlessElse`:
|
||||
# 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.
|
||||
#
|
||||
# @example NotNilAndNotEmpty: true (default)
|
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