gl_rubocop 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/default.yml +8 -0
- data/gl_rubocop.gemspec +1 -0
- data/lib/gl_rubocop/gl_cops/unique_identifier.rb +62 -0
- data/lib/gl_rubocop/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20051ad7be570098d65231ae0699f2a8e0388ac1d46e635c2b967b04d4490278
|
4
|
+
data.tar.gz: 92d0f9a01f967880e8db09a2715adad74144071489e3a39e0b05fd260dd54f33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ad7a44349b6182c777f3277b84458624ed4010c6e8d5effc08461779262dc021081a83b2dbe1c0a325f86292b621ac2f73181c06ee24cda60b69a5ecd79f0eb
|
7
|
+
data.tar.gz: 17b072554bdbcb5df215abe5dd0c01c7d64324a0db62fdd555c8e931b16fbaa259d97a1a1028581fc3340b27e6e4bfb93963581c7414f5300d322a577d826ccd
|
data/default.yml
CHANGED
@@ -3,10 +3,13 @@ require:
|
|
3
3
|
- rubocop-rails
|
4
4
|
- rubocop-rspec
|
5
5
|
- rubocop-magic_numbers
|
6
|
+
- rubocop-haml
|
6
7
|
- ./lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
7
8
|
- ./lib/gl_rubocop/gl_cops/callback_method_names.rb
|
8
9
|
- ./lib/gl_rubocop/gl_cops/prevent_erb_files.rb
|
9
10
|
- ./lib/gl_rubocop/gl_cops/sidekiq_inherits_from_sidekiq_job.rb
|
11
|
+
- ./lib/gl_rubocop/gl_cops/unique_identifier.rb
|
12
|
+
|
10
13
|
|
11
14
|
AllCops:
|
12
15
|
SuggestExtensions: false
|
@@ -39,6 +42,11 @@ GLCops/SidekiqInheritsFromSidekiqJob:
|
|
39
42
|
- 'app/**/*_worker.rb'
|
40
43
|
- 'app/**/*_job.rb'
|
41
44
|
|
45
|
+
GLCops/UniqueIdentifier:
|
46
|
+
Enabled: true
|
47
|
+
Include:
|
48
|
+
- 'app/components/**/*.haml'
|
49
|
+
|
42
50
|
Layout/LineLength:
|
43
51
|
Max: 100
|
44
52
|
AllowedPatterns:
|
data/gl_rubocop.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
28
|
spec.add_dependency 'rubocop', '~> 1.62.0'
|
29
|
+
spec.add_dependency 'rubocop-haml', '~> 0.2.4'
|
29
30
|
spec.add_dependency 'rubocop-magic_numbers'
|
30
31
|
spec.add_dependency 'rubocop-performance'
|
31
32
|
spec.add_dependency 'rubocop-rails'
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module GLRubocop
|
2
|
+
module GLCops
|
3
|
+
class UniqueIdentifier < RuboCop::Cop::Base
|
4
|
+
# This cop ensures that view components include a data-test-id attribute.
|
5
|
+
#
|
6
|
+
# Good:
|
7
|
+
# {data-test-id: "unique-id"}
|
8
|
+
# {data-test-id: @unique_id }
|
9
|
+
# {'data-test-id': "unique-id"}
|
10
|
+
# {"data-test-id": "unique-id"}
|
11
|
+
#
|
12
|
+
# Bad:
|
13
|
+
# {data: {testId: "unique-id"}}
|
14
|
+
# {data: {test: {id: "unique-id"}}
|
15
|
+
|
16
|
+
MSG = 'View components must include a data-test-id attribute'.freeze
|
17
|
+
EMPTY_MSG = 'data-test-id attribute must not be empty'.freeze
|
18
|
+
UNIQUE_IDENTIFIER = 'data-test-id'.freeze
|
19
|
+
|
20
|
+
def on_send(node)
|
21
|
+
return unless file_exists? && valid_method_name?(node)
|
22
|
+
|
23
|
+
return add_offense(node) unless raw_content.include?(UNIQUE_IDENTIFIER)
|
24
|
+
|
25
|
+
add_offense(node, message: EMPTY_MSG) if test_id_value.strip.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def file_exists?
|
31
|
+
File.exist?(processed_source.file_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def identifiable_line
|
35
|
+
line_number = raw_content.lines.find_index { |line| line.include?(UNIQUE_IDENTIFIER) }
|
36
|
+
raw_content.lines[line_number]
|
37
|
+
end
|
38
|
+
|
39
|
+
def raw_content
|
40
|
+
@raw_content ||= File.read(processed_source.file_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def regex_for_indentifier_and_value
|
44
|
+
key = Regexp.quote(UNIQUE_IDENTIFIER)
|
45
|
+
/(?:#{key}|["']#{key}["']):\s*(["']([^"']*)["']|@\w+)/
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_id_value
|
49
|
+
match = identifiable_line.match(regex_for_indentifier_and_value)
|
50
|
+
|
51
|
+
return '' unless match
|
52
|
+
|
53
|
+
value = match[1]
|
54
|
+
value.start_with?('"', "'") ? value[1..-2] : value
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid_method_name?(node)
|
58
|
+
node.method_name == :render || node.method_name == :template
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/gl_rubocop/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.4
|
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-01-
|
11
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.62.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-haml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.4
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubocop-magic_numbers
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +124,7 @@ files:
|
|
110
124
|
- lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
111
125
|
- lib/gl_rubocop/gl_cops/prevent_erb_files.rb
|
112
126
|
- lib/gl_rubocop/gl_cops/sidekiq_inherits_from_sidekiq_job.rb
|
127
|
+
- lib/gl_rubocop/gl_cops/unique_identifier.rb
|
113
128
|
- lib/gl_rubocop/version.rb
|
114
129
|
homepage: https://github.com/givelively/gl_rubocop
|
115
130
|
licenses:
|