Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull example group node matchers up #934

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/rubocop/cop/rspec/describe_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class DescribeClass < Cop
)
PATTERN

def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern

def on_top_level_describe(node, (described_value, _))
return if shared_group?(root_node)
return if valid_describe?(node)
Expand Down
4 changes: 0 additions & 4 deletions lib/rubocop/cop/rspec/instance_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ class InstanceVariable < Cop
MSG = 'Avoid instance variables – use let, ' \
'a method call, or a local variable (if possible).'

EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL

def_node_matcher :spec_group?, EXAMPLE_GROUP_METHODS.block_pattern

def_node_matcher :dynamic_class?, <<-PATTERN
(block (send (const nil? :Class) :new ...) ...)
PATTERN
Expand Down
5 changes: 1 addition & 4 deletions lib/rubocop/cop/rspec/leaky_constant_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,8 @@ def on_module(node)
private

def inside_describe_block?(node)
node.each_ancestor(:block).any?(&method(:in_example_or_shared_group?))
node.each_ancestor(:block).any?(&method(:spec_group?))
end

def_node_matcher :in_example_or_shared_group?,
(ExampleGroups::ALL + SharedGroups::ALL).block_pattern
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/rspec/language/node_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module NodePattern
extend RuboCop::NodePattern::Macros

def_node_matcher :example_group?, ExampleGroups::ALL.block_pattern
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern

spec_groups = ExampleGroups::ALL + SharedGroups::ALL
def_node_matcher :spec_group?, spec_groups.block_pattern

def_node_matcher :example_group_with_body?, <<-PATTERN
(block #{ExampleGroups::ALL.send_pattern} args [!nil?])
Expand Down