Class: GLRubocop::GLCops::UniqueIdentifier
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- GLRubocop::GLCops::UniqueIdentifier
- Defined in:
- lib/gl_rubocop/gl_cops/unique_identifier.rb
Constant Summary collapse
- MSG =
This cop ensures that view components include a data-test-id attribute.
Good:
{data-test-id: 'unique-id'} {data-test-id: @unique_id } {'data-test-id': 'unique-id'} {"data-test-id": "unique-id"} {data: {test-id: 'unique-id'}} {data: {'test-id': 'unique-id'}}Bad:
{data: {testId: "unique-id"}} {data: {test: {id: "unique-id"}} 'View components must include a data-test-id attribute'.freeze
- EMPTY_MSG =
'data-test-id attribute must not be empty'.freeze
- UNIQUE_IDENTIFIER =
'test-id'.freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/gl_rubocop/gl_cops/unique_identifier.rb', line 22 def on_send(node) return unless file_exists? && valid_method_name?(node) return add_offense(node) unless raw_content.include?(UNIQUE_IDENTIFIER) add_offense(node, message: EMPTY_MSG) if test_id_value.strip.empty? end |