gl_rubocop 0.5.1 → 0.5.2
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa594b531f0d00238170541e84317172b54acf43dde2e41eede7ad26f7d20d19
|
|
4
|
+
data.tar.gz: 6f3a07046f7d082f0bcbfe6f98754350ab5966d10c97de0cbac00ad3e189f955
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6726a89cc1d5de58ecb536f729af9ac08a44735ff91e03cba605e50d59193e773644474da29e0068e4b204e169973d921f7a2f3b85b10c666850c5422f61d685
|
|
7
|
+
data.tar.gz: d9497503468a4d3ce800156293299f857ec5766bbae85887e20699aa62ed71af7d4a5aded239ca56c49c07cad272b778576086dc505013fe30c1c7941ff6cb17
|
data/default.yml
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
module GLRubocop
|
|
2
2
|
module GLCops
|
|
3
|
-
# This cop checks
|
|
3
|
+
# This cop checks naming for classes inheriting from
|
|
4
|
+
# ApplicationViewComponent or ApplicationViewComponentPreview.
|
|
4
5
|
#
|
|
5
6
|
# Good:
|
|
6
|
-
# class Component <
|
|
7
|
+
# class Component < ApplicationViewComponent
|
|
7
8
|
# end
|
|
8
9
|
#
|
|
9
|
-
# class
|
|
10
|
+
# class ComponentPreview < ApplicationViewComponentPreview
|
|
10
11
|
# end
|
|
11
12
|
#
|
|
12
13
|
# Bad:
|
|
13
|
-
# class UserCardComponent <
|
|
14
|
+
# class UserCardComponent < ApplicationViewComponent
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# class UserCardComponentPreview < ApplicationViewComponentPreview
|
|
14
18
|
# end
|
|
15
19
|
class ViewComponentClassNaming < RuboCop::Cop::Base
|
|
16
20
|
def on_class(node)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
parent_class = node.parent_class&.const_name
|
|
22
|
+
if parent_class == 'ApplicationViewComponent'
|
|
23
|
+
return true if node.identifier.const_name == 'Component'
|
|
24
|
+
|
|
25
|
+
add_offense(node, message: 'ViewComponent class names must be "Component".')
|
|
26
|
+
end
|
|
27
|
+
if parent_class == 'ApplicationViewComponentPreview'
|
|
28
|
+
return true if node.identifier.const_name == 'ComponentPreview'
|
|
20
29
|
|
|
21
|
-
|
|
30
|
+
add_offense(node, message: 'ViewComponentPreview class names must be "ComponentPreview".')
|
|
31
|
+
end
|
|
32
|
+
true
|
|
22
33
|
end
|
|
23
34
|
end
|
|
24
35
|
end
|
|
@@ -3,35 +3,62 @@ module GLRubocop
|
|
|
3
3
|
# This cop checks that all ViewComponent classes inherit from an allowlisted base class.
|
|
4
4
|
#
|
|
5
5
|
# Good:
|
|
6
|
+
# class ApplicationViewComponent < ViewComponent::Base
|
|
7
|
+
# end
|
|
8
|
+
#
|
|
9
|
+
# class ApplicationViewComponentPreview < ViewComponent::Preview
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
6
12
|
# class Components::HeroComponent < ApplicationViewComponent
|
|
7
13
|
# end
|
|
8
14
|
#
|
|
9
|
-
# class Components::
|
|
15
|
+
# class Components::CardComponentPreview < ApplicationViewComponentPreview
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# class SomeHelperClass < SomeOtherClass
|
|
10
19
|
# end
|
|
11
20
|
#
|
|
12
21
|
# Bad:
|
|
13
|
-
# class Components::HeroComponent
|
|
22
|
+
# class Components::HeroComponent
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# class Components::CardComponent < ViewComponent::Base
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# class Components::CardComponentPreview < ViewComponent::Preview
|
|
14
29
|
# end
|
|
15
30
|
#
|
|
16
|
-
# class Components::
|
|
31
|
+
# class Components::CardComponentPreview
|
|
17
32
|
# end
|
|
18
33
|
class ViewComponentInheritance < RuboCop::Cop::Base
|
|
19
|
-
|
|
34
|
+
COMPONENT_MSG = 'ViewComponents must inherit from ApplicationViewComponent'.freeze
|
|
35
|
+
PREVIEW_MSG = 'ViewComponentPreviews must inherit from ApplicationViewComponentPreview'.freeze
|
|
20
36
|
|
|
21
37
|
def on_class(node)
|
|
22
|
-
|
|
38
|
+
parent = node.parent_class&.const_name
|
|
39
|
+
class_name = node.identifier.const_name
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
if class_name.end_with?('ComponentPreview')
|
|
42
|
+
return true if component_preview_valid?(parent, class_name)
|
|
43
|
+
|
|
44
|
+
add_offense(node, message: PREVIEW_MSG)
|
|
45
|
+
elsif class_name.end_with?('Component')
|
|
46
|
+
return true if component_valid?(parent, class_name)
|
|
26
47
|
|
|
27
|
-
|
|
48
|
+
add_offense(node, message: COMPONENT_MSG)
|
|
49
|
+
else
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
28
53
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
54
|
+
def component_preview_valid?(parent, class_name)
|
|
55
|
+
class_name == 'ApplicationViewComponentPreview' ||
|
|
56
|
+
parent == 'ApplicationViewComponentPreview'
|
|
57
|
+
end
|
|
32
58
|
|
|
33
|
-
|
|
34
|
-
|
|
59
|
+
def component_valid?(parent, class_name)
|
|
60
|
+
class_name == 'ApplicationViewComponent' ||
|
|
61
|
+
parent == 'ApplicationViewComponent'
|
|
35
62
|
end
|
|
36
63
|
end
|
|
37
64
|
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.5.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Give Lively
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|