betterlint 1.7.0 → 1.8.0

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: ec284b88f4606e1f10bb1a7e0c26794135b2f605077ac2ef472c9fff8ae1d80f
4
- data.tar.gz: 25e9df31ca75903e469dadb172847f992b2bf4005679f76cc15343850697c5c2
3
+ metadata.gz: 65b957bbe3e091232127a01b3803411610b8968c9a2cecd0be839196c4edd66a
4
+ data.tar.gz: 66f79246845f20ab4cbb43104de461f14988831d5377ce4d2279e6c739353256
5
5
  SHA512:
6
- metadata.gz: 56be31837c8216b387b4ad5baa0fb4362152354bb5b5c71ccd95f2cf49d58da5c3499f6765a3509b8773b585bd6a0df22d4092dbeefb2152011ec095520a2293
7
- data.tar.gz: c0b3a8a0fde1eae38420afe105cba2a5f9b3ac9d5704695c45337a6ba78ddcd04b8642ba701d610ea2434fb3814459fc810e9e877839c06bb69194bbfabaa564
6
+ metadata.gz: 7c4e37ddc5f6285ea890fa8a06ff8a46564801fe182ab215e6a43af7977f69166be914f52f379d11a1166d8ab3b0dd1b155a60f9d708ac387016f59c1aa82935
7
+ data.tar.gz: 746e680bf2720c96e826fe1d9299169e7334cacafb367b820008cee18cdd1b3626e7cb37a6b2fd356134d549187e37b8e50db969c0510f19720557491a4c2a95
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Betterment
6
+ class FetchBoolean < Base
7
+ MSG = <<~MSG
8
+ A boolean fetched from query params or ENV will never be false when
9
+ explicitly specified on the request or env var. Please use a model
10
+ with a boolean attribute, or cast the value.
11
+ MSG
12
+
13
+ # @!method fetch_boolean?(node)
14
+ def_node_matcher :fetch_boolean?, <<-PATTERN
15
+ (send _ :fetch _ (boolean))
16
+ PATTERN
17
+
18
+ # @!method fetch_env_boolean?(node)
19
+ def_node_matcher :fetch_env_boolean?, <<-PATTERN
20
+ (send (const nil? :ENV) :fetch _ (boolean))
21
+ PATTERN
22
+
23
+ # @!method boolean_cast?(node)
24
+ def_node_search :boolean_cast?, <<-PATTERN
25
+ (send
26
+ (send
27
+ (const
28
+ (const
29
+ (const nil? :ActiveModel) :Type) :Boolean) :new) :cast
30
+ ...)
31
+ PATTERN
32
+
33
+ # @!method action_controller?(node)
34
+ def_node_search :action_controller?, <<~PATTERN
35
+ {
36
+ (const {nil? cbase} :ApplicationController)
37
+ (const (const {nil? cbase} :ActionController) :Base)
38
+ }
39
+ PATTERN
40
+
41
+ def on_send(node)
42
+ return unless fetch_env_boolean?(node) ||
43
+ (fetch_boolean?(node) && inherit_action_controller_base?(node))
44
+
45
+ return if node.each_ancestor(:send).any? { |ancestor| boolean_cast?(ancestor) }
46
+
47
+ add_offense(node)
48
+ end
49
+
50
+ private
51
+
52
+ def inherit_action_controller_base?(node)
53
+ class_node = node.each_ancestor(:class).first
54
+ return false unless class_node
55
+
56
+ action_controller?(class_node)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -19,3 +19,4 @@ require 'rubocop/cop/betterment/allowlist_blocklist'
19
19
  require 'rubocop/cop/betterment/server_error_assertion'
20
20
  require 'rubocop/cop/betterment/hardcoded_id'
21
21
  require 'rubocop/cop/betterment/vague_serialize'
22
+ require 'rubocop/cop/betterment/fetch_boolean'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-18 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -95,6 +95,7 @@ files:
95
95
  - lib/rubocop/cop/betterment/allowlist_blocklist.rb
96
96
  - lib/rubocop/cop/betterment/authorization_in_controller.rb
97
97
  - lib/rubocop/cop/betterment/dynamic_params.rb
98
+ - lib/rubocop/cop/betterment/fetch_boolean.rb
98
99
  - lib/rubocop/cop/betterment/hardcoded_id.rb
99
100
  - lib/rubocop/cop/betterment/implicit_redirect_type.rb
100
101
  - lib/rubocop/cop/betterment/memoization_with_arguments.rb
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubygems_version: 3.4.22
133
+ rubygems_version: 3.5.6
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: Betterment rubocop configuration