rubocop-rails 2.11.2 → 2.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +23 -2
- data/config/default.yml +316 -20
- data/config/obsoletion.yml +10 -0
- data/lib/rubocop/cop/mixin/active_record_helper.rb +17 -8
- data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +32 -0
- data/lib/rubocop/cop/mixin/class_send_node_helper.rb +20 -0
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +1 -1
- data/lib/rubocop/cop/mixin/index_method.rb +7 -17
- data/lib/rubocop/cop/mixin/migrations_helper.rb +26 -0
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +112 -0
- data/lib/rubocop/cop/rails/action_controller_test_case.rb +47 -0
- data/lib/rubocop/cop/rails/action_filter.rb +2 -2
- data/lib/rubocop/cop/rails/action_order.rb +116 -0
- data/lib/rubocop/cop/rails/active_record_aliases.rb +9 -6
- data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +8 -13
- data/lib/rubocop/cop/rails/active_record_override.rb +2 -5
- data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
- data/lib/rubocop/cop/rails/active_support_on_load.rb +70 -0
- data/lib/rubocop/cop/rails/add_column_index.rb +3 -6
- data/lib/rubocop/cop/rails/after_commit_override.rb +3 -13
- data/lib/rubocop/cop/rails/application_controller.rb +6 -2
- data/lib/rubocop/cop/rails/application_job.rb +7 -3
- data/lib/rubocop/cop/rails/application_mailer.rb +6 -2
- data/lib/rubocop/cop/rails/application_record.rb +7 -2
- data/lib/rubocop/cop/rails/arel_star.rb +8 -2
- data/lib/rubocop/cop/rails/assert_not.rb +1 -1
- data/lib/rubocop/cop/rails/attribute_default_block_value.rb +1 -1
- data/lib/rubocop/cop/rails/belongs_to.rb +2 -5
- data/lib/rubocop/cop/rails/blank.rb +13 -13
- data/lib/rubocop/cop/rails/bulk_change_table.rb +28 -31
- data/lib/rubocop/cop/rails/compact_blank.rb +111 -0
- data/lib/rubocop/cop/rails/content_tag.rb +42 -33
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +16 -8
- data/lib/rubocop/cop/rails/date.rb +12 -17
- data/lib/rubocop/cop/rails/default_scope.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +24 -18
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +2 -2
- data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +168 -0
- data/lib/rubocop/cop/rails/dot_separated_keys.rb +71 -0
- data/lib/rubocop/cop/rails/duplicate_association.rb +56 -0
- data/lib/rubocop/cop/rails/duplicate_scope.rb +46 -0
- data/lib/rubocop/cop/rails/duration_arithmetic.rb +98 -0
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +31 -15
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +6 -2
- data/lib/rubocop/cop/rails/enum_hash.rb +3 -4
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +3 -6
- data/lib/rubocop/cop/rails/environment_comparison.rb +3 -4
- 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 +41 -24
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_by_id.rb +3 -3
- data/lib/rubocop/cop/rails/find_each.rb +27 -4
- data/lib/rubocop/cop/rails/freeze_time.rb +79 -0
- 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 +19 -9
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +3 -3
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +29 -11
- data/lib/rubocop/cop/rails/http_status.rb +6 -11
- data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +96 -0
- data/lib/rubocop/cop/rails/i18n_locale_assignment.rb +1 -1
- data/lib/rubocop/cop/rails/i18n_locale_texts.rb +110 -0
- data/lib/rubocop/cop/rails/ignored_columns_assignment.rb +50 -0
- data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +5 -14
- data/lib/rubocop/cop/rails/index_by.rb +8 -8
- data/lib/rubocop/cop/rails/index_with.rb +8 -8
- data/lib/rubocop/cop/rails/inquiry.rb +1 -1
- data/lib/rubocop/cop/rails/inverse_of.rb +20 -10
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +44 -16
- data/lib/rubocop/cop/rails/link_to_blank.rb +4 -7
- data/lib/rubocop/cop/rails/mailer_name.rb +9 -5
- data/lib/rubocop/cop/rails/match_route.rb +1 -1
- data/lib/rubocop/cop/rails/migration_class_name.rb +63 -0
- data/lib/rubocop/cop/rails/negate_include.rb +5 -4
- data/lib/rubocop/cop/rails/not_null_column.rb +10 -7
- data/lib/rubocop/cop/rails/order_by_id.rb +2 -3
- data/lib/rubocop/cop/rails/output.rb +26 -10
- data/lib/rubocop/cop/rails/output_safety.rb +6 -2
- data/lib/rubocop/cop/rails/pick.rb +8 -1
- data/lib/rubocop/cop/rails/pluck.rb +51 -11
- data/lib/rubocop/cop/rails/pluck_id.rb +5 -2
- data/lib/rubocop/cop/rails/pluck_in_where.rb +8 -7
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +4 -5
- data/lib/rubocop/cop/rails/presence.rb +22 -13
- data/lib/rubocop/cop/rails/present.rb +10 -13
- data/lib/rubocop/cop/rails/rake_environment.rb +8 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +52 -15
- data/lib/rubocop/cop/rails/redundant_allow_nil.rb +7 -17
- data/lib/rubocop/cop/rails/redundant_foreign_key.rb +3 -3
- data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +257 -0
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +31 -27
- data/lib/rubocop/cop/rails/redundant_travel_back.rb +57 -0
- data/lib/rubocop/cop/rails/reflection_class_name.rb +39 -4
- data/lib/rubocop/cop/rails/refute_methods.rb +1 -5
- data/lib/rubocop/cop/rails/relative_date_constant.rb +9 -9
- 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 +2 -3
- data/lib/rubocop/cop/rails/require_dependency.rb +2 -2
- data/lib/rubocop/cop/rails/response_parsed_body.rb +57 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +29 -67
- data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +6 -15
- data/lib/rubocop/cop/rails/root_join_chain.rb +72 -0
- data/lib/rubocop/cop/rails/root_pathname_methods.rb +238 -0
- data/lib/rubocop/cop/rails/root_public_path.rb +59 -0
- data/lib/rubocop/cop/rails/safe_navigation.rb +8 -13
- data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +14 -7
- data/lib/rubocop/cop/rails/save_bang.rb +30 -23
- data/lib/rubocop/cop/rails/schema_comment.rb +104 -0
- data/lib/rubocop/cop/rails/scope_args.rb +6 -2
- data/lib/rubocop/cop/rails/short_i18n.rb +3 -6
- data/lib/rubocop/cop/rails/skips_model_validations.rb +3 -4
- data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +13 -8
- data/lib/rubocop/cop/rails/strip_heredoc.rb +56 -0
- data/lib/rubocop/cop/rails/table_name_assignment.rb +44 -0
- data/lib/rubocop/cop/rails/three_state_boolean_column.rb +73 -0
- data/lib/rubocop/cop/rails/time_zone.rb +37 -32
- data/lib/rubocop/cop/rails/time_zone_assignment.rb +4 -4
- data/lib/rubocop/cop/rails/to_formatted_s.rb +46 -0
- data/lib/rubocop/cop/rails/to_s_with_argument.rb +78 -0
- data/lib/rubocop/cop/rails/top_level_hash_with_indifferent_access.rb +49 -0
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +99 -0
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +32 -41
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +16 -9
- data/lib/rubocop/cop/rails/unknown_env.rb +3 -5
- data/lib/rubocop/cop/rails/unused_ignored_columns.rb +9 -2
- data/lib/rubocop/cop/rails/validation.rb +5 -13
- data/lib/rubocop/cop/rails/where_equals.rb +6 -2
- data/lib/rubocop/cop/rails/where_exists.rb +11 -10
- data/lib/rubocop/cop/rails/where_missing.rb +118 -0
- data/lib/rubocop/cop/rails/where_not.rb +2 -2
- data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +55 -0
- data/lib/rubocop/cop/rails_cops.rb +34 -0
- data/lib/rubocop/rails/schema_loader/schema.rb +8 -5
- data/lib/rubocop/rails/version.rb +1 -1
- data/lib/rubocop/rails.rb +1 -1
- data/lib/rubocop-rails.rb +19 -0
- metadata +42 -8
- data/bin/setup +0 -7
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# Use `where.missing(...)` to find missing relationship records.
|
7
|
+
#
|
8
|
+
# This cop is enabled in Rails 6.1 or higher.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# Post.left_joins(:author).where(authors: { id: nil })
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# Post.where.missing(:author)
|
16
|
+
#
|
17
|
+
class WhereMissing < Base
|
18
|
+
include RangeHelp
|
19
|
+
extend AutoCorrector
|
20
|
+
extend TargetRailsVersion
|
21
|
+
|
22
|
+
MSG = 'Use `where.missing(:%<left_joins_association>s)` instead of ' \
|
23
|
+
'`%<left_joins_method>s(:%<left_joins_association>s).where(%<where_association>s: { id: nil })`.'
|
24
|
+
RESTRICT_ON_SEND = %i[left_joins left_outer_joins].freeze
|
25
|
+
|
26
|
+
minimum_target_rails_version 6.1
|
27
|
+
|
28
|
+
# @!method where_node_and_argument(node)
|
29
|
+
def_node_search :where_node_and_argument, <<~PATTERN
|
30
|
+
$(send ... :where (hash <(pair $(sym _) (hash (pair (sym :id) (nil))))...> ))
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
# @!method missing_relationship(node)
|
34
|
+
def_node_search :missing_relationship, <<~PATTERN
|
35
|
+
(pair (sym _) (hash (pair (sym :id) (nil))))
|
36
|
+
PATTERN
|
37
|
+
|
38
|
+
def on_send(node)
|
39
|
+
return unless node.first_argument.sym_type?
|
40
|
+
|
41
|
+
root_receiver = root_receiver(node)
|
42
|
+
where_node_and_argument(root_receiver) do |where_node, where_argument|
|
43
|
+
next unless root_receiver == root_receiver(where_node)
|
44
|
+
next unless same_relationship?(where_argument, node.first_argument)
|
45
|
+
|
46
|
+
range = range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
|
47
|
+
register_offense(node, where_node, where_argument, range)
|
48
|
+
break
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def root_receiver(node)
|
55
|
+
parent = node.parent
|
56
|
+
if !parent&.send_type? || parent.method?(:or) || parent.method?(:and)
|
57
|
+
node
|
58
|
+
else
|
59
|
+
root_receiver(parent)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def same_relationship?(where, left_joins)
|
64
|
+
where.value.to_s.match?(/^#{left_joins.value}s?$/)
|
65
|
+
end
|
66
|
+
|
67
|
+
def register_offense(node, where_node, where_argument, range)
|
68
|
+
add_offense(range, message: message(node, where_argument)) do |corrector|
|
69
|
+
corrector.replace(node.loc.selector, 'where.missing')
|
70
|
+
if multi_condition?(where_node.first_argument)
|
71
|
+
replace_where_method(corrector, where_node)
|
72
|
+
else
|
73
|
+
remove_where_method(corrector, node, where_node)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def replace_where_method(corrector, where_node)
|
79
|
+
missing_relationship(where_node) do |where_clause|
|
80
|
+
corrector.remove(replace_range(where_clause))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def replace_range(child)
|
85
|
+
if (right_sibling = child.right_sibling)
|
86
|
+
range_between(child.source_range.begin_pos, right_sibling.source_range.begin_pos)
|
87
|
+
else
|
88
|
+
range_between(child.left_sibling.source_range.end_pos, child.source_range.end_pos)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def remove_where_method(corrector, node, where_node)
|
93
|
+
range = range_between(where_node.loc.selector.begin_pos, where_node.loc.end.end_pos)
|
94
|
+
if node.multiline? && !same_line?(node, where_node)
|
95
|
+
range = range_by_whole_lines(range, include_final_newline: true)
|
96
|
+
else
|
97
|
+
corrector.remove(where_node.loc.dot)
|
98
|
+
end
|
99
|
+
|
100
|
+
corrector.remove(range)
|
101
|
+
end
|
102
|
+
|
103
|
+
def same_line?(left_joins_node, where_node)
|
104
|
+
left_joins_node.loc.selector.line == where_node.loc.selector.line
|
105
|
+
end
|
106
|
+
|
107
|
+
def multi_condition?(where_arg)
|
108
|
+
where_arg.children.count > 1
|
109
|
+
end
|
110
|
+
|
111
|
+
def message(node, where_argument)
|
112
|
+
format(MSG, left_joins_association: node.first_argument.value, left_joins_method: node.method_name,
|
113
|
+
where_association: where_argument.value)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Rails
|
6
|
-
#
|
6
|
+
# Identifies places where manually constructed SQL
|
7
7
|
# in `where` can be replaced with `where.not(...)`.
|
8
8
|
#
|
9
9
|
# @example
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
private
|
65
65
|
|
66
66
|
def offense_range(node)
|
67
|
-
range_between(node.loc.selector.begin_pos, node.
|
67
|
+
range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
|
68
68
|
end
|
69
69
|
|
70
70
|
def extract_column_and_value(template_node, value_node)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# Identifies calls to `where.not` with multiple hash arguments.
|
7
|
+
#
|
8
|
+
# The behavior of `where.not` changed in Rails 6.1. Prior to the change,
|
9
|
+
# `.where.not(trashed: true, role: 'admin')` evaluated to
|
10
|
+
# `WHERE trashed != TRUE AND role != 'admin'`.
|
11
|
+
# From Rails 6.1 onwards, this executes the query
|
12
|
+
# `WHERE NOT (trashed == TRUE AND roles == 'admin')`.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # bad
|
16
|
+
# User.where.not(trashed: true, role: 'admin')
|
17
|
+
# User.where.not(trashed: true, role: ['moderator', 'admin'])
|
18
|
+
# User.joins(:posts).where.not(posts: { trashed: true, title: 'Rails' })
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# User.where.not(trashed: true)
|
22
|
+
# User.where.not(role: ['moderator', 'admin'])
|
23
|
+
# User.where.not(trashed: true).where.not(role: ['moderator', 'admin'])
|
24
|
+
# User.where.not('trashed = ? OR role = ?', true, 'admin')
|
25
|
+
class WhereNotWithMultipleConditions < Base
|
26
|
+
MSG = 'Use a SQL statement instead of `where.not` with multiple conditions.'
|
27
|
+
RESTRICT_ON_SEND = %i[not].freeze
|
28
|
+
|
29
|
+
def_node_matcher :where_not_call?, <<~PATTERN
|
30
|
+
(send (send _ :where) :not $...)
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
def on_send(node)
|
34
|
+
where_not_call?(node) do |args|
|
35
|
+
next unless args[0]&.hash_type?
|
36
|
+
next unless multiple_arguments_hash? args[0]
|
37
|
+
|
38
|
+
range = node.receiver.loc.selector.with(end_pos: node.source_range.end_pos)
|
39
|
+
|
40
|
+
add_offense(range)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def multiple_arguments_hash?(hash)
|
47
|
+
return true if hash.pairs.size >= 2
|
48
|
+
return false unless hash.values[0]&.hash_type?
|
49
|
+
|
50
|
+
multiple_arguments_hash?(hash.values[0])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'mixin/active_record_helper'
|
4
|
+
require_relative 'mixin/active_record_migrations_helper'
|
5
|
+
require_relative 'mixin/class_send_node_helper'
|
4
6
|
require_relative 'mixin/enforce_superclass'
|
5
7
|
require_relative 'mixin/index_method'
|
8
|
+
require_relative 'mixin/migrations_helper'
|
6
9
|
require_relative 'mixin/target_rails_version'
|
7
10
|
|
11
|
+
require_relative 'rails/action_controller_flash_before_render'
|
12
|
+
require_relative 'rails/action_controller_test_case'
|
8
13
|
require_relative 'rails/action_filter'
|
14
|
+
require_relative 'rails/action_order'
|
9
15
|
require_relative 'rails/active_record_aliases'
|
10
16
|
require_relative 'rails/active_record_callbacks_order'
|
11
17
|
require_relative 'rails/active_record_override'
|
12
18
|
require_relative 'rails/active_support_aliases'
|
19
|
+
require_relative 'rails/active_support_on_load'
|
13
20
|
require_relative 'rails/add_column_index'
|
14
21
|
require_relative 'rails/after_commit_override'
|
15
22
|
require_relative 'rails/application_controller'
|
@@ -22,12 +29,18 @@ require_relative 'rails/attribute_default_block_value'
|
|
22
29
|
require_relative 'rails/belongs_to'
|
23
30
|
require_relative 'rails/blank'
|
24
31
|
require_relative 'rails/bulk_change_table'
|
32
|
+
require_relative 'rails/compact_blank'
|
25
33
|
require_relative 'rails/content_tag'
|
26
34
|
require_relative 'rails/create_table_with_timestamps'
|
27
35
|
require_relative 'rails/date'
|
28
36
|
require_relative 'rails/default_scope'
|
29
37
|
require_relative 'rails/delegate'
|
30
38
|
require_relative 'rails/delegate_allow_blank'
|
39
|
+
require_relative 'rails/deprecated_active_model_errors_methods'
|
40
|
+
require_relative 'rails/dot_separated_keys'
|
41
|
+
require_relative 'rails/duplicate_association'
|
42
|
+
require_relative 'rails/duplicate_scope'
|
43
|
+
require_relative 'rails/duration_arithmetic'
|
31
44
|
require_relative 'rails/dynamic_find_by'
|
32
45
|
require_relative 'rails/eager_evaluation_log_message'
|
33
46
|
require_relative 'rails/enum_hash'
|
@@ -40,12 +53,16 @@ require_relative 'rails/file_path'
|
|
40
53
|
require_relative 'rails/find_by'
|
41
54
|
require_relative 'rails/find_by_id'
|
42
55
|
require_relative 'rails/find_each'
|
56
|
+
require_relative 'rails/freeze_time'
|
43
57
|
require_relative 'rails/has_and_belongs_to_many'
|
44
58
|
require_relative 'rails/has_many_or_has_one_dependent'
|
45
59
|
require_relative 'rails/helper_instance_variable'
|
46
60
|
require_relative 'rails/http_positional_arguments'
|
47
61
|
require_relative 'rails/http_status'
|
62
|
+
require_relative 'rails/i18n_lazy_lookup'
|
48
63
|
require_relative 'rails/i18n_locale_assignment'
|
64
|
+
require_relative 'rails/i18n_locale_texts'
|
65
|
+
require_relative 'rails/ignored_columns_assignment'
|
49
66
|
require_relative 'rails/ignored_skip_action_filter_option'
|
50
67
|
require_relative 'rails/index_by'
|
51
68
|
require_relative 'rails/index_with'
|
@@ -55,6 +72,7 @@ require_relative 'rails/lexically_scoped_action_filter'
|
|
55
72
|
require_relative 'rails/link_to_blank'
|
56
73
|
require_relative 'rails/mailer_name'
|
57
74
|
require_relative 'rails/match_route'
|
75
|
+
require_relative 'rails/migration_class_name'
|
58
76
|
require_relative 'rails/negate_include'
|
59
77
|
require_relative 'rails/not_null_column'
|
60
78
|
require_relative 'rails/order_by_id'
|
@@ -71,7 +89,9 @@ require_relative 'rails/rake_environment'
|
|
71
89
|
require_relative 'rails/read_write_attribute'
|
72
90
|
require_relative 'rails/redundant_allow_nil'
|
73
91
|
require_relative 'rails/redundant_foreign_key'
|
92
|
+
require_relative 'rails/redundant_presence_validation_on_belongs_to'
|
74
93
|
require_relative 'rails/redundant_receiver_in_with_options'
|
94
|
+
require_relative 'rails/redundant_travel_back'
|
75
95
|
require_relative 'rails/reflection_class_name'
|
76
96
|
require_relative 'rails/refute_methods'
|
77
97
|
require_relative 'rails/relative_date_constant'
|
@@ -79,17 +99,29 @@ require_relative 'rails/render_inline'
|
|
79
99
|
require_relative 'rails/render_plain_text'
|
80
100
|
require_relative 'rails/request_referer'
|
81
101
|
require_relative 'rails/require_dependency'
|
102
|
+
require_relative 'rails/response_parsed_body'
|
82
103
|
require_relative 'rails/reversible_migration'
|
83
104
|
require_relative 'rails/reversible_migration_method_definition'
|
105
|
+
require_relative 'rails/root_join_chain'
|
106
|
+
require_relative 'rails/root_pathname_methods'
|
107
|
+
require_relative 'rails/root_public_path'
|
84
108
|
require_relative 'rails/safe_navigation'
|
85
109
|
require_relative 'rails/safe_navigation_with_blank'
|
86
110
|
require_relative 'rails/save_bang'
|
111
|
+
require_relative 'rails/schema_comment'
|
87
112
|
require_relative 'rails/scope_args'
|
88
113
|
require_relative 'rails/short_i18n'
|
89
114
|
require_relative 'rails/skips_model_validations'
|
90
115
|
require_relative 'rails/squished_sql_heredocs'
|
116
|
+
require_relative 'rails/strip_heredoc'
|
117
|
+
require_relative 'rails/table_name_assignment'
|
118
|
+
require_relative 'rails/three_state_boolean_column'
|
91
119
|
require_relative 'rails/time_zone'
|
92
120
|
require_relative 'rails/time_zone_assignment'
|
121
|
+
require_relative 'rails/to_formatted_s'
|
122
|
+
require_relative 'rails/to_s_with_argument'
|
123
|
+
require_relative 'rails/top_level_hash_with_indifferent_access'
|
124
|
+
require_relative 'rails/transaction_exit_statement'
|
93
125
|
require_relative 'rails/uniq_before_pluck'
|
94
126
|
require_relative 'rails/unique_validation_without_index'
|
95
127
|
require_relative 'rails/unknown_env'
|
@@ -97,4 +129,6 @@ require_relative 'rails/unused_ignored_columns'
|
|
97
129
|
require_relative 'rails/validation'
|
98
130
|
require_relative 'rails/where_equals'
|
99
131
|
require_relative 'rails/where_exists'
|
132
|
+
require_relative 'rails/where_missing'
|
100
133
|
require_relative 'rails/where_not'
|
134
|
+
require_relative 'rails/where_not_with_multiple_conditions'
|
@@ -5,11 +5,11 @@ module RuboCop
|
|
5
5
|
module SchemaLoader
|
6
6
|
# Represent db/schema.rb
|
7
7
|
class Schema
|
8
|
-
attr_reader :tables, :
|
8
|
+
attr_reader :tables, :add_indices
|
9
9
|
|
10
10
|
def initialize(ast)
|
11
11
|
@tables = []
|
12
|
-
@
|
12
|
+
@add_indices = []
|
13
13
|
|
14
14
|
build!(ast)
|
15
15
|
end
|
@@ -20,8 +20,8 @@ module RuboCop
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
23
|
+
def add_indices_by(table_name:)
|
24
|
+
add_indices.select do |add_index|
|
25
25
|
add_index.table_name == table_name
|
26
26
|
end
|
27
27
|
end
|
@@ -32,12 +32,14 @@ module RuboCop
|
|
32
32
|
raise "Unexpected type: #{ast.type}" unless ast.block_type?
|
33
33
|
|
34
34
|
each_table(ast) do |table_def|
|
35
|
+
next unless table_def.method?(:create_table)
|
36
|
+
|
35
37
|
@tables << Table.new(table_def)
|
36
38
|
end
|
37
39
|
|
38
40
|
# Compatibility for Rails 4.2.
|
39
41
|
each_add_index(ast) do |add_index_def|
|
40
|
-
@
|
42
|
+
@add_indices << AddIndex.new(add_index_def)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -56,6 +58,7 @@ module RuboCop
|
|
56
58
|
|
57
59
|
def each_add_index(ast)
|
58
60
|
ast.body.children.each do |node|
|
61
|
+
next unless node.respond_to?(:send_type?)
|
59
62
|
next if !node&.send_type? || !node.method?(:add_index)
|
60
63
|
|
61
64
|
yield(node)
|
data/lib/rubocop/rails.rb
CHANGED
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Rails
|
6
6
|
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
7
7
|
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
8
|
-
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
8
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read, permitted_classes: [Regexp, Symbol]).freeze
|
9
9
|
|
10
10
|
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
11
11
|
|
data/lib/rubocop-rails.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'rubocop'
|
4
4
|
require 'rack/utils'
|
5
5
|
require 'active_support/inflector'
|
6
|
+
require 'active_support/core_ext/object/blank'
|
6
7
|
|
7
8
|
require_relative 'rubocop/rails'
|
8
9
|
require_relative 'rubocop/rails/version'
|
@@ -13,3 +14,21 @@ require_relative 'rubocop/rails/schema_loader/schema'
|
|
13
14
|
RuboCop::Rails::Inject.defaults!
|
14
15
|
|
15
16
|
require_relative 'rubocop/cop/rails_cops'
|
17
|
+
|
18
|
+
RuboCop::Cop::Style::HashExcept.minimum_target_ruby_version(2.0)
|
19
|
+
|
20
|
+
RuboCop::Cop::Style::MethodCallWithArgsParentheses.singleton_class.prepend(
|
21
|
+
Module.new do
|
22
|
+
def autocorrect_incompatible_with
|
23
|
+
super.push(RuboCop::Cop::Rails::EagerEvaluationLogMessage)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
)
|
27
|
+
|
28
|
+
RuboCop::Cop::Style::RedundantSelf.singleton_class.prepend(
|
29
|
+
Module.new do
|
30
|
+
def autocorrect_incompatible_with
|
31
|
+
super.push(RuboCop::Cop::Rails::SafeNavigation)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.19.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-04-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
49
|
+
version: 1.33.0
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2.0'
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.
|
59
|
+
version: 1.33.0
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '2.0'
|
@@ -72,19 +72,25 @@ extra_rdoc_files:
|
|
72
72
|
files:
|
73
73
|
- LICENSE.txt
|
74
74
|
- README.md
|
75
|
-
- bin/setup
|
76
75
|
- config/default.yml
|
77
76
|
- config/obsoletion.yml
|
78
77
|
- lib/rubocop-rails.rb
|
79
78
|
- lib/rubocop/cop/mixin/active_record_helper.rb
|
79
|
+
- lib/rubocop/cop/mixin/active_record_migrations_helper.rb
|
80
|
+
- lib/rubocop/cop/mixin/class_send_node_helper.rb
|
80
81
|
- lib/rubocop/cop/mixin/enforce_superclass.rb
|
81
82
|
- lib/rubocop/cop/mixin/index_method.rb
|
83
|
+
- lib/rubocop/cop/mixin/migrations_helper.rb
|
82
84
|
- lib/rubocop/cop/mixin/target_rails_version.rb
|
85
|
+
- lib/rubocop/cop/rails/action_controller_flash_before_render.rb
|
86
|
+
- lib/rubocop/cop/rails/action_controller_test_case.rb
|
83
87
|
- lib/rubocop/cop/rails/action_filter.rb
|
88
|
+
- lib/rubocop/cop/rails/action_order.rb
|
84
89
|
- lib/rubocop/cop/rails/active_record_aliases.rb
|
85
90
|
- lib/rubocop/cop/rails/active_record_callbacks_order.rb
|
86
91
|
- lib/rubocop/cop/rails/active_record_override.rb
|
87
92
|
- lib/rubocop/cop/rails/active_support_aliases.rb
|
93
|
+
- lib/rubocop/cop/rails/active_support_on_load.rb
|
88
94
|
- lib/rubocop/cop/rails/add_column_index.rb
|
89
95
|
- lib/rubocop/cop/rails/after_commit_override.rb
|
90
96
|
- lib/rubocop/cop/rails/application_controller.rb
|
@@ -97,12 +103,18 @@ files:
|
|
97
103
|
- lib/rubocop/cop/rails/belongs_to.rb
|
98
104
|
- lib/rubocop/cop/rails/blank.rb
|
99
105
|
- lib/rubocop/cop/rails/bulk_change_table.rb
|
106
|
+
- lib/rubocop/cop/rails/compact_blank.rb
|
100
107
|
- lib/rubocop/cop/rails/content_tag.rb
|
101
108
|
- lib/rubocop/cop/rails/create_table_with_timestamps.rb
|
102
109
|
- lib/rubocop/cop/rails/date.rb
|
103
110
|
- lib/rubocop/cop/rails/default_scope.rb
|
104
111
|
- lib/rubocop/cop/rails/delegate.rb
|
105
112
|
- lib/rubocop/cop/rails/delegate_allow_blank.rb
|
113
|
+
- lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb
|
114
|
+
- lib/rubocop/cop/rails/dot_separated_keys.rb
|
115
|
+
- lib/rubocop/cop/rails/duplicate_association.rb
|
116
|
+
- lib/rubocop/cop/rails/duplicate_scope.rb
|
117
|
+
- lib/rubocop/cop/rails/duration_arithmetic.rb
|
106
118
|
- lib/rubocop/cop/rails/dynamic_find_by.rb
|
107
119
|
- lib/rubocop/cop/rails/eager_evaluation_log_message.rb
|
108
120
|
- lib/rubocop/cop/rails/enum_hash.rb
|
@@ -115,12 +127,16 @@ files:
|
|
115
127
|
- lib/rubocop/cop/rails/find_by.rb
|
116
128
|
- lib/rubocop/cop/rails/find_by_id.rb
|
117
129
|
- lib/rubocop/cop/rails/find_each.rb
|
130
|
+
- lib/rubocop/cop/rails/freeze_time.rb
|
118
131
|
- lib/rubocop/cop/rails/has_and_belongs_to_many.rb
|
119
132
|
- lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb
|
120
133
|
- lib/rubocop/cop/rails/helper_instance_variable.rb
|
121
134
|
- lib/rubocop/cop/rails/http_positional_arguments.rb
|
122
135
|
- lib/rubocop/cop/rails/http_status.rb
|
136
|
+
- lib/rubocop/cop/rails/i18n_lazy_lookup.rb
|
123
137
|
- lib/rubocop/cop/rails/i18n_locale_assignment.rb
|
138
|
+
- lib/rubocop/cop/rails/i18n_locale_texts.rb
|
139
|
+
- lib/rubocop/cop/rails/ignored_columns_assignment.rb
|
124
140
|
- lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb
|
125
141
|
- lib/rubocop/cop/rails/index_by.rb
|
126
142
|
- lib/rubocop/cop/rails/index_with.rb
|
@@ -130,6 +146,7 @@ files:
|
|
130
146
|
- lib/rubocop/cop/rails/link_to_blank.rb
|
131
147
|
- lib/rubocop/cop/rails/mailer_name.rb
|
132
148
|
- lib/rubocop/cop/rails/match_route.rb
|
149
|
+
- lib/rubocop/cop/rails/migration_class_name.rb
|
133
150
|
- lib/rubocop/cop/rails/negate_include.rb
|
134
151
|
- lib/rubocop/cop/rails/not_null_column.rb
|
135
152
|
- lib/rubocop/cop/rails/order_by_id.rb
|
@@ -146,7 +163,9 @@ files:
|
|
146
163
|
- lib/rubocop/cop/rails/read_write_attribute.rb
|
147
164
|
- lib/rubocop/cop/rails/redundant_allow_nil.rb
|
148
165
|
- lib/rubocop/cop/rails/redundant_foreign_key.rb
|
166
|
+
- lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb
|
149
167
|
- lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
|
168
|
+
- lib/rubocop/cop/rails/redundant_travel_back.rb
|
150
169
|
- lib/rubocop/cop/rails/reflection_class_name.rb
|
151
170
|
- lib/rubocop/cop/rails/refute_methods.rb
|
152
171
|
- lib/rubocop/cop/rails/relative_date_constant.rb
|
@@ -154,17 +173,29 @@ files:
|
|
154
173
|
- lib/rubocop/cop/rails/render_plain_text.rb
|
155
174
|
- lib/rubocop/cop/rails/request_referer.rb
|
156
175
|
- lib/rubocop/cop/rails/require_dependency.rb
|
176
|
+
- lib/rubocop/cop/rails/response_parsed_body.rb
|
157
177
|
- lib/rubocop/cop/rails/reversible_migration.rb
|
158
178
|
- lib/rubocop/cop/rails/reversible_migration_method_definition.rb
|
179
|
+
- lib/rubocop/cop/rails/root_join_chain.rb
|
180
|
+
- lib/rubocop/cop/rails/root_pathname_methods.rb
|
181
|
+
- lib/rubocop/cop/rails/root_public_path.rb
|
159
182
|
- lib/rubocop/cop/rails/safe_navigation.rb
|
160
183
|
- lib/rubocop/cop/rails/safe_navigation_with_blank.rb
|
161
184
|
- lib/rubocop/cop/rails/save_bang.rb
|
185
|
+
- lib/rubocop/cop/rails/schema_comment.rb
|
162
186
|
- lib/rubocop/cop/rails/scope_args.rb
|
163
187
|
- lib/rubocop/cop/rails/short_i18n.rb
|
164
188
|
- lib/rubocop/cop/rails/skips_model_validations.rb
|
165
189
|
- lib/rubocop/cop/rails/squished_sql_heredocs.rb
|
190
|
+
- lib/rubocop/cop/rails/strip_heredoc.rb
|
191
|
+
- lib/rubocop/cop/rails/table_name_assignment.rb
|
192
|
+
- lib/rubocop/cop/rails/three_state_boolean_column.rb
|
166
193
|
- lib/rubocop/cop/rails/time_zone.rb
|
167
194
|
- lib/rubocop/cop/rails/time_zone_assignment.rb
|
195
|
+
- lib/rubocop/cop/rails/to_formatted_s.rb
|
196
|
+
- lib/rubocop/cop/rails/to_s_with_argument.rb
|
197
|
+
- lib/rubocop/cop/rails/top_level_hash_with_indifferent_access.rb
|
198
|
+
- lib/rubocop/cop/rails/transaction_exit_statement.rb
|
168
199
|
- lib/rubocop/cop/rails/uniq_before_pluck.rb
|
169
200
|
- lib/rubocop/cop/rails/unique_validation_without_index.rb
|
170
201
|
- lib/rubocop/cop/rails/unknown_env.rb
|
@@ -172,7 +203,9 @@ files:
|
|
172
203
|
- lib/rubocop/cop/rails/validation.rb
|
173
204
|
- lib/rubocop/cop/rails/where_equals.rb
|
174
205
|
- lib/rubocop/cop/rails/where_exists.rb
|
206
|
+
- lib/rubocop/cop/rails/where_missing.rb
|
175
207
|
- lib/rubocop/cop/rails/where_not.rb
|
208
|
+
- lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb
|
176
209
|
- lib/rubocop/cop/rails_cops.rb
|
177
210
|
- lib/rubocop/rails.rb
|
178
211
|
- lib/rubocop/rails/inject.rb
|
@@ -186,8 +219,9 @@ metadata:
|
|
186
219
|
homepage_uri: https://docs.rubocop.org/rubocop-rails/
|
187
220
|
changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
|
188
221
|
source_code_uri: https://github.com/rubocop/rubocop-rails/
|
189
|
-
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.
|
222
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.19/
|
190
223
|
bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
|
224
|
+
rubygems_mfa_required: 'true'
|
191
225
|
post_install_message:
|
192
226
|
rdoc_options: []
|
193
227
|
require_paths:
|
@@ -196,14 +230,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
230
|
requirements:
|
197
231
|
- - ">="
|
198
232
|
- !ruby/object:Gem::Version
|
199
|
-
version: 2.
|
233
|
+
version: 2.6.0
|
200
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
235
|
requirements:
|
202
236
|
- - ">="
|
203
237
|
- !ruby/object:Gem::Version
|
204
238
|
version: '0'
|
205
239
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
240
|
+
rubygems_version: 3.5.0.dev
|
207
241
|
signing_key:
|
208
242
|
specification_version: 4
|
209
243
|
summary: Automatic Rails code style checking tool.
|