rubocop-rails 2.21.2 → 2.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/config/default.yml +11 -3
- data/lib/rubocop/cop/mixin/active_record_helper.rb +9 -2
- data/lib/rubocop/cop/mixin/database_type_resolvable.rb +66 -0
- data/lib/rubocop/cop/rails/action_filter.rb +3 -0
- data/lib/rubocop/cop/rails/active_record_aliases.rb +2 -2
- data/lib/rubocop/cop/rails/active_support_aliases.rb +6 -5
- data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
- data/lib/rubocop/cop/rails/bulk_change_table.rb +6 -56
- data/lib/rubocop/cop/rails/content_tag.rb +1 -1
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +10 -2
- data/lib/rubocop/cop/rails/duplicate_association.rb +66 -12
- data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +2 -2
- data/lib/rubocop/cop/rails/env_local.rb +46 -0
- data/lib/rubocop/cop/rails/file_path.rb +5 -5
- data/lib/rubocop/cop/rails/find_by.rb +2 -2
- data/lib/rubocop/cop/rails/find_by_id.rb +9 -23
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +1 -1
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +1 -1
- data/lib/rubocop/cop/rails/inquiry.rb +1 -0
- data/lib/rubocop/cop/rails/inverse_of.rb +1 -1
- data/lib/rubocop/cop/rails/not_null_column.rb +13 -3
- data/lib/rubocop/cop/rails/output.rb +3 -2
- data/lib/rubocop/cop/rails/pick.rb +6 -5
- data/lib/rubocop/cop/rails/pluck.rb +1 -1
- data/lib/rubocop/cop/rails/pluck_id.rb +2 -1
- data/lib/rubocop/cop/rails/pluck_in_where.rb +18 -5
- data/lib/rubocop/cop/rails/rake_environment.rb +2 -2
- data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +53 -2
- data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +7 -0
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
- data/lib/rubocop/cop/rails/response_parsed_body.rb +52 -10
- data/lib/rubocop/cop/rails/reversible_migration.rb +2 -2
- data/lib/rubocop/cop/rails/save_bang.rb +11 -6
- data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
- data/lib/rubocop/cop/rails/unknown_env.rb +5 -1
- data/lib/rubocop/cop/rails/validation.rb +2 -2
- data/lib/rubocop/cop/rails/where_equals.rb +3 -2
- data/lib/rubocop/cop/rails/where_exists.rb +9 -8
- data/lib/rubocop/cop/rails/where_missing.rb +1 -1
- data/lib/rubocop/cop/rails/where_not.rb +8 -6
- data/lib/rubocop/cop/rails_cops.rb +2 -0
- data/lib/rubocop/rails/schema_loader/schema.rb +2 -2
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +26 -4
@@ -55,11 +55,11 @@ module RuboCop
|
|
55
55
|
RESTRICT_ON_SEND = %i[exists?].freeze
|
56
56
|
|
57
57
|
def_node_matcher :where_exists_call?, <<~PATTERN
|
58
|
-
(
|
58
|
+
(call (call _ :where $...) :exists?)
|
59
59
|
PATTERN
|
60
60
|
|
61
61
|
def_node_matcher :exists_with_args?, <<~PATTERN
|
62
|
-
(
|
62
|
+
(call _ :exists? $...)
|
63
63
|
PATTERN
|
64
64
|
|
65
65
|
def on_send(node)
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
return unless convertable_args?(args)
|
68
68
|
|
69
69
|
range = correction_range(node)
|
70
|
-
good_method = build_good_method(args)
|
70
|
+
good_method = build_good_method(args, dot_source: node.loc.dot.source)
|
71
71
|
message = format(MSG, good_method: good_method, bad_method: range.source)
|
72
72
|
|
73
73
|
add_offense(range, message: message) do |corrector|
|
@@ -75,6 +75,7 @@ module RuboCop
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
|
+
alias on_csend on_send
|
78
79
|
|
79
80
|
private
|
80
81
|
|
@@ -108,11 +109,11 @@ module RuboCop
|
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
111
|
-
def build_good_method(args)
|
112
|
+
def build_good_method(args, dot_source: '.')
|
112
113
|
if exists_style?
|
113
114
|
build_good_method_exists(args)
|
114
115
|
elsif where_style?
|
115
|
-
build_good_method_where(args)
|
116
|
+
build_good_method_where(args, dot_source)
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
@@ -124,11 +125,11 @@ module RuboCop
|
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
|
-
def build_good_method_where(args)
|
128
|
+
def build_good_method_where(args, dot_source)
|
128
129
|
if args.size > 1
|
129
|
-
"where(#{args.map(&:source).join(', ')})
|
130
|
+
"where(#{args.map(&:source).join(', ')})#{dot_source}exists?"
|
130
131
|
else
|
131
|
-
"where(#{args[0].source})
|
132
|
+
"where(#{args[0].source})#{dot_source}exists?"
|
132
133
|
end
|
133
134
|
end
|
134
135
|
end
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
PATTERN
|
37
37
|
|
38
38
|
def on_send(node)
|
39
|
-
return unless node.first_argument
|
39
|
+
return unless node.first_argument&.sym_type?
|
40
40
|
|
41
41
|
root_receiver = root_receiver(node)
|
42
42
|
where_node_and_argument(root_receiver) do |where_node, where_argument|
|
@@ -32,8 +32,8 @@ module RuboCop
|
|
32
32
|
|
33
33
|
def_node_matcher :where_method_call?, <<~PATTERN
|
34
34
|
{
|
35
|
-
(
|
36
|
-
(
|
35
|
+
(call _ :where (array $str_type? $_ ?))
|
36
|
+
(call _ :where $str_type? $_ ?)
|
37
37
|
}
|
38
38
|
PATTERN
|
39
39
|
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
46
46
|
column_and_value = extract_column_and_value(template_node, value_node)
|
47
47
|
return unless column_and_value
|
48
48
|
|
49
|
-
good_method = build_good_method(*column_and_value)
|
49
|
+
good_method = build_good_method(node.loc.dot&.source, *column_and_value)
|
50
50
|
message = format(MSG, good_method: good_method)
|
51
51
|
|
52
52
|
add_offense(range, message: message) do |corrector|
|
@@ -54,6 +54,7 @@ module RuboCop
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
+
alias on_csend on_send
|
57
58
|
|
58
59
|
NOT_EQ_ANONYMOUS_RE = /\A([\w.]+)\s+(?:!=|<>)\s+\?\z/.freeze # column != ?, column <> ?
|
59
60
|
NOT_IN_ANONYMOUS_RE = /\A([\w.]+)\s+NOT\s+IN\s+\(\?\)\z/i.freeze # column NOT IN (?)
|
@@ -86,13 +87,14 @@ module RuboCop
|
|
86
87
|
[Regexp.last_match(1), value]
|
87
88
|
end
|
88
89
|
|
89
|
-
def build_good_method(column, value)
|
90
|
+
def build_good_method(dot, column, value)
|
91
|
+
dot ||= '.'
|
90
92
|
if column.include?('.')
|
91
93
|
table, column = column.split('.')
|
92
94
|
|
93
|
-
"where
|
95
|
+
"where#{dot}not(#{table}: { #{column}: #{value} })"
|
94
96
|
else
|
95
|
-
"where
|
97
|
+
"where#{dot}not(#{column}: #{value})"
|
96
98
|
end
|
97
99
|
end
|
98
100
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'mixin/active_record_helper'
|
4
4
|
require_relative 'mixin/active_record_migrations_helper'
|
5
5
|
require_relative 'mixin/class_send_node_helper'
|
6
|
+
require_relative 'mixin/database_type_resolvable'
|
6
7
|
require_relative 'mixin/enforce_superclass'
|
7
8
|
require_relative 'mixin/index_method'
|
8
9
|
require_relative 'mixin/migrations_helper'
|
@@ -46,6 +47,7 @@ require_relative 'rails/dynamic_find_by'
|
|
46
47
|
require_relative 'rails/eager_evaluation_log_message'
|
47
48
|
require_relative 'rails/enum_hash'
|
48
49
|
require_relative 'rails/enum_uniqueness'
|
50
|
+
require_relative 'rails/env_local'
|
49
51
|
require_relative 'rails/environment_comparison'
|
50
52
|
require_relative 'rails/environment_variable_access'
|
51
53
|
require_relative 'rails/exit'
|
@@ -127,7 +127,7 @@ module RuboCop
|
|
127
127
|
private
|
128
128
|
|
129
129
|
def analyze_keywords!(node)
|
130
|
-
pairs = node.
|
130
|
+
pairs = node.last_argument
|
131
131
|
return unless pairs.hash_type?
|
132
132
|
|
133
133
|
pairs.each_pair do |k, v|
|
@@ -158,7 +158,7 @@ module RuboCop
|
|
158
158
|
end
|
159
159
|
|
160
160
|
def analyze_keywords!(node)
|
161
|
-
pairs = node.
|
161
|
+
pairs = node.last_argument
|
162
162
|
return unless pairs.hash_type?
|
163
163
|
|
164
164
|
pairs.each_pair do |k, v|
|
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.23.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: 2023-
|
13
|
+
date: 2023-12-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -60,6 +60,26 @@ dependencies:
|
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '2.0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rubocop-ast
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.30.0
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.0'
|
73
|
+
type: :runtime
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.30.0
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
63
83
|
description: |
|
64
84
|
Automatic Rails code style checking tool.
|
65
85
|
A RuboCop extension focused on enforcing Rails best practices and coding conventions.
|
@@ -78,6 +98,7 @@ files:
|
|
78
98
|
- lib/rubocop/cop/mixin/active_record_helper.rb
|
79
99
|
- lib/rubocop/cop/mixin/active_record_migrations_helper.rb
|
80
100
|
- lib/rubocop/cop/mixin/class_send_node_helper.rb
|
101
|
+
- lib/rubocop/cop/mixin/database_type_resolvable.rb
|
81
102
|
- lib/rubocop/cop/mixin/enforce_superclass.rb
|
82
103
|
- lib/rubocop/cop/mixin/index_method.rb
|
83
104
|
- lib/rubocop/cop/mixin/migrations_helper.rb
|
@@ -120,6 +141,7 @@ files:
|
|
120
141
|
- lib/rubocop/cop/rails/eager_evaluation_log_message.rb
|
121
142
|
- lib/rubocop/cop/rails/enum_hash.rb
|
122
143
|
- lib/rubocop/cop/rails/enum_uniqueness.rb
|
144
|
+
- lib/rubocop/cop/rails/env_local.rb
|
123
145
|
- lib/rubocop/cop/rails/environment_comparison.rb
|
124
146
|
- lib/rubocop/cop/rails/environment_variable_access.rb
|
125
147
|
- lib/rubocop/cop/rails/exit.rb
|
@@ -223,7 +245,7 @@ metadata:
|
|
223
245
|
homepage_uri: https://docs.rubocop.org/rubocop-rails/
|
224
246
|
changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
|
225
247
|
source_code_uri: https://github.com/rubocop/rubocop-rails/
|
226
|
-
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.
|
248
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.23/
|
227
249
|
bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
|
228
250
|
rubygems_mfa_required: 'true'
|
229
251
|
post_install_message:
|
@@ -241,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
263
|
- !ruby/object:Gem::Version
|
242
264
|
version: '0'
|
243
265
|
requirements: []
|
244
|
-
rubygems_version: 3.
|
266
|
+
rubygems_version: 3.4.19
|
245
267
|
signing_key:
|
246
268
|
specification_version: 4
|
247
269
|
summary: Automatic Rails code style checking tool.
|