Skip to content

Commit 3869184

Browse files
committed
upgrade autocorrects
1 parent 83d0f9c commit 3869184

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

lib/rubocop/cop/bugcrowd/replica_identity_required.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module RuboCop
44
module Cop
55
module Bugcrowd
66
class ReplicaIdentityRequired < Base
7+
extend AutoCorrector
8+
79
# Checks that tables have a replica identity defined
810
#
911
# @example
@@ -48,18 +50,15 @@ def calls_set_replica_identity?(node)
4850

4951
def on_send(node)
5052
# look for an `up` or `change` node with `create_table` but not `set_replica_identity`
51-
within_change_or_up_method?(node) && create_table?(node) && \
52-
!calls_set_replica_identity?(node) && add_offense(node)
53-
end
54-
55-
def autocorrect(node)
56-
lambda do |corrector|
57-
table_sym = node.arguments[0].value
58-
indent = node.source_range.source_line[/^(\s+)/] || ''
59-
corrector.insert_after(
60-
node.parent,
61-
"\n#{indent}set_replica_identity(:#{table_sym}, :full)"
62-
)
53+
if within_change_or_up_method?(node) && create_table?(node) &&
54+
!calls_set_replica_identity?(node)
55+
add_offense(node) do |corrector|
56+
indent = node.source_range.source_line[/^(\s+)/] || ''
57+
corrector.insert_after(
58+
node.parent,
59+
"\n#{indent}set_replica_identity(:#{node.arguments[0].value}, :full)"
60+
)
61+
end
6362
end
6463
end
6564
end

lib/rubocop/cop/bugcrowd/require_optional_for_belongs_to.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module RuboCop
44
module Cop
55
module Bugcrowd
66
class RequireOptionalForBelongsTo < Base
7+
extend AutoCorrector
8+
79
# Ensures that the :optional argument is supplied to the belongs_to method
810
# to help with upgrading to the new rails default
911
#
@@ -53,16 +55,12 @@ class RequireOptionalForBelongsTo < Base
5355

5456
def on_send(node)
5557
if in_belongs_to?(node) && !belongs_to_with_optional?(node)
56-
add_offense(node)
57-
end
58-
end
59-
60-
def autocorrect(node)
61-
lambda do |corrector|
62-
corrector.replace(
63-
node.last_argument.loc.expression,
64-
"#{node.last_argument.source}, optional: false"
65-
)
58+
add_offense(node) do |corrector|
59+
corrector.replace(
60+
node.last_argument.loc.expression,
61+
"#{node.last_argument.source}, optional: false"
62+
)
63+
end
6664
end
6765
end
6866
end

0 commit comments

Comments
 (0)