diff --git a/CHANGELOG.md b/CHANGELOG.md index 3935d025002..44c05a76e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### Changes * [#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][]) ## 0.80.1 (2020-02-29) diff --git a/config/default.yml b/config/default.yml index 1f9e67aa03c..b8199f8b368 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1712,9 +1712,9 @@ Lint/SuppressedException: Description: "Don't suppress exceptions." StyleGuide: '#dont-hide-exceptions' Enabled: true - AllowComments: false + AllowComments: true VersionAdded: '0.9' - VersionChanged: '0.77' + VersionChanged: '0.81' Lint/Syntax: Description: 'Checks syntax error.' diff --git a/lib/rubocop/cop/lint/suppressed_exception.rb b/lib/rubocop/cop/lint/suppressed_exception.rb index 1f1a619471b..db5a4499570 100644 --- a/lib/rubocop/cop/lint/suppressed_exception.rb +++ b/lib/rubocop/cop/lint/suppressed_exception.rb @@ -5,7 +5,7 @@ module Cop module Lint # This cop checks for *rescue* blocks with no body. # - # @example AllowComments: false (default) + # @example # # # bad # def some_method @@ -14,25 +14,11 @@ module Lint # end # # # bad - # def some_method - # do_something - # rescue - # # do nothing - # end - # - # # bad # begin # do_something # rescue # end # - # # bad - # begin - # do_something - # rescue - # # do nothing - # end - # # # good # def some_method # do_something @@ -47,32 +33,36 @@ module Lint # handle_exception # end # - # @example AllowComments: true + # @example AllowComments: true (default) # - # # bad + # # good # def some_method # do_something # rescue + # # do nothing # end # - # # bad + # # good # begin # do_something # rescue + # # do nothing # end # - # # good + # @example AllowComments: false + # + # # bad # def some_method # do_something # rescue - # # do nothing but comment + # # do nothing # end # - # # good + # # bad # begin # do_something # rescue - # # do nothing but comment + # # do nothing # end class SuppressedException < Cop MSG = 'Do not suppress exceptions.' diff --git a/lib/rubocop/formatter/clang_style_formatter.rb b/lib/rubocop/formatter/clang_style_formatter.rb index 9c08e53e896..826fa3cb4fb 100644 --- a/lib/rubocop/formatter/clang_style_formatter.rb +++ b/lib/rubocop/formatter/clang_style_formatter.rb @@ -29,7 +29,7 @@ def report_offense(file, offense) report_line(offense.location) report_highlighted_area(offense.highlighted_area) - rescue IndexError # rubocop:disable Lint/SuppressedException + rescue IndexError # range is not on a valid line; perhaps the source file is empty end end diff --git a/lib/rubocop/formatter/tap_formatter.rb b/lib/rubocop/formatter/tap_formatter.rb index 945de0ec12a..b1a982c7f77 100644 --- a/lib/rubocop/formatter/tap_formatter.rb +++ b/lib/rubocop/formatter/tap_formatter.rb @@ -56,7 +56,7 @@ def report_offense(file, offense) report_line(offense.location) report_highlighted_area(offense.highlighted_area) - rescue IndexError # rubocop:disable Lint/SuppressedException + rescue IndexError # range is not on a valid line; perhaps the source file is empty end end diff --git a/lib/rubocop/processed_source.rb b/lib/rubocop/processed_source.rb index d2add4c8be0..9822018f433 100644 --- a/lib/rubocop/processed_source.rb +++ b/lib/rubocop/processed_source.rb @@ -163,7 +163,7 @@ def tokenize(parser) ast, comments, tokens = parser.tokenize(@buffer) ast.respond_to?(:complete!) && ast.complete! - rescue Parser::SyntaxError # rubocop:disable Lint/SuppressedException + rescue Parser::SyntaxError # All errors are in diagnostics. No need to handle exception. end diff --git a/manual/cops_lint.md b/manual/cops_lint.md index 3907702d039..665c2443778 100644 --- a/manual/cops_lint.md +++ b/manual/cops_lint.md @@ -2279,14 +2279,12 @@ end Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged --- | --- | --- | --- | --- -Enabled | Yes | No | 0.9 | 0.77 +Enabled | Yes | No | 0.9 | 0.81 This cop checks for *rescue* blocks with no body. ### Examples -#### AllowComments: false (default) - ```ruby # bad def some_method @@ -2294,26 +2292,12 @@ def some_method rescue end -# bad -def some_method - do_something -rescue - # do nothing -end - # bad begin do_something rescue end -# bad -begin - do_something -rescue - # do nothing -end - # good def some_method do_something @@ -2328,33 +2312,38 @@ rescue handle_exception end ``` -#### AllowComments: true +#### AllowComments: true (default) ```ruby -# bad +# good def some_method do_something rescue + # do nothing end -# bad +# good begin do_something rescue + # do nothing end +``` +#### AllowComments: false -# good +```ruby +# bad def some_method do_something rescue - # do nothing but comment + # do nothing end -# good +# bad begin do_something rescue - # do nothing but comment + # do nothing end ``` @@ -2362,7 +2351,7 @@ end Name | Default value | Configurable values --- | --- | --- -AllowComments | `false` | Boolean +AllowComments | `true` | Boolean ### References