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/SingleLineDoEndBlock
cop
#12227
Conversation
config/default.yml
Outdated
@@ -5186,6 +5186,11 @@ Style/SingleLineBlockParams: | |||
- acc | |||
- elem | |||
|
|||
Style/SingleLineDoEnd: |
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 think there's a style guide entry that you can refer here.
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.
Sure! I've opened rubocop/ruby-style-guide#922 to add a new rule for this one.
module RuboCop | ||
module Cop | ||
module Style | ||
# Checks for single-line `do`...`end` blocks. |
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.
You might also add a note about why the auto-correct doesn't replace do/end
with {}
, as perhaps this won't be clear for some people.
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.
Indeed, I've added an explain for that.
Follow up rubocop/rubocop#12227 (comment) This PR adds new `Single-line `do`...`end` block` rule. Use multi-line `do`...`end` block instead of single-line `do`...`end` block. ```ruby # bad foo do |arg| bar(arg) end # good foo do |arg| bar(arg) end # bad ->(arg) do bar(arg) end # good ->(arg) { bar(arg) } ```
Follow up rubocop/rubocop#12227 (comment) This PR adds new `Single-line `do`...`end` block` rule. Use multi-line `do`...`end` block instead of single-line `do`...`end` block. ```ruby # bad foo do |arg| bar(arg) end # good foo do |arg| bar(arg) end # bad ->(arg) do bar(arg) end # good ->(arg) { bar(arg) } ```
Follow up rubocop/rubocop#12227 (comment) This PR adds new "Single-line `do`...`end` block" rule. Use multi-line `do`...`end` block instead of single-line `do`...`end` block. ```ruby # bad foo do |arg| bar(arg) end # good foo do |arg| bar(arg) end # bad ->(arg) do bar(arg) end # good ->(arg) { bar(arg) } ```
d3fcf5b
to
74a9b8f
Compare
Style/SingleLineDoEnd
copStyle/SingleLineDoEndBlock
cop
This PR adds new `Style/SingleLineDoEndBlock` cop that checks for single-line `do`...`end` blocks. ```ruby # bad foo do |arg| bar(arg) end # good foo do |arg| bar(arg) end # bad ->(arg) do bar(arg) end # good ->(arg) { bar(arg) } ``` In practice a single line `do`...`end` is autocorrected when `EnforcedStyle: semantic` in `Style/BlockDelimiters`. It can also be detected by this cop if it is written by handcraft. So I decided to introduce this new cop instead of an autocorrect extension of `Style/BlockDelimiters`.
74a9b8f
to
8ad7335
Compare
Thanks! |
Follow up rubocop/rubocop#12227 (comment) This PR adds new "Single-line `do`...`end` block" rule. Use multi-line `do`...`end` block instead of single-line `do`...`end` block. ```ruby # bad foo do |arg| bar(arg) end # good foo do |arg| bar(arg) end # bad ->(arg) do bar(arg) end # good ->(arg) { bar(arg) } ```
* Update rubocop requirement from ~> 1.56.4 to ~> 1.58.0 Updates the requirements on [rubocop](https://github.com/rubocop/rubocop) to permit the latest version. - [Release notes](https://github.com/rubocop/rubocop/releases) - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md) - [Commits](rubocop/rubocop@v1.56.4...v1.58.0) --- updated-dependencies: - dependency-name: rubocop dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> * Suppress `Style/SingleLineDoEndBlock` in tests rubocop/rubocop#12227 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kenichi Kamiya <kachick1@gmail.com>
This PR adds new
Style/SingleLineDoEndBlock
cop that checks for single-linedo
...end
blocks.In practice a single line
do
...end
is autocorrected whenEnforcedStyle: semantic
inStyle/BlockDelimiters
. It can also be detected by this cop if it is written by handcraft. So I decided to introduce this new cop instead of an autocorrect extension ofStyle/BlockDelimiters
.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.