Skip to content

Commit 297e022

Browse files
committed
Suppress new Style/ReturnNilInPredicateMethodDefinition offenses
Follow up Follow up rubocop/rubocop#11967. This commit suppresses the following new `Style/ReturnNilInPredicateMethodDefinition` offenses: ```console $ bundle exec rubocop (snip) Offenses: lib/rubocop/cop/rails/action_controller_flash_before_render.rb:88:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless class_node ^^^^^^ lib/rubocop/cop/rails/date.rb:142:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless node.method?(:to_time) ^^^^^^ lib/rubocop/cop/rails/dynamic_find_by.rb:77:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless cop_config['AllowedMethods'] ^^^^^^ lib/rubocop/cop/rails/dynamic_find_by.rb:83:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless cop_config['AllowedReceivers'] && node.receiver ^^^^^^ lib/rubocop/cop/rails/dynamic_find_by.rb:91:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless whitelist_config ^^^^^^ lib/rubocop/cop/rails/freeze_time.rb:72:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return if time_argument ^^^^^^ lib/rubocop/cop/rails/save_bang.rb:191:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless assignment.referenced? ^^^^^^ lib/rubocop/cop/rails/save_bang.rb:301:11: C: [Corrected] Style/ReturnNilInPredicateMethodDefinition: Use return false instead of return in the predicate method. return unless method && (method.def_type? || method.block_type?) ^^^^^^ 281 files inspected, 8 offenses detected, 8 offenses corrected ```
1 parent 024b6a4 commit 297e022

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

lib/rubocop/cop/rails/action_controller_flash_before_render.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def followed_by_render?(flash_node)
8585

8686
def inherit_action_controller_base?(node)
8787
class_node = find_ancestor(node, type: :class)
88-
return unless class_node
88+
return false unless class_node
8989

9090
action_controller?(class_node)
9191
end

lib/rubocop/cop/rails/date.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def safe_chain?(node)
139139
end
140140

141141
def safe_to_time?(node)
142-
return unless node.method?(:to_time)
142+
return false unless node.method?(:to_time)
143143

144144
if node.receiver.str_type?
145145
zone_regexp = /([+-][\d:]+|\dZ)\z/

lib/rubocop/cop/rails/dynamic_find_by.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ def allowed_invocation?(node)
7474
end
7575

7676
def allowed_method?(node)
77-
return unless cop_config['AllowedMethods']
77+
return false unless cop_config['AllowedMethods']
7878

7979
cop_config['AllowedMethods'].include?(node.method_name.to_s)
8080
end
8181

8282
def allowed_receiver?(node)
83-
return unless cop_config['AllowedReceivers'] && node.receiver
83+
return false unless cop_config['AllowedReceivers'] && node.receiver
8484

8585
cop_config['AllowedReceivers'].include?(node.receiver.source)
8686
end
8787

8888
# config option `WhiteList` will be deprecated soon
8989
def whitelisted?(node)
9090
whitelist_config = cop_config['Whitelist']
91-
return unless whitelist_config
91+
return false unless whitelist_config
9292

9393
whitelist_config.include?(node.method_name.to_s)
9494
end

lib/rubocop/cop/rails/freeze_time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def current_time_with_convert?(node, method_name)
6969
return false unless CONVERT_METHODS.include?(method_name)
7070

7171
child_node, child_method_name, time_argument = *node.children
72-
return if time_argument
72+
return false if time_argument
7373

7474
current_time?(child_node, child_method_name)
7575
end

lib/rubocop/cop/rails/save_bang.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def right_assignment_node(assignment)
188188
end
189189

190190
def persisted_referenced?(assignment)
191-
return unless assignment.referenced?
191+
return false unless assignment.referenced?
192192

193193
assignment.variable.references.any? do |reference|
194194
call_to_persisted?(reference.node.parent)
@@ -298,7 +298,7 @@ def implicit_return?(node)
298298

299299
node = assignable_node(node)
300300
method, sibling_index = find_method_with_sibling_index(node.parent)
301-
return unless method && (method.def_type? || method.block_type?)
301+
return false unless method && (method.def_type? || method.block_type?)
302302

303303
method.children.size == node.sibling_index + sibling_index
304304
end

0 commit comments

Comments
 (0)