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

Change AllowComments of Lint/SuppressedException to true by default #7805

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions config/default.yml
Expand Up @@ -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.'
Expand Down
34 changes: 12 additions & 22 deletions lib/rubocop/cop/lint/suppressed_exception.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/clang_style_formatter.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/tap_formatter.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/processed_source.rb
Expand Up @@ -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

Expand Down
39 changes: 14 additions & 25 deletions manual/cops_lint.md
Expand Up @@ -2279,41 +2279,25 @@ 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
do_something
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
Expand All @@ -2328,41 +2312,46 @@ 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
```

### Configurable attributes

Name | Default value | Configurable values
--- | --- | ---
AllowComments | `false` | Boolean
AllowComments | `true` | Boolean

### References

Expand Down