gl_rubocop 0.2.14 → 0.2.16

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: f4ff64d4fe8319c6a27df33579794a878e3abcfd76af266befae6a7df22aea31
4
- data.tar.gz: 6817379d374994edd63c8df2dc5410b923ca67b30dc29e95a36f52ef5be9883e
3
+ metadata.gz: 506bb7fe1d711020cc9b6875c92fa3171f8efb90e035eb5955039eb51d7a0937
4
+ data.tar.gz: 7a88ba78b296bca4bd143f18c91bc6ba73c34f5a9a32f8b16c92067db5716d71
5
5
  SHA512:
6
- metadata.gz: de6a83b5ffb2b2e2e5a36855b239211b8f3d78d5e1357772273767fab853eff71743466157d64422d139e161915379986d079caec6db2c26b321bed90c32a9ab
7
- data.tar.gz: 8905a71df576ee38712fed81329d91ccfd0f4e0071f20840ce1f33bc74f09919745fb57bcc6a27213fa8796a9d08f99bae4ad5270fc98c934efbd5570460d2a4
6
+ metadata.gz: 335abd0579fdf6a7db7f34e3c26c8ec550b86d18cf6dfc9a417fa5cfb7072f6bf10eacc941f406225eaa34cdd2a4685e2a6defe24abb3b8cbc85aa30a3504028
7
+ data.tar.gz: 7f8ea4867d5e773eb4c38517a21379e63862fc2e394791f1a2c9c083fac77a678e56416d302aae20dc2ce3087592f2658e1d22fec0fbc748876ffc6f09905953
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,80 @@
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
+ ALLOWED_FLASH_KEYS = %i[success info warning danger].freeze
20
+
21
+ # Matches the Rails flash hash assignment
22
+ def_node_matcher :rails_flash?, <<~PATTERN
23
+ {
24
+ (send
25
+ (send nil? :flash) :[]=
26
+ (sym $_)
27
+ _*
28
+ )
29
+ (send
30
+ (send
31
+ (send nil? :flash) :now) :[]=
32
+ (sym $_)
33
+ _*
34
+ )
35
+ }
36
+ PATTERN
37
+
38
+ def_node_matcher :alert_component_new?, <<~PATTERN
39
+ (send
40
+ (const
41
+ (const nil? :Alert) :Component) :new
42
+ (hash
43
+ (pair (sym :type) (sym $_)) _*
44
+ )
45
+ )
46
+ PATTERN
47
+
48
+ def_node_matcher :notifications_dismissible_component_new?, <<~PATTERN
49
+ (send
50
+ (const
51
+ (const
52
+ (const nil? :Notifications) :Dismissible
53
+ ) :Component
54
+ ) :new
55
+ (hash
56
+ (pair (sym :variant) (sym $_))
57
+ (...)
58
+ )
59
+ )
60
+ PATTERN
61
+
62
+ # Checks for usage of flash or flash.now with keys not in the allowlist
63
+ def on_send(node)
64
+ check_key(node, rails_flash?(node))
65
+ check_key(node, alert_component_new?(node))
66
+ check_key(node, notifications_dismissible_component_new?(node))
67
+ end
68
+
69
+ def check_key(node, key)
70
+ return false unless key
71
+ return false if ALLOWED_FLASH_KEYS.include?(key)
72
+
73
+ add_offense(
74
+ node,
75
+ message: "'#{key}' is not one of the permitted flash keys: #{ALLOWED_FLASH_KEYS}"
76
+ )
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module GLRubocop
2
- VERSION = '0.2.14'.freeze
2
+ VERSION = '0.2.16'.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.2.14
4
+ version: 0.2.16
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-04 00:00:00.000000000 Z
11
+ date: 2025-08-18 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