gl_rubocop 0.5.1 → 0.5.3
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: 1047a8465eb718c62b4582a7c18f339e17acb15bf0861c60460d21f2f1d74a65
|
|
4
|
+
data.tar.gz: c85258ff5eb9526fc05b9eb6d8dd15aa8b63f94fe868ed434356259080153fc8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39d62d81dfbb69a9e213efb8df7f02486906849e9218572d3a48a76758715e3f598c14bbbcce9abfd483edc96f32f8d9dcb2167c44085774bd3e71573ac552a9
|
|
7
|
+
data.tar.gz: c32264166f4d1ba98cd73606541671718308de01b47e38c9b08cc59d9aa4496f1ea9a33385807e1aabe9a129e2c920e0433266107588028ad038c98b83e595af
|
data/default.yml
CHANGED
|
@@ -12,6 +12,7 @@ require:
|
|
|
12
12
|
- ./lib/gl_rubocop/gl_cops/consolidate_request_system_specs.rb
|
|
13
13
|
- ./lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
|
14
14
|
- ./lib/gl_rubocop/gl_cops/limit_flash_options.rb
|
|
15
|
+
- ./lib/gl_rubocop/gl_cops/no_stubbing_env.rb
|
|
15
16
|
- ./lib/gl_rubocop/gl_cops/no_stubbing_perform_async.rb
|
|
16
17
|
- ./lib/gl_rubocop/gl_cops/prevent_haml_files.rb
|
|
17
18
|
- ./lib/gl_rubocop/gl_cops/rails_cache.rb
|
|
@@ -62,6 +63,11 @@ GLCops/InteractorInheritsFromInteractorBase:
|
|
|
62
63
|
GLCops/LimitFlashOptions:
|
|
63
64
|
Enabled: true
|
|
64
65
|
|
|
66
|
+
GLCops/NoStubbingEnv:
|
|
67
|
+
Enabled: true
|
|
68
|
+
Include:
|
|
69
|
+
- "**/*spec.rb"
|
|
70
|
+
|
|
65
71
|
GLCops/NoStubbingPerformAsync:
|
|
66
72
|
Enabled: true
|
|
67
73
|
Include:
|
|
@@ -112,7 +118,7 @@ GLCops/ViewComponentDirectoryStructure:
|
|
|
112
118
|
GLCops/ViewComponentInheritance:
|
|
113
119
|
Enabled: true
|
|
114
120
|
Include:
|
|
115
|
-
- "app/components
|
|
121
|
+
- "app/components/**/*.rb"
|
|
116
122
|
|
|
117
123
|
GLCops/ViewComponentInitializeKeywordArgs:
|
|
118
124
|
Enabled: true
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module GLRubocop
|
|
2
|
+
module GLCops
|
|
3
|
+
# This cop ensures that you don't stub ENV with `allow`/`expect` + `receive`.
|
|
4
|
+
#
|
|
5
|
+
# Stubbing ENV this way (even with `and_call_original`) only stubs the env vars the
|
|
6
|
+
# spec explicitly knows about. Any var that is read but not stubbed - for example a
|
|
7
|
+
# var that is present on CI but not locally, or vice versa - behaves inconsistently
|
|
8
|
+
# and causes flaky failures.
|
|
9
|
+
#
|
|
10
|
+
# Instead, replace ENV wholesale with `stub_const`, building the hash from the real
|
|
11
|
+
# ENV so unrelated vars keep working everywhere:
|
|
12
|
+
#
|
|
13
|
+
# Good:
|
|
14
|
+
# stub_const('ENV', ENV.to_hash.except('VAR_TO_UNSET').merge('VAR_TO_SET' => 'value'))
|
|
15
|
+
#
|
|
16
|
+
# Bad:
|
|
17
|
+
# allow(ENV).to receive(:[]).and_call_original
|
|
18
|
+
# allow(ENV).to receive(:[]).with('VAR_TO_SET').and_return('value')
|
|
19
|
+
# expect(ENV).to receive(:fetch)
|
|
20
|
+
class NoStubbingEnv < RuboCop::Cop::Base
|
|
21
|
+
MSG = "Don't stub ENV with allow/expect + receive. Use " \
|
|
22
|
+
"stub_const('ENV', ENV.to_hash.except('VAR_TO_UNSET')." \
|
|
23
|
+
"merge('VAR_TO_SET' => 'value')) instead, so unrelated ENV vars " \
|
|
24
|
+
'(e.g. on CI) keep working.'.freeze
|
|
25
|
+
|
|
26
|
+
# Match `allow(ENV).to receive(...)` / `expect(ENV).not_to receive(...)`, including
|
|
27
|
+
# chained forms like `.and_call_original`, `.and_return(...)`, `.with(...)`.
|
|
28
|
+
def_node_matcher :stubbing_env?, <<~PATTERN
|
|
29
|
+
(send
|
|
30
|
+
(send nil? {:allow :expect} (const {nil? cbase} :ENV))
|
|
31
|
+
{:to :not_to :to_not}
|
|
32
|
+
`(send nil? :receive ...))
|
|
33
|
+
PATTERN
|
|
34
|
+
|
|
35
|
+
def on_send(node)
|
|
36
|
+
return unless stubbing_env?(node)
|
|
37
|
+
|
|
38
|
+
add_offense(node)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -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.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: 2026-
|
|
11
|
+
date: 2026-05-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|
|
@@ -166,6 +166,7 @@ files:
|
|
|
166
166
|
- lib/gl_rubocop/gl_cops/consolidate_request_system_specs.rb
|
|
167
167
|
- lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
|
168
168
|
- lib/gl_rubocop/gl_cops/limit_flash_options.rb
|
|
169
|
+
- lib/gl_rubocop/gl_cops/no_stubbing_env.rb
|
|
169
170
|
- lib/gl_rubocop/gl_cops/no_stubbing_perform_async.rb
|
|
170
171
|
- lib/gl_rubocop/gl_cops/prevent_haml_files.rb
|
|
171
172
|
- lib/gl_rubocop/gl_cops/rails_cache.rb
|
|
@@ -201,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
201
202
|
- !ruby/object:Gem::Version
|
|
202
203
|
version: '0'
|
|
203
204
|
requirements: []
|
|
204
|
-
rubygems_version: 3.
|
|
205
|
+
rubygems_version: 3.5.22
|
|
205
206
|
signing_key:
|
|
206
207
|
specification_version: 4
|
|
207
208
|
summary: A shareable configuration of Give Lively's rubocop rules.
|