Class: GLRubocop::GLCops::ValidDataTestId

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
ErbContentHelper, HamlContentHelper
Defined in:
lib/gl_rubocop/gl_cops/valid_data_test_id.rb

Constant Summary collapse

MSG =
'Use data-test-id instead of %<invalid>s'
INVALID_PATTERN =

Invalid variations of data-test-id Matches: data-testid, data_test_id, datatestid, dataTestId, etc. Does NOT match: data-test-id (the valid format)

/\bdata(?!-test-id\b)[-_]?test[-_]?id\b/i

Instance Method Summary collapse

Methods included from ErbContentHelper

#erb_file?, #read_erb_file

Methods included from HamlContentHelper

#haml_file?, #read_haml_file

Instance Method Details

#investigate(processed_source) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/gl_rubocop/gl_cops/valid_data_test_id.rb', line 19

def investigate(processed_source)
  return unless haml_file? || erb_file?

  content = haml_file? ? read_haml_file : read_erb_file
  return unless content

  check_file_content(content, processed_source)
end

#on_str(node) ⇒ Object



28
29
30
31
32
# File 'lib/gl_rubocop/gl_cops/valid_data_test_id.rb', line 28

def on_str(node)
  return unless node.str_type?

  check_string_content(node.value, node)
end