gl_rubocop 0.5.0 → 0.5.1
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 +25 -0
- data/lib/gl_rubocop/gl_cops/view_component_directory_structure.rb +33 -0
- data/lib/gl_rubocop/gl_cops/view_component_inheritance.rb +38 -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: 55c5e4d549add201fba2d9cdcf5c63b3adf2fff339785be177d2b992c841750a
|
|
4
|
+
data.tar.gz: 50d1687524ca84b65fca2ab5e8d9502446991aa69b3d0b06f9711d614393785d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ddaebd810428c15841487137a7f692a17124bd95278244422107540690858398c69667111102f9f9d43e18a5e6326eef3e95fe6e77ff5341fbcdb6844b64aef
|
|
7
|
+
data.tar.gz: dd7ad7ea6d9f11648bf103da2e743540c6709444e28f926eb6d4692d768a4ae5a6c3da37f023b5ab9f08305fb7c6c52e91a43a57ec89e69555bf716564fa5432
|
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/**/component.rb"
|
|
116
|
+
|
|
99
117
|
GLCops/ViewComponentInitializeKeywordArgs:
|
|
100
118
|
Enabled: true
|
|
101
119
|
Include:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module GLRubocop
|
|
2
|
+
module GLCops
|
|
3
|
+
# This cop checks that the class name is "Component" or "ApplicationViewComponent".
|
|
4
|
+
#
|
|
5
|
+
# Good:
|
|
6
|
+
# class Component < ViewComponent::Base
|
|
7
|
+
# end
|
|
8
|
+
#
|
|
9
|
+
# class ApplicationViewComponent < ViewComponent::Base
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# Bad:
|
|
13
|
+
# class UserCardComponent < ViewComponent::Base
|
|
14
|
+
# end
|
|
15
|
+
class ViewComponentClassNaming < RuboCop::Cop::Base
|
|
16
|
+
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'
|
|
20
|
+
|
|
21
|
+
add_offense(node, message: 'ViewComponent class names must be "Component".')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
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,38 @@
|
|
|
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 Components::HeroComponent < ApplicationViewComponent
|
|
7
|
+
# end
|
|
8
|
+
#
|
|
9
|
+
# class Components::CardComponent < ViewComponent::Base
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# Bad:
|
|
13
|
+
# class Components::HeroComponent < ViewComponent
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# class Components::CardComponent
|
|
17
|
+
# end
|
|
18
|
+
class ViewComponentInheritance < RuboCop::Cop::Base
|
|
19
|
+
INHERITANCE_MSG = 'ViewComponent must inherit from ApplicationViewComponent'.freeze
|
|
20
|
+
|
|
21
|
+
def on_class(node)
|
|
22
|
+
return true if inherits_from_application_view_component(node)
|
|
23
|
+
|
|
24
|
+
add_offense(node, message: INHERITANCE_MSG)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def inherits_from_application_view_component(node)
|
|
30
|
+
parent = node.parent_class
|
|
31
|
+
return false unless parent
|
|
32
|
+
|
|
33
|
+
parent_name = parent.const_name
|
|
34
|
+
%w[ApplicationViewComponent ViewComponent::Base].include?(parent_name)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
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.1
|
|
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-04-20 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.
|