Sha256: 25f0600e2fea82e7f00de3bfe270008f3d93f0073d78435e23dd98392e15dc20

Contents?: true

Size: 1.17 KB

Versions: 72

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Helper methods for top level example group cops
      module TopLevelGroup
        extend RuboCop::NodePattern::Macros

        def on_new_investigation
          super

          top_level_groups.each do |node|
            on_top_level_example_group(node) if example_group?(node)
            on_top_level_group(node)
          end
        end

        def top_level_groups
          @top_level_groups ||=
            top_level_nodes(root_node).select { |n| spec_group?(n) }
        end

        private

        # Dummy methods to be overridden in the consumer
        def on_top_level_example_group(_node); end

        def on_top_level_group(_node); end

        def top_level_group?(node)
          top_level_groups.include?(node)
        end

        def top_level_nodes(node)
          return [] if node.nil?

          case node.type
          when :begin
            node.children
          when :module, :class
            top_level_nodes(node.body)
          else
            [node]
          end
        end

        def root_node
          processed_source.ast
        end
      end
    end
  end
end

Version data entries

72 entries across 66 versions & 7 rubygems

Version Path
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.26.1/lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.26.1 lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.26.0 lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.25.0 lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.24.1 lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.24.0 lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.23.2 lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.23.1 lib/rubocop/cop/rspec/mixin/top_level_group.rb
rubocop-rspec-2.23.0 lib/rubocop/cop/rspec/mixin/top_level_group.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.9.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.12.1/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.13.1/lib/rubocop/cop/rspec/mixin/top_level_group.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/mixin/top_level_group.rb