gl_rubocop 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d0d6882bfbd2fb93c58c4c0e3a9302e4f98ac4977aa469e0b40a57856a7cfd0
4
- data.tar.gz: 86ea3ab20f3b8899e6b8806ad1daabf561d732c6ad26c80017102e57c8f67bf1
3
+ metadata.gz: 2dc8147315555f5d211c9d5577a449f69d73b913126481bc1477ea5ede612f38
4
+ data.tar.gz: ddd3961ae821ea369248be94d91dc23559ef5993261f75e660cdf05246a28358
5
5
  SHA512:
6
- metadata.gz: bac9a336b0f9e60517d727a5791f8cf909d824ce978e30dff1bb3a4788d22ed358fff0106e14db757c64c3079a0fa7df7b7cb632df258bce529a963b3d6763d4
7
- data.tar.gz: 7b84eda9ac0ea8feddc5996f499b36c4d0408d729f764b95b882dbdcfdf5fe7a44e08d1e1eaa6dec5e726bfcfd75e45ad88e157d017afc3497ea4e43378ef5a4
6
+ metadata.gz: d1b05b7ffd3b6917ac6838fea98e817572629d5b25258816b773a69671b51487754caabf5283cb840451b800f2f695fa551b4ddf4faebfe93ab2c914a7456f70
7
+ data.tar.gz: 60be23fbb3bfb84505da907c041bb7708a1f0b7f5e7ff5dcfbd6b3fa1db37866880092612d7a7302ec5eefdf6f97751244bf0df37e5ecd95223b1ce74a0e2dee
data/default.yml CHANGED
@@ -17,6 +17,7 @@ require:
17
17
  - ./lib/gl_rubocop/gl_cops/sidekiq_inherits_from_sidekiq_job.rb
18
18
  - ./lib/gl_rubocop/gl_cops/unique_identifier.rb
19
19
  - ./lib/gl_rubocop/gl_cops/tailwind_no_contradicting_class_name.rb
20
+ - ./lib/gl_rubocop/gl_cops/valid_data_test_id.rb
20
21
  - ./lib/gl_rubocop/gl_cops/view_component_initialize_keyword_args.rb
21
22
 
22
23
  AllCops:
@@ -76,6 +77,13 @@ GLCops/UniqueIdentifier:
76
77
  Include:
77
78
  - "app/components/**/*.erb"
78
79
 
80
+ GLCops/ValidDataTestId:
81
+ Enabled: true
82
+ Include:
83
+ - "**/*.erb"
84
+ - "**/*.haml"
85
+ - "**/*.rb"
86
+
79
87
  GLCops/ViewComponentInitializeKeywordArgs:
80
88
  Enabled: true
81
89
  Include:
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../helpers/haml_content_helper'
4
+ require_relative '../helpers/erb_content_helper'
5
+
6
+ module GLRubocop
7
+ module GLCops
8
+ class ValidDataTestId < RuboCop::Cop::Cop
9
+ include GLRubocop::HamlContentHelper
10
+ include GLRubocop::ErbContentHelper
11
+
12
+ MSG = 'Use data-test-id instead of %<invalid>s'
13
+
14
+ # Invalid variations of data-test-id
15
+ # Matches: data-testid, data_test_id, datatestid, dataTestId, etc.
16
+ # Does NOT match: data-test-id (the valid format)
17
+ INVALID_PATTERN = /\bdata(?!-test-id\b)[-_]?test[-_]?id\b/i
18
+
19
+ def investigate(processed_source)
20
+ return unless haml_file? || erb_file?
21
+
22
+ content = haml_file? ? read_haml_file : read_erb_file
23
+ return unless content
24
+
25
+ check_file_content(content, processed_source)
26
+ end
27
+
28
+ def on_str(node)
29
+ return unless node.str_type?
30
+
31
+ check_string_content(node.value, node)
32
+ end
33
+
34
+ private
35
+
36
+ def check_file_content(content, processed_source)
37
+ return unless content.match?(INVALID_PATTERN)
38
+
39
+ match = content.match(INVALID_PATTERN)
40
+ invalid_attr = match[0].split(/[=:]/).first.gsub(/["']/, '')
41
+ range = processed_source.buffer.source_range
42
+ add_offense(
43
+ nil,
44
+ location: range,
45
+ message: format(MSG, invalid: invalid_attr)
46
+ )
47
+ end
48
+
49
+ def check_string_content(content, node)
50
+ return unless content.match?(INVALID_PATTERN)
51
+
52
+ match = content.match(INVALID_PATTERN)
53
+ invalid_attr = match[0].split(/[=:]/).first.gsub(/["']/, '')
54
+ add_offense(
55
+ node,
56
+ message: format(MSG, invalid: invalid_attr)
57
+ )
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module GLRubocop
2
- VERSION = '0.3.3'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Give Lively
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-12 00:00:00.000000000 Z
11
+ date: 2026-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -171,6 +171,7 @@ files:
171
171
  - lib/gl_rubocop/gl_cops/sidekiq_inherits_from_sidekiq_job.rb
172
172
  - lib/gl_rubocop/gl_cops/tailwind_no_contradicting_class_name.rb
173
173
  - lib/gl_rubocop/gl_cops/unique_identifier.rb
174
+ - lib/gl_rubocop/gl_cops/valid_data_test_id.rb
174
175
  - lib/gl_rubocop/gl_cops/view_component_initialize_keyword_args.rb
175
176
  - lib/gl_rubocop/helpers/erb_content_helper.rb
176
177
  - lib/gl_rubocop/helpers/haml_content_helper.rb