rubocop-rails 2.30.1 → 2.30.2
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/rails/blank.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +7 -0
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +11 -1
- data/lib/rubocop/cop/rails/present.rb +1 -1
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +10 -33
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69854cebe11dde8160c57b94c6ebbe60e7df48c1357aae64b932f73bb2f230ad
|
4
|
+
data.tar.gz: 04b388703ccde52554cb01f0e04a50291beada4dec9199fbb46b3dd750d8a4ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79fda1fbb14ab98b4472576b7cb776294f3c46eb56c3b0751e47c5fba308615b4f1579a41ea3b14a8c2fb22e19e693ea1e615fe48c5d9fff6f8c857ef887a53f
|
7
|
+
data.tar.gz: f219f779b57f3ecd44937c02e85872058b453bdd7ce5c83cc1d6ac05175b2c93c01d2548a02c9b46ca26bc2dca6af116611a9d9595d81b53e5a165e47a8b6cf4
|
@@ -123,7 +123,7 @@ module RuboCop
|
|
123
123
|
def on_if(node)
|
124
124
|
return unless cop_config['UnlessPresent']
|
125
125
|
return unless node.unless?
|
126
|
-
return if node.else? && config.
|
126
|
+
return if node.else? && config.cop_enabled?('Style/UnlessElse')
|
127
127
|
|
128
128
|
unless_present?(node) do |method_call, receiver|
|
129
129
|
range = unless_condition(node, method_call)
|
@@ -74,6 +74,7 @@ module RuboCop
|
|
74
74
|
def on_def(node)
|
75
75
|
return unless trivial_delegate?(node)
|
76
76
|
return if private_or_protected_delegation(node)
|
77
|
+
return if module_function_declared?(node)
|
77
78
|
|
78
79
|
register_offense(node)
|
79
80
|
end
|
@@ -163,6 +164,12 @@ module RuboCop
|
|
163
164
|
private_or_protected_inline(node) || node_visibility(node) != :public
|
164
165
|
end
|
165
166
|
|
167
|
+
def module_function_declared?(node)
|
168
|
+
node.each_ancestor(:module, :begin).any? do |ancestor|
|
169
|
+
ancestor.children.any? { |child| child.send_type? && child.method?(:module_function) }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
166
173
|
def private_or_protected_inline(node)
|
167
174
|
processed_source[node.first_line - 1].strip.match?(/\A(private )|(protected )/)
|
168
175
|
end
|
@@ -115,6 +115,10 @@ module RuboCop
|
|
115
115
|
$_)))
|
116
116
|
PATTERN
|
117
117
|
|
118
|
+
def_node_matcher :delegated_methods, <<~PATTERN
|
119
|
+
(send nil? :delegate (sym $_)+ (hash <(pair (sym :to) _) ...>))
|
120
|
+
PATTERN
|
121
|
+
|
118
122
|
def on_send(node)
|
119
123
|
methods_node = only_or_except_filter_methods(node)
|
120
124
|
return unless methods_node
|
@@ -139,7 +143,13 @@ module RuboCop
|
|
139
143
|
return [] unless block
|
140
144
|
|
141
145
|
defined_methods = block.each_child_node(:def).map(&:method_name)
|
142
|
-
defined_methods + aliased_action_methods(block, defined_methods)
|
146
|
+
defined_methods + delegated_action_methods(block) + aliased_action_methods(block, defined_methods)
|
147
|
+
end
|
148
|
+
|
149
|
+
def delegated_action_methods(node)
|
150
|
+
node.each_child_node(:send).flat_map do |child_node|
|
151
|
+
delegated_methods(child_node) || []
|
152
|
+
end
|
143
153
|
end
|
144
154
|
|
145
155
|
def aliased_action_methods(node, defined_methods)
|
@@ -110,7 +110,7 @@ module RuboCop
|
|
110
110
|
def on_if(node)
|
111
111
|
return unless cop_config['UnlessBlank']
|
112
112
|
return unless node.unless?
|
113
|
-
return if node.else? && config.
|
113
|
+
return if node.else? && config.cop_enabled?('Style/UnlessElse')
|
114
114
|
|
115
115
|
unless_blank?(node) do |method_call, receiver|
|
116
116
|
range = unless_condition(node, method_call)
|
@@ -51,51 +51,28 @@ module RuboCop
|
|
51
51
|
|
52
52
|
MSG = 'Use `distinct` before `pluck`.'
|
53
53
|
RESTRICT_ON_SEND = %i[uniq].freeze
|
54
|
-
NEWLINE = "\n"
|
55
|
-
PATTERN = '[!^block (send (send %<type>s :pluck ...) :uniq ...)]'
|
56
54
|
|
57
|
-
def_node_matcher :
|
58
|
-
|
59
|
-
def_node_matcher :aggressive_node_match, format(PATTERN, type: '_')
|
55
|
+
def_node_matcher :uniq_before_pluck, '[!^block $(send $(send _ :pluck ...) :uniq ...)]'
|
60
56
|
|
61
57
|
def on_send(node)
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
aggressive_node_match(node)
|
66
|
-
end
|
67
|
-
|
68
|
-
return unless uniq
|
58
|
+
uniq_before_pluck(node) do |uniq_node, pluck_node|
|
59
|
+
next if style == :conservative && !pluck_node.receiver&.const_type?
|
69
60
|
|
70
|
-
|
71
|
-
|
61
|
+
add_offense(uniq_node.loc.selector) do |corrector|
|
62
|
+
autocorrect(corrector, uniq_node, pluck_node)
|
63
|
+
end
|
72
64
|
end
|
73
65
|
end
|
74
66
|
|
75
67
|
private
|
76
68
|
|
77
|
-
def autocorrect(corrector,
|
78
|
-
|
69
|
+
def autocorrect(corrector, uniq_node, pluck_node)
|
70
|
+
corrector.remove(range_between(pluck_node.loc.end.end_pos, uniq_node.loc.selector.end_pos))
|
79
71
|
|
80
|
-
|
81
|
-
if (dot = node.receiver.loc.dot)
|
72
|
+
if (dot = pluck_node.loc.dot)
|
82
73
|
corrector.insert_before(dot.begin, '.distinct')
|
83
74
|
else
|
84
|
-
corrector.insert_before(
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def dot_method_with_whitespace(method, node)
|
89
|
-
range_between(dot_method_begin_pos(method, node), node.loc.selector.end_pos)
|
90
|
-
end
|
91
|
-
|
92
|
-
def dot_method_begin_pos(method, node)
|
93
|
-
lines = node.source.split(NEWLINE)
|
94
|
-
|
95
|
-
if lines.last.strip == ".#{method}"
|
96
|
-
node.source.rindex(NEWLINE)
|
97
|
-
else
|
98
|
-
node.loc.dot.begin_pos
|
75
|
+
corrector.insert_before(pluck_node, 'distinct.')
|
99
76
|
end
|
100
77
|
end
|
101
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.30.
|
4
|
+
version: 2.30.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Yuji Nakayama
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-02-
|
12
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|