gl_rubocop 0.5.0 → 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 +4 -4
- data/default.yml +18 -0
- data/lib/gl_rubocop/gl_cops/view_component_class_naming.rb +36 -0
- data/lib/gl_rubocop/gl_cops/view_component_directory_structure.rb +33 -0
- data/lib/gl_rubocop/gl_cops/view_component_inheritance.rb +65 -0
- data/lib/gl_rubocop/version.rb +1 -1
- metadata +6 -3
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
|
@@ -21,6 +21,9 @@ require:
|
|
|
21
21
|
- ./lib/gl_rubocop/gl_cops/valid_data_test_id.rb
|
|
22
22
|
- ./lib/gl_rubocop/gl_cops/vcr_cassette_names.rb
|
|
23
23
|
- ./lib/gl_rubocop/gl_cops/view_component_initialize_keyword_args.rb
|
|
24
|
+
- ./lib/gl_rubocop/gl_cops/view_component_class_naming.rb
|
|
25
|
+
- ./lib/gl_rubocop/gl_cops/view_component_inheritance.rb
|
|
26
|
+
- ./lib/gl_rubocop/gl_cops/view_component_directory_structure.rb
|
|
24
27
|
|
|
25
28
|
AllCops:
|
|
26
29
|
SuggestExtensions: false
|
|
@@ -96,6 +99,21 @@ GLCops/VcrCassetteNames:
|
|
|
96
99
|
Include:
|
|
97
100
|
- "**/*spec.rb"
|
|
98
101
|
|
|
102
|
+
GLCops/ViewComponentClassNaming:
|
|
103
|
+
Enabled: true
|
|
104
|
+
Include:
|
|
105
|
+
- "app/components/**/*.rb"
|
|
106
|
+
|
|
107
|
+
GLCops/ViewComponentDirectoryStructure:
|
|
108
|
+
Enabled: true
|
|
109
|
+
Include:
|
|
110
|
+
- "app/components/**/component.rb"
|
|
111
|
+
|
|
112
|
+
GLCops/ViewComponentInheritance:
|
|
113
|
+
Enabled: true
|
|
114
|
+
Include:
|
|
115
|
+
- "app/components/**/*.rb"
|
|
116
|
+
|
|
99
117
|
GLCops/ViewComponentInitializeKeywordArgs:
|
|
100
118
|
Enabled: true
|
|
101
119
|
Include:
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module GLRubocop
|
|
2
|
+
module GLCops
|
|
3
|
+
# This cop checks naming for classes inheriting from
|
|
4
|
+
# ApplicationViewComponent or ApplicationViewComponentPreview.
|
|
5
|
+
#
|
|
6
|
+
# Good:
|
|
7
|
+
# class Component < ApplicationViewComponent
|
|
8
|
+
# end
|
|
9
|
+
#
|
|
10
|
+
# class ComponentPreview < ApplicationViewComponentPreview
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# Bad:
|
|
14
|
+
# class UserCardComponent < ApplicationViewComponent
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# class UserCardComponentPreview < ApplicationViewComponentPreview
|
|
18
|
+
# end
|
|
19
|
+
class ViewComponentClassNaming < RuboCop::Cop::Base
|
|
20
|
+
def on_class(node)
|
|
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'
|
|
29
|
+
|
|
30
|
+
add_offense(node, message: 'ViewComponentPreview class names must be "ComponentPreview".')
|
|
31
|
+
end
|
|
32
|
+
true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module GLRubocop
|
|
2
|
+
module GLCops
|
|
3
|
+
# This cop checks that all ViewComponent is part of an allowlisted base module.
|
|
4
|
+
#
|
|
5
|
+
# Good:
|
|
6
|
+
# module Core
|
|
7
|
+
# module Users
|
|
8
|
+
# class Component < ApplicationViewComponent
|
|
9
|
+
# end
|
|
10
|
+
# end
|
|
11
|
+
# end
|
|
12
|
+
#
|
|
13
|
+
# Bad:
|
|
14
|
+
# module Billing
|
|
15
|
+
# class Component < ApplicationViewComponent
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
class ViewComponentDirectoryStructure < RuboCop::Cop::Base
|
|
19
|
+
MSG = 'ViewComponent must belong to an allowed base module: %<allowed>s'.freeze
|
|
20
|
+
ALLOWED_MODULES = %w[Core Admin NonprofitAdmin Packs Users].freeze
|
|
21
|
+
|
|
22
|
+
def on_class(node)
|
|
23
|
+
return true if node.identifier.const_name == 'ApplicationViewComponent'
|
|
24
|
+
|
|
25
|
+
base_module = node.parent_module_name&.split('::')&.first
|
|
26
|
+
return true if base_module.nil?
|
|
27
|
+
return true if ALLOWED_MODULES.include?(base_module)
|
|
28
|
+
|
|
29
|
+
add_offense(node, message: format(MSG, allowed: ALLOWED_MODULES.join(', ')))
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module GLRubocop
|
|
2
|
+
module GLCops
|
|
3
|
+
# This cop checks that all ViewComponent classes inherit from an allowlisted base class.
|
|
4
|
+
#
|
|
5
|
+
# Good:
|
|
6
|
+
# class ApplicationViewComponent < ViewComponent::Base
|
|
7
|
+
# end
|
|
8
|
+
#
|
|
9
|
+
# class ApplicationViewComponentPreview < ViewComponent::Preview
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# class Components::HeroComponent < ApplicationViewComponent
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# class Components::CardComponentPreview < ApplicationViewComponentPreview
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# class SomeHelperClass < SomeOtherClass
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# Bad:
|
|
22
|
+
# class Components::HeroComponent
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# class Components::CardComponent < ViewComponent::Base
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# class Components::CardComponentPreview < ViewComponent::Preview
|
|
29
|
+
# end
|
|
30
|
+
#
|
|
31
|
+
# class Components::CardComponentPreview
|
|
32
|
+
# end
|
|
33
|
+
class ViewComponentInheritance < RuboCop::Cop::Base
|
|
34
|
+
COMPONENT_MSG = 'ViewComponents must inherit from ApplicationViewComponent'.freeze
|
|
35
|
+
PREVIEW_MSG = 'ViewComponentPreviews must inherit from ApplicationViewComponentPreview'.freeze
|
|
36
|
+
|
|
37
|
+
def on_class(node)
|
|
38
|
+
parent = node.parent_class&.const_name
|
|
39
|
+
class_name = node.identifier.const_name
|
|
40
|
+
|
|
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)
|
|
47
|
+
|
|
48
|
+
add_offense(node, message: COMPONENT_MSG)
|
|
49
|
+
else
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def component_preview_valid?(parent, class_name)
|
|
55
|
+
class_name == 'ApplicationViewComponentPreview' ||
|
|
56
|
+
parent == 'ApplicationViewComponentPreview'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def component_valid?(parent, class_name)
|
|
60
|
+
class_name == 'ApplicationViewComponent' ||
|
|
61
|
+
parent == 'ApplicationViewComponent'
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
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
|
|
@@ -174,6 +174,9 @@ files:
|
|
|
174
174
|
- lib/gl_rubocop/gl_cops/unique_identifier.rb
|
|
175
175
|
- lib/gl_rubocop/gl_cops/valid_data_test_id.rb
|
|
176
176
|
- lib/gl_rubocop/gl_cops/vcr_cassette_names.rb
|
|
177
|
+
- lib/gl_rubocop/gl_cops/view_component_class_naming.rb
|
|
178
|
+
- lib/gl_rubocop/gl_cops/view_component_directory_structure.rb
|
|
179
|
+
- lib/gl_rubocop/gl_cops/view_component_inheritance.rb
|
|
177
180
|
- lib/gl_rubocop/gl_cops/view_component_initialize_keyword_args.rb
|
|
178
181
|
- lib/gl_rubocop/helpers/erb_content_helper.rb
|
|
179
182
|
- lib/gl_rubocop/helpers/haml_content_helper.rb
|
|
@@ -198,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
198
201
|
- !ruby/object:Gem::Version
|
|
199
202
|
version: '0'
|
|
200
203
|
requirements: []
|
|
201
|
-
rubygems_version: 3.
|
|
204
|
+
rubygems_version: 3.3.26
|
|
202
205
|
signing_key:
|
|
203
206
|
specification_version: 4
|
|
204
207
|
summary: A shareable configuration of Give Lively's rubocop rules.
|