gl_rubocop 0.2.2 → 0.2.3
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 +58 -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: d20b890fc0655b53c0dcc83817c48487dd7a30f62566cd4d05c9aecf4ff8b4b8
|
4
|
+
data.tar.gz: 7781b08914c2cdfba1265349799ef45f0b64ce585adb4ca0cfdb14212970e28c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d526e27669d0c354503003303f2c86f6f51ce80d5428c81ce1a5abfd2bd94aa3ad76d3270d1d23ef1066d191f6b6d6e7fb55f34f7d0f777e51c6dccec7782be
|
7
|
+
data.tar.gz: 13b9fd998f8d22bb8f7ce7cbc3e71521ff2c17f13d7485ef44bcdc5f6c9f7617fce9d4d2998f03e35346558585649a00155d5ac0e96d40b4ee5149155d3ea779
|
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,58 @@
|
|
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
|
+
#
|
9
|
+
# Bad:
|
10
|
+
# {data: {testId: "unique-id"}}
|
11
|
+
# {data: {test: {id: "unique-id"}}
|
12
|
+
|
13
|
+
MSG = 'View components must include a data-test-id attribute'.freeze
|
14
|
+
EMPTY_MSG = 'data-test-id attribute must not be empty'.freeze
|
15
|
+
UNIQUE_IDENTIFIER = 'data-test-id'.freeze
|
16
|
+
|
17
|
+
def on_send(node)
|
18
|
+
return unless file_exists? && valid_method_name?(node)
|
19
|
+
|
20
|
+
return add_offense(node) unless raw_content.include?(UNIQUE_IDENTIFIER)
|
21
|
+
|
22
|
+
add_offense(node, message: EMPTY_MSG) if test_id_value.strip.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def file_exists?
|
28
|
+
File.exist?(processed_source.file_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def identifiable_line
|
32
|
+
line_number = raw_content.lines.find_index { |line| line.include?(UNIQUE_IDENTIFIER) }
|
33
|
+
raw_content.lines[line_number]
|
34
|
+
end
|
35
|
+
|
36
|
+
def raw_content
|
37
|
+
@raw_content ||= File.read(processed_source.file_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def regex_for_indentifier_and_value
|
41
|
+
/#{Regexp.quote(UNIQUE_IDENTIFIER)}:\s*(["']([^"']*)["']|@\w+)/
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_id_value
|
45
|
+
match = identifiable_line.match(regex_for_indentifier_and_value)
|
46
|
+
|
47
|
+
return '' unless match
|
48
|
+
|
49
|
+
value = match[1]
|
50
|
+
value.start_with?('"', "'") ? value[1..-2] : value
|
51
|
+
end
|
52
|
+
|
53
|
+
def valid_method_name?(node)
|
54
|
+
node.method_name == :render || node.method_name == :template
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
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.3
|
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:
|