File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,7 @@ def on_send(node) # rubocop:disable Metrics/CyclomaticComplexity
146
146
147
147
add_offense_for_node ( node )
148
148
end
149
+ alias on_csend on_send
149
150
150
151
def autocorrect ( node )
151
152
save_loc = node . loc . selector
Original file line number Diff line number Diff line change 60
60
'if the return value is not checked.' ] )
61
61
end
62
62
63
+ context 'when using safe navigation operator' , :ruby23 do
64
+ it "when using #{ method } without arguments" do
65
+ inspect_source ( "object&.#{ method } " )
66
+
67
+ expect ( cop . messages )
68
+ . to eq ( [ "Use `#{ method } !` instead of `#{ method } ` " \
69
+ 'if the return value is not checked.' ] )
70
+ end
71
+ end
72
+
63
73
it "when using #{ method } !" do
64
74
expect_no_offenses ( "object.#{ method } !" )
65
75
end
77
87
78
88
expect ( new_source ) . to eq ( "object.#{ method } !()" )
79
89
end
90
+
91
+ context 'when using safe navigation operator' , :ruby23 do
92
+ it 'autocorrects' do
93
+ new_source = autocorrect_source ( "object&.#{ method } ()" )
94
+
95
+ expect ( new_source ) . to eq ( "object&.#{ method } !()" )
96
+ end
97
+ end
80
98
end
81
99
82
100
shared_examples 'checks_variable_return_use_offense' do |method , update |
You can’t perform that action at this time.
0 commit comments