brew vendor-gems: commit updates.
This commit is contained in:
parent
e240ced331
commit
2b44142efb
@ -86,7 +86,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.1.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.27.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.14.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.14.2/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.15.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.11.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.8/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-3.0.0/lib"
|
||||
|
||||
@ -60,6 +60,7 @@ Rails/ActionFilter:
|
||||
- filter
|
||||
Include:
|
||||
- app/controllers/**/*.rb
|
||||
- app/mailers/**/*.rb
|
||||
|
||||
Rails/ActiveRecordAliases:
|
||||
Description: >-
|
||||
@ -107,7 +108,7 @@ Rails/AddColumnIndex:
|
||||
|
||||
Rails/AfterCommitOverride:
|
||||
Description: >-
|
||||
This cop enforces that there is only one call to `after_commit`
|
||||
Enforces that there is only one call to `after_commit`
|
||||
(and its aliases - `after_create_commit`, `after_update_commit`,
|
||||
and `after_destroy_commit`) with the same callback name per model.
|
||||
Enabled: 'pending'
|
||||
@ -271,6 +272,13 @@ Rails/DeprecatedActiveModelErrorsMethods:
|
||||
Enabled: pending
|
||||
Safe: false
|
||||
VersionAdded: '2.14'
|
||||
VersionChanged: '2.15'
|
||||
|
||||
Rails/DotSeparatedKeys:
|
||||
Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.'
|
||||
StyleGuide: 'https://rails.rubystyle.guide/#dot-separated-keys'
|
||||
Enabled: pending
|
||||
VersionAdded: '2.15'
|
||||
|
||||
Rails/DuplicateAssociation:
|
||||
Description: "Don't repeat associations in a model."
|
||||
@ -476,6 +484,7 @@ Rails/IgnoredSkipActionFilterOption:
|
||||
VersionAdded: '0.63'
|
||||
Include:
|
||||
- app/controllers/**/*.rb
|
||||
- app/mailers/**/*.rb
|
||||
|
||||
Rails/IndexBy:
|
||||
Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
|
||||
@ -504,13 +513,14 @@ Rails/InverseOf:
|
||||
- app/models/**/*.rb
|
||||
|
||||
Rails/LexicallyScopedActionFilter:
|
||||
Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the controller."
|
||||
Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
|
||||
StyleGuide: 'https://rails.rubystyle.guide#lexically-scoped-action-filter'
|
||||
Enabled: true
|
||||
Safe: false
|
||||
VersionAdded: '0.52'
|
||||
Include:
|
||||
- app/controllers/**/*.rb
|
||||
- app/mailers/**/*.rb
|
||||
|
||||
Rails/LinkToBlank:
|
||||
Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
|
||||
@ -690,7 +700,7 @@ Rails/RedundantReceiverInWithOptions:
|
||||
VersionAdded: '0.52'
|
||||
|
||||
Rails/RedundantTravelBack:
|
||||
Description: This cop checks for redundant `travel_back` calls.
|
||||
Description: Checks for redundant `travel_back` calls.
|
||||
Enabled: pending
|
||||
VersionAdded: '2.12'
|
||||
Include:
|
||||
@ -774,6 +784,11 @@ Rails/RootJoinChain:
|
||||
Enabled: pending
|
||||
VersionAdded: '2.13'
|
||||
|
||||
Rails/RootPublicPath:
|
||||
Description: "Favor `Rails.public_path` over `Rails.root` with `'public'`."
|
||||
Enabled: pending
|
||||
VersionAdded: '2.15'
|
||||
|
||||
Rails/SafeNavigation:
|
||||
Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`."
|
||||
Enabled: true
|
||||
@ -808,7 +823,7 @@ Rails/SaveBang:
|
||||
|
||||
Rails/SchemaComment:
|
||||
Description: >-
|
||||
This cop enforces the use of the `comment` option when adding a new table or column
|
||||
Enforces the use of the `comment` option when adding a new table or column
|
||||
to the database during a migration.
|
||||
Enabled: false
|
||||
VersionAdded: '2.13'
|
||||
@ -867,9 +882,15 @@ Rails/SquishedSQLHeredocs:
|
||||
VersionAdded: '2.8'
|
||||
VersionChanged: '2.9'
|
||||
# Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines
|
||||
# to be preserved in order to work, thus auto-correction is not safe.
|
||||
# to be preserved in order to work, thus autocorrection is not safe.
|
||||
SafeAutoCorrect: false
|
||||
|
||||
Rails/StripHeredoc:
|
||||
Description: 'Enforces the use of squiggly heredoc over `strip_heredoc`.'
|
||||
StyleGuide: 'https://rails.rubystyle.guide/#prefer-squiggly-heredoc'
|
||||
Enabled: pending
|
||||
VersionAdded: '2.15'
|
||||
|
||||
Rails/TableNameAssignment:
|
||||
Description: >-
|
||||
Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead.
|
||||
@ -905,6 +926,16 @@ Rails/TimeZoneAssignment:
|
||||
- spec/**/*.rb
|
||||
- test/**/*.rb
|
||||
|
||||
Rails/ToFormattedS:
|
||||
Description: 'Checks for consistent uses of `to_fs` or `to_formatted_s`.'
|
||||
StyleGuide: 'https://rails.rubystyle.guide/#prefer-to-fs'
|
||||
Enabled: pending
|
||||
EnforcedStyle: to_fs
|
||||
SupportedStyles:
|
||||
- to_fs
|
||||
- to_formatted_s
|
||||
VersionAdded: '2.15'
|
||||
|
||||
Rails/TransactionExitStatement:
|
||||
Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
|
||||
Enabled: pending
|
||||
@ -13,3 +13,11 @@ require_relative 'rubocop/rails/schema_loader/schema'
|
||||
RuboCop::Rails::Inject.defaults!
|
||||
|
||||
require_relative 'rubocop/cop/rails_cops'
|
||||
|
||||
RuboCop::Cop::Style::RedundantSelf.singleton_class.prepend(
|
||||
Module.new do
|
||||
def autocorrect_incompatible_with
|
||||
super.push(RuboCop::Cop::Rails::SafeNavigation)
|
||||
end
|
||||
end
|
||||
)
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces the consistent use of action filter methods.
|
||||
# Enforces the consistent use of action filter methods.
|
||||
#
|
||||
# The cop is configurable and can enforce the use of the older
|
||||
# something_filter methods or the newer something_action methods.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that Active Record callbacks are declared
|
||||
# Checks that Active Record callbacks are declared
|
||||
# in the order in which they will be executed.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that ActiveSupport aliases to core ruby methods
|
||||
# Checks that ActiveSupport aliases to core ruby methods
|
||||
# are not used.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for migrations using `add_column` that have an `index`
|
||||
# Checks for migrations using `add_column` that have an `index`
|
||||
# key. `add_column` does not accept `index`, but also does not raise an
|
||||
# error for extra keys, so it is possible to mistakenly add the key without
|
||||
# realizing it will not actually add an index.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces that there is only one call to `after_commit`
|
||||
# Enforces that there is only one call to `after_commit`
|
||||
# (and its aliases - `after_create_commit`, `after_update_commit`,
|
||||
# and `after_destroy_commit`) with the same callback name per model.
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that controllers subclass `ApplicationController`.
|
||||
# Checks that controllers subclass `ApplicationController`.
|
||||
#
|
||||
# @safety
|
||||
# This cop's autocorrection is unsafe because it may let the logic from `ApplicationController`
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that jobs subclass `ApplicationJob` with Rails 5.0.
|
||||
# Checks that jobs subclass `ApplicationJob` with Rails 5.0.
|
||||
#
|
||||
# @safety
|
||||
# This cop's autocorrection is unsafe because it may let the logic from `ApplicationJob`
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that mailers subclass `ApplicationMailer` with Rails 5.0.
|
||||
# Checks that mailers subclass `ApplicationMailer` with Rails 5.0.
|
||||
#
|
||||
# @safety
|
||||
# This cop's autocorrection is unsafe because it may let the logic from `ApplicationMailer`
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that models subclass `ApplicationRecord` with Rails 5.0.
|
||||
# Checks that models subclass `ApplicationRecord` with Rails 5.0.
|
||||
#
|
||||
# @safety
|
||||
# This cop's autocorrection is unsafe because it may let the logic from `ApplicationRecord`
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop prevents usage of `"*"` on an Arel::Table column reference.
|
||||
# Prevents usage of `"*"` on an Arel::Table column reference.
|
||||
#
|
||||
# Using `arel_table["*"]` causes the outputted string to be a literal
|
||||
# quoted asterisk (e.g. <tt>`my_model`.`*`</tt>). This causes the
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for `attribute` class methods that specify a `:default` option
|
||||
# Looks for `attribute` class methods that specify a `:default` option
|
||||
# which value is an array, string literal or method call without a block.
|
||||
# It will accept all other values, such as string, symbol, integer and float literals
|
||||
# as well as constants.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for belongs_to associations where we control whether the
|
||||
# Looks for belongs_to associations where we control whether the
|
||||
# association is required via the deprecated `required` option instead.
|
||||
#
|
||||
# Since Rails 5, belongs_to associations are required by default and this
|
||||
@ -3,17 +3,17 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for code that can be written with simpler conditionals
|
||||
# Checks for code that can be written with simpler conditionals
|
||||
# using `Object#blank?` defined by Active Support.
|
||||
#
|
||||
# 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
|
||||
# to prevent interference between the auto-correction of the two cops.
|
||||
# to prevent interference between the autocorrection of the two cops.
|
||||
#
|
||||
# @safety
|
||||
# This cop is unsafe auto-correction, because `' '.empty?` returns false,
|
||||
# but `' '.blank?` returns true. Therefore, auto-correction is not compatible
|
||||
# This cop is unsafe autocorrection, because `' '.empty?` returns false,
|
||||
# but `' '.blank?` returns true. Therefore, autocorrection is not compatible
|
||||
# if the receiver is a non-empty blank string, tab, or newline meta characters.
|
||||
#
|
||||
# @example NilOrEmpty: true (default)
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This Cop checks whether alter queries are combinable.
|
||||
# Checks whether alter queries are combinable.
|
||||
# If combinable queries are detected, it suggests to you
|
||||
# to use `change_table` with `bulk: true` instead.
|
||||
# This option causes the migration to generate a single
|
||||
@ -17,7 +17,7 @@ module RuboCop
|
||||
# `ActionController::Parameters`.
|
||||
# `Array#compact_blank!`, `Hash#compact_blank!` are equivalent to `delete_if(&:blank?)`.
|
||||
# `ActionController::Parameters#compact_blank!` is equivalent to `reject!(&:blank?)`.
|
||||
# If the cop makes a mistake, auto-corrected code may get unexpected behavior.
|
||||
# If the cop makes a mistake, autocorrected code may get unexpected behavior.
|
||||
#
|
||||
# @example
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks legacy syntax usage of `tag`
|
||||
# Checks legacy syntax usage of `tag`
|
||||
#
|
||||
# NOTE: Allow `tag` when the first argument is a variable because
|
||||
# `tag(name)` is simpler rather than `tag.public_send(name)`.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks the migration for which timestamps are not included
|
||||
# Checks the migration for which timestamps are not included
|
||||
# when creating a new table.
|
||||
# In many cases, timestamps are useful information and should be added.
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the correct use of Date methods,
|
||||
# Checks for the correct use of Date methods,
|
||||
# such as Date.today, Date.current etc.
|
||||
#
|
||||
# Using `Date.today` is dangerous, because it doesn't know anything about
|
||||
@ -22,16 +22,6 @@ module RuboCop
|
||||
# And you can set a warning for `to_time` with `AllowToTime: false`.
|
||||
# `AllowToTime` is `true` by default to prevent false positive on `DateTime` object.
|
||||
#
|
||||
# @example EnforcedStyle: strict
|
||||
# # bad
|
||||
# Date.current
|
||||
# Date.yesterday
|
||||
# Date.today
|
||||
#
|
||||
# # good
|
||||
# Time.zone.today
|
||||
# Time.zone.today - 1.day
|
||||
#
|
||||
# @example EnforcedStyle: flexible (default)
|
||||
# # bad
|
||||
# Date.today
|
||||
@ -43,6 +33,16 @@ module RuboCop
|
||||
# Date.yesterday
|
||||
# date.in_time_zone
|
||||
#
|
||||
# @example EnforcedStyle: strict
|
||||
# # bad
|
||||
# Date.current
|
||||
# Date.yesterday
|
||||
# Date.today
|
||||
#
|
||||
# # good
|
||||
# Time.zone.today
|
||||
# Time.zone.today - 1.day
|
||||
#
|
||||
# @example AllowToTime: true (default)
|
||||
# # good
|
||||
# date.to_time
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for uses of `default_scope`.
|
||||
# Looks for uses of `default_scope`.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for delegations that could have been created
|
||||
# Looks for delegations that could have been created
|
||||
# automatically with the `delegate` method.
|
||||
#
|
||||
# Safe navigation `&.` is ignored because Rails' `allow_nil`
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for delegations that pass :allow_blank as an option
|
||||
# Looks for delegations that pass :allow_blank as an option
|
||||
# instead of :allow_nil. :allow_blank is not a valid option to pass
|
||||
# to ActiveSupport#delegate.
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks direct manipulation of ActiveModel#errors as hash.
|
||||
# Checks direct manipulation of ActiveModel#errors as hash.
|
||||
# These operations are deprecated in Rails 6.1 and will not work in Rails 7.
|
||||
#
|
||||
# @safety
|
||||
@ -26,8 +26,18 @@ module RuboCop
|
||||
# # good
|
||||
# user.errors.delete(:name)
|
||||
#
|
||||
# # bad
|
||||
# user.errors.keys.include?(:attr)
|
||||
#
|
||||
# # good
|
||||
# user.errors.attribute_names.include?(:attr)
|
||||
#
|
||||
class DeprecatedActiveModelErrorsMethods < Base
|
||||
include RangeHelp
|
||||
extend AutoCorrector
|
||||
|
||||
MSG = 'Avoid manipulating ActiveModel errors as hash directly.'
|
||||
AUTOCORECTABLE_METHODS = %i[<< clear keys].freeze
|
||||
|
||||
MANIPULATIVE_METHODS = Set[
|
||||
*%i[
|
||||
@ -45,6 +55,7 @@ module RuboCop
|
||||
{
|
||||
#root_manipulation?
|
||||
#root_assignment?
|
||||
#errors_keys?
|
||||
#messages_details_manipulation?
|
||||
#messages_details_assignment?
|
||||
}
|
||||
@ -66,6 +77,12 @@ module RuboCop
|
||||
...)
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :errors_keys?, <<~PATTERN
|
||||
(send
|
||||
(send #receiver_matcher :errors)
|
||||
:keys)
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :messages_details_manipulation?, <<~PATTERN
|
||||
(send
|
||||
(send
|
||||
@ -89,12 +106,49 @@ module RuboCop
|
||||
|
||||
def on_send(node)
|
||||
any_manipulation?(node) do
|
||||
add_offense(node)
|
||||
add_offense(node) do |corrector|
|
||||
next unless AUTOCORECTABLE_METHODS.include?(node.method_name)
|
||||
|
||||
autocorrect(corrector, node)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def autocorrect(corrector, node)
|
||||
receiver = node.receiver
|
||||
|
||||
if receiver.receiver.method?(:messages)
|
||||
corrector.remove(receiver.receiver.loc.dot)
|
||||
corrector.remove(receiver.receiver.loc.selector)
|
||||
end
|
||||
|
||||
range = offense_range(node, receiver)
|
||||
replacement = replacement(node, receiver)
|
||||
|
||||
corrector.replace(range, replacement)
|
||||
end
|
||||
|
||||
def offense_range(node, receiver)
|
||||
range_between(receiver.receiver.source_range.end_pos, node.source_range.end_pos)
|
||||
end
|
||||
|
||||
def replacement(node, receiver)
|
||||
return '.errors.attribute_names' if node.method?(:keys)
|
||||
|
||||
key = receiver.first_argument.source
|
||||
|
||||
case node.method_name
|
||||
when :<<
|
||||
value = node.first_argument.source
|
||||
|
||||
".add(#{key}, #{value})"
|
||||
when :clear
|
||||
".delete(#{key})"
|
||||
end
|
||||
end
|
||||
|
||||
def receiver_matcher(node)
|
||||
model_file? ? receiver_matcher_inside_model(node) : receiver_matcher_outside_model(node)
|
||||
end
|
||||
@ -0,0 +1,71 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# Enforces the use of dot-separated locale keys instead of specifying the `:scope` option
|
||||
# with an array or a single symbol in `I18n` translation methods.
|
||||
# Dot-separated notation is easier to read and trace the hierarchy.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# I18n.t :record_invalid, scope: [:activerecord, :errors, :messages]
|
||||
# I18n.t :title, scope: :invitation
|
||||
#
|
||||
# # good
|
||||
# I18n.t 'activerecord.errors.messages.record_invalid'
|
||||
# I18n.t :record_invalid, scope: 'activerecord.errors.messages'
|
||||
#
|
||||
class DotSeparatedKeys < Base
|
||||
include RangeHelp
|
||||
extend AutoCorrector
|
||||
|
||||
MSG = 'Use the dot-separated keys instead of specifying the `:scope` option.'
|
||||
TRANSLATE_METHODS = %i[translate t].freeze
|
||||
|
||||
def_node_matcher :translate_with_scope?, <<~PATTERN
|
||||
(send {nil? (const nil? :I18n)} {:translate :t} ${sym_type? str_type?}
|
||||
(hash <$(pair (sym :scope) ${array_type? sym_type?}) ...>)
|
||||
)
|
||||
PATTERN
|
||||
|
||||
def on_send(node)
|
||||
return unless TRANSLATE_METHODS.include?(node.method_name)
|
||||
|
||||
translate_with_scope?(node) do |key_node, scope_node|
|
||||
return unless should_convert_scope?(scope_node)
|
||||
|
||||
add_offense(scope_node) do |corrector|
|
||||
# Eat the comma on the left.
|
||||
range = range_with_surrounding_space(range: scope_node.source_range, side: :left)
|
||||
range = range_with_surrounding_comma(range, :left)
|
||||
corrector.remove(range)
|
||||
|
||||
corrector.replace(key_node, new_key(key_node, scope_node))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def should_convert_scope?(scope_node)
|
||||
scopes(scope_node).all?(&:basic_literal?)
|
||||
end
|
||||
|
||||
def new_key(key_node, scope_node)
|
||||
"'#{scopes(scope_node).map(&:value).join('.')}.#{key_node.value}'"
|
||||
end
|
||||
|
||||
def scopes(scope_node)
|
||||
value = scope_node.value
|
||||
|
||||
if value.array_type?
|
||||
value.values
|
||||
else
|
||||
[value]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for associations that have been defined multiple times in the same file.
|
||||
# Looks for associations that have been defined multiple times in the same file.
|
||||
#
|
||||
# When an association is defined multiple times on a model, Active Record overrides the
|
||||
# previously defined association with the new one. Because of this, this cop's autocorrection
|
||||
@ -35,7 +35,7 @@ module RuboCop
|
||||
offenses(class_node).each do |name, nodes|
|
||||
nodes.each do |node|
|
||||
add_offense(node, message: format(MSG, name: name)) do |corrector|
|
||||
next if nodes.last == node
|
||||
next if same_line?(nodes.last, node)
|
||||
|
||||
corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
|
||||
end
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for multiple scopes in a model that have the same `where` clause. This
|
||||
# Checks for multiple scopes in a model that have the same `where` clause. This
|
||||
# often means you copy/pasted a scope, updated the name, and forgot to change the condition.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks if a duration is added to or subtracted from `Time.current`.
|
||||
# Checks if a duration is added to or subtracted from `Time.current`.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks dynamic `find_by_*` methods.
|
||||
# Checks dynamic `find_by_*` methods.
|
||||
# Use `find_by` instead of dynamic method.
|
||||
# See. https://rails.rubystyle.guide#find_by
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that blocks are used for interpolated strings passed to
|
||||
# Checks that blocks are used for interpolated strings passed to
|
||||
# `Rails.logger.debug`.
|
||||
#
|
||||
# By default, Rails production environments use the `:info` log level.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for enums written with array syntax.
|
||||
# Looks for enums written with array syntax.
|
||||
#
|
||||
# When using array syntax, adding an element in a
|
||||
# position other than the last causes all previous
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for duplicate values in enum declarations.
|
||||
# Looks for duplicate values in enum declarations.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that Rails.env is compared using `.production?`-like
|
||||
# Checks that Rails.env is compared using `.production?`-like
|
||||
# methods instead of equality against a string or symbol.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for direct access to environment variables through the
|
||||
# Looks for direct access to environment variables through the
|
||||
# `ENV` variable within the application code. This can lead to runtime
|
||||
# errors due to misconfiguration that could have been discovered at boot
|
||||
# time if the environment variables were loaded as part of initialization
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces that `exit` calls are not used within a rails app.
|
||||
# Enforces that `exit` calls are not used within a rails app.
|
||||
# Valid options are instead to raise an error, break, return, or some
|
||||
# other form of stopping execution of current request.
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for expanded date range. It only compatible `..` range is targeted.
|
||||
# Checks for expanded date range. It only compatible `..` range is targeted.
|
||||
# Incompatible `...` range is ignored.
|
||||
#
|
||||
# @example
|
||||
@ -3,19 +3,10 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop is used to identify usages of file path joining process
|
||||
# Identifies usages of file path joining process
|
||||
# to use `Rails.root.join` clause. It is used to add uniformity when
|
||||
# joining paths.
|
||||
#
|
||||
# @example EnforcedStyle: arguments
|
||||
# # bad
|
||||
# Rails.root.join('app/models/goober')
|
||||
# File.join(Rails.root, 'app/models/goober')
|
||||
# "#{Rails.root}/app/models/goober"
|
||||
#
|
||||
# # good
|
||||
# Rails.root.join('app', 'models', 'goober')
|
||||
#
|
||||
# @example EnforcedStyle: slashes (default)
|
||||
# # bad
|
||||
# Rails.root.join('app', 'models', 'goober')
|
||||
@ -25,6 +16,15 @@ module RuboCop
|
||||
# # good
|
||||
# Rails.root.join('app/models/goober')
|
||||
#
|
||||
# @example EnforcedStyle: arguments
|
||||
# # bad
|
||||
# Rails.root.join('app/models/goober')
|
||||
# File.join(Rails.root, 'app/models/goober')
|
||||
# "#{Rails.root}/app/models/goober"
|
||||
#
|
||||
# # good
|
||||
# Rails.root.join('app', 'models', 'goober')
|
||||
#
|
||||
class FilePath < Base
|
||||
include ConfigurableEnforcedStyle
|
||||
include RangeHelp
|
||||
@ -48,8 +48,11 @@ module RuboCop
|
||||
def on_dstr(node)
|
||||
return unless rails_root_nodes?(node)
|
||||
return unless node.children.last.str_type?
|
||||
return unless node.children.last.source.start_with?('.') ||
|
||||
node.children.last.source.include?(File::SEPARATOR)
|
||||
|
||||
last_child_source = node.children.last.source
|
||||
return unless last_child_source.start_with?('.') ||
|
||||
last_child_source.include?(File::SEPARATOR)
|
||||
return if last_child_source.start_with?(':')
|
||||
|
||||
register_offense(node)
|
||||
end
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop is used to identify usages of `where.take` and change them to use `find_by` instead.
|
||||
# Identifies usages of `where.take` and change them to use `find_by` instead.
|
||||
#
|
||||
# And `where(...).first` can return different results from `find_by`.
|
||||
# (They order records differently, so the "first" record can be different.)
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces that `ActiveRecord#find` is used instead of
|
||||
# Enforces that `ActiveRecord#find` is used instead of
|
||||
# `where.take!`, `find_by!`, and `find_by_id!` to retrieve a single record
|
||||
# by primary key when you expect it to be found.
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop is used to identify usages of `all.each` and
|
||||
# Identifies usages of `all.each` and
|
||||
# change them to use `all.find_each` instead.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the use of the has_and_belongs_to_many macro.
|
||||
# Checks for the use of the has_and_belongs_to_many macro.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for `has_many` or `has_one` associations that don't
|
||||
# Looks for `has_many` or `has_one` associations that don't
|
||||
# specify a `:dependent` option.
|
||||
#
|
||||
# It doesn't register an offense if `:through` or `dependent: nil`
|
||||
@ -116,7 +116,7 @@ module RuboCop
|
||||
def valid_options?(options)
|
||||
return false if options.nil?
|
||||
|
||||
options = options.first.children.first.pairs if options.first.kwsplat_type?
|
||||
options = extract_option_if_kwsplat(options)
|
||||
|
||||
return true unless options
|
||||
return true if options.any? do |o|
|
||||
@ -126,6 +126,14 @@ module RuboCop
|
||||
false
|
||||
end
|
||||
|
||||
def extract_option_if_kwsplat(options)
|
||||
if options.first.kwsplat_type? && options.first.children.first.hash_type?
|
||||
return options.first.children.first.pairs
|
||||
end
|
||||
|
||||
options
|
||||
end
|
||||
|
||||
def active_resource?(node)
|
||||
return false if node.nil?
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for use of the helper methods which reference
|
||||
# Checks for use of the helper methods which reference
|
||||
# instance variables.
|
||||
#
|
||||
# Relying on instance variables makes it difficult to re-use helper
|
||||
# methods.
|
||||
#
|
||||
# If it seems awkward to explicitly pass in each dependent
|
||||
# variable, consider moving the behaviour elsewhere, for
|
||||
# variable, consider moving the behavior elsewhere, for
|
||||
# example to a model, decorator or presenter.
|
||||
#
|
||||
# Provided that a class inherits `ActionView::Helpers::FormBuilder`,
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop is used to identify usages of http methods like `get`, `post`,
|
||||
# Identifies usages of http methods like `get`, `post`,
|
||||
# `put`, `patch` without the usage of keyword arguments in your tests and
|
||||
# change them to use keyword args. This cop only applies to Rails >= 5.
|
||||
# If you are running Rails < 5 you should disable the
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for places where I18n "lazy" lookup can be used.
|
||||
# Checks for places where I18n "lazy" lookup can be used.
|
||||
#
|
||||
# @example
|
||||
# # en.yml
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the use of `I18n.locale=` method.
|
||||
# Checks for the use of `I18n.locale=` method.
|
||||
#
|
||||
# The `locale` attribute persists for the rest of the Ruby runtime, potentially causing
|
||||
# unexpected behavior at a later time.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that `if` and `only` (or `except`) are not used together
|
||||
# Checks that `if` and `only` (or `except`) are not used together
|
||||
# as options of `skip_*` action filter.
|
||||
#
|
||||
# The `if` option will be ignored when `if` and `only` are used together.
|
||||
@ -80,7 +80,7 @@ module RuboCop
|
||||
def options_hash(options)
|
||||
options.pairs
|
||||
.select { |pair| pair.key.sym_type? }
|
||||
.map { |pair| [pair.key.value, pair] }.to_h
|
||||
.to_h { |pair| [pair.key.value, pair] }
|
||||
end
|
||||
|
||||
def if_and_only?(options)
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for uses of `each_with_object({}) { ... }`,
|
||||
# Looks for uses of `each_with_object({}) { ... }`,
|
||||
# `map { ... }.to_h`, and `Hash[map { ... }]` that are transforming
|
||||
# an enumerable into a hash where the values are the original elements.
|
||||
# Rails provides the `index_by` method for this purpose.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for uses of `each_with_object({}) { ... }`,
|
||||
# Looks for uses of `each_with_object({}) { ... }`,
|
||||
# `map { ... }.to_h`, and `Hash[map { ... }]` that are transforming
|
||||
# an enumerable into a hash where the keys are the original elements.
|
||||
# Rails provides the `index_with` method for this purpose.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that Active Support's `inquiry` method is not used.
|
||||
# Checks that Active Support's `inquiry` method is not used.
|
||||
#
|
||||
# @example
|
||||
# # bad - String#inquiry
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for has_(one|many) and belongs_to associations where
|
||||
# Looks for has_(one|many) and belongs_to associations where
|
||||
# Active Record can't automatically determine the inverse association
|
||||
# because of a scope or the options used. Using the blog with order scope
|
||||
# example below, traversing the a Blog's association in both directions
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks that methods specified in the filter's `only` or
|
||||
# Checks that methods specified in the filter's `only` or
|
||||
# `except` options are defined within the same class or module.
|
||||
#
|
||||
# @safety
|
||||
@ -12,7 +12,7 @@ module RuboCop
|
||||
# methods that are defined in other classes or modules, you should
|
||||
# define the filter in that class or module.
|
||||
#
|
||||
# If you rely on behaviour defined in the superclass actions, you must
|
||||
# If you rely on behavior defined in the superclass actions, you must
|
||||
# remember to invoke `super` in the subclass actions.
|
||||
#
|
||||
# @example
|
||||
@ -71,7 +71,7 @@ module RuboCop
|
||||
# class ArticlesController < ContentController
|
||||
# before_action :load_article, only: [:update]
|
||||
#
|
||||
# # the cop requires this method, but it relies on behaviour defined
|
||||
# # the cop requires this method, but it relies on behavior defined
|
||||
# # in the superclass, so needs to invoke `super`
|
||||
# def update
|
||||
# super
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for calls to `link_to` that contain a
|
||||
# Checks for calls to `link_to` that contain a
|
||||
# `target: '_blank'` but no `rel: 'noopener'`. This can be a security
|
||||
# risk as the loaded page will have control over the previous page
|
||||
# and could change its location for phishing purposes.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces that mailer names end with `Mailer` suffix.
|
||||
# Enforces that mailer names end with `Mailer` suffix.
|
||||
#
|
||||
# Without the `Mailer` suffix it isn't immediately apparent what's a mailer
|
||||
# and which views are related to the mailer.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop identifies places where defining routes with `match`
|
||||
# Identifies places where defining routes with `match`
|
||||
# can be replaced with a specific HTTP method.
|
||||
#
|
||||
# Don't use `match` to define any routes unless there is a need to map multiple request types
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop makes sure that each migration file defines a migration class
|
||||
# Makes sure that each migration file defines a migration class
|
||||
# whose name matches the file name.
|
||||
# (e.g. `20220224111111_create_users.rb` should define `CreateUsers` class.)
|
||||
#
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces the use of `collection.exclude?(obj)`
|
||||
# Enforces the use of `collection.exclude?(obj)`
|
||||
# over `!collection.include?(obj)`.
|
||||
#
|
||||
# @safety
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for add_column call with NOT NULL constraint
|
||||
# Checks for add_column call with NOT NULL constraint
|
||||
# in migration file.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for places where ordering by `id` column is used.
|
||||
# Checks for places where ordering by `id` column is used.
|
||||
#
|
||||
# Don't use the `id` column for ordering. The sequence of ids is not guaranteed
|
||||
# to be in any particular order, despite often (incidentally) being chronological.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the use of output calls like puts and print
|
||||
# Checks for the use of output calls like puts and print
|
||||
#
|
||||
# @safety
|
||||
# This cop's autocorrection is unsafe because depending on the Rails log level configuration,
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the use of output safety calls like `html_safe`,
|
||||
# Checks for the use of output safety calls like `html_safe`,
|
||||
# `raw`, and `safe_concat`. These methods do not escape content. They
|
||||
# simply return a SafeBuffer containing the content as is. Instead,
|
||||
# use `safe_join` to join content and escape it and concat to
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces the use of `pick` over `pluck(...).first`.
|
||||
# Enforces the use of `pick` over `pluck(...).first`.
|
||||
#
|
||||
# Using `pluck` followed by `first` creates an intermediate array, which
|
||||
# `pick` avoids. When called on an Active Record relation, `pick` adds a
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces the use of `pluck` over `map`.
|
||||
# Enforces the use of `pluck` over `map`.
|
||||
#
|
||||
# `pluck` can be used instead of `map` to extract a single key from each
|
||||
# element in an enumerable. When called on an Active Record relation, it
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`.
|
||||
# Enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`.
|
||||
#
|
||||
# @safety
|
||||
# This cop is unsafe if the receiver object is not an Active Record object.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop identifies places where `pluck` is used in `where` query methods
|
||||
# Identifies places where `pluck` is used in `where` query methods
|
||||
# and can be replaced with `select`.
|
||||
#
|
||||
# Since `pluck` is an eager method and hits the database immediately,
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for correct grammar when using ActiveSupport's
|
||||
# Checks for correct grammar when using ActiveSupport's
|
||||
# core extensions to the numeric classes.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks code that can be written more easily using
|
||||
# Checks code that can be written more easily using
|
||||
# `Object#presence` defined by Active Support.
|
||||
#
|
||||
# @example
|
||||
@ -3,13 +3,13 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for code that can be written with simpler conditionals
|
||||
# Checks for code that can be written with simpler conditionals
|
||||
# using `Object#present?` defined by Active Support.
|
||||
#
|
||||
# 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
|
||||
# to prevent interference between the auto-correction of the two cops.
|
||||
# to prevent interference between the autocorrection of the two cops.
|
||||
#
|
||||
# @example NotNilAndNotEmpty: true (default)
|
||||
# # Converts usages of `!nil? && !empty?` to `present?`
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for Rake tasks without the `:environment` task
|
||||
# Checks for Rake tasks without the `:environment` task
|
||||
# dependency. The `:environment` task loads application code for other
|
||||
# Rake tasks. Without it, tasks cannot make use of application code like
|
||||
# models.
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the use of the `read_attribute` or `write_attribute`
|
||||
# Checks for the use of the `read_attribute` or `write_attribute`
|
||||
# methods and recommends square brackets instead.
|
||||
#
|
||||
# If an attribute is missing from the instance (for example, when
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop detects cases where the `:foreign_key` option on associations
|
||||
# Detects cases where the `:foreign_key` option on associations
|
||||
# is redundant.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for redundant receiver in `with_options`.
|
||||
# Checks for redundant receiver in `with_options`.
|
||||
# Receiver is implicit from Rails 4.2 or higher.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for redundant `travel_back` calls.
|
||||
# Checks for redundant `travel_back` calls.
|
||||
# Since Rails 5.2, `travel_back` is automatically called at the end of the test.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks if the value of the option `class_name`, in
|
||||
# Checks if the value of the option `class_name`, in
|
||||
# the definition of a reflection is a string.
|
||||
#
|
||||
# @safety
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks whether constant value isn't relative date.
|
||||
# Checks whether constant value isn't relative date.
|
||||
# Because the relative date will be evaluated only once.
|
||||
#
|
||||
# @safety
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop looks for inline rendering within controller actions.
|
||||
# Looks for inline rendering within controller actions.
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop identifies places where `render text:` can be
|
||||
# Identifies places where `render text:` can be
|
||||
# replaced with `render plain:`.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for consistent uses of `request.referer` or
|
||||
# Checks for consistent uses of `request.referer` or
|
||||
# `request.referrer`, depending on the cop's configuration.
|
||||
#
|
||||
# @example EnforcedStyle: referer (default)
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks for the usage of `require_dependency`.
|
||||
# Checks for the usage of `require_dependency`.
|
||||
#
|
||||
# `require_dependency` is an obsolete method for Rails applications running in Zeitwerk mode.
|
||||
# In Zeitwerk mode, the semantics should match Ruby's and no need to be defensive with load order,
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks whether the change method of the migration file is
|
||||
# Checks whether the change method of the migration file is
|
||||
# reversible.
|
||||
#
|
||||
# @example
|
||||
@ -3,7 +3,7 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Rails
|
||||
# This cop checks whether the migration implements
|
||||
# Checks whether the migration implements
|
||||
# either a `change` method or both an `up` and a `down`
|
||||
# method.
|
||||
#
|
||||
@ -49,15 +49,15 @@ module RuboCop
|
||||
'both an `up` and a `down` method.'
|
||||
|
||||
def_node_matcher :change_method?, <<~PATTERN
|
||||
[ #migration_class? `(def :change (args) _) ]
|
||||
`(def :change (args) _)
|
||||
PATTERN
|
||||
|
||||
def_node_matcher :up_and_down_methods?, <<~PATTERN
|
||||
[ #migration_class? `(def :up (args) _) `(def :down (args) _) ]
|
||||
[`(def :up (args) _) `(def :down (args) _)]
|
||||
PATTERN
|
||||
|
||||
def on_class(node)
|
||||
return if change_method?(node) || up_and_down_methods?(node)
|
||||
return if !migration_class?(node) || change_method?(node) || up_and_down_methods?(node)
|
||||
|
||||
add_offense(node)
|
||||
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