-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add new Style/EmptyLinesAroundExceptionHandlingKeywords
cop
#3995
Add new Style/EmptyLinesAroundExceptionHandlingKeywords
cop
#3995
Conversation
c9164de
to
e4c3cd9
Compare
module RuboCop | ||
module Cop | ||
module Style | ||
# This cops checks if empty lines exist around the bodies of begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add backquotes around keyword names.
module Cop | ||
module Style | ||
# This cops checks if empty lines exist around the bodies of begin | ||
# sections. This cop doesn't check empty lines at begin body starting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at begin
body beginning/end.
end | ||
|
||
def keyword_locations_in_rescue(node) | ||
_, *resbodies, _ = *node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use _something
names here. They add more clarity IMO.
include_examples :offense, | ||
'rescue section ending for method definition', | ||
<<-CODE, <<-CORRECTION | ||
def foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really hate outdented hereblocks. Use the strip_margin
method from powerpack
to pretty those up a bit.
end | ||
end | ||
|
||
def style |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a placeholder for making the cop configurable?
line = loc.line | ||
keyword = loc.source | ||
# on the keyword | ||
check_line(style, line, format(MSG, 'on', keyword), &:empty?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on -> before
# on the keyword | ||
check_line(style, line, format(MSG, 'on', keyword), &:empty?) | ||
# under the keyword | ||
check_line(style, line - 2, format(MSG, 'under', keyword), &:empty?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
under -> after
include EmptyLinesAroundBody | ||
include OnMethodDef | ||
|
||
MSG = 'Extra empty line detected %s the %s.'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the %s -> %s
(in backquotes)
e4c3cd9
to
163ce88
Compare
Thanks for the nice suggestion 👍
No, I imitated here. https://github.com/bbatsov/rubocop/blob/ec3123fc3454b080e1100e35480c6466d1240fff/lib/rubocop/cop/style/empty_lines_around_method_body.rb#L35-L37 I've updated the other suggestions. |
Looks good but has to be rebased. |
```ruby # bad begin foo rescue bar end # good begin foo rescue bar end ``` See also rubocop#3984 Fix
163ce88
to
6f02896
Compare
I've rebased. Thanks. |
See also #3984
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).