rubocop-rails 2.14.2 → 2.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +36 -5
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +1 -1
- data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
- data/lib/rubocop/cop/rails/add_column_index.rb +1 -1
- data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
- data/lib/rubocop/cop/rails/application_controller.rb +1 -1
- data/lib/rubocop/cop/rails/application_job.rb +1 -1
- data/lib/rubocop/cop/rails/application_mailer.rb +1 -1
- data/lib/rubocop/cop/rails/application_record.rb +1 -1
- data/lib/rubocop/cop/rails/arel_star.rb +1 -1
- data/lib/rubocop/cop/rails/attribute_default_block_value.rb +1 -1
- data/lib/rubocop/cop/rails/belongs_to.rb +1 -1
- data/lib/rubocop/cop/rails/blank.rb +4 -4
- data/lib/rubocop/cop/rails/bulk_change_table.rb +1 -1
- data/lib/rubocop/cop/rails/compact_blank.rb +1 -1
- data/lib/rubocop/cop/rails/content_tag.rb +1 -1
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +1 -1
- data/lib/rubocop/cop/rails/date.rb +8 -8
- data/lib/rubocop/cop/rails/default_scope.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
- data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +56 -2
- data/lib/rubocop/cop/rails/dot_separated_keys.rb +71 -0
- data/lib/rubocop/cop/rails/duplicate_association.rb +2 -2
- data/lib/rubocop/cop/rails/duplicate_scope.rb +1 -1
- data/lib/rubocop/cop/rails/duration_arithmetic.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -1
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +1 -1
- data/lib/rubocop/cop/rails/enum_hash.rb +1 -1
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +1 -1
- data/lib/rubocop/cop/rails/environment_comparison.rb +1 -1
- data/lib/rubocop/cop/rails/environment_variable_access.rb +1 -1
- data/lib/rubocop/cop/rails/exit.rb +1 -1
- data/lib/rubocop/cop/rails/expanded_date_range.rb +1 -1
- data/lib/rubocop/cop/rails/file_path.rb +12 -9
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_by_id.rb +1 -1
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +10 -2
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +2 -2
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
- data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +1 -1
- data/lib/rubocop/cop/rails/i18n_locale_assignment.rb +1 -1
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +2 -2
- data/lib/rubocop/cop/rails/index_by.rb +1 -1
- data/lib/rubocop/cop/rails/index_with.rb +1 -1
- data/lib/rubocop/cop/rails/inquiry.rb +1 -1
- data/lib/rubocop/cop/rails/inverse_of.rb +1 -1
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
- data/lib/rubocop/cop/rails/link_to_blank.rb +1 -1
- data/lib/rubocop/cop/rails/mailer_name.rb +1 -1
- data/lib/rubocop/cop/rails/match_route.rb +1 -1
- data/lib/rubocop/cop/rails/migration_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/negate_include.rb +1 -1
- data/lib/rubocop/cop/rails/not_null_column.rb +1 -1
- data/lib/rubocop/cop/rails/order_by_id.rb +1 -1
- data/lib/rubocop/cop/rails/output.rb +1 -1
- data/lib/rubocop/cop/rails/output_safety.rb +1 -1
- data/lib/rubocop/cop/rails/pick.rb +1 -1
- data/lib/rubocop/cop/rails/pluck.rb +1 -1
- data/lib/rubocop/cop/rails/pluck_id.rb +1 -1
- data/lib/rubocop/cop/rails/pluck_in_where.rb +1 -1
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +1 -1
- data/lib/rubocop/cop/rails/presence.rb +1 -1
- data/lib/rubocop/cop/rails/present.rb +2 -2
- data/lib/rubocop/cop/rails/rake_environment.rb +1 -1
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_foreign_key.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_travel_back.rb +1 -1
- data/lib/rubocop/cop/rails/reflection_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/render_inline.rb +1 -1
- data/lib/rubocop/cop/rails/render_plain_text.rb +1 -1
- data/lib/rubocop/cop/rails/request_referer.rb +1 -1
- data/lib/rubocop/cop/rails/require_dependency.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +4 -4
- data/lib/rubocop/cop/rails/root_public_path.rb +59 -0
- data/lib/rubocop/cop/rails/safe_navigation.rb +7 -12
- data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +1 -1
- data/lib/rubocop/cop/rails/save_bang.rb +2 -2
- data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
- data/lib/rubocop/cop/rails/scope_args.rb +1 -1
- data/lib/rubocop/cop/rails/short_i18n.rb +1 -1
- data/lib/rubocop/cop/rails/skips_model_validations.rb +1 -1
- data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +1 -1
- data/lib/rubocop/cop/rails/strip_heredoc.rb +56 -0
- data/lib/rubocop/cop/rails/table_name_assignment.rb +1 -1
- data/lib/rubocop/cop/rails/time_zone.rb +7 -7
- data/lib/rubocop/cop/rails/time_zone_assignment.rb +1 -1
- data/lib/rubocop/cop/rails/to_formatted_s.rb +45 -0
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +16 -9
- data/lib/rubocop/cop/rails/unknown_env.rb +1 -1
- data/lib/rubocop/cop/rails/unused_ignored_columns.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/rails/where_equals.rb +1 -1
- data/lib/rubocop/cop/rails/where_exists.rb +2 -2
- data/lib/rubocop/cop/rails/where_not.rb +1 -1
- data/lib/rubocop/cop/rails_cops.rb +4 -0
- data/lib/rubocop/rails/schema_loader/schema.rb +3 -0
- data/lib/rubocop/rails/version.rb +1 -1
- data/lib/rubocop-rails.rb +8 -0
- metadata +9 -5
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Enforces that `exit` calls are not used within a rails app.
|
7
7
|
# Valid options are instead to raise an error, break, return, or some
|
8
8
|
# other form of stopping execution of current request.
|
9
9
|
#
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for expanded date range. It only compatible `..` range is targeted.
|
7
7
|
# Incompatible `...` range is ignored.
|
8
8
|
#
|
9
9
|
# @example
|
@@ -3,27 +3,27 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Identifies usages of file path joining process
|
7
7
|
# to use `Rails.root.join` clause. It is used to add uniformity when
|
8
8
|
# joining paths.
|
9
9
|
#
|
10
|
-
# @example EnforcedStyle:
|
10
|
+
# @example EnforcedStyle: slashes (default)
|
11
11
|
# # bad
|
12
|
-
# Rails.root.join('app
|
12
|
+
# Rails.root.join('app', 'models', 'goober')
|
13
13
|
# File.join(Rails.root, 'app/models/goober')
|
14
14
|
# "#{Rails.root}/app/models/goober"
|
15
15
|
#
|
16
16
|
# # good
|
17
|
-
# Rails.root.join('app
|
17
|
+
# Rails.root.join('app/models/goober')
|
18
18
|
#
|
19
|
-
# @example EnforcedStyle:
|
19
|
+
# @example EnforcedStyle: arguments
|
20
20
|
# # bad
|
21
|
-
# Rails.root.join('app
|
21
|
+
# Rails.root.join('app/models/goober')
|
22
22
|
# File.join(Rails.root, 'app/models/goober')
|
23
23
|
# "#{Rails.root}/app/models/goober"
|
24
24
|
#
|
25
25
|
# # good
|
26
|
-
# Rails.root.join('app
|
26
|
+
# Rails.root.join('app', 'models', 'goober')
|
27
27
|
#
|
28
28
|
class FilePath < Base
|
29
29
|
include ConfigurableEnforcedStyle
|
@@ -48,8 +48,11 @@ module RuboCop
|
|
48
48
|
def on_dstr(node)
|
49
49
|
return unless rails_root_nodes?(node)
|
50
50
|
return unless node.children.last.str_type?
|
51
|
-
|
52
|
-
|
51
|
+
|
52
|
+
last_child_source = node.children.last.source
|
53
|
+
return unless last_child_source.start_with?('.') ||
|
54
|
+
last_child_source.include?(File::SEPARATOR)
|
55
|
+
return if last_child_source.start_with?(':')
|
53
56
|
|
54
57
|
register_offense(node)
|
55
58
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Identifies usages of `where.take` and change them to use `find_by` instead.
|
7
7
|
#
|
8
8
|
# And `where(...).first` can return different results from `find_by`.
|
9
9
|
# (They order records differently, so the "first" record can be different.)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Enforces that `ActiveRecord#find` is used instead of
|
7
7
|
# `where.take!`, `find_by!`, and `find_by_id!` to retrieve a single record
|
8
8
|
# by primary key when you expect it to be found.
|
9
9
|
#
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Looks for `has_many` or `has_one` associations that don't
|
7
7
|
# specify a `:dependent` option.
|
8
8
|
#
|
9
9
|
# It doesn't register an offense if `:through` or `dependent: nil`
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
116
116
|
def valid_options?(options)
|
117
117
|
return false if options.nil?
|
118
118
|
|
119
|
-
options = options
|
119
|
+
options = extract_option_if_kwsplat(options)
|
120
120
|
|
121
121
|
return true unless options
|
122
122
|
return true if options.any? do |o|
|
@@ -126,6 +126,14 @@ module RuboCop
|
|
126
126
|
false
|
127
127
|
end
|
128
128
|
|
129
|
+
def extract_option_if_kwsplat(options)
|
130
|
+
if options.first.kwsplat_type? && options.first.children.first.hash_type?
|
131
|
+
return options.first.children.first.pairs
|
132
|
+
end
|
133
|
+
|
134
|
+
options
|
135
|
+
end
|
136
|
+
|
129
137
|
def active_resource?(node)
|
130
138
|
return false if node.nil?
|
131
139
|
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for use of the helper methods which reference
|
7
7
|
# instance variables.
|
8
8
|
#
|
9
9
|
# Relying on instance variables makes it difficult to re-use helper
|
10
10
|
# methods.
|
11
11
|
#
|
12
12
|
# If it seems awkward to explicitly pass in each dependent
|
13
|
-
# variable, consider moving the
|
13
|
+
# variable, consider moving the behavior elsewhere, for
|
14
14
|
# example to a model, decorator or presenter.
|
15
15
|
#
|
16
16
|
# Provided that a class inherits `ActionView::Helpers::FormBuilder`,
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Identifies usages of http methods like `get`, `post`,
|
7
7
|
# `put`, `patch` without the usage of keyword arguments in your tests and
|
8
8
|
# change them to use keyword args. This cop only applies to Rails >= 5.
|
9
9
|
# If you are running Rails < 5 you should disable the
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for the use of `I18n.locale=` method.
|
7
7
|
#
|
8
8
|
# The `locale` attribute persists for the rest of the Ruby runtime, potentially causing
|
9
9
|
# unexpected behavior at a later time.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks that `if` and `only` (or `except`) are not used together
|
7
7
|
# as options of `skip_*` action filter.
|
8
8
|
#
|
9
9
|
# The `if` option will be ignored when `if` and `only` are used together.
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
def options_hash(options)
|
81
81
|
options.pairs
|
82
82
|
.select { |pair| pair.key.sym_type? }
|
83
|
-
.
|
83
|
+
.to_h { |pair| [pair.key.value, pair] }
|
84
84
|
end
|
85
85
|
|
86
86
|
def if_and_only?(options)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Looks for uses of `each_with_object({}) { ... }`,
|
7
7
|
# `map { ... }.to_h`, and `Hash[map { ... }]` that are transforming
|
8
8
|
# an enumerable into a hash where the values are the original elements.
|
9
9
|
# Rails provides the `index_by` method for this purpose.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Looks for uses of `each_with_object({}) { ... }`,
|
7
7
|
# `map { ... }.to_h`, and `Hash[map { ... }]` that are transforming
|
8
8
|
# an enumerable into a hash where the keys are the original elements.
|
9
9
|
# Rails provides the `index_with` method for this purpose.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Looks for has_(one|many) and belongs_to associations where
|
7
7
|
# Active Record can't automatically determine the inverse association
|
8
8
|
# because of a scope or the options used. Using the blog with order scope
|
9
9
|
# example below, traversing the a Blog's association in both directions
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks that methods specified in the filter's `only` or
|
7
7
|
# `except` options are defined within the same class or module.
|
8
8
|
#
|
9
9
|
# @safety
|
@@ -12,7 +12,7 @@ module RuboCop
|
|
12
12
|
# methods that are defined in other classes or modules, you should
|
13
13
|
# define the filter in that class or module.
|
14
14
|
#
|
15
|
-
# If you rely on
|
15
|
+
# If you rely on behavior defined in the superclass actions, you must
|
16
16
|
# remember to invoke `super` in the subclass actions.
|
17
17
|
#
|
18
18
|
# @example
|
@@ -71,7 +71,7 @@ module RuboCop
|
|
71
71
|
# class ArticlesController < ContentController
|
72
72
|
# before_action :load_article, only: [:update]
|
73
73
|
#
|
74
|
-
# # the cop requires this method, but it relies on
|
74
|
+
# # the cop requires this method, but it relies on behavior defined
|
75
75
|
# # in the superclass, so needs to invoke `super`
|
76
76
|
# def update
|
77
77
|
# super
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for calls to `link_to` that contain a
|
7
7
|
# `target: '_blank'` but no `rel: 'noopener'`. This can be a security
|
8
8
|
# risk as the loaded page will have control over the previous page
|
9
9
|
# and could change its location for phishing purposes.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Enforces that mailer names end with `Mailer` suffix.
|
7
7
|
#
|
8
8
|
# Without the `Mailer` suffix it isn't immediately apparent what's a mailer
|
9
9
|
# and which views are related to the mailer.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Identifies places where defining routes with `match`
|
7
7
|
# can be replaced with a specific HTTP method.
|
8
8
|
#
|
9
9
|
# Don't use `match` to define any routes unless there is a need to map multiple request types
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Makes sure that each migration file defines a migration class
|
7
7
|
# whose name matches the file name.
|
8
8
|
# (e.g. `20220224111111_create_users.rb` should define `CreateUsers` class.)
|
9
9
|
#
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for places where ordering by `id` column is used.
|
7
7
|
#
|
8
8
|
# Don't use the `id` column for ordering. The sequence of ids is not guaranteed
|
9
9
|
# to be in any particular order, despite often (incidentally) being chronological.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for the use of output calls like puts and print
|
7
7
|
#
|
8
8
|
# @safety
|
9
9
|
# This cop's autocorrection is unsafe because depending on the Rails log level configuration,
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for the use of output safety calls like `html_safe`,
|
7
7
|
# `raw`, and `safe_concat`. These methods do not escape content. They
|
8
8
|
# simply return a SafeBuffer containing the content as is. Instead,
|
9
9
|
# use `safe_join` to join content and escape it and concat to
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Enforces the use of `pick` over `pluck(...).first`.
|
7
7
|
#
|
8
8
|
# Using `pluck` followed by `first` creates an intermediate array, which
|
9
9
|
# `pick` avoids. When called on an Active Record relation, `pick` adds a
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Enforces the use of `pluck` over `map`.
|
7
7
|
#
|
8
8
|
# `pluck` can be used instead of `map` to extract a single key from each
|
9
9
|
# element in an enumerable. When called on an Active Record relation, it
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`.
|
7
7
|
#
|
8
8
|
# @safety
|
9
9
|
# This cop is unsafe if the receiver object is not an Active Record object.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Identifies places where `pluck` is used in `where` query methods
|
7
7
|
# and can be replaced with `select`.
|
8
8
|
#
|
9
9
|
# Since `pluck` is an eager method and hits the database immediately,
|
@@ -3,13 +3,13 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for code that can be written with simpler conditionals
|
7
7
|
# using `Object#present?` defined by Active Support.
|
8
8
|
#
|
9
9
|
# Interaction with `Style/UnlessElse`:
|
10
10
|
# The configuration of `NotBlank` will not produce an offense in the
|
11
11
|
# context of `unless else` if `Style/UnlessElse` is inabled. This is
|
12
|
-
# to prevent interference between the
|
12
|
+
# to prevent interference between the autocorrection of the two cops.
|
13
13
|
#
|
14
14
|
# @example NotNilAndNotEmpty: true (default)
|
15
15
|
# # Converts usages of `!nil? && !empty?` to `present?`
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for Rake tasks without the `:environment` task
|
7
7
|
# dependency. The `:environment` task loads application code for other
|
8
8
|
# Rake tasks. Without it, tasks cannot make use of application code like
|
9
9
|
# models.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for the use of the `read_attribute` or `write_attribute`
|
7
7
|
# methods and recommends square brackets instead.
|
8
8
|
#
|
9
9
|
# If an attribute is missing from the instance (for example, when
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for consistent uses of `request.referer` or
|
7
7
|
# `request.referrer`, depending on the cop's configuration.
|
8
8
|
#
|
9
9
|
# @example EnforcedStyle: referer (default)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks for the usage of `require_dependency`.
|
7
7
|
#
|
8
8
|
# `require_dependency` is an obsolete method for Rails applications running in Zeitwerk mode.
|
9
9
|
# In Zeitwerk mode, the semantics should match Ruby's and no need to be defensive with load order,
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Checks whether the migration implements
|
7
7
|
# either a `change` method or both an `up` and a `down`
|
8
8
|
# method.
|
9
9
|
#
|
@@ -49,15 +49,15 @@ module RuboCop
|
|
49
49
|
'both an `up` and a `down` method.'
|
50
50
|
|
51
51
|
def_node_matcher :change_method?, <<~PATTERN
|
52
|
-
|
52
|
+
`(def :change (args) _)
|
53
53
|
PATTERN
|
54
54
|
|
55
55
|
def_node_matcher :up_and_down_methods?, <<~PATTERN
|
56
|
-
[
|
56
|
+
[`(def :up (args) _) `(def :down (args) _)]
|
57
57
|
PATTERN
|
58
58
|
|
59
59
|
def on_class(node)
|
60
|
-
return if change_method?(node) || up_and_down_methods?(node)
|
60
|
+
return if !migration_class?(node) || change_method?(node) || up_and_down_methods?(node)
|
61
61
|
|
62
62
|
add_offense(node)
|
63
63
|
end
|