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: 55c5e4d549add201fba2d9cdcf5c63b3adf2fff339785be177d2b992c841750a
4
- data.tar.gz: 50d1687524ca84b65fca2ab5e8d9502446991aa69b3d0b06f9711d614393785d
3
+ metadata.gz: fa594b531f0d00238170541e84317172b54acf43dde2e41eede7ad26f7d20d19
4
+ data.tar.gz: 6f3a07046f7d082f0bcbfe6f98754350ab5966d10c97de0cbac00ad3e189f955
5
5
  SHA512:
6
- metadata.gz: 3ddaebd810428c15841487137a7f692a17124bd95278244422107540690858398c69667111102f9f9d43e18a5e6326eef3e95fe6e77ff5341fbcdb6844b64aef
7
- data.tar.gz: dd7ad7ea6d9f11648bf103da2e743540c6709444e28f926eb6d4692d768a4ae5a6c3da37f023b5ab9f08305fb7c6c52e91a43a57ec89e69555bf716564fa5432
6
+ metadata.gz: 6726a89cc1d5de58ecb536f729af9ac08a44735ff91e03cba605e50d59193e773644474da29e0068e4b204e169973d921f7a2f3b85b10c666850c5422f61d685
7
+ data.tar.gz: d9497503468a4d3ce800156293299f857ec5766bbae85887e20699aa62ed71af7d4a5aded239ca56c49c07cad272b778576086dc505013fe30c1c7941ff6cb17
data/default.yml CHANGED
@@ -112,7 +112,7 @@ GLCops/ViewComponentDirectoryStructure:
112
112
  GLCops/ViewComponentInheritance:
113
113
  Enabled: true
114
114
  Include:
115
- - "app/components/**/component.rb"
115
+ - "app/components/**/*.rb"
116
116
 
117
117
  GLCops/ViewComponentInitializeKeywordArgs:
118
118
  Enabled: true
@@ -1,24 +1,35 @@
1
1
  module GLRubocop
2
2
  module GLCops
3
- # This cop checks that the class name is "Component" or "ApplicationViewComponent".
3
+ # This cop checks naming for classes inheriting from
4
+ # ApplicationViewComponent or ApplicationViewComponentPreview.
4
5
  #
5
6
  # Good:
6
- # class Component < ViewComponent::Base
7
+ # class Component < ApplicationViewComponent
7
8
  # end
8
9
  #
9
- # class ApplicationViewComponent < ViewComponent::Base
10
+ # class ComponentPreview < ApplicationViewComponentPreview
10
11
  # end
11
12
  #
12
13
  # Bad:
13
- # class UserCardComponent < ViewComponent::Base
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
- class_name = node.identifier.const_name
18
- return true if class_name == 'Component'
19
- return true if class_name == 'ApplicationViewComponent'
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
- add_offense(node, message: 'ViewComponent class names must be "Component".')
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::CardComponent < ViewComponent::Base
15
+ # class Components::CardComponentPreview < ApplicationViewComponentPreview
16
+ # end
17
+ #
18
+ # class SomeHelperClass < SomeOtherClass
10
19
  # end
11
20
  #
12
21
  # Bad:
13
- # class Components::HeroComponent < ViewComponent
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::CardComponent
31
+ # class Components::CardComponentPreview
17
32
  # end
18
33
  class ViewComponentInheritance < RuboCop::Cop::Base
19
- INHERITANCE_MSG = 'ViewComponent must inherit from ApplicationViewComponent'.freeze
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
- return true if inherits_from_application_view_component(node)
38
+ parent = node.parent_class&.const_name
39
+ class_name = node.identifier.const_name
23
40
 
24
- add_offense(node, message: INHERITANCE_MSG)
25
- end
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
- private
48
+ add_offense(node, message: COMPONENT_MSG)
49
+ else
50
+ true
51
+ end
52
+ end
28
53
 
29
- def inherits_from_application_view_component(node)
30
- parent = node.parent_class
31
- return false unless parent
54
+ def component_preview_valid?(parent, class_name)
55
+ class_name == 'ApplicationViewComponentPreview' ||
56
+ parent == 'ApplicationViewComponentPreview'
57
+ end
32
58
 
33
- parent_name = parent.const_name
34
- %w[ApplicationViewComponent ViewComponent::Base].include?(parent_name)
59
+ def component_valid?(parent, class_name)
60
+ class_name == 'ApplicationViewComponent' ||
61
+ parent == 'ApplicationViewComponent'
35
62
  end
36
63
  end
37
64
  end
@@ -1,3 +1,3 @@
1
1
  module GLRubocop
2
- VERSION = '0.5.1'.freeze
2
+ VERSION = '0.5.2'.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.5.1
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-04-20 00:00:00.000000000 Z
11
+ date: 2026-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop