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

Add new Lint/EmptyBlock cop #8895

Merged
merged 1 commit into from Oct 22, 2020
Merged

Conversation

fatkodima
Copy link
Contributor

This cop checks for blocks without a body.

# bad
items.each { |item| }

# good
items.each { |item| puts item }

Blocks without a body most of the time indicate useless code (left after refactoring, for example) or that some explanation about its emptiness should be given (using a comment).

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 16, 2020

I'm guessing an empty one-line block with a comment after it would fine as well. E.g.

x = ->{} # no-op

@fatkodima
Copy link
Contributor Author

I'm guessing an empty one-line block with a comment after it would fine as well. E.g.
x = ->{} # no-op

This will conflict with Style/InlineComment

How about preceding comment then?

# no-op
x = ->{}

@marcandre
Copy link
Contributor

This will conflict with Style/InlineComment

That cop is (thankfully) disabled by default. In any case, inline comment should be supported.

@fatkodima
Copy link
Contributor Author

Added support for inline comments.

config/default.yml Outdated Show resolved Hide resolved
@bbatsov bbatsov merged commit 437216b into rubocop:master Oct 22, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 22, 2020

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants