betterlint 1.4.9 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 583f9b1d4c78270257202f26d509a0f262e41da066da447d88b868f1631f73fe
|
4
|
+
data.tar.gz: 246b11e285e7631a944b358f41603c438bf8677539189a6fa5de7817c464995a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad19a059466a165bfe7bd9ec1a6dc8db2e86f9ec2c9f0e32bde0f09a5ce7703d60a60e9c79981cb0c073dac33789b99d636185bbbd5ffaab3065f9d21d161b17
|
7
|
+
data.tar.gz: '092f3ca327562d77edc0def71aa2ee62d86d3e0175c341e3fa4f38c9af380b888203e4642655b6e66aa5bc0483f35a1152ac5d38b65efcfc19406e20b6823b8c'
|
@@ -17,7 +17,7 @@ module RuboCop
|
|
17
17
|
See here for more information on this error:
|
18
18
|
https://github.com/Betterment/betterlint/blob/main/README.md#bettermentunscopedfind
|
19
19
|
MSG
|
20
|
-
METHOD_PATTERN = /^find_by_(.+?)(!)
|
20
|
+
METHOD_PATTERN = /^find_by_(.+?)(!)?$/
|
21
21
|
FINDS = %i(find find_by find_by! where).freeze
|
22
22
|
|
23
23
|
def_node_matcher :custom_scope_find?, <<-PATTERN
|
@@ -1,74 +1,76 @@
|
|
1
1
|
module RuboCop
|
2
2
|
module Cop
|
3
|
-
module
|
4
|
-
|
5
|
-
|
3
|
+
module Betterment
|
4
|
+
module Utils
|
5
|
+
class HardcodedAttribute
|
6
|
+
extend RuboCop::NodePattern::Macros
|
6
7
|
|
7
|
-
|
8
|
+
attr_reader :node, :let_node, :let_name
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def initialize(node)
|
11
|
+
@node = node
|
12
|
+
@let_node = node.parent&.parent&.parent
|
13
|
+
@let_name = extract_let_name(@let_node)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def correctable?
|
17
|
+
key == :id && !let_name.nil?
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def replacement
|
21
|
+
"#{let_name}.#{key}"
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def each_integer_reference
|
25
|
+
each_possible_reference(:int) do |ref|
|
26
|
+
yield ref if ref.value == value
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def each_string_reference
|
31
|
+
each_possible_reference(:str) do |ref|
|
32
|
+
yield ref if ref.value.match?(value_pattern)
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def each_range_within_string(reference)
|
37
|
+
reference.source.enum_for(:scan, value_pattern).each do
|
38
|
+
yield create_range(reference, Regexp.last_match)
|
39
|
+
end
|
38
40
|
end
|
39
|
-
end
|
40
41
|
|
41
|
-
|
42
|
+
private
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def create_range(node, match)
|
45
|
+
range = node.source_range
|
46
|
+
begin_pos = range.begin_pos + match.begin(0)
|
47
|
+
end_pos = range.begin_pos + match.end(0)
|
48
|
+
range.with(begin_pos: begin_pos, end_pos: end_pos)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def key
|
52
|
+
node.key.value
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def value
|
56
|
+
node.value.value.to_i
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def value_pattern
|
60
|
+
/\b#{value}\b/
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def each_possible_reference(type, &block)
|
64
|
+
let_node.parent.each_descendant(:block) do |block_node|
|
65
|
+
block_node.each_descendant(type, &block) unless block_node == let_node
|
66
|
+
end
|
65
67
|
end
|
66
|
-
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
# @!method extract_let_name(node)
|
70
|
+
def_node_matcher :extract_let_name, <<~PATTERN
|
71
|
+
(block (send nil? {:let | :let!} (sym $_let_name)) _block_args _block_body)
|
72
|
+
PATTERN
|
73
|
+
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
@@ -1,45 +1,47 @@
|
|
1
1
|
module RuboCop
|
2
2
|
module Cop
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Betterment
|
4
|
+
module Utils
|
5
|
+
module MethodReturnTable
|
6
|
+
class << self
|
7
|
+
def populate_index(node)
|
8
|
+
raise "not a class" unless node.class_type?
|
9
|
+
|
10
|
+
get_methods_for_class(node).each do |method|
|
11
|
+
track_method(method.method_name, Utils::Parser.get_return_values(method))
|
12
|
+
end
|
13
|
+
|
14
|
+
node.descendants.each do |descendant|
|
15
|
+
lhs, rhs = *descendant
|
16
|
+
next unless descendant.equals_asgn? && (descendant.type != :casgn) && rhs&.send_type?
|
17
|
+
|
18
|
+
track_method(lhs, [rhs])
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
next unless descendant.equals_asgn? && (descendant.type != :casgn) && rhs&.send_type?
|
16
|
-
|
17
|
-
track_method(lhs, [rhs])
|
22
|
+
def indexed_methods
|
23
|
+
@indexed_methods ||= {}
|
18
24
|
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def indexed_methods
|
22
|
-
@indexed_methods ||= {}
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def get_method(method_name)
|
27
|
+
indexed_methods[method_name]
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def has_method?(method_name)
|
31
|
+
indexed_methods.include?(method_name)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
+
private
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def track_method(method_name, returns)
|
37
|
+
indexed_methods[method_name] = returns
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
def get_methods_for_class(node)
|
41
|
+
return [] unless node.children && node.class_type?
|
41
42
|
|
42
|
-
|
43
|
+
node.descendants.select(&:def_type?)
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -1,113 +1,115 @@
|
|
1
1
|
module RuboCop
|
2
2
|
module Cop
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
name = nil
|
27
|
-
end
|
28
|
-
# rubocop:enable InternalAffairs/NodeDestructuring
|
29
|
-
|
30
|
-
name
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.get_return_values(node) # rubocop:disable Metrics/AbcSize
|
34
|
-
return [] unless node
|
35
|
-
return explicit_returns(node) + get_return_values(node.body) if node.def_type?
|
36
|
-
return [node] if node.literal? || node.variable?
|
37
|
-
|
38
|
-
case node.type
|
39
|
-
when :begin
|
40
|
-
get_return_values(node.children.last)
|
41
|
-
when :block
|
42
|
-
get_return_values(node.body)
|
43
|
-
when :if
|
44
|
-
if_rets = get_return_values(node.if_branch)
|
45
|
-
else_rets = get_return_values(node.else_branch)
|
46
|
-
if_rets + else_rets
|
47
|
-
when :case
|
48
|
-
cases = []
|
49
|
-
node.each_when do |block|
|
50
|
-
cases += get_return_values(block.body)
|
51
|
-
end
|
52
|
-
|
53
|
-
cases + get_return_values(node.else_branch)
|
54
|
-
when :send
|
55
|
-
[node]
|
3
|
+
module Betterment
|
4
|
+
module Utils
|
5
|
+
module Parser
|
6
|
+
def self.get_root_token(node) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
|
7
|
+
return nil unless node
|
8
|
+
|
9
|
+
return get_root_token(node.receiver) if node.receiver
|
10
|
+
|
11
|
+
# rubocop:disable InternalAffairs/NodeDestructuring
|
12
|
+
if node.send_type?
|
13
|
+
name = node.method_name
|
14
|
+
elsif node.variable?
|
15
|
+
name, = *node
|
16
|
+
elsif node.literal?
|
17
|
+
_, name = *node
|
18
|
+
elsif node.const_type?
|
19
|
+
name = node.const_name.to_sym
|
20
|
+
elsif node.sym_type?
|
21
|
+
name = node.value
|
22
|
+
elsif node.self_type?
|
23
|
+
name = :self
|
24
|
+
elsif node.block_pass_type?
|
25
|
+
name, = *node.children
|
56
26
|
else
|
57
|
-
|
27
|
+
name = nil
|
28
|
+
end
|
29
|
+
# rubocop:enable InternalAffairs/NodeDestructuring
|
30
|
+
|
31
|
+
name
|
58
32
|
end
|
59
|
-
end
|
60
33
|
|
61
|
-
|
62
|
-
|
63
|
-
|
34
|
+
def self.get_return_values(node) # rubocop:disable Metrics/AbcSize
|
35
|
+
return [] unless node
|
36
|
+
return explicit_returns(node) + get_return_values(node.body) if node.def_type?
|
37
|
+
return [node] if node.literal? || node.variable?
|
38
|
+
|
39
|
+
case node.type
|
40
|
+
when :begin
|
41
|
+
get_return_values(node.children.last)
|
42
|
+
when :block
|
43
|
+
get_return_values(node.body)
|
44
|
+
when :if
|
45
|
+
if_rets = get_return_values(node.if_branch)
|
46
|
+
else_rets = get_return_values(node.else_branch)
|
47
|
+
if_rets + else_rets
|
48
|
+
when :case
|
49
|
+
cases = []
|
50
|
+
node.each_when do |block|
|
51
|
+
cases += get_return_values(block.body)
|
52
|
+
end
|
53
|
+
|
54
|
+
cases + get_return_values(node.else_branch)
|
55
|
+
when :send
|
56
|
+
[node]
|
57
|
+
else
|
58
|
+
[]
|
59
|
+
end
|
64
60
|
end
|
65
|
-
end
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
def self.explicit_returns(node)
|
63
|
+
node.descendants.select(&:return_type?).filter_map do |x|
|
64
|
+
x&.children&.first
|
65
|
+
end
|
66
|
+
end
|
69
67
|
|
70
|
-
arguments
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
def self.params_from_arguments(arguments) # rubocop:disable Metrics/PerceivedComplexity
|
69
|
+
parameter_names = []
|
70
|
+
|
71
|
+
arguments.each do |arg|
|
72
|
+
if arg.hash_type?
|
73
|
+
arg.children.each do |pair|
|
74
|
+
value = pair.value
|
75
|
+
parameter_names << value.value if value.sym_type? || value.str_type?
|
76
|
+
end
|
77
|
+
elsif arg.sym_type? || arg.str_type?
|
78
|
+
parameter_names << arg.value
|
75
79
|
end
|
76
|
-
elsif arg.sym_type? || arg.str_type?
|
77
|
-
parameter_names << arg.value
|
78
80
|
end
|
81
|
+
|
82
|
+
parameter_names
|
79
83
|
end
|
80
84
|
|
81
|
-
|
82
|
-
|
85
|
+
def self.get_extracted_parameters(node, param_aliases: []) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
86
|
+
return [] unless node.send_type?
|
83
87
|
|
84
|
-
|
85
|
-
|
88
|
+
parameter_names = []
|
89
|
+
param_aliases << :params
|
86
90
|
|
87
|
-
|
88
|
-
|
91
|
+
if node.method?(:[]) && param_aliases.include?(get_root_token(node))
|
92
|
+
return node.arguments.select { |x|
|
93
|
+
x.sym_type? || x.str_type?
|
94
|
+
}.map(&:value)
|
95
|
+
end
|
89
96
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}.map(&:value)
|
94
|
-
end
|
97
|
+
children = node.descendants.select do |child|
|
98
|
+
child.send_type? && param_aliases.include?(child.method_name)
|
99
|
+
end
|
95
100
|
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
children.each do |child|
|
102
|
+
ancestors = child.ancestors.select do |ancestor|
|
103
|
+
ancestor.send_type? && ancestor.method?(:permit)
|
104
|
+
end
|
99
105
|
|
100
|
-
|
101
|
-
|
102
|
-
|
106
|
+
ancestors.each do |ancestor|
|
107
|
+
parameter_names += params_from_arguments(ancestor.arguments)
|
108
|
+
end
|
103
109
|
end
|
104
110
|
|
105
|
-
|
106
|
-
parameter_names += params_from_arguments(ancestor.arguments)
|
107
|
-
end
|
111
|
+
parameter_names.map(&:to_sym)
|
108
112
|
end
|
109
|
-
|
110
|
-
parameter_names.map(&:to_sym)
|
111
113
|
end
|
112
114
|
end
|
113
115
|
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.5.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-09-
|
11
|
+
date: 2023-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -122,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '3.0'
|
126
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.4.19
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Betterment rubocop configuration
|