Sha256: 0a7339a3f215ff8ac17979d14e53d4e6c2a3936316357be35ad25111a874d169

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

module RuboCop
  module Cop
    module Salsify
      # 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\./.freeze
        MSG = 'Use ".<class method>" instead of "self.<class method>" for example group description.'.freeze

        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) if SELF_DOT_REGEXP =~ doc.source
          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

6 entries across 6 versions & 1 rubygems

Version Path
salsify_rubocop-0.78.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-0.78.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-0.63.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-0.62.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-0.60.0.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-0.60.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb