Skip to content

Commit

Permalink
Tweak document and message for Style/FlipFlop cop
Browse files Browse the repository at this point in the history
flip-flop operator is deprecated since Ruby 2.6.0.

> The flip-flop syntax is deprecated. [Feature #5400]

- https://github.com/ruby/ruby/blob/v2_6_0/NEWS#language-changes
- https://bugs.ruby-lang.org/issues/5400

```console
% cat example.rb
(1..20).each do |x|
  puts x if (x == 5) .. (x == 10)
end

% ruby -v
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin17]

% ruby example.rb
example.rb:2: warning: flip-flop is deprecated
5
6
7
8
9
10
```

This PR tweaks document and offense message for `Style/FlipFlop` cop.
It will more clarify the reason for checking flip-flop operator.
  • Loading branch information
koic authored and bbatsov committed Jan 8, 2019
1 parent b4f89dc commit 698e622
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/default.yml
Expand Up @@ -3129,7 +3129,7 @@ Style/ExpandPathArguments:
VersionAdded: '0.53'

Style/FlipFlop:
Description: 'Checks for flip flops'
Description: 'Checks for flip-flops'
StyleGuide: '#no-flip-flops'
Enabled: true
VersionAdded: '0.16'
Expand Down
5 changes: 3 additions & 2 deletions lib/rubocop/cop/style/flip_flop.rb
Expand Up @@ -3,7 +3,8 @@
module RuboCop
module Cop
module Style
# This cop looks for uses of flip flop operator
# This cop looks for uses of flip-flop operator.
# flip-flop operator is deprecated since Ruby 2.6.0.
#
# @example
# # bad
Expand All @@ -16,7 +17,7 @@ module Style
# puts x if (x >= 5) && (x <= 10)
# end
class FlipFlop < Cop
MSG = 'Avoid the use of flip flop operators.'.freeze
MSG = 'Avoid the use of flip-flop operators.'.freeze

def on_iflipflop(node)
add_offense(node)
Expand Down
3 changes: 2 additions & 1 deletion manual/cops_style.md
Expand Up @@ -1895,7 +1895,8 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
--- | --- | --- | --- | ---
Enabled | Yes | No | 0.16 | -

This cop looks for uses of flip flop operator
This cop looks for uses of flip-flop operator.
flip-flop operator is deprecated since Ruby 2.6.0.

### Examples

Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/style/flip_flop_spec.rb
Expand Up @@ -3,20 +3,20 @@
RSpec.describe RuboCop::Cop::Style::FlipFlop do
subject(:cop) { described_class.new }

it 'registers an offense for inclusive flip flops' do
it 'registers an offense for inclusive flip-flops' do
expect_offense(<<-RUBY.strip_indent)
DATA.each_line do |line|
print line if (line =~ /begin/)..(line =~ /end/)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of flip flop operators.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of flip-flop operators.
end
RUBY
end

it 'registers an offense for exclusive flip flops' do
it 'registers an offense for exclusive flip-flops' do
expect_offense(<<-RUBY.strip_indent)
DATA.each_line do |line|
print line if (line =~ /begin/)...(line =~ /end/)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of flip flop operators.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of flip-flop operators.
end
RUBY
end
Expand Down

0 comments on commit 698e622

Please sign in to comment.