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: d607b36a006c41af535225cf9ea3c32771dae29a2cc6bee9092f50d8fc6cab0c
4
- data.tar.gz: 9cea34ee8efe8657ba6387b08001a95301e61af4a0e0be69a653de02e7d41cbb
3
+ metadata.gz: 583f9b1d4c78270257202f26d509a0f262e41da066da447d88b868f1631f73fe
4
+ data.tar.gz: 246b11e285e7631a944b358f41603c438bf8677539189a6fa5de7817c464995a
5
5
  SHA512:
6
- metadata.gz: efb8a0837eef49c7a41152194b21fa6e004923a4705812365234375bfc05140bda6bdf25742c4e1e8d6ad002b2940885b8a9c46dfbfa56864bf4bfbe3a18b583
7
- data.tar.gz: e4d1fdb860e7f9806f1f0e0593999ac998a34345a159de8c2e1030b3464f42473e9ef8d9d3911720898fba489d42690d29ff47b777921bff7ebc80afabdab14e
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_(.+?)(!)?$/.freeze
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 Utils
4
- class HardcodedAttribute
5
- extend RuboCop::NodePattern::Macros
3
+ module Betterment
4
+ module Utils
5
+ class HardcodedAttribute
6
+ extend RuboCop::NodePattern::Macros
6
7
 
7
- attr_reader :node, :let_node, :let_name
8
+ attr_reader :node, :let_node, :let_name
8
9
 
9
- def initialize(node)
10
- @node = node
11
- @let_node = node.parent&.parent&.parent
12
- @let_name = extract_let_name(@let_node)
13
- end
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
- def correctable?
16
- key == :id && !let_name.nil?
17
- end
16
+ def correctable?
17
+ key == :id && !let_name.nil?
18
+ end
18
19
 
19
- def replacement
20
- "#{let_name}.#{key}"
21
- end
20
+ def replacement
21
+ "#{let_name}.#{key}"
22
+ end
22
23
 
23
- def each_integer_reference
24
- each_possible_reference(:int) do |ref|
25
- yield ref if ref.value == value
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
- def each_string_reference
30
- each_possible_reference(:str) do |ref|
31
- yield ref if ref.value.match?(value_pattern)
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
- def each_range_within_string(reference)
36
- reference.source.enum_for(:scan, value_pattern).each do
37
- yield create_range(reference, Regexp.last_match)
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
- private
42
+ private
42
43
 
43
- def create_range(node, match)
44
- range = node.source_range
45
- begin_pos = range.begin_pos + match.begin(0)
46
- end_pos = range.begin_pos + match.end(0)
47
- range.with(begin_pos: begin_pos, end_pos: end_pos)
48
- end
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
- def key
51
- node.key.value
52
- end
51
+ def key
52
+ node.key.value
53
+ end
53
54
 
54
- def value
55
- node.value.value.to_i
56
- end
55
+ def value
56
+ node.value.value.to_i
57
+ end
57
58
 
58
- def value_pattern
59
- /\b#{value}\b/
60
- end
59
+ def value_pattern
60
+ /\b#{value}\b/
61
+ end
61
62
 
62
- def each_possible_reference(type, &block)
63
- let_node.parent.each_descendant(:block) do |block_node|
64
- block_node.each_descendant(type, &block) unless block_node == let_node
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
- # @!method extract_let_name(node)
69
- def_node_matcher :extract_let_name, <<~PATTERN
70
- (block (send nil? {:let | :let!} (sym $_let_name)) _block_args _block_body)
71
- PATTERN
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 Utils
4
- module MethodReturnTable
5
- class << self
6
- def populate_index(node)
7
- raise "not a class" unless node.class_type?
8
-
9
- get_methods_for_class(node).each do |method|
10
- track_method(method.method_name, Utils::Parser.get_return_values(method))
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
- node.descendants.each do |descendant|
14
- lhs, rhs = *descendant
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
- def get_method(method_name)
26
- indexed_methods[method_name]
27
- end
26
+ def get_method(method_name)
27
+ indexed_methods[method_name]
28
+ end
28
29
 
29
- def has_method?(method_name)
30
- indexed_methods.include?(method_name)
31
- end
30
+ def has_method?(method_name)
31
+ indexed_methods.include?(method_name)
32
+ end
32
33
 
33
- private
34
+ private
34
35
 
35
- def track_method(method_name, returns)
36
- indexed_methods[method_name] = returns
37
- end
36
+ def track_method(method_name, returns)
37
+ indexed_methods[method_name] = returns
38
+ end
38
39
 
39
- def get_methods_for_class(node)
40
- return [] unless node.children && node.class_type?
40
+ def get_methods_for_class(node)
41
+ return [] unless node.children && node.class_type?
41
42
 
42
- node.descendants.select(&:def_type?)
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 Utils
4
- module Parser
5
- def self.get_root_token(node) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
6
- return nil unless node
7
-
8
- return get_root_token(node.receiver) if node.receiver
9
-
10
- # rubocop:disable InternalAffairs/NodeDestructuring
11
- if node.send_type?
12
- name = node.method_name
13
- elsif node.variable?
14
- name, = *node
15
- elsif node.literal?
16
- _, name = *node
17
- elsif node.const_type?
18
- name = node.const_name.to_sym
19
- elsif node.sym_type?
20
- name = node.value
21
- elsif node.self_type?
22
- name = :self
23
- elsif node.block_pass_type?
24
- name, = *node.children
25
- else
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
- def self.explicit_returns(node)
62
- node.descendants.select(&:return_type?).filter_map do |x|
63
- x&.children&.first
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
- def self.params_from_arguments(arguments) # rubocop:disable Metrics/PerceivedComplexity
68
- parameter_names = []
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.each do |arg|
71
- if arg.hash_type?
72
- arg.children.each do |pair|
73
- value = pair.value
74
- parameter_names << value.value if value.sym_type? || value.str_type?
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
- parameter_names
82
- end
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
- def self.get_extracted_parameters(node, param_aliases: []) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
85
- return [] unless node.send_type?
88
+ parameter_names = []
89
+ param_aliases << :params
86
90
 
87
- parameter_names = []
88
- param_aliases << :params
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
- if node.method?(:[]) && param_aliases.include?(get_root_token(node))
91
- return node.arguments.select { |x|
92
- x.sym_type? || x.str_type?
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
- children = node.descendants.select do |child|
97
- child.send_type? && param_aliases.include?(child.method_name)
98
- end
101
+ children.each do |child|
102
+ ancestors = child.ancestors.select do |ancestor|
103
+ ancestor.send_type? && ancestor.method?(:permit)
104
+ end
99
105
 
100
- children.each do |child|
101
- ancestors = child.ancestors.select do |ancestor|
102
- ancestor.send_type? && ancestor.method?(:permit)
106
+ ancestors.each do |ancestor|
107
+ parameter_names += params_from_arguments(ancestor.arguments)
108
+ end
103
109
  end
104
110
 
105
- ancestors.each do |ancestor|
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.9
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-08 00:00:00.000000000 Z
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: '2.7'
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.2.32
132
+ rubygems_version: 3.4.19
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Betterment rubocop configuration