File tree Expand file tree Collapse file tree 2 files changed +19
-22
lines changed Expand file tree Collapse file tree 2 files changed +19
-22
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments