Sha256: f31693580a8775dfc805c3ee63905f5d3730245724071278885b240f5c254a1c

Contents?: true

Size: 1.29 KB

Versions: 20

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Ezcater
      # Use ".<class method>" instead of "self.<class method>" in RSpec example
      # group descriptions.
      #
      # @example
      #
      #   # good
      #   describe ".does_stuff" do
      #     ...
      #   end
      #
      #   # bad
      #   describe "self.does_stuff" do
      #     ...
      #   end
      class RspecDotNotSelfDot < Cop
        SELF_DOT_REGEXP = /["']self\./
        MSG = 'Use ".<class method>" instead of "self.<class method>" for example group description.'

        def_node_matcher :example_group_match, <<-PATTERN
          (send _ #{RuboCop::RSpec::Language::ExampleGroups::ALL.node_pattern_union} $_ ...)
        PATTERN

        def on_send(node)
          example_group_match(node) do |doc|
            add_offense(doc, location: :expression, message: MSG) if doc.source.match?(SELF_DOT_REGEXP)
          end
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(Parser::Source::Range.new(node.source_range.source_buffer,
                                                       node.source_range.begin_pos + 1,
                                                       node.source_range.begin_pos + 5))
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ezcater_rubocop-0.58.1 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.58.0 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.58.0.rc1 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.58.0.rc0 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.4 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.3 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.2 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.2.rc1 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.1 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.1.rc4 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.1.rc3 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.1.rc2 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.1.rc1 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.0 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.0.rc3 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.0.rc2 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.0.rc1 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.57.0.rc0 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.52.8 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
ezcater_rubocop-0.52.7 lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb