Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from rubocop:master #5

Open
wants to merge 675 commits into
base: master
Choose a base branch
from
Open

Conversation

pull[bot]
Copy link

@pull pull bot commented Jun 6, 2024

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

@pull pull bot added the ⤵️ pull label Jun 6, 2024
dvandersluis and others added 29 commits November 1, 2024 23:12
…ng_a_method

Fix `Style/BitwisePredicate` when using a method
…gative, depending on `AllowModifiersOnSymbols` value) access modifiers with multiple symbols.
…mes for `IgnoreNotImplementedMethods` to be configured.
Fixes #13412.

This PR fixes a false positive for `Style/RedundantLineContinuation`
when there is a line continuation at the end of Ruby code followed by `__END__` data.
Fixes #13199.

This PR makes `Style/RedundantCondition` skip autocorrection to avoid removing comments
when a branch has a comment.
…Name`

Fixes #13415.

This PR fixes false positives for `Naming/MemoizedInstanceVariableName`
when using `initialize_clone`, `initialize_copy`, or `initialize_dup`.
…moized_instance_variable_name

[Fix #13415] Fix false positives for `Naming/MemoizedInstanceVariableName`
…ssl-constant

Fix `Lint/DeprecatedOpenSSLConstant` false positive when the argument is a `csend` node
Use a newer rubocop-ast version, and reduce node destructuring on
MasgnNode, OpAsgnNode, CasgnNode, AsgnNode nodes etc.
Update `Lint/RedundantSafeNavigation` to register an offense when the receiver is `self`
Fixes #13421 and #13423.

This PR fixes false positives for `Style/SafeNavigation`
when using a method chain that exceeds the `MaxChainLength` value and
includes safe navigation operator.
…e_navigation

[Fix #13421] Fix false positives for `Style/SafeNavigation`
This is one of those where it is not immediatly obvious what
you should actually do.

Add code demonstrating what this cop is for and add
basic example implementations
```sh
$ ruby-parse --27 -e 'def foo(bar: bar); end'
(fragment:0):1:14: error: circular argument reference bar
(fragment:0):1: def foo(bar: bar); end
(fragment:0):1:              ^~~
```
…alse-positive-against-nil

Fix false positive for `Lint/FloatComparison` against nil
viralpraxis and others added 30 commits December 14, 2024 18:03
…tants

This works fine:

```console
echo 'File.delete(path) if File.exist?(path)' | rubocop --stdin bug.rb --only Lint/NonAtomicFileOperation
Inspecting 1 file
W

Offenses:

bug.rb:1:1: W: Lint/NonAtomicFileOperation: Use atomic file operation method FileUtils.rm_f. (https://rubystyle.guide#atomic-file-operations)
File.delete(path) if File.exist?(path)
```

This does not:

```console
echo 'File.delete(path) if ::File.exist?(path)' | rubocop --stdin bug.rb --only Lint/NonAtomicFileOperation
Inspecting 1 file
.

1 file inspected, no offenses detected

```
…peration-cop-to-detect-offenses-with-full-constants

Fix `Lint/NonAtomicFileOperation` cop to detect offenses with FQ constants
This PR fixes false positives for `Style/MultipleComparison`
when using multiple safe navigation method calls.
False negatives were appearing in non-modifier form of if blocks, e.g.

  ```
  if condition
    42
  end
  something_else
  ```

This likely indicates a missing assignment or return.

Clean up comments, changelog.
…fier-conditionals

[Fix #12393] Fix false negative in Lint/Void inside of non-modifier if blocks
[Fix #13578] Update `Layout/LineContinuationSpacing` to ignore continuations inside a `regexp` or `xstr`
…`if`

```console
echo 's ? s : (raise s unless $VERBOSE)' | rubocop --stdin /bin/true --only Style/RedundantCondition -d

An error occurred while Style/RedundantCondition cop was inspecting /bin/true:1:0.
undefined method `line' for nil
lib/rubocop/cop/mixin/comments_help.rb:88:in `find_end_line'
lib/rubocop/cop/mixin/comments_help.rb:22:in `comments_in_range'
lib/rubocop/cop/mixin/comments_help.rb:15:in `contains_comments?'
```
```console
echo 'if false; end; p :ok' | rubocop --stdin /bin/true --only Lint/Void -d

For /bin: An error occurred while Lint/Void cop was inspecting /bin/true:1:0.
undefined method `type' for nil
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:248:in `entirely_literal?'
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:158:in `check_literal'
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:119:in `check_expression'
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:111:in `block in check_begin'
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:104:in `each'
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:104:in `check_begin'
/home/viralpraxis/Documents/open_source/ruby-gems/rubocop/lib/rubocop/cop/lint/void.rb:91:in `on_begin'
```
…ion-cop-error-on-parentheses-and-modifier-if

Fix `Style/RedundantCondition` cop error on parentheses and modifier `if`
…-if-without-body

Fix `Lint/Void` cop error on `if` without body
…ferent comparison operators were aligned with each other
This PR fixes false positives for `Lint/NestedMethodDefinition`
when defining a method on a constant or a method call.
It follows the same reasoning as #12961. This should respect
the intent of the code and should not be linted.
Since we have two cops that need to safely parse regular expressions,
it makes sense to add a specific method to the RuboCop::Cop::Util module.
[Fix #11013]

Guards against bugs from mutable literals used as default arguments during
Hash initialization.

Since that will return the same mutable objectfor all missing keys, it would allow each mutation to affect the values of all keys initialized with the default value simultaneously.

Reference: https://stackoverflow.com/questions/2698460/strange-unexpected-behavior-disappearing-changing-values-when-using-hash-defa
[DOC] Fix typo in `Style/ExponentialNotation`
Add a new search method for determining the target ruby version: the
RUBOCOP_TARGET_RUBY_VERSION environment variable. This is now the first
source checked, allowing it to override all other sources of the target
ruby version.
Currently, there are exactly three instances where the receiver-mutating
`String#force_encoding` method is used. In all cases except for
`to_string_literal`, a `String#dup` call is included to ensure compatibility
with frozen strings. I couldn't identify any counterexamples in rubocop core that would result
in a runtime error, but there is at least one instance in `rubocop-performance` [1]
where a frozen string might be passed. To ensure everything works correctly,
we need to add a `#dup` call in the implementation of `to_string_literal`.

For additional context, it's worth noting that the Prism parser might start
freezing AST leaf nodes in the future [2],
and whitequark's parser has some unpredictability in this regard [3].

[1] rubocop/rubocop-performance#480
[2] ruby/prism#3309
[3] rubocop/rubocop-ast#342
… when continuations are inside begin nodes
…-in-to-string-literal-helper

Dup possibly frozen string in `to_string_literal` helper
```console
echo '"#{"\201\203"}"' | rubocop --stdin bug.rb --only Lint/LiteralInInterpolation -d

An error occurred while Lint/LiteralInInterpolation cop was inspecting bug.rb:1:0.
invalid byte sequence in UTF-8
lib/active_support/core_ext/object/blank.rb:159:in `match?'
lib/active_support/core_ext/object/blank.rb:159:in `blank?'
lib/rubocop/cop/lint/literal_in_interpolation.rb:171:in `space_literal?'
lib/rubocop/cop/lint/literal_in_interpolation.rb:51:in `offending?'
lib/rubocop/cop/lint/literal_in_interpolation.rb:26:in `on_interpolation'
```

Co-authored-by: Koichi ITO <[email protected]>
[Fix #13614] Fix false positives for `Style/RaiseArgs` with anonymous splat and triple dot forwarding
…olation-error-on-invalid-string

Fix `Lint/LiteralInInterpolation` cop error on invalid string literal
Fix incorrect autocorrect for `Style/RedundantRegexpArgument`  when the regex contains a single quote.
[Fix #12430] Fix false negatives in `Style/RedundantLineContinuation` when continuations are inside begin nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.