gl_rubocop 0.2.13 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b577c0d013512c5d8ba1aceb36e2fd627b253c81712043fc34fc0ceead445fe2
4
- data.tar.gz: 58eb42711279ba3c0f36f9809e57fcd1ed9d178cf764c8f1367d4f74c486f80b
3
+ metadata.gz: b30fd98a7f750b5929387d4b241f9c3105cfce56b9e6f9de1f51668c3c8a094c
4
+ data.tar.gz: ca04a1801385c3967576191fd524a39a45155028c0cc54bac6221f6b607fe691
5
5
  SHA512:
6
- metadata.gz: 400902b6f175f59a4fb56a18edf45a6d216787221d6355d3d054cb1b96694607be98d8b5a522964b4e816358b819532e6735bf76c47d2aeeb517ec251f7d0dfc
7
- data.tar.gz: 593697de8795b407b31c5789db03ceee26b8bf7de461f3e9db6e09b6101f4880bd0f9ea882cf9fb861aa34c61e19e67b643fcfccdd4971e84e94febd3ccd8bc7
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
 
@@ -68,6 +72,7 @@ Layout/ClassStructure:
68
72
  Layout/LineLength:
69
73
  AllowedPatterns:
70
74
  - "^ *#" # Ignores full lines starting with any indentation and a comment (#)
75
+ - "^\\s*['\"].*['\"]\\s*$" # ignores lines that are string literals
71
76
  Max: 100
72
77
 
73
78
  Lint/MissingSuper:
@@ -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
@@ -1,3 +1,3 @@
1
1
  module GLRubocop
2
- VERSION = '0.2.13'.freeze
2
+ VERSION = '0.2.15'.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.13
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-07-24 00:00:00.000000000 Z
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