rubocop-rails 2.14.2 → 2.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/default.yml +38 -6
- 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 +5 -10
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +1 -1
- data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +58 -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 +2 -3
- 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 +39 -23
- 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 +2 -3
- 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 +3 -3
- data/lib/rubocop/cop/rails/to_formatted_s.rb +46 -0
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +17 -10
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +2 -2
- 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 +8 -5
- 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
|
+
# Looks for enums written with array syntax.
|
|
7
7
|
#
|
|
8
8
|
# When using array syntax, adding an element in a
|
|
9
9
|
# position other than the last causes all previous
|
|
@@ -20,8 +20,7 @@ module RuboCop
|
|
|
20
20
|
class EnumHash < Base
|
|
21
21
|
extend AutoCorrector
|
|
22
22
|
|
|
23
|
-
MSG = 'Enum defined as an array found in `%<enum>s` enum declaration. '
|
|
24
|
-
'Use hash syntax instead.'
|
|
23
|
+
MSG = 'Enum defined as an array found in `%<enum>s` enum declaration. Use hash syntax instead.'
|
|
25
24
|
RESTRICT_ON_SEND = %i[enum].freeze
|
|
26
25
|
|
|
27
26
|
def_node_matcher :enum?, <<~PATTERN
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Rails
|
|
6
|
-
#
|
|
6
|
+
# Looks for direct access to environment variables through the
|
|
7
7
|
# `ENV` variable within the application code. This can lead to runtime
|
|
8
8
|
# errors due to misconfiguration that could have been discovered at boot
|
|
9
9
|
# time if the environment variables were loaded as part of initialization
|
|
@@ -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
|
|
@@ -29,14 +29,6 @@ module RuboCop
|
|
|
29
29
|
|
|
30
30
|
minimum_target_rails_version 5.1
|
|
31
31
|
|
|
32
|
-
def_node_matcher :expanded_date_range, <<~PATTERN
|
|
33
|
-
(irange
|
|
34
|
-
(send
|
|
35
|
-
$_ {:beginning_of_day :beginning_of_week :beginning_of_month :beginning_of_quarter :beginning_of_year})
|
|
36
|
-
(send
|
|
37
|
-
$_ {:end_of_day :end_of_week :end_of_month :end_of_quarter :end_of_year}))
|
|
38
|
-
PATTERN
|
|
39
|
-
|
|
40
32
|
PREFERRED_METHODS = {
|
|
41
33
|
beginning_of_day: 'all_day',
|
|
42
34
|
beginning_of_week: 'all_week',
|
|
@@ -54,31 +46,55 @@ module RuboCop
|
|
|
54
46
|
}.freeze
|
|
55
47
|
|
|
56
48
|
def on_irange(node)
|
|
57
|
-
return unless expanded_date_range(node)
|
|
58
|
-
|
|
59
49
|
begin_node = node.begin
|
|
60
50
|
end_node = node.end
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
beginning_method = begin_node.method_name
|
|
64
|
-
end_method = end_node.method_name
|
|
65
|
-
return unless use_mapped_methods?(beginning_method, end_method)
|
|
51
|
+
return if allow?(begin_node, end_node)
|
|
66
52
|
|
|
67
|
-
preferred_method =
|
|
53
|
+
preferred_method = preferred_method(begin_node)
|
|
54
|
+
if begin_node.method?(:beginning_of_week) && begin_node.arguments.one?
|
|
55
|
+
return unless same_argument?(begin_node, end_node)
|
|
68
56
|
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
preferred_method << "(#{begin_node.first_argument.source})"
|
|
58
|
+
elsif any_arguments?(begin_node, end_node)
|
|
59
|
+
return
|
|
71
60
|
end
|
|
61
|
+
|
|
62
|
+
register_offense(node, preferred_method)
|
|
72
63
|
end
|
|
73
64
|
|
|
74
65
|
private
|
|
75
66
|
|
|
76
|
-
def
|
|
77
|
-
|
|
67
|
+
def allow?(begin_node, end_node)
|
|
68
|
+
return true unless (begin_source = receiver_source(begin_node))
|
|
69
|
+
return true unless (end_source = receiver_source(end_node))
|
|
70
|
+
|
|
71
|
+
begin_source != end_source || MAPPED_DATE_RANGE_METHODS[begin_node.method_name] != end_node.method_name
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def receiver_source(node)
|
|
75
|
+
return if !node&.send_type? || node.receiver.nil?
|
|
76
|
+
|
|
77
|
+
node.receiver.source
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def
|
|
81
|
-
|
|
80
|
+
def same_argument?(begin_node, end_node)
|
|
81
|
+
begin_node.first_argument.source == end_node.first_argument.source
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def preferred_method(begin_node)
|
|
85
|
+
+"#{begin_node.receiver.source}.#{PREFERRED_METHODS[begin_node.method_name]}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def any_arguments?(begin_node, end_node)
|
|
89
|
+
begin_node.arguments.any? || end_node.arguments.any?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def register_offense(node, preferred_method)
|
|
93
|
+
message = format(MSG, preferred_method: preferred_method)
|
|
94
|
+
|
|
95
|
+
add_offense(node, message: message) do |corrector|
|
|
96
|
+
corrector.replace(node, preferred_method)
|
|
97
|
+
end
|
|
82
98
|
end
|
|
83
99
|
end
|
|
84
100
|
end
|
|
@@ -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.
|
|
@@ -23,8 +23,7 @@ module RuboCop
|
|
|
23
23
|
class OrderById < Base
|
|
24
24
|
include RangeHelp
|
|
25
25
|
|
|
26
|
-
MSG = 'Do not use the `id` column for ordering. '
|
|
27
|
-
'Use a timestamp column to order chronologically.'
|
|
26
|
+
MSG = 'Do not use the `id` column for ordering. Use a timestamp column to order chronologically.'
|
|
28
27
|
RESTRICT_ON_SEND = %i[order].freeze
|
|
29
28
|
|
|
30
29
|
def_node_matcher :order_by_id?, <<~PATTERN
|
|
@@ -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
|