Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move FlipFlop cop from Style to Lint department #6636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* [#6526](https://github.com/rubocop-hq/rubocop/issues/6526): Fix a wrong line highlight in `Lint/ShadowedException` cop. ([@tatsuyafw][])
* [#6617](https://github.com/rubocop-hq/rubocop/issues/6617): Prevent traversal error on infinite ranges. ([@drenmi][])

### 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
Original file line number Diff line number Diff line change
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'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbatsov Is it necessary to add VersionChanged metadata when moving a department? I have not added VersionChanged: '0.63' because there is no behavior change of this cop.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's fine.


Lint/FloatOutOfRange:
Description: >-
Catches floating-point literals too large or small for Ruby to
Expand Down Expand Up @@ -3128,12 +3134,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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