Add new Style/SingleLineDoEndBlock cop#12227
Merged
bbatsov merged 1 commit intorubocop:masterfrom Sep 29, 2023
Merged
Conversation
bbatsov
reviewed
Sep 29, 2023
config/default.yml
Outdated
Collaborator
There was a problem hiding this comment.
I think there's a style guide entry that you can refer here.
Member
Author
There was a problem hiding this comment.
Sure! I've opened rubocop/ruby-style-guide#922 to add a new rule for this one.
bbatsov
reviewed
Sep 29, 2023
Collaborator
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
Indeed, I've added an explain for that.
koic
added a commit
to koic/ruby-style-guide
that referenced
this pull request
Sep 29, 2023
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) } ```
koic
added a commit
to koic/ruby-style-guide
that referenced
this pull request
Sep 29, 2023
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) } ```
koic
added a commit
to koic/ruby-style-guide
that referenced
this pull request
Sep 29, 2023
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
Collaborator
|
Thanks! |
bbatsov
pushed a commit
to rubocop/ruby-style-guide
that referenced
this pull request
Nov 5, 2023
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) } ```
kachick
added a commit
to kachick/striuct
that referenced
this pull request
Dec 4, 2023
kachick
added a commit
to kachick/striuct
that referenced
this pull request
Dec 4, 2023
* 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] <[email protected]> * Suppress `Style/SingleLineDoEndBlock` in tests rubocop/rubocop#12227 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Kenichi Kamiya <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds new
Style/SingleLineDoEndBlockcop that checks for single-linedo...endblocks.In practice a single line
do...endis autocorrected whenEnforcedStyle: semanticinStyle/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}.mdif the new code introduces user-observable changes. See changelog entry format for details.