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

Fix false negative in Lint/Void with initialize and setter methods #4457

Merged
merged 1 commit into from
Jun 5, 2017

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented Jun 2, 2017

In initialize and setter methods, returned value is ignored(See #4153).

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.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

@Drenmi
Copy link
Collaborator

Drenmi commented Jun 3, 2017

Hi, @pocke!

There's work started on this in #4201. Maybe you two can collaborate? 🙂

end

it 'registers two offenses for void literals in an initialize method' do
expect_offense(<<-END.strip_indent)
Copy link
Collaborator

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.

@@ -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
Copy link
Collaborator

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? &&
Copy link
Collaborator

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. :-)

Copy link
Collaborator

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.
@pocke
Copy link
Collaborator Author

pocke commented Jun 5, 2017

@bbatsov Thanks for your reviewing. I updated the commit, and rebased.

@Drenmi

There's work started on this in #4201. Maybe you two can collaborate?

Hmm, I can collaborate on the pull-request if @harold-s is busy.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 5, 2017

Hmm, I can collaborate on the pull-request if @harold-s is busy.

That'd be best - he hasn't touched this in months and I have doubts he'll pick it up any time soon.

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.

3 participants