-
-
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
Fix false negative in Lint/Void
with initialize and setter methods
#4457
Conversation
spec/rubocop/cop/lint/void_spec.rb
Outdated
end | ||
|
||
it 'registers two offenses for void literals in an initialize method' do | ||
expect_offense(<<-END.strip_indent) |
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.
Use RUBY
everywhere consistently. We really need a cop to warn for usages of END
.
lib/rubocop/cop/lint/void.rb
Outdated
@@ -102,6 +104,17 @@ def check_for_defined(node) | |||
|
|||
add_offense(node, :expression, format(DEFINED_MSG, node.source)) | |||
end | |||
|
|||
# `initialize` and setter methods is not return value of last |
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.
do not return
parent = node.parent | ||
return false unless parent | ||
method = parent.children.first | ||
parent.def_type? && |
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.
@Drenmi I see a def
node extension potential 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.
Yes. Both def
and defs
have been on my list for some time. They're probably next. 🙂
In `initialize` and setter methods, returned value is ignored(See rubocop#4153). ```ruby def initialize 42 # This value is ignored. end ``` However, `Lint/Void` cop doesn't add an offense for the above code. This change makes to add an offense for the code.
That'd be best - he hasn't touched this in months and I have doubts he'll pick it up any time soon. |
In
initialize
and setter methods, returned value is ignored(See #4153).However,
Lint/Void
cop doesn't add an offense for the above code.This change makes to add an offense for the code.
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).