rubocop-rails 2.30.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a51001f37d829dd1fe4436e613503b741fe0b0792ff30775ffe5fbe029b5748e
4
- data.tar.gz: 326c2f809f1b73a5ce041a5035e0243362b9ab2228e929d9cac148c30de65bed
3
+ metadata.gz: 69854cebe11dde8160c57b94c6ebbe60e7df48c1357aae64b932f73bb2f230ad
4
+ data.tar.gz: 04b388703ccde52554cb01f0e04a50291beada4dec9199fbb46b3dd750d8a4ff
5
5
  SHA512:
6
- metadata.gz: e205cacccb63affdb2b270e4c0776eb3fc26e4114bc769adfa7d110803770616a916f501776c800357e8eb994ab126b7fe8d010ffd2118852c32f59af0e77b9e
7
- data.tar.gz: b327dfd7f483ef356ddf0ab17102fa1bee86760a76f816f2e7f739b5ce087d012f023c11fdb16d5fb3177c499174111e1ed8e9cdf9b80c5a55e1e5d2cb151e0f
6
+ metadata.gz: 79fda1fbb14ab98b4472576b7cb776294f3c46eb56c3b0751e47c5fba308615b4f1579a41ea3b14a8c2fb22e19e693ea1e615fe48c5d9fff6f8c857ef887a53f
7
+ data.tar.gz: f219f779b57f3ecd44937c02e85872058b453bdd7ce5c83cc1d6ac05175b2c93c01d2548a02c9b46ca26bc2dca6af116611a9d9595d81b53e5a165e47a8b6cf4
data/config/default.yml CHANGED
@@ -28,7 +28,7 @@ AllCops:
28
28
  # By specifying `MigratedSchemaVersion` option, migration files that have been migrated can be ignored.
29
29
  # When `MigratedSchemaVersion: '20241231000000'` is set. Migration files lower than or equal to '20250101000000' will be ignored.
30
30
  # For example, this is the timestamp in db/migrate/20250101000000_create_articles.rb.
31
- MigratedSchemaVersion: ~
31
+ MigratedSchemaVersion: '19700101000000' # NOTE: Used as a sentinel value for the UNIX epoch time.
32
32
 
33
33
  Lint/NumberConversion:
34
34
  # Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
@@ -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.for_cop('Style/UnlessElse')['Enabled']
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.for_cop('Style/UnlessElse')['Enabled']
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 :conservative_node_match, format(PATTERN, type: 'const')
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
- uniq = if style == :conservative
63
- conservative_node_match(node)
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
- add_offense(node.loc.selector) do |corrector|
71
- autocorrect(corrector, node)
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, node)
78
- method = node.method_name
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
- corrector.remove(dot_method_with_whitespace(method, node))
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(node.receiver, 'distinct.')
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
@@ -24,8 +24,25 @@ module RuboCop
24
24
 
25
25
  ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')
26
26
 
27
+ # FIXME: This is a dirty hack relying on a private constant to prevent
28
+ # "Warning: AllCops does not support TargetRailsVersion parameter".
29
+ # It should be updated to a better design in the future.
30
+ without_warnings do
31
+ ConfigValidator.const_set(:COMMON_PARAMS, ConfigValidator::COMMON_PARAMS.dup << 'TargetRailsVersion')
32
+ end
33
+
27
34
  LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
28
35
  end
36
+
37
+ private
38
+
39
+ def without_warnings
40
+ original_verbose = $VERBOSE
41
+ $VERBOSE = nil
42
+ yield
43
+ ensure
44
+ $VERBOSE = original_verbose
45
+ end
29
46
  end
30
47
  end
31
48
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Rails
5
5
  # This module holds the RuboCop Rails version information.
6
6
  module Version
7
- STRING = '2.30.0'
7
+ STRING = '2.30.2'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
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.0
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-15 00:00:00.000000000 Z
12
+ date: 2025-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport