Skip to content

Commit

Permalink
Make Style/SelfAssignment aware of some operators
Browse files Browse the repository at this point in the history
Follow up rubocop#12410 (comment).

This PR makes `Style/SelfAssignment` aware of `%`, `^`, `<<`, and `>>` operators.
  • Loading branch information
koic committed Nov 29, 2023
1 parent a31a37c commit 2f9a2d2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12421](https://github.com/rubocop/rubocop/pull/12421): Make `Style/SelfAssignment` aware of `%`, `^`, `<<`, and `>>` operators. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/self_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SelfAssignment < Base
extend AutoCorrector

MSG = 'Use self-assignment shorthand `%<method>s=`.'
OPS = %i[+ - * ** / | &].freeze
OPS = %i[+ - * ** / % ^ << >> | &].freeze

def self.autocorrect_incompatible_with
[Layout::SpaceAroundOperators]
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/style/self_assignment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Style::SelfAssignment, :config do
%i[+ - * ** / | & || &&].product(['x', '@x', '@@x']).each do |op, var|
%i[+ - * ** / % ^ << >> | & || &&].product(['x', '@x', '@@x']).each do |op, var|
it "registers an offense for non-shorthand assignment #{op} and #{var}" do
expect_offense(<<~RUBY, op: op, var: var)
%{var} = %{var} %{op} y
Expand Down

0 comments on commit 2f9a2d2

Please sign in to comment.