rubocop-rails 2.23.1 → 2.24.1
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 +3 -1
- data/lib/rubocop/cop/mixin/active_record_helper.rb +6 -1
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +2 -0
- data/lib/rubocop/cop/rails/active_support_on_load.rb +21 -1
- data/lib/rubocop/cop/rails/dangerous_column_names.rb +1 -2
- data/lib/rubocop/cop/rails/expanded_date_range.rb +1 -1
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -1
- data/lib/rubocop/cop/rails/save_bang.rb +2 -0
- data/lib/rubocop/cop/rails/time_zone.rb +2 -1
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +12 -4
- data/lib/rubocop/cop/rails/where_exists.rb +3 -3
- data/lib/rubocop/cop/rails/where_missing.rb +5 -1
- data/lib/rubocop/rails/schema_loader/schema.rb +1 -0
- data/lib/rubocop/rails/schema_loader.rb +5 -15
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee7d9bdd0fa7838d8bfecece133ccd92cc308603bcdf120c14224c5f2e312344
|
4
|
+
data.tar.gz: 7d740b495ffa368d26a73808af9adff990bb9c1d317d905f877b4f3e2025487c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98172f41e7b1aab55931f351757425815850809edd6fc4f5bc55c59271d9f12459ac51c2002e409534b623f321ab27798c32aaccb2d15d60c7bf309a9c044d58
|
7
|
+
data.tar.gz: c78e9a0d9e53e5203a2dd1846a79c3e9c7a16af69e98d94e6b7ae6358ae6a29b71c2ac3f09ddb2a9be06dc64097a736c3379730f50b9309c0e2ae084267aee70
|
data/config/default.yml
CHANGED
@@ -165,6 +165,7 @@ Rails/ActiveSupportOnLoad:
|
|
165
165
|
- 'https://guides.rubyonrails.org/engines.html#available-load-hooks'
|
166
166
|
SafeAutoCorrect: false
|
167
167
|
VersionAdded: '2.16'
|
168
|
+
VersionChanged: '2.24'
|
168
169
|
|
169
170
|
Rails/AddColumnIndex:
|
170
171
|
Description: >-
|
@@ -445,9 +446,10 @@ Rails/EnvironmentVariableAccess:
|
|
445
446
|
# TODO: Set to `pending` status in RuboCop Rails 2 series when migration doc will be written.
|
446
447
|
Enabled: false
|
447
448
|
VersionAdded: '2.10'
|
448
|
-
VersionChanged: '2.
|
449
|
+
VersionChanged: '2.24'
|
449
450
|
Include:
|
450
451
|
- app/**/*.rb
|
452
|
+
- config/initializers/**/*.rb
|
451
453
|
- lib/**/*.rb
|
452
454
|
Exclude:
|
453
455
|
- lib/**/*.rake
|
@@ -39,7 +39,12 @@ module RuboCop
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def schema
|
42
|
-
RuboCop
|
42
|
+
# For compatibility with RuboCop 1.61.0 or lower.
|
43
|
+
if respond_to?(:parser_engine)
|
44
|
+
RuboCop::Rails::SchemaLoader.load(target_ruby_version, parser_engine)
|
45
|
+
else
|
46
|
+
RuboCop::Rails::SchemaLoader.load(target_ruby_version, :parser_whitequark)
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def table_name(class_node)
|
@@ -99,6 +99,8 @@ module RuboCop
|
|
99
99
|
|
100
100
|
def use_redirect_to?(context)
|
101
101
|
context.right_siblings.compact.any? do |sibling|
|
102
|
+
# Unwrap `return redirect_to :index`
|
103
|
+
sibling = sibling.children.first if sibling.return_type? && sibling.children.one?
|
102
104
|
sibling.send_type? && sibling.method?(:redirect_to)
|
103
105
|
end
|
104
106
|
end
|
@@ -55,15 +55,35 @@ module RuboCop
|
|
55
55
|
'ActiveSupport::TestCase' => 'active_support_test_case'
|
56
56
|
}.freeze
|
57
57
|
|
58
|
+
RAILS_5_2_LOAD_HOOKS = {
|
59
|
+
'ActiveRecord::ConnectionAdapters::SQLite3Adapter' => 'active_record_sqlite3adapter'
|
60
|
+
}.freeze
|
61
|
+
|
62
|
+
RAILS_7_1_LOAD_HOOKS = {
|
63
|
+
'ActiveRecord::TestFixtures' => 'active_record_fixtures',
|
64
|
+
'ActiveModel::Model' => 'active_model',
|
65
|
+
'ActionText::EncryptedRichText' => 'action_text_encrypted_rich_text',
|
66
|
+
'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'active_record_postgresqladapter',
|
67
|
+
'ActiveRecord::ConnectionAdapters::Mysql2Adapter' => 'active_record_mysql2adapter',
|
68
|
+
'ActiveRecord::ConnectionAdapters::TrilogyAdapter' => 'active_record_trilogyadapter'
|
69
|
+
}.freeze
|
70
|
+
|
58
71
|
def on_send(node)
|
59
72
|
receiver, method, arguments = *node # rubocop:disable InternalAffairs/NodeDestructuring
|
60
|
-
return unless
|
73
|
+
return unless arguments && (hook = hook_for_const(receiver&.const_name))
|
61
74
|
|
62
75
|
preferred = "ActiveSupport.on_load(:#{hook}) { #{method} #{arguments.source} }"
|
63
76
|
add_offense(node, message: format(MSG, prefer: preferred, current: node.source)) do |corrector|
|
64
77
|
corrector.replace(node, preferred)
|
65
78
|
end
|
66
79
|
end
|
80
|
+
|
81
|
+
def hook_for_const(const_name)
|
82
|
+
hook = LOAD_HOOKS[const_name]
|
83
|
+
hook ||= RAILS_5_2_LOAD_HOOKS[const_name] if target_rails_version >= 5.2
|
84
|
+
hook ||= RAILS_7_1_LOAD_HOOKS[const_name] if target_rails_version >= 7.1
|
85
|
+
hook
|
86
|
+
end
|
67
87
|
end
|
68
88
|
end
|
69
89
|
end
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
time
|
32
32
|
].to_set.freeze
|
33
33
|
|
34
|
-
# Generated from `ActiveRecord::AttributeMethods.dangerous_attribute_methods` on activerecord 7.1.
|
34
|
+
# Generated from `ActiveRecord::AttributeMethods.dangerous_attribute_methods` on activerecord 7.1.3.
|
35
35
|
# rubocop:disable Metrics/CollectionLiteralLength
|
36
36
|
DANGEROUS_COLUMN_NAMES = %w[
|
37
37
|
__callbacks
|
@@ -290,7 +290,6 @@ module RuboCop
|
|
290
290
|
new_record
|
291
291
|
no_touching
|
292
292
|
normalize_reflection_attribute
|
293
|
-
object_id
|
294
293
|
partial_inserts
|
295
294
|
partial_updates
|
296
295
|
perform_validations
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
return if allow?(begin_node, end_node)
|
52
52
|
|
53
53
|
preferred_method = preferred_method(begin_node)
|
54
|
-
if begin_node.method?(:beginning_of_week) && begin_node.arguments.one?
|
54
|
+
if begin_node.method?(:beginning_of_week) && begin_node.arguments.one? && end_node.arguments.one?
|
55
55
|
return unless same_argument?(begin_node, end_node)
|
56
56
|
|
57
57
|
preferred_method << "(#{begin_node.first_argument.source})"
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
59
59
|
return if node.method?(:first)
|
60
60
|
|
61
61
|
where_loc = node.receiver.loc.selector
|
62
|
-
first_loc = range_between(node.
|
62
|
+
first_loc = range_between(node.receiver.source_range.end_pos, node.loc.selector.end_pos)
|
63
63
|
|
64
64
|
corrector.replace(where_loc, 'find_by')
|
65
65
|
corrector.replace(first_loc, '')
|
@@ -69,9 +69,10 @@ module RuboCop
|
|
69
69
|
return if !node.receiver&.str_type? || !node.method?(:to_time)
|
70
70
|
|
71
71
|
add_offense(node.loc.selector, message: MSG_STRING_TO_TIME) do |corrector|
|
72
|
-
corrector.replace(node, "Time.zone.parse(#{node.receiver.source})")
|
72
|
+
corrector.replace(node, "Time.zone.parse(#{node.receiver.source})") unless node.csend_type?
|
73
73
|
end
|
74
74
|
end
|
75
|
+
alias on_csend on_send
|
75
76
|
|
76
77
|
private
|
77
78
|
|
@@ -68,15 +68,23 @@ module RuboCop
|
|
68
68
|
return unless uniq
|
69
69
|
|
70
70
|
add_offense(node.loc.selector) do |corrector|
|
71
|
-
|
72
|
-
|
73
|
-
corrector.remove(dot_method_with_whitespace(method, node))
|
74
|
-
corrector.insert_before(node.receiver.loc.dot.begin, '.distinct')
|
71
|
+
autocorrect(corrector, node)
|
75
72
|
end
|
76
73
|
end
|
77
74
|
|
78
75
|
private
|
79
76
|
|
77
|
+
def autocorrect(corrector, node)
|
78
|
+
method = node.method_name
|
79
|
+
|
80
|
+
corrector.remove(dot_method_with_whitespace(method, node))
|
81
|
+
if (dot = node.receiver.loc.dot)
|
82
|
+
corrector.insert_before(dot.begin, '.distinct')
|
83
|
+
else
|
84
|
+
corrector.insert_before(node.receiver, 'distinct.')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
80
88
|
def dot_method_with_whitespace(method, node)
|
81
89
|
range_between(dot_method_begin_pos(method, node), node.loc.selector.end_pos)
|
82
90
|
end
|
@@ -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: node.loc.dot)
|
71
71
|
message = format(MSG, good_method: good_method, bad_method: range.source)
|
72
72
|
|
73
73
|
add_offense(range, message: message) do |corrector|
|
@@ -109,11 +109,11 @@ module RuboCop
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
def build_good_method(args,
|
112
|
+
def build_good_method(args, dot:)
|
113
113
|
if exists_style?
|
114
114
|
build_good_method_exists(args)
|
115
115
|
elsif where_style?
|
116
|
-
build_good_method_where(args,
|
116
|
+
build_good_method_where(args, dot&.source || '.')
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -89,16 +89,20 @@ module RuboCop
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
# rubocop:disable Metrics/AbcSize
|
92
93
|
def remove_where_method(corrector, node, where_node)
|
93
94
|
range = range_between(where_node.loc.selector.begin_pos, where_node.loc.end.end_pos)
|
94
95
|
if node.multiline? && !same_line?(node, where_node)
|
95
96
|
range = range_by_whole_lines(range, include_final_newline: true)
|
96
|
-
|
97
|
+
elsif where_node.receiver
|
97
98
|
corrector.remove(where_node.loc.dot)
|
99
|
+
else
|
100
|
+
corrector.remove(node.loc.dot)
|
98
101
|
end
|
99
102
|
|
100
103
|
corrector.remove(range)
|
101
104
|
end
|
105
|
+
# rubocop:enable Metrics/AbcSize
|
102
106
|
|
103
107
|
def same_line?(left_joins_node, where_node)
|
104
108
|
left_joins_node.loc.selector.line == where_node.loc.selector.line
|
@@ -12,10 +12,10 @@ module RuboCop
|
|
12
12
|
# So a cop that uses the loader should handle `nil` properly.
|
13
13
|
#
|
14
14
|
# @return [Schema, nil]
|
15
|
-
def load(target_ruby_version)
|
15
|
+
def load(target_ruby_version, parser_engine)
|
16
16
|
return @load if defined?(@load)
|
17
17
|
|
18
|
-
@load = load!(target_ruby_version)
|
18
|
+
@load = load!(target_ruby_version, parser_engine)
|
19
19
|
end
|
20
20
|
|
21
21
|
def reset!
|
@@ -38,23 +38,13 @@ module RuboCop
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
def load!(target_ruby_version)
|
41
|
+
def load!(target_ruby_version, parser_engine)
|
42
42
|
path = db_schema_path
|
43
43
|
return unless path
|
44
44
|
|
45
|
-
ast =
|
46
|
-
Schema.new(ast) if ast
|
47
|
-
end
|
48
|
-
|
49
|
-
def parse(path, target_ruby_version)
|
50
|
-
klass_name = :"Ruby#{target_ruby_version.to_s.sub('.', '')}"
|
51
|
-
klass = ::Parser.const_get(klass_name)
|
52
|
-
parser = klass.new(RuboCop::AST::Builder.new)
|
45
|
+
ast = RuboCop::ProcessedSource.new(File.read(path), target_ruby_version, path, parser_engine: parser_engine).ast
|
53
46
|
|
54
|
-
|
55
|
-
buffer.source = path.read
|
56
|
-
|
57
|
-
parser.parse(buffer)
|
47
|
+
Schema.new(ast) if ast
|
58
48
|
end
|
59
49
|
end
|
60
50
|
end
|
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.24.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: 2024-03-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.
|
69
|
+
version: 1.31.1
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '2.0'
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 1.
|
79
|
+
version: 1.31.1
|
80
80
|
- - "<"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
@@ -245,7 +245,7 @@ metadata:
|
|
245
245
|
homepage_uri: https://docs.rubocop.org/rubocop-rails/
|
246
246
|
changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
|
247
247
|
source_code_uri: https://github.com/rubocop/rubocop-rails/
|
248
|
-
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.
|
248
|
+
documentation_uri: https://docs.rubocop.org/rubocop-rails/2.24/
|
249
249
|
bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
|
250
250
|
rubygems_mfa_required: 'true'
|
251
251
|
post_install_message:
|
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
265
|
requirements: []
|
266
|
-
rubygems_version: 3.
|
266
|
+
rubygems_version: 3.3.26
|
267
267
|
signing_key:
|
268
268
|
specification_version: 4
|
269
269
|
summary: Automatic Rails code style checking tool.
|