betterlint 1.6.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:
|
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
|
data/config/default.yml
CHANGED
@@ -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
|
@@ -21,6 +21,7 @@ module RuboCop
|
|
21
21
|
MSG
|
22
22
|
METHOD_PATTERN = /^find_by_(.+?)(!)?$/
|
23
23
|
FINDS = %i(find find_by find_by! where).freeze
|
24
|
+
GRAPHQL_PATTERN = /\bGraphQL\b/i
|
24
25
|
|
25
26
|
def_node_matcher :custom_scope_find?, <<-PATTERN
|
26
27
|
(send (send (const ... _) ...) {#{FINDS.map(&:inspect).join(' ')}} ...)
|
@@ -30,6 +31,10 @@ module RuboCop
|
|
30
31
|
(send (const ... _) {#{FINDS.map(&:inspect).join(' ')}} ...)
|
31
32
|
PATTERN
|
32
33
|
|
34
|
+
def_node_search :find_graphql_namespace_nodes, <<~PATTERN, name: GRAPHQL_PATTERN
|
35
|
+
(const _ %name)
|
36
|
+
PATTERN
|
37
|
+
|
33
38
|
def initialize(config = nil, options = nil)
|
34
39
|
super(config, options)
|
35
40
|
config = @config.for_cop(self)
|
@@ -44,16 +49,26 @@ module RuboCop
|
|
44
49
|
_, _, *arg_nodes = *node # rubocop:disable InternalAffairs/NodeDestructuring
|
45
50
|
return unless
|
46
51
|
(
|
47
|
-
|
48
|
-
|
49
|
-
|
52
|
+
find?(node) ||
|
53
|
+
custom_scope_find?(node) ||
|
54
|
+
static_method_name(node.method_name)
|
50
55
|
) && !@unauthenticated_models.include?(Utils::Parser.get_root_token(node))
|
51
56
|
|
52
|
-
add_offense(node) if find_param_arg(arg_nodes)
|
57
|
+
add_offense(node) if find_param_arg(arg_nodes) || graphql_file? || graphql_namespace?(node)
|
53
58
|
end
|
54
59
|
|
55
60
|
private
|
56
61
|
|
62
|
+
def graphql_file?
|
63
|
+
processed_source.path&.match?(GRAPHQL_PATTERN)
|
64
|
+
end
|
65
|
+
|
66
|
+
def graphql_namespace?(node)
|
67
|
+
node
|
68
|
+
.each_ancestor(:class, :module)
|
69
|
+
.any? { |ancestor| find_graphql_namespace_nodes(ancestor).any? }
|
70
|
+
end
|
71
|
+
|
57
72
|
def find_param_arg(arg_nodes)
|
58
73
|
return unless arg_nodes
|
59
74
|
|
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
|