diff --git a/CHANGELOG.md b/CHANGELOG.md index 02e91f90df9..ecca066d9e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ * [#7797](https://github.com/rubocop-hq/rubocop/pull/7797): Allow unicode-display_width dependency version 1.7.0. ([@yuritomanek][]) * [#7779](https://github.com/rubocop-hq/rubocop/issues/7779): Change `AllowComments` option of `Lint/SuppressedException` to true by default. ([@koic][]) * [#7320](https://github.com/rubocop-hq/rubocop/issues/7320): `Naming/MethodName` now flags `attr_reader/attr_writer/attr_accessor/attr`. ([@denys281][]) +* [#7813](https://github.com/rubocop-hq/rubocop/issues/7813): **(Breaking)** Remove `Lint/EndInMethod` cop. ([@tejasbubane][]) ## 0.80.1 (2020-02-29) diff --git a/config/default.yml b/config/default.yml index 2663f926824..ead623326e8 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1395,11 +1395,6 @@ Lint/EmptyWhen: Enabled: true VersionAdded: '0.45' -Lint/EndInMethod: - Description: 'END blocks should not be placed inside method definitions.' - Enabled: true - VersionAdded: '0.9' - Lint/EnsureReturn: Description: 'Do not use return in an ensure block.' StyleGuide: '#no-return-ensure' diff --git a/lib/rubocop.rb b/lib/rubocop.rb index 5cd3f0e0f9e..d9f4d8d6706 100644 --- a/lib/rubocop.rb +++ b/lib/rubocop.rb @@ -300,7 +300,6 @@ require_relative 'rubocop/cop/lint/empty_expression' require_relative 'rubocop/cop/lint/empty_interpolation' require_relative 'rubocop/cop/lint/empty_when' -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' diff --git a/lib/rubocop/config_obsoletion.rb b/lib/rubocop/config_obsoletion.rb index cfe2c1e0c96..588714380f1 100644 --- a/lib/rubocop/config_obsoletion.rb +++ b/lib/rubocop/config_obsoletion.rb @@ -19,6 +19,7 @@ class ConfigObsoletion 'Layout/LeadingBlankLines' => 'Layout/LeadingEmptyLines', 'Layout/TrailingBlankLines' => 'Layout/TrailingEmptyLines', 'Lint/DuplicatedKey' => 'Lint/DuplicateHashKey', + 'Lint/EndInMethod' => 'Style/EndBlock', 'Lint/HandleExceptions' => 'Lint/SuppressedException', 'Lint/MultipleCompare' => 'Lint/MultipleComparison', 'Lint/StringConversionInInterpolation' => 'Lint/RedundantStringCoercion', diff --git a/lib/rubocop/cop/lint/end_in_method.rb b/lib/rubocop/cop/lint/end_in_method.rb deleted file mode 100644 index f15cb23a3df..00000000000 --- a/lib/rubocop/cop/lint/end_in_method.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module Lint - # This cop checks for END blocks in method definitions. - # - # @example - # - # # bad - # - # def some_method - # END { do_something } - # end - # - # @example - # - # # good - # - # def some_method - # at_exit { do_something } - # end - # - # @example - # - # # good - # - # # outside defs - # END { do_something } - class EndInMethod < Cop - MSG = '`END` found in method definition. Use `at_exit` instead.' - - def on_postexe(node) - inside_of_method = node.each_ancestor(:def, :defs).count.nonzero? - add_offense(node, location: :keyword) if inside_of_method - end - end - end - end -end diff --git a/manual/cops.md b/manual/cops.md index d233f13ffce..ae10d5af5d6 100644 --- a/manual/cops.md +++ b/manual/cops.md @@ -195,7 +195,6 @@ In the following section you find all available cops: * [Lint/EmptyExpression](cops_lint.md#lintemptyexpression) * [Lint/EmptyInterpolation](cops_lint.md#lintemptyinterpolation) * [Lint/EmptyWhen](cops_lint.md#lintemptywhen) -* [Lint/EndInMethod](cops_lint.md#lintendinmethod) * [Lint/EnsureReturn](cops_lint.md#lintensurereturn) * [Lint/ErbNewArguments](cops_lint.md#linterbnewarguments) * [Lint/FlipFlop](cops_lint.md#lintflipflop) diff --git a/manual/cops_lint.md b/manual/cops_lint.md index e202e963dd7..4b21ba02ece 100644 --- a/manual/cops_lint.md +++ b/manual/cops_lint.md @@ -618,37 +618,6 @@ when baz then 2 end ``` -## Lint/EndInMethod - -Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged ---- | --- | --- | --- | --- -Enabled | Yes | No | 0.9 | - - -This cop checks for END blocks in method definitions. - -### Examples - -```ruby -# bad - -def some_method - END { do_something } -end -``` -```ruby -# good - -def some_method - at_exit { do_something } -end -``` -```ruby -# good - -# outside defs -END { do_something } -``` - ## Lint/EnsureReturn Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged diff --git a/spec/rubocop/cop/lint/end_in_method_spec.rb b/spec/rubocop/cop/lint/end_in_method_spec.rb deleted file mode 100644 index 7fafe9c2d6b..00000000000 --- a/spec/rubocop/cop/lint/end_in_method_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe RuboCop::Cop::Lint::EndInMethod do - subject(:cop) { described_class.new } - - it 'registers an offense for def with an END inside' do - expect_offense(<<~RUBY) - def test - END { something } - ^^^ `END` found in method definition. Use `at_exit` instead. - end - RUBY - end - - it 'registers an offense for defs with an END inside' do - expect_offense(<<~RUBY) - def self.test - END { something } - ^^^ `END` found in method definition. Use `at_exit` instead. - end - RUBY - end - - it 'accepts END outside of def(s)' do - expect_no_offenses('END { something }') - end -end