Skip to content

Commit

Permalink
Use Node#any_block_type?
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Jan 27, 2025
1 parent c5e79cc commit 8f3be2f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/return_in_test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def on_return(node)
private

def inside_block?(node)
node.ancestors.any?(&:block_type?) || node.ancestors.any?(&:numblock_type?)
node.ancestors.any?(&:any_block_type?)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ def assertions_count(node)
end
end

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def assertion_method?(node)
return false unless node
return assertion_method?(node.expression) if node.assignment? && node.respond_to?(:expression)
return false if !node.send_type? && !node.block_type? && !node.numblock_type?
return false if !node.send_type? && !node.any_block_type?

ASSERTION_PREFIXES.any? do |prefix|
method_name = node.method_name

method_name.start_with?(prefix) || node.method?(:flunk)
end
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity

def lifecycle_hook_method?(node)
node.def_type? && LIFECYCLE_HOOK_METHODS.include?(node.method_name)
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cop/mixin/predicate_assertion_handleable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module PredicateAssertionHandleable
MSG = 'Prefer using `%<assertion_type>s_predicate(%<new_arguments>s)`.'

def on_send(node)
return unless node.first_argument
return if node.first_argument.block_type? || node.first_argument.numblock_type?
return if node.first_argument&.any_block_type?
return unless predicate_method?(node.first_argument)
return unless node.first_argument.arguments.count.zero?

Expand Down
2 changes: 1 addition & 1 deletion rubocop-minitest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'rubocop', '>= 1.61', '< 2.0'
spec.add_dependency 'rubocop-ast', '>= 1.36.1', '< 2.0'
spec.add_dependency 'rubocop-ast', '>= 1.38.0', '< 2.0'
end

0 comments on commit 8f3be2f

Please sign in to comment.