From 8c52ab632d0d99e580a7e9fa8276a95c8e7c453c Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Tue, 8 Jan 2019 20:22:37 +0900 Subject: [PATCH] Move `FlipFlop` cop from `Style` to `Lint` department Follow up of https://github.com/rubocop-hq/rubocop/pull/6635#issuecomment-452243479. 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. --- CHANGELOG.md | 4 +++ config/default.yml | 12 ++++----- lib/rubocop.rb | 2 +- lib/rubocop/config.rb | 2 ++ lib/rubocop/cop/{style => lint}/flip_flop.rb | 2 +- manual/cops.md | 2 +- manual/cops_lint.md | 27 +++++++++++++++++++ manual/cops_style.md | 27 ------------------- .../generator/require_file_injector_spec.rb | 18 ++++++++----- .../cop/{style => lint}/flip_flop_spec.rb | 2 +- 10 files changed, 55 insertions(+), 43 deletions(-) rename lib/rubocop/cop/{style => lint}/flip_flop.rb (97%) rename spec/rubocop/cop/{style => lint}/flip_flop_spec.rb (93%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e21e2085c5e..e3b8979058a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/config/default.yml b/config/default.yml index 958bce3762b..840d70d0da5 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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 @@ -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' diff --git a/lib/rubocop.rb b/lib/rubocop.rb index efcfe4d5d4f..b7ed87e2e4b 100644 --- a/lib/rubocop.rb +++ b/lib/rubocop.rb @@ -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' @@ -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' diff --git a/lib/rubocop/config.rb b/lib/rubocop/config.rb index 3ebea19ae7c..1353fdf2e8f 100644 --- a/lib/rubocop/config.rb +++ b/lib/rubocop/config.rb @@ -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`, ' \ diff --git a/lib/rubocop/cop/style/flip_flop.rb b/lib/rubocop/cop/lint/flip_flop.rb similarity index 97% rename from lib/rubocop/cop/style/flip_flop.rb rename to lib/rubocop/cop/lint/flip_flop.rb index 085ebf7070a..a13527601b3 100644 --- a/lib/rubocop/cop/style/flip_flop.rb +++ b/lib/rubocop/cop/lint/flip_flop.rb @@ -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. # diff --git a/manual/cops.md b/manual/cops.md index 4620a197a62..87fccab43af 100644 --- a/manual/cops.md +++ b/manual/cops.md @@ -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) @@ -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) diff --git a/manual/cops_lint.md b/manual/cops_lint.md index baa0bc7bd6e..3201be83362 100644 --- a/manual/cops_lint.md +++ b/manual/cops_lint.md @@ -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 diff --git a/manual/cops_style.md b/manual/cops_style.md index 0374eba459d..2044814c511 100644 --- a/manual/cops_style.md +++ b/manual/cops_style.md @@ -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 diff --git a/spec/rubocop/cop/generator/require_file_injector_spec.rb b/spec/rubocop/cop/generator/require_file_injector_spec.rb index 9ad0cd548c1..5ee01e514c1 100644 --- a/spec/rubocop/cop/generator/require_file_injector_spec.rb +++ b/spec/rubocop/cop/generator/require_file_injector_spec.rb @@ -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' @@ -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' @@ -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' @@ -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' @@ -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' @@ -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' diff --git a/spec/rubocop/cop/style/flip_flop_spec.rb b/spec/rubocop/cop/lint/flip_flop_spec.rb similarity index 93% rename from spec/rubocop/cop/style/flip_flop_spec.rb rename to spec/rubocop/cop/lint/flip_flop_spec.rb index cd7eab30d0a..aa199d7ecae 100644 --- a/spec/rubocop/cop/style/flip_flop_spec.rb +++ b/spec/rubocop/cop/lint/flip_flop_spec.rb @@ -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