Class: Cops::NoChromeTag

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
RuboCop::Cop::RangeHelp
Defined in:
lib/generators/rolemodel/linters/rubocop/templates/lib/cops/no_chrome_tag.rb

Overview

Detect occurences of the chrome tag in specs, and warn and remove them.

Constant Summary collapse

MSG =
'The :chrome tag is only for testing, and should not be checked into the repository.'
RESTRICT_ON_SEND =
%i[describe context it feature scenario].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/rolemodel/linters/rubocop/templates/lib/cops/no_chrome_tag.rb', line 14

def on_send(node) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  node.arguments.each do |a|
    if a.sym_type? && a.value == :chrome
      range = range_with_surrounding_comma(a.source_range)
      add_offense(range) do |corrector|
        corrector.replace(range, '')
      end
    end

    next unless a.hash_type?

    a.pairs.each do |pair|
      next unless pair.key.value == :chrome

      range = range_with_surrounding_comma(pair.source_range)
      add_offense(range) do |corrector|
        corrector.replace(range, '')
      end
    end
  end
end

#range_with_surrounding_comma(source_range) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/generators/rolemodel/linters/rubocop/templates/lib/cops/no_chrome_tag.rb', line 36

def range_with_surrounding_comma(source_range)
  buffer = source_range.source_buffer
  src = buffer.source
  end_pos = source_range.end_pos
  comma_index = src[...end_pos].rindex(/\s*,\s*/)

  Parser::Source::Range.new(buffer, comma_index, end_pos)
end