gl_rubocop 0.2.14 → 0.2.15
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 +4 -0
- data/lib/gl_rubocop/gl_cops/limit_flash_options.rb +81 -0
- data/lib/gl_rubocop/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b30fd98a7f750b5929387d4b241f9c3105cfce56b9e6f9de1f51668c3c8a094c
|
4
|
+
data.tar.gz: ca04a1801385c3967576191fd524a39a45155028c0cc54bac6221f6b607fe691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5a4b2c4768adf655531073ad7dd87477f3c1b005c8728cf9690526fd9d8b3fae766a6ce0166a2343dfe1e80026bc3316bd32e9fa39ce738d8ba91780f533b23
|
7
|
+
data.tar.gz: 92b84460fed08c5a9337b6b551f37068b1fdd411a0e9281ed99c362f96e80a5305a5187038eaef5af5b713ce3894d027219381654bf2b44522bcf3ed9a42c211
|
data/default.yml
CHANGED
@@ -8,6 +8,7 @@ require:
|
|
8
8
|
- rubocop-sorbet
|
9
9
|
- ./lib/gl_rubocop/gl_cops/callback_method_names.rb
|
10
10
|
- ./lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
11
|
+
- ./lib/gl_rubocop/gl_cops/limit_flash_options.rb
|
11
12
|
- ./lib/gl_rubocop/gl_cops/no_stubbing_perform_async.rb
|
12
13
|
- ./lib/gl_rubocop/gl_cops/prevent_erb_files.rb
|
13
14
|
- ./lib/gl_rubocop/gl_cops/rails_cache.rb
|
@@ -43,6 +44,9 @@ GLCops/InteractorInheritsFromInteractorBase:
|
|
43
44
|
Include:
|
44
45
|
- "app/interactors/**/*"
|
45
46
|
|
47
|
+
GLCops/LimitFlashOptions:
|
48
|
+
Enabled: true
|
49
|
+
|
46
50
|
GLCops/NoStubbingPerformAsync:
|
47
51
|
Enabled: true
|
48
52
|
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GLRubocop
|
4
|
+
module GLCops
|
5
|
+
class LimitFlashOptions < RuboCop::Cop::Base
|
6
|
+
# This cop ensures that the use of any of our notification methods only accept the allowed keys for type
|
7
|
+
# and variant.
|
8
|
+
# Good:
|
9
|
+
# flash[:success] = "Operation successful"
|
10
|
+
# flash.now[:info] = "This is an info message"
|
11
|
+
# Alert::Component.new(type: :success, message: "Success")
|
12
|
+
# Notifications::Dismissible::Component.new(variant: :info, message: "Info")
|
13
|
+
|
14
|
+
# Bad:
|
15
|
+
# flash[:error] = "Not allowed"
|
16
|
+
# flash.now[:anything_else] = "Not allowed"
|
17
|
+
# Alert::Component.new(type: :notice, message: "Error")
|
18
|
+
# Notifications::Dismissible::Component.new(variant: :blue_box, message: "Error")
|
19
|
+
|
20
|
+
MSG = 'This cop checks for the use of flash options not in the allowlist. ' \
|
21
|
+
'Please limit flash options to those defined in the application configuration.'
|
22
|
+
|
23
|
+
ALLOWED_FLASH_KEYS = %i[success info warning danger].freeze
|
24
|
+
|
25
|
+
# Matches the Rails flash hash assignment
|
26
|
+
def_node_matcher :rails_flash?, <<~PATTERN
|
27
|
+
{
|
28
|
+
(send
|
29
|
+
(send nil? :flash) :[]=
|
30
|
+
(sym $_)
|
31
|
+
_*
|
32
|
+
)
|
33
|
+
(send
|
34
|
+
(send
|
35
|
+
(send nil? :flash) :now) :[]=
|
36
|
+
(sym $_)
|
37
|
+
_*
|
38
|
+
)
|
39
|
+
}
|
40
|
+
PATTERN
|
41
|
+
|
42
|
+
def_node_matcher :alert_component_new?, <<~PATTERN
|
43
|
+
(send
|
44
|
+
(const
|
45
|
+
(const nil? :Alert) :Component) :new
|
46
|
+
(hash
|
47
|
+
(pair (sym :type) (sym $_)) _*
|
48
|
+
)
|
49
|
+
)
|
50
|
+
PATTERN
|
51
|
+
|
52
|
+
def_node_matcher :notifications_dismissible_component_new?, <<~PATTERN
|
53
|
+
(send
|
54
|
+
(const
|
55
|
+
(const
|
56
|
+
(const nil? :Notifications) :Dismissible
|
57
|
+
) :Component
|
58
|
+
) :new
|
59
|
+
(hash
|
60
|
+
(pair (sym :variant) (sym $_))
|
61
|
+
(...)
|
62
|
+
)
|
63
|
+
)
|
64
|
+
PATTERN
|
65
|
+
|
66
|
+
# Checks for usage of flash or flash.now with keys not in the allowlist
|
67
|
+
def on_send(node)
|
68
|
+
check_key(node, rails_flash?(node))
|
69
|
+
check_key(node, alert_component_new?(node))
|
70
|
+
check_key(node, notifications_dismissible_component_new?(node))
|
71
|
+
end
|
72
|
+
|
73
|
+
def check_key(node, key)
|
74
|
+
return false unless key
|
75
|
+
return false if ALLOWED_FLASH_KEYS.include?(key)
|
76
|
+
|
77
|
+
add_offense(node, message: MSG)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
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.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Give Lively
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-08-
|
11
|
+
date: 2025-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/gl_rubocop.rb
|
137
137
|
- lib/gl_rubocop/gl_cops/callback_method_names.rb
|
138
138
|
- lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
139
|
+
- lib/gl_rubocop/gl_cops/limit_flash_options.rb
|
139
140
|
- lib/gl_rubocop/gl_cops/no_stubbing_perform_async.rb
|
140
141
|
- lib/gl_rubocop/gl_cops/prevent_erb_files.rb
|
141
142
|
- lib/gl_rubocop/gl_cops/rails_cache.rb
|