Skip to content

Commit

Permalink
Merge pull request #12421 from koic/make_style_self_assignment_aware_…
Browse files Browse the repository at this point in the history
…of_some_operators

Make `Style/SelfAssignment` aware of some operators
  • Loading branch information
koic authored Nov 29, 2023
2 parents a31a37c + 2f9a2d2 commit 4753e92
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 4753e92

Please sign in to comment.