betterlint 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/betterment/fetch_boolean.rb +61 -0
- data/lib/rubocop/cop/betterment.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65b957bbe3e091232127a01b3803411610b8968c9a2cecd0be839196c4edd66a
|
4
|
+
data.tar.gz: 66f79246845f20ab4cbb43104de461f14988831d5377ce4d2279e6c739353256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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:
|
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.
|
133
|
+
rubygems_version: 3.5.6
|
133
134
|
signing_key:
|
134
135
|
specification_version: 4
|
135
136
|
summary: Betterment rubocop configuration
|