Skip to content

Commit

Permalink
Move FlipFlop cop from Style to Lint department
Browse files Browse the repository at this point in the history
Follow up of #6635 (comment).

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

This PR moves `FlipFlop` cop from `Style` department to `Lint` department.
  • Loading branch information
koic authored and bbatsov committed Jan 11, 2019
1 parent b2ce7b6 commit 8c52ab6
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,10 @@

* [#6641](https://github.com/rubocop-hq/rubocop/issues/6641): Specify `Performance/RangeInclude` as unsafe because `Range#include?` and `Range#cover?` are not equivalent. ([@koic][])

### Changes

* [#6636](https://github.com/rubocop-hq/rubocop/pull/6636): Move `FlipFlop` cop from `Style` to `Lint` department because flip-flop is deprecated since Ruby 2.6.0. ([@koic][])

## 0.62.0 (2019-01-01)

### New features
Expand Down
12 changes: 6 additions & 6 deletions config/default.yml
Expand Up @@ -1255,6 +1255,12 @@ Lint/ErbNewArguments:
Enabled: true
VersionAdded: '0.56'

Lint/FlipFlop:
Description: 'Checks for flip-flops'
StyleGuide: '#no-flip-flops'
Enabled: true
VersionAdded: '0.16'

Lint/FloatOutOfRange:
Description: >-
Catches floating-point literals too large or small for Ruby to
Expand Down Expand Up @@ -3129,12 +3135,6 @@ Style/ExpandPathArguments:
Enabled: true
VersionAdded: '0.53'

Style/FlipFlop:
Description: 'Checks for flip-flops'
StyleGuide: '#no-flip-flops'
Enabled: true
VersionAdded: '0.16'

Style/For:
Description: 'Checks use of for or each in multiline loops.'
StyleGuide: '#no-for-loops'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop.rb
Expand Up @@ -278,6 +278,7 @@
require_relative 'rubocop/cop/lint/end_in_method'
require_relative 'rubocop/cop/lint/ensure_return'
require_relative 'rubocop/cop/lint/erb_new_arguments'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/lint/float_out_of_range'
require_relative 'rubocop/cop/lint/format_parameter_mismatch'
require_relative 'rubocop/cop/lint/handle_exceptions'
Expand Down Expand Up @@ -437,7 +438,6 @@
require_relative 'rubocop/cop/style/eval_with_location'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/expand_path_arguments'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/style/for'
require_relative 'rubocop/cop/style/format_string'
require_relative 'rubocop/cop/style/format_string_token'
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/config.rb
Expand Up @@ -26,6 +26,8 @@ class Config
RUBY_VERSION_FILENAME = '.ruby-version'.freeze
DEFAULT_RAILS_VERSION = 5.0
OBSOLETE_COPS = {
'Style/FlipFlop' =>
'The `Style/FlipFlop` cop has been moved to `Lint/FlipFlop`.',
'Style/TrailingComma' =>
'The `Style/TrailingComma` cop no longer exists. Please use ' \
'`Style/TrailingCommaInArguments`, ' \
Expand Down
Expand Up @@ -2,7 +2,7 @@

module RuboCop
module Cop
module Style
module Lint
# This cop looks for uses of flip-flop operator.
# flip-flop operator is deprecated since Ruby 2.6.0.
#
Expand Down
2 changes: 1 addition & 1 deletion manual/cops.md
Expand Up @@ -210,6 +210,7 @@ In the following section you find all available cops:
* [Lint/EndInMethod](cops_lint.md#lintendinmethod)
* [Lint/EnsureReturn](cops_lint.md#lintensurereturn)
* [Lint/ErbNewArguments](cops_lint.md#linterbnewarguments)
* [Lint/FlipFlop](cops_lint.md#lintflipflop)
* [Lint/FloatOutOfRange](cops_lint.md#lintfloatoutofrange)
* [Lint/FormatParameterMismatch](cops_lint.md#lintformatparametermismatch)
* [Lint/HandleExceptions](cops_lint.md#linthandleexceptions)
Expand Down Expand Up @@ -432,7 +433,6 @@ In the following section you find all available cops:
* [Style/EvalWithLocation](cops_style.md#styleevalwithlocation)
* [Style/EvenOdd](cops_style.md#styleevenodd)
* [Style/ExpandPathArguments](cops_style.md#styleexpandpatharguments)
* [Style/FlipFlop](cops_style.md#styleflipflop)
* [Style/For](cops_style.md#stylefor)
* [Style/FormatString](cops_style.md#styleformatstring)
* [Style/FormatStringToken](cops_style.md#styleformatstringtoken)
Expand Down
27 changes: 27 additions & 0 deletions manual/cops_lint.md
Expand Up @@ -699,6 +699,33 @@ else
end
```

## Lint/FlipFlop

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | No | 0.16 | -

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

### Examples

```ruby
# bad
(1..20).each do |x|
puts x if (x == 5) .. (x == 10)
end

# good
(1..20).each do |x|
puts x if (x >= 5) && (x <= 10)
end
```

### References

* [https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops](https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops)

## Lint/FloatOutOfRange

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
Expand Down
27 changes: 0 additions & 27 deletions manual/cops_style.md
Expand Up @@ -1889,33 +1889,6 @@ Pathname.new(__FILE__).parent.expand_path
Pathname.new(__dir__).expand_path
```

## Style/FlipFlop

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | No | 0.16 | -

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

### Examples

```ruby
# bad
(1..20).each do |x|
puts x if (x == 5) .. (x == 10)
end
# good
(1..20).each do |x|
puts x if (x >= 5) && (x <= 10)
end
```

### References

* [https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops](https://github.com/rubocop-hq/ruby-style-guide#no-flip-flops)

## Style/For

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
Expand Down
18 changes: 12 additions & 6 deletions spec/rubocop/cop/generator/require_file_injector_spec.rb
Expand Up @@ -36,10 +36,11 @@
require_relative 'rubocop/version'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/style/end_block'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/file_name'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/rails/action_filter'
Expand All @@ -61,11 +62,12 @@
require_relative 'rubocop/version'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/style/end_block'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/fake_cop'
require_relative 'rubocop/cop/style/file_name'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/rails/action_filter'
Expand Down Expand Up @@ -97,10 +99,11 @@
require_relative 'rubocop/version'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/style/end_block'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/file_name'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/rails/action_filter'
Expand All @@ -122,10 +125,11 @@
require_relative 'rubocop/version'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/style/end_block'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/file_name'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/style/the_end_of_style'
require_relative 'rubocop/cop/rails/action_filter'
Expand Down Expand Up @@ -156,11 +160,12 @@
require_relative 'rubocop/version'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/style/end_block'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/fake_cop'
require_relative 'rubocop/cop/style/file_name'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/rails/action_filter'
Expand Down Expand Up @@ -194,11 +199,12 @@
require_relative 'rubocop/version'
require_relative 'rubocop/cop/lint/flip_flop'
require_relative 'rubocop/cop/style/end_block'
require_relative 'rubocop/cop/style/even_odd'
require_relative 'rubocop/cop/style/fake_cop'
require_relative 'rubocop/cop/style/file_name'
require_relative 'rubocop/cop/style/flip_flop'
require_relative 'rubocop/cop/rails/action_filter'
Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Style::FlipFlop do
RSpec.describe RuboCop::Cop::Lint::FlipFlop do
subject(:cop) { described_class.new }

it 'registers an offense for inclusive flip-flops' do
Expand Down

0 comments on commit 8c52ab6

Please sign in to comment.