rubocop-rails 2.30.3 → 2.31.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a45ebdeef3a184afbb85ff1e1685fa978198ee00cf3bbbc0f1cbfa04b56f9dc7
4
- data.tar.gz: 2d06943201b3836891ed9f8c0bd9a5e2bebd90de7736351add71af9460e271b7
3
+ metadata.gz: ba4876948bedd432dc186a3c060c26c3808f1c7126b8fe69072e056a5f160d94
4
+ data.tar.gz: 7f890ec180a125abe4a40ad146661e71c088596eb093eacf12d322135c7f6907
5
5
  SHA512:
6
- metadata.gz: ed82ce027a4bee9e6dfa16dd763fa856d7b19b96356b918d469ef1274ef0c5a4e8ea5e949c6aaed84ee6d0f290ca838e34e352929640294a6bd4d579c0145cdd
7
- data.tar.gz: 7e11061742bc02b64742e4219ccfea80d5befb27572cb043d7ebc57c7a616f2fd2c8b829ac08dfad6b644f23d8a0f096c8b571cc5b8e9ecf34e7769f1f551fb4
6
+ metadata.gz: 719fd043fd8ae7738eebb0c78abba01a23f2bc30c6d8c9825c89c7cbcc6cd48fd0077918e9bc84c9c471afecd62b69597d3f046c757606ecaec4af9daf8ef183
7
+ data.tar.gz: b7173eeaf159ee8673fe2f2c16a1c92bcbb55601d1202db18e5b48d09d1d1ef0207c17a182dcfb2b39c6e686d2b82871b191d5f90c4416a1af7d7b038a12c218
@@ -29,8 +29,8 @@ module RuboCop
29
29
  end
30
30
 
31
31
  def database_from_env
32
- url = ENV['DATABASE_URL'].presence
33
- return unless url
32
+ url = ENV.fetch('DATABASE_URL', '')
33
+ return if url.blank?
34
34
 
35
35
  case url
36
36
  when %r{\A(mysql2|trilogy)://}
@@ -1,7 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RuboCop
4
- module Cop
4
+ module Cop # rubocop:disable Style/Documentation
5
+ # The EnforceSuperclass module is also defined in `rubocop` (for backwards
6
+ # compatibility), so here we remove it before (re)defining it, to avoid
7
+ # warnings about methods in the module being redefined.
8
+ remove_const(:EnforceSuperclass) if defined?(EnforceSuperclass)
9
+
5
10
  # Common functionality for enforcing a specific superclass.
6
11
  module EnforceSuperclass
7
12
  def self.included(base)
@@ -58,7 +58,7 @@ module RuboCop
58
58
  end
59
59
 
60
60
  def set_new_arg_name(transformed_argname, corrector)
61
- return if block_node.numblock_type?
61
+ return unless block_node.block_type?
62
62
 
63
63
  corrector.replace(block_node.arguments, "|#{transformed_argname}|")
64
64
  end
@@ -84,6 +84,7 @@ module RuboCop
84
84
  end
85
85
 
86
86
  alias on_numblock on_block
87
+ alias on_itblock on_block
87
88
 
88
89
  def on_send(node)
89
90
  on_bad_map_to_h(node) do |*match|
@@ -5,14 +5,14 @@ module RuboCop
5
5
  module Rails
6
6
  # Prevents usage of `"*"` on an Arel::Table column reference.
7
7
  #
8
- # Using `arel_table["*"]` causes the outputted string to be a literal
9
- # quoted asterisk (e.g. <tt>`my_model`.`*`</tt>). This causes the
10
- # database to look for a column named <tt>`*`</tt> (or `"*"`) as opposed
8
+ # Using `arel_table["\*"]` causes the outputted string to be a literal
9
+ # quoted asterisk (e.g. `my_model`.`*`). This causes the
10
+ # database to look for a column named `\*` (or `"*"`) as opposed
11
11
  # to expanding the column list as one would likely expect.
12
12
  #
13
13
  # @safety
14
- # This cop's autocorrection is unsafe because it turns a quoted `*` into
15
- # an SQL `*`, unquoted. `*` is a valid column name in certain databases
14
+ # This cop's autocorrection is unsafe because it turns a quoted `\*` into
15
+ # an SQL `*`, unquoted. `\*` is a valid column name in certain databases
16
16
  # supported by Rails, and even though it is usually a mistake,
17
17
  # it might denote legitimate access to a column named `*`.
18
18
  #
@@ -45,12 +45,10 @@ module RuboCop
45
45
  return if node.parent&.block_type?
46
46
 
47
47
  interpolated_string_passed_to_debug(node) do |arguments|
48
- message = format(MSG)
49
-
50
48
  range = replacement_range(node)
51
49
  replacement = replacement_source(node, arguments)
52
50
 
53
- add_offense(range, message: message) do |corrector|
51
+ add_offense(range) do |corrector|
54
52
  corrector.replace(range, replacement)
55
53
  end
56
54
  end
@@ -37,6 +37,9 @@ module RuboCop
37
37
  (numblock
38
38
  (call _ :to_h) $1
39
39
  (array $_ (lvar :_1)))
40
+ (itblock
41
+ (call _ :to_h) $:it
42
+ (array $_ (lvar :it)))
40
43
  }
41
44
  PATTERN
42
45
 
@@ -50,6 +53,9 @@ module RuboCop
50
53
  (numblock
51
54
  (call _ {:map :collect}) $1
52
55
  (array $_ (lvar :_1)))
56
+ (itblock
57
+ (call _ {:map :collect}) $:it
58
+ (array $_ (lvar :it)))
53
59
  }
54
60
  :to_h)
55
61
  PATTERN
@@ -66,6 +72,9 @@ module RuboCop
66
72
  (numblock
67
73
  (call _ {:map :collect}) $1
68
74
  (array $_ (lvar :_1)))
75
+ (itblock
76
+ (call _ {:map :collect}) $:it
77
+ (array $_ (lvar :it)))
69
78
  }
70
79
  )
71
80
  PATTERN
@@ -40,6 +40,9 @@ module RuboCop
40
40
  (numblock
41
41
  (call _ :to_h) $1
42
42
  (array (lvar :_1) $_))
43
+ (itblock
44
+ (call _ :to_h) $:it
45
+ (array (lvar :it) $_))
43
46
  }
44
47
  PATTERN
45
48
 
@@ -53,6 +56,9 @@ module RuboCop
53
56
  (numblock
54
57
  (call _ {:map :collect}) $1
55
58
  (array (lvar :_1) $_))
59
+ (itblock
60
+ (call _ {:map :collect}) $:it
61
+ (array (lvar :it) $_))
56
62
  }
57
63
  :to_h)
58
64
  PATTERN
@@ -69,6 +75,9 @@ module RuboCop
69
75
  (numblock
70
76
  (call _ {:map :collect}) $1
71
77
  (array (lvar :_1) $_))
78
+ (itblock
79
+ (call _ {:map :collect}) $:it
80
+ (array (lvar :it) $_))
72
81
  }
73
82
  )
74
83
  PATTERN
@@ -23,7 +23,6 @@ module RuboCop
23
23
 
24
24
  MSG = "Do not write to stdout. Use Rails's logger if you want to log."
25
25
  RESTRICT_ON_SEND = %i[ap p pp pretty_print print puts binwrite syswrite write write_nonblock].freeze
26
- ALLOWED_TYPES = %i[send csend block numblock].freeze
27
26
 
28
27
  def_node_matcher :output?, <<~PATTERN
29
28
  (send nil? {:ap :p :pp :pretty_print :print :puts} ...)
@@ -40,7 +39,7 @@ module RuboCop
40
39
  PATTERN
41
40
 
42
41
  def on_send(node)
43
- return if ALLOWED_TYPES.include?(node.parent&.type)
42
+ return if node.parent&.call_type? || node.block_node
44
43
  return if !output?(node) && !io_output?(node)
45
44
 
46
45
  range = offense_range(node)
@@ -59,6 +59,7 @@ module RuboCop
59
59
  (any_block (call _ {:map :collect}) $_argument (send lvar :[] $_key))
60
60
  PATTERN
61
61
 
62
+ # rubocop:disable Metrics/AbcSize
62
63
  def on_block(node)
63
64
  return if node.each_ancestor(:any_block).any?
64
65
 
@@ -68,20 +69,25 @@ module RuboCop
68
69
  match = if node.block_type?
69
70
  block_argument = argument.children.first.source
70
71
  use_block_argument_in_key?(block_argument, key)
71
- else # numblock
72
- argument == 1 && use_block_argument_in_key?('_1', key)
72
+ elsif node.numblock_type?
73
+ use_block_argument_in_key?('_1', key)
74
+ else # itblock
75
+ use_block_argument_in_key?('it', key)
73
76
  end
74
77
  next unless match
75
78
 
76
79
  register_offense(node, key)
77
80
  end
78
81
  end
82
+ # rubocop:enable Metrics/AbcSize
79
83
  alias on_numblock on_block
84
+ alias on_itblock on_block
80
85
 
81
86
  private
82
87
 
83
88
  def use_one_block_argument?(argument)
84
- return true if argument == 1 # Checks for numbered argument `_1`.
89
+ # Checks for numbered argument `_1` or `it block parameter.
90
+ return true if [1, :it].include?(argument)
85
91
 
86
92
  argument.respond_to?(:one?) && argument.one?
87
93
  end
@@ -85,18 +85,22 @@ module RuboCop
85
85
  end
86
86
 
87
87
  alias on_numblock on_block
88
+ alias on_itblock on_block
88
89
 
89
90
  private
90
91
 
91
92
  def autocorrect(corrector, send_node, node)
92
93
  corrector.remove(send_node.receiver)
93
94
  corrector.remove(send_node.loc.dot)
94
- corrector.remove(block_argument_range(send_node)) unless node.numblock_type?
95
+ corrector.remove(block_argument_range(send_node)) if node.block_type?
95
96
  end
96
97
 
98
+ # rubocop:disable Metrics/AbcSize
97
99
  def redundant_receiver?(send_nodes, node)
98
100
  proc = if node.numblock_type?
99
101
  ->(n) { n.receiver.lvar_type? && n.receiver.source == '_1' }
102
+ elsif node.itblock_type?
103
+ ->(n) { n.receiver.lvar_type? && n.receiver.source == 'it' }
100
104
  else
101
105
  return false if node.arguments.empty?
102
106
 
@@ -106,6 +110,7 @@ module RuboCop
106
110
 
107
111
  send_nodes.all?(&proc)
108
112
  end
113
+ # rubocop:enable Metrics/AbcSize
109
114
 
110
115
  def block_argument_range(node)
111
116
  block_node = node.each_ancestor(:block).first
@@ -76,7 +76,7 @@ module RuboCop
76
76
  def autocorrect(corrector, class_config)
77
77
  class_value = class_config.value
78
78
  replacement = const_or_string(class_value)
79
- return unless replacement.present?
79
+ return unless replacement
80
80
 
81
81
  corrector.replace(class_value, replacement.source.inspect)
82
82
  end
@@ -205,6 +205,7 @@ module RuboCop
205
205
  end
206
206
 
207
207
  alias on_numblock on_block
208
+ alias on_itblock on_block
208
209
 
209
210
  private
210
211
 
@@ -39,7 +39,7 @@ module RuboCop
39
39
 
40
40
  # @!method comment_present?(node)
41
41
  def_node_matcher :comment_present?, <<~PATTERN
42
- (hash <(pair {(sym :comment) (str "comment")} (_ [present?])) ...>)
42
+ (hash <(pair {(sym :comment) (str "comment")} (_ !blank?)) ...>)
43
43
  PATTERN
44
44
 
45
45
  # @!method add_column?(node)
@@ -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.3'
7
+ STRING = '2.31.0'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
data/lib/rubocop-rails.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'rubocop'
4
4
  require 'rack/utils'
5
5
  require 'active_support/inflector'
6
- require 'active_support/core_ext/object/blank'
7
6
 
8
7
  require_relative 'rubocop/rails'
9
8
  require_relative 'rubocop/rails/version'
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.3
4
+ version: 2.31.0
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-03-03 00:00:00.000000000 Z
12
+ date: 2025-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.72.1
62
+ version: 1.75.0
63
63
  - - "<"
64
64
  - !ruby/object:Gem::Version
65
65
  version: '2.0'
@@ -69,7 +69,7 @@ dependencies:
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.72.1
72
+ version: 1.75.0
73
73
  - - "<"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.0'
@@ -264,7 +264,7 @@ metadata:
264
264
  homepage_uri: https://docs.rubocop.org/rubocop-rails/
265
265
  changelog_uri: https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md
266
266
  source_code_uri: https://github.com/rubocop/rubocop-rails/
267
- documentation_uri: https://docs.rubocop.org/rubocop-rails/2.30/
267
+ documentation_uri: https://docs.rubocop.org/rubocop-rails/2.31/
268
268
  bug_tracker_uri: https://github.com/rubocop/rubocop-rails/issues
269
269
  rubygems_mfa_required: 'true'
270
270
  default_lint_roller_plugin: RuboCop::Rails::Plugin