Sha256: 838b21b327af6e3c2288b53858becac74be62425120cda13a6163abb4bbb8043

Contents?: true

Size: 1.25 KB

Versions: 14

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

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 < RuboCop::Cop::RSpec::Base
        extend RuboCop::Cop::AutoCorrector

        SELF_DOT_REGEXP = /["']self\./.freeze
        MSG = 'Use ".<class method>" instead of "self.<class method>" for example group description.'

        def_node_matcher :example_group_match, <<-PATTERN
          (send _ #ExampleGroups.all $_ ...)
        PATTERN

        def on_send(node)
          example_group_match(node) do |doc|
            next unless SELF_DOT_REGEXP.match?(doc.source)

            add_offense(doc) do |corrector|
              corrector.remove(Parser::Source::Range.new(doc.source_range.source_buffer,
                                                         doc.source_range.begin_pos + 1,
                                                         doc.source_range.begin_pos + 5))
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
salsify_rubocop-1.68.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.59.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.59.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.43.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.43.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.42.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.42.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.27.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.27.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.2.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.1.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.0.2 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.0.1 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb
salsify_rubocop-1.0.0 lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb