betterlint 1.24.0 → 1.25.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 +4 -4
- data/lib/rubocop/cop/betterment/authorization_in_controller.rb +24 -11
- data/lib/rubocop/cop/betterment/unscoped_find.rb +13 -4
- data/lib/rubocop/cop/betterment/utils/parser.rb +20 -3
- data/lib/rubocop/cop/betterment.rb +0 -1
- metadata +4 -5
- data/lib/rubocop/cop/betterment/utils/method_return_table.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04c560ef56ed92b4393449c238d64d433b16caa1db01dbcb81c647c04f9931d6
|
4
|
+
data.tar.gz: bac5e05a6ec457e6c047eba8c1d709549167ceae3b408fa084c5aa83c9594676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57bf6d2446f5ec19e463e3bad15bb22934b08104a7614f08b1f67291bd8243ef7c1fdbccd7d8259f8b7b69c10f995248561c2e2cecf032c2bac01df2fd074aba
|
7
|
+
data.tar.gz: f2cee92d7b16ba483562f7bb1ebf822ff186e106cbf1df9f3f026f013f801a2f4f9fb01737e50b3e8bbfe83f4ee26af1b44614e35a48cf65028e7d3f6afb1dd2
|
@@ -37,17 +37,17 @@ module RuboCop
|
|
37
37
|
super
|
38
38
|
@unsafe_parameters = cop_config.fetch("unsafe_parameters").map(&:to_sym)
|
39
39
|
@unsafe_regex = Regexp.new cop_config.fetch("unsafe_regex")
|
40
|
-
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_new_investigation
|
43
|
+
super
|
44
|
+
@class_methods = {}.freeze
|
45
|
+
@param_wrappers = [].freeze
|
41
46
|
end
|
42
47
|
|
43
48
|
def on_class(node)
|
44
|
-
Utils::
|
45
|
-
|
46
|
-
method_returns.each do |x|
|
47
|
-
name = Utils::Parser.get_root_token(x)
|
48
|
-
@param_wrappers << method_name if name == :params || @param_wrappers.include?(name)
|
49
|
-
end
|
50
|
-
end
|
49
|
+
@class_methods = Utils::Parser.get_instance_methods(node).freeze
|
50
|
+
@param_wrappers = find_param_wrappers(@class_methods).freeze
|
51
51
|
end
|
52
52
|
|
53
53
|
def on_send(node) # rubocop:disable Metrics/PerceivedComplexity
|
@@ -88,7 +88,7 @@ module RuboCop
|
|
88
88
|
|
89
89
|
# Flags objects being created/updated with unsafe
|
90
90
|
# params indirectly from params or through params.permit
|
91
|
-
def flag_indirect_param_use(node) # rubocop:disable Metrics/PerceivedComplexity
|
91
|
+
def flag_indirect_param_use(node) # rubocop:disable Metrics/PerceivedComplexity
|
92
92
|
name = Utils::Parser.get_root_token(node)
|
93
93
|
# extracted_params contains parameters used like:
|
94
94
|
# def create
|
@@ -99,7 +99,7 @@ module RuboCop
|
|
99
99
|
# end
|
100
100
|
extracted_params = Utils::Parser.get_extracted_parameters(node, param_aliases: @param_wrappers)
|
101
101
|
|
102
|
-
returns =
|
102
|
+
returns = get_method_returns(name)
|
103
103
|
returns.each do |ret|
|
104
104
|
# # propagated_params contains parameters used like:
|
105
105
|
# def create
|
@@ -120,7 +120,7 @@ module RuboCop
|
|
120
120
|
if ret.send_type? && ret.method?(:[])
|
121
121
|
internal_params = ret.arguments.select { |x| x.sym_type? || x.str_type? }.map(&:value)
|
122
122
|
else
|
123
|
-
internal_returns =
|
123
|
+
internal_returns = get_method_returns(Utils::Parser.get_root_token(ret))
|
124
124
|
internal_params = internal_returns.flat_map { |x| Utils::Parser.get_extracted_parameters(x, param_aliases: @param_wrappers) }
|
125
125
|
end
|
126
126
|
|
@@ -144,6 +144,19 @@ module RuboCop
|
|
144
144
|
def suspicious_id?(symbol_name)
|
145
145
|
@unsafe_parameters.include?(symbol_name.to_sym) || @unsafe_regex.match(symbol_name) # symbol_name.to_s.end_with?("_id")
|
146
146
|
end
|
147
|
+
|
148
|
+
def find_param_wrappers(class_methods)
|
149
|
+
class_methods.each_with_object([]) do |(method_name, method_returns), param_wrappers|
|
150
|
+
param_wrappers << method_name if method_returns.any? do |return_value|
|
151
|
+
name = Utils::Parser.get_root_token(return_value)
|
152
|
+
name.equal?(:params) || param_wrappers.include?(name)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def get_method_returns(method_name)
|
158
|
+
@class_methods.fetch(method_name, [])
|
159
|
+
end
|
147
160
|
end
|
148
161
|
end
|
149
162
|
end
|
@@ -40,8 +40,13 @@ module RuboCop
|
|
40
40
|
@unauthenticated_models = cop_config.fetch("unauthenticated_models").map(&:to_sym)
|
41
41
|
end
|
42
42
|
|
43
|
+
def on_new_investigation
|
44
|
+
super
|
45
|
+
@class_methods = {}.freeze
|
46
|
+
end
|
47
|
+
|
43
48
|
def on_class(node)
|
44
|
-
Utils::
|
49
|
+
@class_methods = Utils::Parser.get_instance_methods(node).freeze
|
45
50
|
end
|
46
51
|
|
47
52
|
def on_send(node)
|
@@ -86,9 +91,7 @@ module RuboCop
|
|
86
91
|
|
87
92
|
def uses_params?(node)
|
88
93
|
root = Utils::Parser.get_root_token(node)
|
89
|
-
root
|
90
|
-
Utils::Parser.get_root_token(x) == :params
|
91
|
-
end
|
94
|
+
root.equal?(:params) || method_returns_params?(root)
|
92
95
|
end
|
93
96
|
|
94
97
|
# yoinked from Rails/DynamicFindBy
|
@@ -98,6 +101,12 @@ module RuboCop
|
|
98
101
|
|
99
102
|
match[2] ? 'find_by!' : 'find_by'
|
100
103
|
end
|
104
|
+
|
105
|
+
def method_returns_params?(method_name)
|
106
|
+
@class_methods.fetch(method_name, []).any? do |return_value|
|
107
|
+
Utils::Parser.get_root_token(return_value).equal?(:params)
|
108
|
+
end
|
109
|
+
end
|
101
110
|
end
|
102
111
|
end
|
103
112
|
end
|
@@ -88,16 +88,16 @@ module RuboCop
|
|
88
88
|
return [] unless node.send_type?
|
89
89
|
|
90
90
|
parameter_names = []
|
91
|
-
param_aliases
|
91
|
+
aliases = param_aliases | %i(params)
|
92
92
|
|
93
|
-
if node.method?(:[]) &&
|
93
|
+
if node.method?(:[]) && aliases.include?(get_root_token(node))
|
94
94
|
return node.arguments.select { |x|
|
95
95
|
x.sym_type? || x.str_type?
|
96
96
|
}.map(&:value)
|
97
97
|
end
|
98
98
|
|
99
99
|
children = node.descendants.select do |child|
|
100
|
-
child.send_type? &&
|
100
|
+
child.send_type? && aliases.include?(child.method_name)
|
101
101
|
end
|
102
102
|
|
103
103
|
children.each do |child|
|
@@ -112,6 +112,23 @@ module RuboCop
|
|
112
112
|
|
113
113
|
parameter_names.map(&:to_sym)
|
114
114
|
end
|
115
|
+
|
116
|
+
def self.get_instance_methods(node) # rubocop:disable Metrics/PerceivedComplexity
|
117
|
+
raise ArgumentError, 'must be a class node' unless node&.class_type?
|
118
|
+
|
119
|
+
methods = node.descendants.select(&:def_type?).to_h do |method|
|
120
|
+
[method.method_name, get_return_values(method)]
|
121
|
+
end
|
122
|
+
|
123
|
+
node.descendants.each do |descendant|
|
124
|
+
lhs, rhs = *descendant
|
125
|
+
if descendant.equals_asgn? && !descendant.type.equal?(:casgn) && rhs&.send_type?
|
126
|
+
methods[lhs] = [rhs]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
methods
|
131
|
+
end
|
115
132
|
end
|
116
133
|
end
|
117
134
|
end
|
@@ -26,6 +26,5 @@ require 'rubocop/cop/betterment/unsafe_job'
|
|
26
26
|
require 'rubocop/cop/betterment/unscoped_find'
|
27
27
|
require 'rubocop/cop/betterment/use_global_strict_loading'
|
28
28
|
require 'rubocop/cop/betterment/utils/hardcoded_attribute'
|
29
|
-
require 'rubocop/cop/betterment/utils/method_return_table'
|
30
29
|
require 'rubocop/cop/betterment/utils/parser'
|
31
30
|
require 'rubocop/cop/betterment/vague_serialize'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Development
|
@@ -129,7 +129,6 @@ files:
|
|
129
129
|
- lib/rubocop/cop/betterment/unscoped_find.rb
|
130
130
|
- lib/rubocop/cop/betterment/use_global_strict_loading.rb
|
131
131
|
- lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb
|
132
|
-
- lib/rubocop/cop/betterment/utils/method_return_table.rb
|
133
132
|
- lib/rubocop/cop/betterment/utils/parser.rb
|
134
133
|
- lib/rubocop/cop/betterment/utils/response_status.rb
|
135
134
|
- lib/rubocop/cop/betterment/vague_serialize.rb
|
@@ -138,10 +137,10 @@ licenses:
|
|
138
137
|
- MIT
|
139
138
|
metadata:
|
140
139
|
homepage_uri: https://github.com/Betterment/betterlint
|
141
|
-
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.
|
142
|
-
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.
|
140
|
+
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.25.0
|
141
|
+
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.25.0/CHANGELOG.md
|
143
142
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
144
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
143
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.25.0
|
145
144
|
rubygems_mfa_required: 'true'
|
146
145
|
rdoc_options: []
|
147
146
|
require_paths:
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module Betterment
|
6
|
-
module Utils
|
7
|
-
module MethodReturnTable
|
8
|
-
class << self
|
9
|
-
def populate_index(node)
|
10
|
-
raise "not a class" unless node.class_type?
|
11
|
-
|
12
|
-
get_methods_for_class(node).each do |method|
|
13
|
-
track_method(method.method_name, Utils::Parser.get_return_values(method))
|
14
|
-
end
|
15
|
-
|
16
|
-
node.descendants.each do |descendant|
|
17
|
-
lhs, rhs = *descendant
|
18
|
-
next unless descendant.equals_asgn? && (descendant.type != :casgn) && rhs&.send_type?
|
19
|
-
|
20
|
-
track_method(lhs, [rhs])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def indexed_methods
|
25
|
-
@indexed_methods ||= {}
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_method(method_name)
|
29
|
-
indexed_methods[method_name]
|
30
|
-
end
|
31
|
-
|
32
|
-
def has_method?(method_name)
|
33
|
-
indexed_methods.include?(method_name)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def track_method(method_name, returns)
|
39
|
-
indexed_methods[method_name] = returns
|
40
|
-
end
|
41
|
-
|
42
|
-
def get_methods_for_class(node)
|
43
|
-
return [] unless node.children && node.class_type?
|
44
|
-
|
45
|
-
node.descendants.select(&:def_type?)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|