Skip to content

Commit

Permalink
Tweak offense messages for Lint/AmbiguousOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Mar 30, 2022
1 parent b11a0cf commit df90ced
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/rubocop/cop/lint/ambiguous_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class AmbiguousOperator < Base
extend AutoCorrector

AMBIGUITIES = {
'+' => { actual: 'positive number', possible: 'addition' },
'-' => { actual: 'negative number', possible: 'subtraction' },
'*' => { actual: 'splat', possible: 'multiplication' },
'&' => { actual: 'block', possible: 'binary AND' },
'**' => { actual: 'keyword splat', possible: 'exponent' }
'+' => { actual: 'positive number', possible: 'an addition' },
'-' => { actual: 'negative number', possible: 'a subtraction' },
'*' => { actual: 'splat', possible: 'a multiplication' },
'&' => { actual: 'block', possible: 'a binary AND' },
'**' => { actual: 'keyword splat', possible: 'an exponent' }
}.each do |key, hash|
hash[:operator] = key
end

MSG_FORMAT = 'Ambiguous %<actual>s operator. Parenthesize the method ' \
"arguments if it's surely a %<actual>s operator, or add " \
'a whitespace to the right of the `%<operator>s` if it ' \
'should be a %<possible>s.'
'should be %<possible>s.'

def on_new_investigation
processed_source.diagnostics.each do |diagnostic|
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/lint/ambiguous_operator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
expect_offense(<<~RUBY)
do_something(+24)
do_something +42
^ Ambiguous positive number operator. Parenthesize the method arguments if it's surely a positive number operator, or add a whitespace to the right of the `+` if it should be a addition.
^ Ambiguous positive number operator. Parenthesize the method arguments if it's surely a positive number operator, or add a whitespace to the right of the `+` if it should be an addition.
RUBY

expect_correction(<<~RUBY)
Expand All @@ -23,7 +23,7 @@
expect_offense(<<~RUBY)
do_something
do_something +42
^ Ambiguous positive number operator. Parenthesize the method arguments if it's surely a positive number operator, or add a whitespace to the right of the `+` if it should be a addition.
^ Ambiguous positive number operator. Parenthesize the method arguments if it's surely a positive number operator, or add a whitespace to the right of the `+` if it should be an addition.
RUBY

expect_correction(<<~RUBY)
Expand Down Expand Up @@ -166,7 +166,7 @@
it 'registers an offense and corrects' do
expect_offense(<<~RUBY)
do_something **kwargs
^^ Ambiguous keyword splat operator. Parenthesize the method arguments if it's surely a keyword splat operator, or add a whitespace to the right of the `**` if it should be a exponent.
^^ Ambiguous keyword splat operator. Parenthesize the method arguments if it's surely a keyword splat operator, or add a whitespace to the right of the `**` if it should be an exponent.
RUBY

expect_correction(<<~RUBY)
Expand Down

0 comments on commit df90ced

Please sign in to comment.