File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change
1
+ * [ #1160 ] ( https://github.com/rubocop/rubocop-rails/issues/1160 ) : Fix ` Rails/SaveBang ` to ignore parenthesis. ([ @fatkodima ] [ ] )
Original file line number Diff line number Diff line change @@ -235,10 +235,10 @@ def check_used_in_condition_or_compound_boolean(node)
235
235
236
236
def in_condition_or_compound_boolean? ( node )
237
237
node = node . block_node || node
238
- parent = node . parent
238
+ parent = node . each_ancestor . find { | ancestor | ! ancestor . begin_type? }
239
239
return false unless parent
240
240
241
- operator_or_single_negative? ( parent ) || ( conditional? ( parent ) && node == parent . condition )
241
+ operator_or_single_negative? ( parent ) || ( conditional? ( parent ) && node == deparenthesize ( parent . condition ) )
242
242
end
243
243
244
244
def operator_or_single_negative? ( node )
@@ -249,6 +249,11 @@ def conditional?(parent)
249
249
parent . if_type? || parent . case_type?
250
250
end
251
251
252
+ def deparenthesize ( node )
253
+ node = node . children . last while node . begin_type?
254
+ node
255
+ end
256
+
252
257
def checked_immediately? ( node )
253
258
node . parent && call_to_persisted? ( node . parent )
254
259
end
Original file line number Diff line number Diff line change 170
170
end
171
171
end
172
172
173
+ it "when using #{ method } wrapped within parenthesis with if" do
174
+ if update
175
+ expect_no_offenses ( <<~RUBY , method : method )
176
+ if (object.#{ method } ); something; end
177
+ RUBY
178
+ else
179
+ expect_offense ( <<~RUBY , method : method )
180
+ if (object.#{ method } ); something; end
181
+ ^{method} `#{ method } ` returns a model which is always truthy.
182
+ RUBY
183
+ end
184
+ end
185
+
173
186
it "when using #{ method } with if with block" do
174
187
if update
175
188
expect_no_offenses ( <<~RUBY )
You can’t perform that action at this time.
0 commit comments