Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package rubygem-rubocop for openSUSE:Factory
checked in at 2023-12-14 22:03:21
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-rubocop (Old)
and /work/SRC/openSUSE:Factory/.rubygem-rubocop.new.25432 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-rubocop"
Thu Dec 14 22:03:21 2023 rev:51 rq:1132980 version:1.59.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/rubygem-rubocop/rubygem-rubocop.changes
2023-12-06 23:49:16.065534158 +0100
+++
/work/SRC/openSUSE:Factory/.rubygem-rubocop.new.25432/rubygem-rubocop.changes
2023-12-14 22:03:23.504610926 +0100
@@ -1,0 +2,55 @@
+Tue Dec 12 16:48:05 UTC 2023 - Mykola Krachkovsky <[email protected]>
+
+- updated to version 1.59.0
+
+ ## 1.59.0 (2023-12-11)
+
+ ### New features
+
+ * [#12518](https://github.com/rubocop/rubocop/pull/12518): Add new
`Lint/ItWithoutArgumentsInBlock` cop. ([@koic][])
+
+ ### Bug fixes
+
+ * [#12434](https://github.com/rubocop/rubocop/issues/12434): Fix a false
positive for `Lint/LiteralAssignmentInCondition` when using interpolated string
or xstring literals. ([@koic][])
+ * [#12435](https://github.com/rubocop/rubocop/issues/12435): Fix a false
positive for `Lint/SelfAssignment` when using attribute assignment with method
call with arguments. ([@koic][])
+ * [#12444](https://github.com/rubocop/rubocop/issues/12444): Fix false
positive for `Style/HashEachMethods` when receiver literal is not a hash
literal. ([@koic][])
+ * [#12524](https://github.com/rubocop/rubocop/issues/12524): Fix a false
positive for `Style/MethodCallWithArgsParentheses` when `EnforcedStyle:
omit_parentheses` and parens in `when` clause is used to pass an argument.
([@koic][])
+ * [#12505](https://github.com/rubocop/rubocop/pull/12505): Fix a false
positive for `Style/RedundantParentheses` when using parenthesized `lambda` or
`proc` with `do`...`end` block. ([@koic][])
+ * [#12442](https://github.com/rubocop/rubocop/issues/12442): Fix an
incorrect autocorrect for `Style/CombinableLoops` when looping over the same
data as previous loop in `do`...`end` and `{`...`}` blocks. ([@koic][])
+ * [#12432](https://github.com/rubocop/rubocop/pull/12432): Fix a false
positive for `Lint/LiteralAssignmentInCondition` when using parallel assignment
with splat operator in block of guard condition. ([@koic][])
+ * [#12441](https://github.com/rubocop/rubocop/issues/12441): Fix false
positives for `Style/HashEachMethods` when using destructed block arguments.
([@koic][])
+ * [#12436](https://github.com/rubocop/rubocop/issues/12436): Fix false
positives for `Style/RedundantParentheses` when a part of range is a
parenthesized condition. ([@koic][])
+ * [#12429](https://github.com/rubocop/rubocop/issues/12429): Fix incorrect
autocorrect for `Style/MapToHash` when using dot method calls for `to_h`.
([@koic][])
+ * [#12488](https://github.com/rubocop/rubocop/issues/12488): Make
`Lint/HashCompareByIdentity` aware of safe navigation operator. ([@koic][])
+ * [#12489](https://github.com/rubocop/rubocop/issues/12489): Make
`Lint/NextWithoutAccumulator` aware of safe navigation operator. ([@koic][])
+ * [#12490](https://github.com/rubocop/rubocop/issues/12490): Make
`Lint/NumberConversion` aware of safe navigation operator. ([@koic][])
+ * [#12491](https://github.com/rubocop/rubocop/issues/12491): Make
`Lint/RedundantWithIndex` aware of safe navigation operator. ([@koic][])
+ * [#12492](https://github.com/rubocop/rubocop/issues/12492): Make
`Lint/RedundantWithObject` aware of safe navigation operator. ([@koic][])
+ * [#12493](https://github.com/rubocop/rubocop/issues/12493): Make
`Lint/UnmodifiedReduceAccumulator` aware of safe navigation operator.
([@koic][])
+ * [#12473](https://github.com/rubocop/rubocop/issues/12473): Make
`Style/ClassCheck` aware of safe navigation operator. ([@koic][])
+ * [#12445](https://github.com/rubocop/rubocop/issues/12445): Make
`Style/CollectionCompact` aware of safe navigation operator. ([@koic][])
+ * [#12474](https://github.com/rubocop/rubocop/issues/12474): Make
`Style/ConcatArrayLiterals` aware of safe navigation operator. ([@koic][])
+ * [#12476](https://github.com/rubocop/rubocop/issues/12476): Make
`Style/DateTime` aware of safe navigation operator. ([@koic][])
+ * [#12479](https://github.com/rubocop/rubocop/issues/12479): Make
`Style/EachWithObject` aware of safe navigation operator. ([@koic][])
+ * [#12446](https://github.com/rubocop/rubocop/issues/12446): Make
`Style/HashExcept` aware of safe navigation operator. ([@koic][])
+ * [#12447](https://github.com/rubocop/rubocop/issues/12447): Make
`Style/MapCompactWithConditionalBlock` aware of safe navigation operator.
([@koic][])
+ * [#12484](https://github.com/rubocop/rubocop/issues/12484): Make
`Style/Next` aware of safe navigation operator. ([@koic][])
+ * [#12486](https://github.com/rubocop/rubocop/issues/12486): Make
`Style/RedundantArgument` aware of safe navigation operator. ([@koic][])
+ * [#12454](https://github.com/rubocop/rubocop/issues/12454): Make
`Style/RedundantFetchBlock` aware of safe navigation operator. ([@koic][])
+ * [#12495](https://github.com/rubocop/rubocop/issues/12495): Make
`Layout/RedundantLineBreak` aware of safe navigation operator. ([@koic][])
+ * [#12455](https://github.com/rubocop/rubocop/issues/12455): Make
`Style/RedundantSortBy` aware of safe navigation operator. ([@koic][])
+ * [#12456](https://github.com/rubocop/rubocop/issues/12456): Make
`Style/RedundantSortBy` aware of safe navigation operator. ([@koic][])
+ * [#12480](https://github.com/rubocop/rubocop/issues/12480): Make
`Style/ExactRegexpMatch` aware of safe navigation operator. ([@koic][])
+ * [#12457](https://github.com/rubocop/rubocop/issues/12457): Make
`Style/Sample` aware of safe navigation operator. ([@koic][])
+ * [#12458](https://github.com/rubocop/rubocop/issues/12458): Make
`Style/SelectByRegexp` cops aware of safe navigation operator. ([@koic][])
+ * [#12494](https://github.com/rubocop/rubocop/issues/12494): Make
`Layout/SingleLineBlockChain` aware of safe navigation operator. ([@koic][])
+ * [#12461](https://github.com/rubocop/rubocop/issues/12461): Make
`Style/StringChars` aware of safe navigation operator. ([@koic][])
+ * [#12468](https://github.com/rubocop/rubocop/issues/12468): Make
`Style/Strip` aware of safe navigation operator. ([@koic][])
+ * [#12469](https://github.com/rubocop/rubocop/issues/12469): Make
`Style/UnpackFirst` aware of safe navigation operator. ([@koic][])
+
+ ### Changes
+
+ * [#12522](https://github.com/rubocop/rubocop/pull/12522): Make
`Style/MethodCallWithoutArgsParentheses` allow the parenthesized `it` method in
a block. ([@koic][])
+ * [#12523](https://github.com/rubocop/rubocop/pull/12523): Make
`Style/RedundantSelf` allow the `self.it` method in a block. ([@koic][])
+
+-------------------------------------------------------------------
Old:
----
rubocop-1.58.0.gem
New:
----
rubocop-1.59.0.gem
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ rubygem-rubocop.spec ++++++
--- /var/tmp/diff_new_pack.AfY1sb/_old 2023-12-14 22:03:24.140633866 +0100
+++ /var/tmp/diff_new_pack.AfY1sb/_new 2023-12-14 22:03:24.140633866 +0100
@@ -24,7 +24,7 @@
#
Name: rubygem-rubocop
-Version: 1.58.0
+Version: 1.59.0
Release: 0
%define mod_name rubocop
%define mod_full_name %{mod_name}-%{version}
++++++ rubocop-1.58.0.gem -> rubocop-1.59.0.gem ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/README.md new/README.md
--- old/README.md 2023-12-01 13:49:31.000000000 +0100
+++ new/README.md 2023-12-11 11:24:09.000000000 +0100
@@ -53,7 +53,7 @@
in your `Gemfile`:
```rb
-gem 'rubocop', '~> 1.58', require: false
+gem 'rubocop', '~> 1.59', require: false
```
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html)
for further details.
Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/config/default.yml new/config/default.yml
--- old/config/default.yml 2023-12-01 13:49:31.000000000 +0100
+++ new/config/default.yml 2023-12-11 11:24:09.000000000 +0100
@@ -1963,6 +1963,12 @@
VersionAdded: '0.50'
VersionChanged: '1.40'
+Lint/ItWithoutArgumentsInBlock:
+ Description: 'Checks uses of `it` calls without arguments in block.'
+ Reference: 'https://bugs.ruby-lang.org/issues/18980'
+ Enabled: pending
+ VersionAdded: '1.59'
+
Lint/LambdaWithoutLiteralBlock:
Description: 'Checks uses of lambda without a literal block.'
Enabled: pending
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/layout/heredoc_indentation.rb
new/lib/rubocop/cop/layout/heredoc_indentation.rb
--- old/lib/rubocop/cop/layout/heredoc_indentation.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/layout/heredoc_indentation.rb 2023-12-11
11:24:09.000000000 +0100
@@ -8,7 +8,7 @@
#
# Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not
default),
# this cop does not add any offenses for long here documents to
- # avoid `Layout/LineLength`'s offenses.
+ # avoid ``Layout/LineLength``'s offenses.
#
# @example
# # bad
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/layout/redundant_line_break.rb
new/lib/rubocop/cop/layout/redundant_line_break.rb
--- old/lib/rubocop/cop/layout/redundant_line_break.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/layout/redundant_line_break.rb 2023-12-11
11:24:09.000000000 +0100
@@ -62,6 +62,7 @@
register_offense(node)
end
+ alias on_csend on_send
private
@@ -135,7 +136,7 @@
.gsub(/" *\\\n\s*'/, %q(" + ')) # Double quote, backslash, and
then single quote
.gsub(/' *\\\n\s*"/, %q(' + ")) # Single quote, backslash, and
then double quote
.gsub(/(["']) *\\\n\s*\1/, '') # Double or single quote,
backslash, then same quote
- .gsub(/\n\s*(?=\.\w)/, '') # Extra space within method
chaining
+ .gsub(/\n\s*(?=(&)?\.\w)/, '') # Extra space within method
chaining which includes `&.`
.gsub(/\s*\\?\n\s*/, ' ') # Any other line break, with or
without backslash
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/layout/single_line_block_chain.rb
new/lib/rubocop/cop/layout/single_line_block_chain.rb
--- old/lib/rubocop/cop/layout/single_line_block_chain.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/layout/single_line_block_chain.rb 2023-12-11
11:24:09.000000000 +0100
@@ -33,6 +33,7 @@
range = offending_range(node)
add_offense(range) { |corrector| corrector.insert_before(range,
"\n") } if range
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb
new/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb
--- old/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb
2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb
2023-12-11 11:24:09.000000000 +0100
@@ -6,10 +6,10 @@
# Checks for places where binary operator has identical operands.
#
# It covers arithmetic operators: `-`, `/`, `%`;
- # comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, `<=`;
+ # comparison operators: `==`, `===`, `=~`, `>`, `>=`, `<`, ``<=``;
# bitwise operators: `|`, `^`, `&`;
# boolean operators: `&&`, `||`
- # and "spaceship" operator - `<=>`.
+ # and "spaceship" operator - ``<=>``.
#
# Simple arithmetic operations are allowed by this cop: `+`, `*`, `**`,
`<<` and `>>`.
# Although these can be rewritten in a different way, it should not be
necessary to
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb
new/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb
--- old/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb 2023-12-11
11:24:09.000000000 +0100
@@ -3,7 +3,7 @@
module RuboCop
module Cop
module Lint
- # Checks for overwriting an exception with an exception result by use
`rescue =>`.
+ # Checks for overwriting an exception with an exception result by use
``rescue =>``.
#
# You intended to write as `rescue StandardError`.
# However, you have written `rescue => StandardError`.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/hash_compare_by_identity.rb
new/lib/rubocop/cop/lint/hash_compare_by_identity.rb
--- old/lib/rubocop/cop/lint/hash_compare_by_identity.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/hash_compare_by_identity.rb 2023-12-11
11:24:09.000000000 +0100
@@ -35,12 +35,13 @@
# @!method id_as_hash_key?(node)
def_node_matcher :id_as_hash_key?, <<~PATTERN
- (send _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
+ (call _ {:key? :has_key? :fetch :[] :[]=} (send _ :object_id) ...)
PATTERN
def on_send(node)
add_offense(node) if id_as_hash_key?(node)
end
+ alias on_csend on_send
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/lint/it_without_arguments_in_block.rb
new/lib/rubocop/cop/lint/it_without_arguments_in_block.rb
--- old/lib/rubocop/cop/lint/it_without_arguments_in_block.rb 1970-01-01
01:00:00.000000000 +0100
+++ new/lib/rubocop/cop/lint/it_without_arguments_in_block.rb 2023-12-11
11:24:09.000000000 +0100
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Lint
+ # Emulates the following Ruby warning in Ruby 3.3.
+ #
+ # [source,ruby]
+ # ----
+ # $ ruby -e '0.times { it }'
+ # -e:1: warning: `it` calls without arguments will refer to the first
block param in Ruby 3.4;
+ # use it() or self.it
+ # ----
+ #
+ # `it` calls without arguments will refer to the first block param in
Ruby 3.4.
+ # So use `it()` or `self.it` to ensure compatibility.
+ #
+ # @example
+ #
+ # # bad
+ # do_something { it }
+ #
+ # # good
+ # do_something { it() }
+ # do_something { self.it }
+ #
+ class ItWithoutArgumentsInBlock < Base
+ include NodePattern::Macros
+
+ MSG = '`it` calls without arguments will refer to the first block
param in Ruby 3.4; ' \
+ 'use `it()` or `self.it`.'
+
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
+ return unless (body = node.body)
+ return unless node.arguments.empty_and_without_delimiters?
+
+ if body.send_type? && deprecated_it_method?(body)
+ add_offense(body)
+ else
+ body.each_descendant(:send).each do |send_node|
+ next unless deprecated_it_method?(send_node)
+
+ add_offense(send_node)
+ end
+ end
+ end
+
+ def deprecated_it_method?(node)
+ return false unless node.method?(:it)
+
+ !node.receiver && node.arguments.empty? && !node.parenthesized? &&
!node.block_literal?
+ end
+ end
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/lint/literal_assignment_in_condition.rb
new/lib/rubocop/cop/lint/literal_assignment_in_condition.rb
--- old/lib/rubocop/cop/lint/literal_assignment_in_condition.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/literal_assignment_in_condition.rb 2023-12-11
11:24:09.000000000 +0100
@@ -41,9 +41,9 @@
next unless asgn_node.loc.operator
rhs = asgn_node.to_a.last
- next unless rhs.respond_to?(:literal?) && rhs.literal?
+ next if !forbidden_literal?(rhs) ||
parallel_assignment_with_splat_operator?(rhs)
- range = asgn_node.loc.operator.join(rhs.source_range.end)
+ range = offense_range(asgn_node, rhs)
add_offense(range, message: format(MSG, literal: rhs.source))
end
@@ -58,6 +58,20 @@
node.each_child_node { |child| traverse_node(child, &block) }
end
+
+ def forbidden_literal?(node)
+ return false if node.dstr_type? || node.xstr_type?
+
+ node.respond_to?(:literal?) && node.literal?
+ end
+
+ def parallel_assignment_with_splat_operator?(node)
+ node.array_type? && node.values.first&.splat_type?
+ end
+
+ def offense_range(asgn_node, rhs)
+ asgn_node.loc.operator.join(rhs.source_range.end)
+ end
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/next_without_accumulator.rb
new/lib/rubocop/cop/lint/next_without_accumulator.rb
--- old/lib/rubocop/cop/lint/next_without_accumulator.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/next_without_accumulator.rb 2023-12-11
11:24:09.000000000 +0100
@@ -34,35 +34,20 @@
add_offense(void_next) if void_next
end
end
-
- def on_numblock(node)
- on_numblock_body_of_reduce(node) do |body|
- void_next = body.each_node(:next).find do |n|
- n.children.empty? && parent_numblock_node(n) == node
- end
-
- add_offense(void_next) if void_next
- end
- end
+ alias on_numblock on_block
private
# @!method on_block_body_of_reduce(node)
def_node_matcher :on_block_body_of_reduce, <<~PATTERN
- (block (send _recv {:reduce :inject} !sym) _blockargs $(begin ...))
- PATTERN
-
- # @!method on_numblock_body_of_reduce(node)
- def_node_matcher :on_numblock_body_of_reduce, <<~PATTERN
- (numblock (send _recv {:reduce :inject} !sym) _argscount $(begin
...))
+ {
+ (block (call _recv {:reduce :inject} !sym) _blockargs $(begin ...))
+ (numblock (call _recv {:reduce :inject} !sym) _argscount $(begin
...))
+ }
PATTERN
def parent_block_node(node)
- node.each_ancestor(:block).first
- end
-
- def parent_numblock_node(node)
- node.each_ancestor(:numblock).first
+ node.each_ancestor(:block, :numblock).first
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/number_conversion.rb
new/lib/rubocop/cop/lint/number_conversion.rb
--- old/lib/rubocop/cop/lint/number_conversion.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/number_conversion.rb 2023-12-11
11:24:09.000000000 +0100
@@ -9,7 +9,7 @@
#
# Conversion with `Integer`, `Float`, etc. will raise an `ArgumentError`
# if given input that is not numeric (eg. an empty string), whereas
- # `to_i`, etc. will try to convert regardless of input (`''.to_i => 0`).
+ # `to_i`, etc. will try to convert regardless of input (``''.to_i =>
0``).
# As such, this cop is disabled by default because it's not necessarily
# always correct to raise if a value is not numeric.
#
@@ -91,19 +91,24 @@
# @!method to_method(node)
def_node_matcher :to_method, <<~PATTERN
- (send $_ ${#{METHODS}})
+ (call $_ ${#{METHODS}})
PATTERN
# @!method to_method_symbol(node)
def_node_matcher :to_method_symbol, <<~PATTERN
- {(send _ $_ ${(sym ${#{METHODS}})} ...)
- (send _ $_ ${(block_pass (sym ${#{METHODS}}))} ...)}
+ (call _ $_ ${
+ {
+ (sym ${#{METHODS}})
+ (block_pass (sym ${#{METHODS}}))
+ }
+ } ...)
PATTERN
def on_send(node)
handle_conversion_method(node)
handle_as_symbol(node)
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/redundant_with_index.rb
new/lib/rubocop/cop/lint/redundant_with_index.rb
--- old/lib/rubocop/cop/lint/redundant_with_index.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/redundant_with_index.rb 2023-12-11
11:24:09.000000000 +0100
@@ -56,10 +56,10 @@
def_node_matcher :redundant_with_index?, <<~PATTERN
{
(block
- $(send _ {:each_with_index :with_index} ...)
+ $(call _ {:each_with_index :with_index} ...)
(args (arg _)) ...)
(numblock
- $(send _ {:each_with_index :with_index} ...) 1 ...)
+ $(call _ {:each_with_index :with_index} ...) 1 ...)
}
PATTERN
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/redundant_with_object.rb
new/lib/rubocop/cop/lint/redundant_with_object.rb
--- old/lib/rubocop/cop/lint/redundant_with_object.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/redundant_with_object.rb 2023-12-11
11:24:09.000000000 +0100
@@ -56,9 +56,9 @@
def_node_matcher :redundant_with_object?, <<~PATTERN
{
(block
- $(send _ {:each_with_object :with_object} _) (args (arg _)) ...)
+ $(call _ {:each_with_object :with_object} _) (args (arg _)) ...)
(numblock
- $(send _ {:each_with_object :with_object} _) 1 ...)
+ $(call _ {:each_with_object :with_object} _) 1 ...)
}
PATTERN
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/self_assignment.rb
new/lib/rubocop/cop/lint/self_assignment.rb
--- old/lib/rubocop/cop/lint/self_assignment.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/lint/self_assignment.rb 2023-12-11 11:24:09.000000000
+0100
@@ -102,6 +102,7 @@
def handle_attribute_assignment(node)
first_argument = node.first_argument
+ return unless first_argument.respond_to?(:arguments) &&
first_argument.arguments.empty?
if first_argument.call_type? &&
node.receiver == first_argument.receiver &&
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
new/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
--- old/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb 2023-12-11
11:24:09.000000000 +0100
@@ -69,8 +69,8 @@
# @!method reduce_with_block?(node)
def_node_matcher :reduce_with_block?, <<~PATTERN
{
- (block (send _recv {:reduce :inject} ...) args ...)
- (numblock (send _recv {:reduce :inject} ...) ...)
+ (block (call _recv {:reduce :inject} ...) args ...)
+ (numblock (call _recv {:reduce :inject} ...) ...)
}
PATTERN
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/lint/useless_times.rb
new/lib/rubocop/cop/lint/useless_times.rb
--- old/lib/rubocop/cop/lint/useless_times.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/lint/useless_times.rb 2023-12-11 11:24:09.000000000
+0100
@@ -4,7 +4,7 @@
module Cop
module Lint
# Checks for uses of `Integer#times` that will never yield
- # (when the integer <= 0) or that will only ever yield once
+ # (when the integer ``<= 0``) or that will only ever yield once
# (`1.times`).
#
# @safety
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/metrics/abc_size.rb
new/lib/rubocop/cop/metrics/abc_size.rb
--- old/lib/rubocop/cop/metrics/abc_size.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/metrics/abc_size.rb 2023-12-11 11:24:09.000000000
+0100
@@ -10,9 +10,9 @@
#
# Interpreting ABC size:
#
- # * <= 17 satisfactory
- # * 18..30 unsatisfactory
- # * > 30 dangerous
+ # * ``<= 17`` satisfactory
+ # * `18..30` unsatisfactory
+ # * `>` 30 dangerous
#
# You can have repeated "attributes" calls count as a single "branch".
# For this purpose, attributes are any method with no argument; no
attempt
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/naming/constant_name.rb
new/lib/rubocop/cop/naming/constant_name.rb
--- old/lib/rubocop/cop/naming/constant_name.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/naming/constant_name.rb 2023-12-11 11:24:09.000000000
+0100
@@ -61,8 +61,7 @@
end
def allowed_method_call_on_rhs?(node)
- node&.send_type? &&
- (node.receiver.nil? || !literal_receiver?(node))
+ node&.send_type? && (node.receiver.nil? || !literal_receiver?(node))
end
# @!method literal_receiver?(node)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/array_first_last.rb
new/lib/rubocop/cop/style/array_first_last.rb
--- old/lib/rubocop/cop/style/array_first_last.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/array_first_last.rb 2023-12-11
11:24:09.000000000 +0100
@@ -4,7 +4,7 @@
module Cop
module Style
# Identifies usages of `arr[0]` and `arr[-1]` and suggests to change
- # them to use `arr.first` and `arr.instead`.
+ # them to use `arr.first` and `arr.last` instead.
#
# The cop is disabled by default due to safety concerns.
#
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/class_check.rb
new/lib/rubocop/cop/style/class_check.rb
--- old/lib/rubocop/cop/style/class_check.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/class_check.rb 2023-12-11 11:24:09.000000000
+0100
@@ -40,6 +40,7 @@
corrector.replace(node.loc.selector, replacement)
end
end
+ alias on_csend on_send
def message(node)
if node.method?(:is_a?)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/collection_compact.rb
new/lib/rubocop/cop/style/collection_compact.rb
--- old/lib/rubocop/cop/style/collection_compact.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/collection_compact.rb 2023-12-11
11:24:09.000000000 +0100
@@ -53,7 +53,7 @@
# @!method reject_method_with_block_pass?(node)
def_node_matcher :reject_method_with_block_pass?, <<~PATTERN
- (send !nil? {:reject :delete_if :reject!}
+ (call !nil? {:reject :delete_if :reject!}
(block_pass
(sym :nil?)))
PATTERN
@@ -61,21 +61,21 @@
# @!method reject_method?(node)
def_node_matcher :reject_method?, <<~PATTERN
(block
- (send
+ (call
!nil? {:reject :delete_if :reject!})
$(args ...)
- (send
+ (call
$(lvar _) :nil?))
PATTERN
# @!method select_method?(node)
def_node_matcher :select_method?, <<~PATTERN
(block
- (send
+ (call
!nil? {:select :select!})
$(args ...)
- (send
- (send
+ (call
+ (call
$(lvar _) :nil?) :!))
PATTERN
@@ -91,6 +91,7 @@
add_offense(range, message: message) { |corrector|
corrector.replace(range, good) }
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/combinable_loops.rb
new/lib/rubocop/cop/style/combinable_loops.rb
--- old/lib/rubocop/cop/style/combinable_loops.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/combinable_loops.rb 2023-12-11
11:24:09.000000000 +0100
@@ -105,6 +105,17 @@
def combine_with_left_sibling(corrector, node)
corrector.remove(node.left_sibling.body.source_range.end.join(node.left_sibling.loc.end))
corrector.remove(node.source_range.begin.join(node.body.source_range.begin))
+
+ correct_end_of_block(corrector, node)
+ end
+
+ def correct_end_of_block(corrector, node)
+ return unless node.left_sibling.respond_to?(:braces?)
+ return if node.right_sibling&.block_type? ||
node.right_sibling&.numblock_type?
+
+ end_of_block = node.left_sibling.braces? ? '}' : ' end'
+ corrector.remove(node.loc.end)
+ corrector.insert_before(node.source_range.end, end_of_block)
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/concat_array_literals.rb
new/lib/rubocop/cop/style/concat_array_literals.rb
--- old/lib/rubocop/cop/style/concat_array_literals.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/concat_array_literals.rb 2023-12-11
11:24:09.000000000 +0100
@@ -63,6 +63,7 @@
end
end
# rubocop:enable Metrics
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/date_time.rb
new/lib/rubocop/cop/style/date_time.rb
--- old/lib/rubocop/cop/style/date_time.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/date_time.rb 2023-12-11 11:24:09.000000000
+0100
@@ -49,12 +49,12 @@
class DateTime < Base
extend AutoCorrector
- CLASS_MSG = 'Prefer Time over DateTime.'
- COERCION_MSG = 'Do not use #to_datetime.'
+ CLASS_MSG = 'Prefer `Time` over `DateTime`.'
+ COERCION_MSG = 'Do not use `#to_datetime`.'
# @!method date_time?(node)
def_node_matcher :date_time?, <<~PATTERN
- (send (const {nil? (cbase)} :DateTime) ...)
+ (call (const {nil? (cbase)} :DateTime) ...)
PATTERN
# @!method historic_date?(node)
@@ -64,7 +64,7 @@
# @!method to_datetime?(node)
def_node_matcher :to_datetime?, <<~PATTERN
- (send _ :to_datetime)
+ (call _ :to_datetime)
PATTERN
def on_send(node)
@@ -75,6 +75,7 @@
add_offense(node, message: message) { |corrector|
autocorrect(corrector, node) }
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/each_with_object.rb
new/lib/rubocop/cop/style/each_with_object.rb
--- old/lib/rubocop/cop/style/each_with_object.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/each_with_object.rb 2023-12-11
11:24:09.000000000 +0100
@@ -58,12 +58,12 @@
# @!method each_with_object_block_candidate?(node)
def_node_matcher :each_with_object_block_candidate?, <<~PATTERN
- (block $(send _ {:inject :reduce} _) $_ $_)
+ (block $(call _ {:inject :reduce} _) $_ $_)
PATTERN
# @!method each_with_object_numblock_candidate?(node)
def_node_matcher :each_with_object_numblock_candidate?, <<~PATTERN
- (numblock $(send _ {:inject :reduce} _) 2 $_)
+ (numblock $(call _ {:inject :reduce} _) 2 $_)
PATTERN
def autocorrect_block(corrector, node, return_value)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/exact_regexp_match.rb
new/lib/rubocop/cop/style/exact_regexp_match.rb
--- old/lib/rubocop/cop/style/exact_regexp_match.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/exact_regexp_match.rb 2023-12-11
11:24:09.000000000 +0100
@@ -30,7 +30,7 @@
# @!method exact_regexp_match(node)
def_node_matcher :exact_regexp_match, <<~PATTERN
- (send
+ (call
_ {:=~ :=== :!~ :match :match?}
(regexp
(str $_)
@@ -49,6 +49,7 @@
corrector.replace(node, prefer)
end
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/hash_each_methods.rb
new/lib/rubocop/cop/style/hash_each_methods.rb
--- old/lib/rubocop/cop/style/hash_each_methods.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/hash_each_methods.rb 2023-12-11
11:24:09.000000000 +0100
@@ -58,18 +58,20 @@
# rubocop:disable Metrics/AbcSize
def on_block(node)
+ return unless handleable?(node)
+
kv_each(node) do |target, method|
register_kv_offense(target, method) and return
end
return unless (key, value = each_arguments(node))
- if unused_block_arg_exist?(node, value.source)
+ if unused_block_arg_exist?(node, value)
message = message('each_key', node.method_name, value.source)
unused_range = key.source_range.end.join(value.source_range.end)
register_each_args_offense(node, message, 'each_key', unused_range)
- elsif unused_block_arg_exist?(node, key.source)
+ elsif unused_block_arg_exist?(node, key)
message = message('each_value', node.method_name, key.source)
unused_range =
key.source_range.begin.join(value.source_range.begin)
@@ -88,6 +90,12 @@
private
+ def handleable?(node)
+ return false unless (root_receiver = root_receiver(node))
+
+ !root_receiver.literal? || root_receiver.hash_type?
+ end
+
def register_kv_offense(target, method)
return unless (parent_receiver = target.receiver.receiver)
return if allowed_receiver?(parent_receiver)
@@ -99,8 +107,16 @@
end
end
- def unused_block_arg_exist?(node, block_arg_source)
-
node.body.each_descendant(:lvar).map(&:source).none?(block_arg_source)
+ def unused_block_arg_exist?(node, block_arg)
+ lvar_sources = node.body.each_descendant(:lvar).map(&:source)
+
+ if block_arg.mlhs_type?
+ block_arg.each_descendant(:arg).all? do |block_arg|
+ lvar_sources.none?(block_arg.source)
+ end
+ else
+ lvar_sources.none?(block_arg.source)
+ end
end
def message(prefer, method_name, unused_code)
@@ -127,6 +143,15 @@
end
end
+ def root_receiver(node)
+ receiver = node.receiver
+ if receiver&.receiver
+ root_receiver(receiver)
+ else
+ receiver
+ end
+ end
+
def format_message(method_name, current)
format(MSG, prefer: "each_#{method_name[0..-2]}", current: current)
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/hash_except.rb
new/lib/rubocop/cop/style/hash_except.rb
--- old/lib/rubocop/cop/style/hash_except.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/hash_except.rb 2023-12-11 11:24:09.000000000
+0100
@@ -43,7 +43,7 @@
# @!method bad_method_with_poro?(node)
def_node_matcher :bad_method_with_poro?, <<~PATTERN
(block
- (send _ _)
+ (call _ _)
(args
$(arg _)
(arg _))
@@ -86,6 +86,7 @@
corrector.replace(range, preferred_method)
end
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/style/map_compact_with_conditional_block.rb
new/lib/rubocop/cop/style/map_compact_with_conditional_block.rb
--- old/lib/rubocop/cop/style/map_compact_with_conditional_block.rb
2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/map_compact_with_conditional_block.rb
2023-12-11 11:24:09.000000000 +0100
@@ -44,9 +44,9 @@
# @!method map_and_compact?(node)
def_node_matcher :map_and_compact?, <<~RUBY
- (send
+ (call
(block
- (send _ :map)
+ (call _ :map)
(args
$(arg _))
{
@@ -85,6 +85,7 @@
end
end
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/map_to_hash.rb
new/lib/rubocop/cop/style/map_to_hash.rb
--- old/lib/rubocop/cop/style/map_to_hash.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/map_to_hash.rb 2023-12-11 11:24:09.000000000
+0100
@@ -68,6 +68,7 @@
removal_range = range_between(to_h.loc.dot.begin_pos,
to_h.loc.selector.end_pos)
corrector.remove(range_with_surrounding_space(removal_range, side:
:left))
+ corrector.replace(map.loc.dot, '.') if to_h.dot?
corrector.replace(map.loc.selector, 'to_h')
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb
new/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb
---
old/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb
2023-12-01 13:49:31.000000000 +0100
+++
new/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb
2023-12-11 11:24:09.000000000 +0100
@@ -86,6 +86,7 @@
def legitimate_call_with_parentheses?(node) # rubocop:disable
Metrics/PerceivedComplexity
call_in_literals?(node) ||
+ node.parent&.when_type? ||
call_with_ambiguous_arguments?(node) ||
call_in_logical_operators?(node) ||
call_in_optional_arguments?(node) ||
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/lib/rubocop/cop/style/method_call_without_args_parentheses.rb
new/lib/rubocop/cop/style/method_call_without_args_parentheses.rb
--- old/lib/rubocop/cop/style/method_call_without_args_parentheses.rb
2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/method_call_without_args_parentheses.rb
2023-12-11 11:24:09.000000000 +0100
@@ -8,6 +8,9 @@
# This cop can be customized allowed methods with `AllowedMethods`.
# By default, there are no methods to allowed.
#
+ # NOTE: This cop allows the use of `it()` without arguments in blocks,
+ # as in `0.times { it() }`, following `Lint/ItWithoutArgumentsInBlock`
cop.
+ #
# @example
# # bad
# object.some_method()
@@ -30,15 +33,18 @@
MSG = 'Do not use parentheses for method calls with no arguments.'
+ # rubocop:disable Metrics/CyclomaticComplexity
def on_send(node)
return unless !node.arguments? && node.parenthesized?
return if ineligible_node?(node)
return if default_argument?(node)
return if allowed_method_name?(node.method_name)
return if same_name_assignment?(node)
+ return if parenthesized_it_method_in_block?(node)
register_offense(node)
end
+ # rubocop:enable Metrics/CyclomaticComplexity
private
@@ -71,6 +77,20 @@
end
end
+ # Respects `Lint/ItWithoutArgumentsInBlock` cop and the following Ruby
3.3's warning:
+ #
+ # $ ruby -e '0.times { begin; it; end }'
+ # -e:1: warning: `it` calls without arguments will refer to the first
block param in
+ # Ruby 3.4; use it() or self.it
+ #
+ def parenthesized_it_method_in_block?(node)
+ return false unless node.method?(:it)
+ return false unless (block_node = node.each_ancestor(:block).first)
+ return false unless
block_node.arguments.empty_and_without_delimiters?
+
+ !node.receiver && node.arguments.empty? && !node.block_literal?
+ end
+
def any_assignment?(node)
node.each_ancestor(*AST::Node::ASSIGNMENTS).any? do |asgn_node|
# `obj.method = value` parses as (send ... :method= ...), and will
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/next.rb
new/lib/rubocop/cop/style/next.rb
--- old/lib/rubocop/cop/style/next.rb 2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/next.rb 2023-12-11 11:24:09.000000000 +0100
@@ -66,7 +66,7 @@
end
def on_block(node)
- return unless node.send_node.send_type? &&
node.send_node.enumerator_method?
+ return unless node.send_node.call_type? &&
node.send_node.enumerator_method?
check(node)
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/operator_method_call.rb
new/lib/rubocop/cop/style/operator_method_call.rb
--- old/lib/rubocop/cop/style/operator_method_call.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/operator_method_call.rb 2023-12-11
11:24:09.000000000 +0100
@@ -4,8 +4,8 @@
module Cop
module Style
# Checks for redundant dot before operator method call.
- # The target operator methods are `|`, `^`, `&`, `<=>`, `==`, `===`,
`=~`, `>`, `>=`, `<`,
- # `<=`, `<<`, `>>`, `+`, `-`, `*`, `/`, `%`, `**`, `~`, `!`, `!=`, and
`!~`.
+ # The target operator methods are `|`, `^`, `&`, ``<=>``, `==`, `===`,
`=~`, `>`, `>=`, `<`,
+ # ``<=``, `<<`, `>>`, `+`, `-`, `*`, `/`, `%`, `**`, `~`, `!`, `!=`, and
`!~`.
#
# @example
#
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_argument.rb
new/lib/rubocop/cop/style/redundant_argument.rb
--- old/lib/rubocop/cop/style/redundant_argument.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/redundant_argument.rb 2023-12-11
11:24:09.000000000 +0100
@@ -73,6 +73,7 @@
corrector.remove(offense_range)
end
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_fetch_block.rb
new/lib/rubocop/cop/style/redundant_fetch_block.rb
--- old/lib/rubocop/cop/style/redundant_fetch_block.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/redundant_fetch_block.rb 2023-12-11
11:24:09.000000000 +0100
@@ -47,7 +47,7 @@
# @!method redundant_fetch_block_candidate?(node)
def_node_matcher :redundant_fetch_block_candidate?, <<~PATTERN
(block
- $(send _ :fetch _)
+ $(call _ :fetch _)
(args)
${nil? #basic_literal? #const_type?})
PATTERN
@@ -61,10 +61,10 @@
bad = build_bad_method(send, body)
add_offense(range, message: format(MSG, good: good, bad: bad)) do
|corrector|
- receiver, _, key = send.children
+ _, _, key = send.children
default_value = body ? body.source : 'nil'
- corrector.replace(node, "#{receiver.source}.fetch(#{key.source},
#{default_value})")
+ corrector.replace(range, "fetch(#{key.source},
#{default_value})")
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_parentheses.rb
new/lib/rubocop/cop/style/redundant_parentheses.rb
--- old/lib/rubocop/cop/style/redundant_parentheses.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/redundant_parentheses.rb 2023-12-11
11:24:09.000000000 +0100
@@ -22,9 +22,6 @@
# @!method square_brackets?(node)
def_node_matcher :square_brackets?, '(send {(send _recv _msg) str
array hash} :[] ...)'
- # @!method range_end?(node)
- def_node_matcher :range_end?, '^^{irange erange}'
-
# @!method method_node_and_args(node)
def_node_matcher :method_node_and_args, '$(call _recv _msg $...)'
@@ -64,7 +61,8 @@
allowed_ancestor?(node) ||
allowed_method_call?(node) ||
allowed_multiple_expression?(node) ||
- allowed_ternary?(node)
+ allowed_ternary?(node) ||
+ node.parent&.range_type?
end
def allowed_ancestor?(node)
@@ -144,7 +142,9 @@
return 'a literal' if disallowed_literal?(begin_node, node)
return 'a variable' if node.variable?
return 'a constant' if node.const_type?
- return 'an expression' if node.lambda_or_proc?
+ if node.lambda_or_proc? && (node.braces? ||
node.send_node.lambda_literal?)
+ return 'an expression'
+ end
return 'an interpolated expression' if interpolation?(begin_node)
return if begin_node.chained?
@@ -229,7 +229,6 @@
def method_call_with_redundant_parentheses?(node)
return false unless node.call_type?
return false if node.prefix_not?
- return false if range_end?(node)
send_node, args = method_node_and_args(node)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_self.rb
new/lib/rubocop/cop/style/redundant_self.rb
--- old/lib/rubocop/cop/style/redundant_self.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/redundant_self.rb 2023-12-11 11:24:09.000000000
+0100
@@ -17,7 +17,8 @@
# protected scope, you cannot send private messages this way.
#
# Note we allow uses of `self` with operators because it would be awkward
- # otherwise.
+ # otherwise. Also allows the use of `self.it` without arguments in
blocks,
+ # as in `0.times { self.it }`, following
`Lint/ItWithoutArgumentsInBlock` cop.
#
# @example
#
@@ -107,8 +108,8 @@
def on_send(node)
return unless node.self_receiver? && regular_method_call?(node)
return if node.parent&.mlhs_type?
-
return if allowed_send_node?(node)
+ return if it_method_in_block?(node)
add_offense(node.receiver) do |corrector|
corrector.remove(node.receiver)
@@ -155,6 +156,20 @@
KERNEL_METHODS.include?(node.method_name)
end
+ # Respects `Lint/ItWithoutArgumentsInBlock` cop and the following Ruby
3.3's warning:
+ #
+ # $ ruby -e '0.times { begin; it; end }'
+ # -e:1: warning: `it` calls without arguments will refer to the first
block param in
+ # Ruby 3.4; use it() or self.it
+ #
+ def it_method_in_block?(node)
+ return false unless node.method?(:it)
+ return false unless (block_node = node.each_ancestor(:block).first)
+ return false unless
block_node.arguments.empty_and_without_delimiters?
+
+ node.arguments.empty? && !node.block_literal?
+ end
+
def regular_method_call?(node)
!(node.operator_method? ||
KEYWORDS.include?(node.method_name) ||
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_sort.rb
new/lib/rubocop/cop/style/redundant_sort.rb
--- old/lib/rubocop/cop/style/redundant_sort.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/redundant_sort.rb 2023-12-11 11:24:09.000000000
+0100
@@ -16,7 +16,7 @@
# This cop is unsafe, because `sort...last` and `max` may not return
the
# same element in all cases.
#
- # In an enumerable where there are multiple elements where `a <=> b ==
0`,
+ # In an enumerable where there are multiple elements where ``a <=> b
== 0``,
# or where the transformation done by the `sort_by` block has the
# same result, `sort.last` and `max` (or `sort_by.last` and `max_by`)
# will return different elements. `sort.last` will return the last
@@ -87,15 +87,15 @@
# @!method redundant_sort?(node)
def_node_matcher :redundant_sort?, <<~MATCHER
{
- (send $(send _ $:sort) ${:last :first})
- (send $(send _ $:sort) ${:[] :at :slice} {(int 0) (int -1)})
+ (call $(call _ $:sort) ${:last :first})
+ (call $(call _ $:sort) ${:[] :at :slice} {(int 0) (int -1)})
- (send $(send _ $:sort_by _) ${:last :first})
+ (call $(call _ $:sort_by _) ${:last :first})
(send $(send _ $:sort_by _) ${:[] :at :slice} {(int 0) (int -1)})
- (send ({block numblock} $(send _ ${:sort_by :sort}) ...) ${:last
:first})
- (send
- ({block numblock} $(send _ ${:sort_by :sort}) ...)
+ (call ({block numblock} $(call _ ${:sort_by :sort}) ...) ${:last
:first})
+ (call
+ ({block numblock} $(call _ ${:sort_by :sort}) ...)
${:[] :at :slice} {(int 0) (int -1)}
)
}
@@ -108,6 +108,7 @@
register_offense(ancestor, sort_node, sorter, accessor)
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/redundant_sort_by.rb
new/lib/rubocop/cop/style/redundant_sort_by.rb
--- old/lib/rubocop/cop/style/redundant_sort_by.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/redundant_sort_by.rb 2023-12-11
11:24:09.000000000 +0100
@@ -46,12 +46,12 @@
# @!method redundant_sort_by_block(node)
def_node_matcher :redundant_sort_by_block, <<~PATTERN
- (block $(send _ :sort_by) (args (arg $_x)) (lvar _x))
+ (block $(call _ :sort_by) (args (arg $_x)) (lvar _x))
PATTERN
# @!method redundant_sort_by_numblock(node)
def_node_matcher :redundant_sort_by_numblock, <<~PATTERN
- (numblock $(send _ :sort_by) 1 (lvar :_1))
+ (numblock $(call _ :sort_by) 1 (lvar :_1))
PATTERN
def sort_by_range(send, node)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/sample.rb
new/lib/rubocop/cop/style/sample.rb
--- old/lib/rubocop/cop/style/sample.rb 2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/sample.rb 2023-12-11 11:24:09.000000000 +0100
@@ -35,7 +35,7 @@
# @!method sample_candidate?(node)
def_node_matcher :sample_candidate?, <<~PATTERN
- (send $(send _ :shuffle $...) ${:#{RESTRICT_ON_SEND.join(' :')}}
$...)
+ (call $(call _ :shuffle $...) ${:#{RESTRICT_ON_SEND.join(' :')}}
$...)
PATTERN
def on_send(node)
@@ -52,6 +52,7 @@
end
end
end
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/select_by_regexp.rb
new/lib/rubocop/cop/style/select_by_regexp.rb
--- old/lib/rubocop/cop/style/select_by_regexp.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/select_by_regexp.rb 2023-12-11
11:24:09.000000000 +0100
@@ -55,8 +55,8 @@
# @!method regexp_match?(node)
def_node_matcher :regexp_match?, <<~PATTERN
{
- (block send (args (arg $_)) ${(send _ %REGEXP_METHODS _)
match-with-lvasgn})
- (numblock send $1 ${(send _ %REGEXP_METHODS _) match-with-lvasgn})
+ (block call (args (arg $_)) ${(send _ %REGEXP_METHODS _)
match-with-lvasgn})
+ (numblock call $1 ${(send _ %REGEXP_METHODS _) match-with-lvasgn})
}
PATTERN
@@ -64,9 +64,9 @@
# @!method creates_hash?(node)
def_node_matcher :creates_hash?, <<~PATTERN
{
- (send (const _ :Hash) {:new :[]} ...)
- (block (send (const _ :Hash) :new ...) ...)
- (send _ { :to_h :to_hash } ...)
+ (call (const _ :Hash) {:new :[]} ...)
+ (block (call (const _ :Hash) :new ...) ...)
+ (call _ { :to_h :to_hash } ...)
}
PATTERN
@@ -100,6 +100,7 @@
register_offense(node, block_node, regexp, replacement)
end
# rubocop:enable Metrics/CyclomaticComplexity,
Metrics/PerceivedComplexity
+ alias on_csend on_send
private
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/single_argument_dig.rb
new/lib/rubocop/cop/style/single_argument_dig.rb
--- old/lib/rubocop/cop/style/single_argument_dig.rb 2023-12-01
13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/single_argument_dig.rb 2023-12-11
11:24:09.000000000 +0100
@@ -3,8 +3,11 @@
module RuboCop
module Cop
module Style
- # Sometimes using dig method ends up with just a single
- # argument. In such cases, dig should be replaced with [].
+ # Sometimes using `dig` method ends up with just a single
+ # argument. In such cases, dig should be replaced with `[]`.
+ #
+ # Since replacing `hash&.dig(:key)` with `hash[:key]` could potentially
lead to error,
+ # calls to the `dig` method using safe navigation will be ignored.
#
# @safety
# This cop is unsafe because it cannot be guaranteed that the receiver
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/string_chars.rb
new/lib/rubocop/cop/style/string_chars.rb
--- old/lib/rubocop/cop/style/string_chars.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/string_chars.rb 2023-12-11 11:24:09.000000000
+0100
@@ -35,6 +35,7 @@
corrector.replace(range, 'chars')
end
end
+ alias on_csend on_send
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/strip.rb
new/lib/rubocop/cop/style/strip.rb
--- old/lib/rubocop/cop/style/strip.rb 2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/cop/style/strip.rb 2023-12-11 11:24:09.000000000 +0100
@@ -22,20 +22,23 @@
# @!method lstrip_rstrip(node)
def_node_matcher :lstrip_rstrip, <<~PATTERN
- {(send $(send _ $:rstrip) $:lstrip)
- (send $(send _ $:lstrip) $:rstrip)}
+ {
+ (call $(call _ :rstrip) :lstrip)
+ (call $(call _ :lstrip) :rstrip)
+ }
PATTERN
def on_send(node)
- lstrip_rstrip(node) do |first_send, method_one, method_two|
+ lstrip_rstrip(node) do |first_send|
range = range_between(first_send.loc.selector.begin_pos,
node.source_range.end_pos)
- message = format(MSG, methods: "#{method_one}.#{method_two}")
+ message = format(MSG, methods: range.source)
add_offense(range, message: message) do |corrector|
corrector.replace(range, 'strip')
end
end
end
+ alias on_csend on_send
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/cop/style/unpack_first.rb
new/lib/rubocop/cop/style/unpack_first.rb
--- old/lib/rubocop/cop/style/unpack_first.rb 2023-12-01 13:49:31.000000000
+0100
+++ new/lib/rubocop/cop/style/unpack_first.rb 2023-12-11 11:24:09.000000000
+0100
@@ -23,38 +23,35 @@
minimum_target_ruby_version 2.4
- MSG = 'Use `%<receiver>s.unpack1(%<format>s)` instead of ' \
- '`%<receiver>s.unpack(%<format>s)%<method>s`.'
+ MSG = 'Use `unpack1(%<format>s)` instead of `%<current>s`.'
RESTRICT_ON_SEND = %i[first [] slice at].freeze
# @!method unpack_and_first_element?(node)
def_node_matcher :unpack_and_first_element?, <<~PATTERN
{
- (send $(send (...) :unpack $(...)) :first)
- (send $(send (...) :unpack $(...)) {:[] :slice :at} (int 0))
+ (call $(call (...) :unpack $(...)) :first)
+ (call $(call (...) :unpack $(...)) {:[] :slice :at} (int 0))
}
PATTERN
def on_send(node)
unpack_and_first_element?(node) do |unpack_call, unpack_arg|
- range = first_element_range(node, unpack_call)
- message = format(MSG,
- receiver: unpack_call.receiver.source,
- format: unpack_arg.source,
- method: range.source)
- add_offense(node, message: message) do |corrector|
- corrector.remove(first_element_range(node, unpack_call))
+ first_element_range = first_element_range(node, unpack_call)
+ offense_range =
unpack_call.loc.selector.join(node.source_range.end)
+ message = format(MSG, format: unpack_arg.source, current:
offense_range.source)
+
+ add_offense(offense_range, message: message) do |corrector|
+ corrector.remove(first_element_range)
corrector.replace(unpack_call.loc.selector, 'unpack1')
end
end
end
+ alias on_csend on_send
private
def first_element_range(node, unpack_call)
- Parser::Source::Range.new(node.source_range.source_buffer,
- unpack_call.source_range.end_pos,
- node.source_range.end_pos)
+ unpack_call.source_range.end.join(node.source_range.end)
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop/version.rb new/lib/rubocop/version.rb
--- old/lib/rubocop/version.rb 2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop/version.rb 2023-12-11 11:24:09.000000000 +0100
@@ -3,7 +3,7 @@
module RuboCop
# This module holds the RuboCop version information.
module Version
- STRING = '1.58.0'
+ STRING = '1.59.0'
MSG = '%<version>s (using Parser %<parser_version>s, ' \
'rubocop-ast %<rubocop_ast_version>s, ' \
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/rubocop.rb new/lib/rubocop.rb
--- old/lib/rubocop.rb 2023-12-01 13:49:31.000000000 +0100
+++ new/lib/rubocop.rb 2023-12-11 11:24:09.000000000 +0100
@@ -332,6 +332,7 @@
require_relative 'rubocop/cop/lint/ineffective_access_modifier'
require_relative 'rubocop/cop/lint/inherit_exception'
require_relative 'rubocop/cop/lint/interpolation_check'
+require_relative 'rubocop/cop/lint/it_without_arguments_in_block'
require_relative 'rubocop/cop/lint/lambda_without_literal_block'
require_relative 'rubocop/cop/lint/literal_as_condition'
require_relative 'rubocop/cop/lint/literal_assignment_in_condition'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/metadata new/metadata
--- old/metadata 2023-12-01 13:49:31.000000000 +0100
+++ new/metadata 2023-12-11 11:24:09.000000000 +0100
@@ -1,16 +1,16 @@
--- !ruby/object:Gem::Specification
name: rubocop
version: !ruby/object:Gem::Version
- version: 1.58.0
+ version: 1.59.0
platform: ruby
authors:
- Bozhidar Batsov
- Jonas Arvidsson
- Yuji Nakayama
-autorequire:
+autorequire:
bindir: exe
cert_chain: []
-date: 2023-12-01 00:00:00.000000000 Z
+date: 2023-12-11 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: json
@@ -467,6 +467,7 @@
- lib/rubocop/cop/lint/ineffective_access_modifier.rb
- lib/rubocop/cop/lint/inherit_exception.rb
- lib/rubocop/cop/lint/interpolation_check.rb
+- lib/rubocop/cop/lint/it_without_arguments_in_block.rb
- lib/rubocop/cop/lint/lambda_without_literal_block.rb
- lib/rubocop/cop/lint/literal_as_condition.rb
- lib/rubocop/cop/lint/literal_assignment_in_condition.rb
@@ -1029,10 +1030,10 @@
homepage_uri: https://rubocop.org/
changelog_uri: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md
source_code_uri: https://github.com/rubocop/rubocop/
- documentation_uri: https://docs.rubocop.org/rubocop/1.58/
+ documentation_uri: https://docs.rubocop.org/rubocop/1.59/
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
rubygems_mfa_required: 'true'
-post_install_message:
+post_install_message:
rdoc_options: []
require_paths:
- lib
@@ -1047,8 +1048,8 @@
- !ruby/object:Gem::Version
version: '0'
requirements: []
-rubygems_version: 3.4.22
-signing_key:
+rubygems_version: 3.3.7
+signing_key:
specification_version: 4
summary: Automatic Ruby code style checking tool.
test_files: []