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 RSpec/EmptyHooks cop #897

Merged
merged 1 commit into from May 1, 2020

Conversation

tejasbubane
Copy link
Contributor

Closes #811


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the changelog if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • Added the new cop to config/default.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.

@tejasbubane tejasbubane force-pushed the empty-hooks-cop branch 6 times, most recently from 236a885 to 1f2d97c Compare April 20, 2020 18:56
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!
A few things can be improved in the cop itself, and the spec might be made more human-readable.

lib/rubocop/cop/rspec/empty_hook.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/empty_hook.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/empty_hook.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/empty_hook.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/empty_hook.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Show resolved Hide resolved
@pirj
Copy link
Member

pirj commented Apr 27, 2020

Ping

@tejasbubane
Copy link
Contributor Author

@pirj Fixed. Please review.

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks incredible, good job!

A few really minor notes concerning simplification.

config/default.yml Outdated Show resolved Hide resolved
lib/rubocop/cop/rspec/empty_hook.rb Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Show resolved Hide resolved
spec/rubocop/cop/rspec/empty_hook_spec.rb Outdated Show resolved Hide resolved
@pirj pirj requested review from Darhazer and bquorning April 28, 2020 10:09
@tejasbubane tejasbubane force-pushed the empty-hooks-cop branch 2 times, most recently from 4a2000d to 3db8502 Compare April 28, 2020 14:47
@tejasbubane
Copy link
Contributor Author

@pirj Changes done.

Copy link
Member

@Darhazer Darhazer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add autocorrect that removes the offending node

lib/rubocop/cop/rspec/empty_hook.rb Outdated Show resolved Hide resolved
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you!

@bquorning
Copy link
Collaborator

You can add autocorrect that removes the offending node

Do you want to give it a shot, @tejasbubane? Otherwise let’s open a new issue so we don’t forget to implement it.

@tejasbubane
Copy link
Contributor Author

tejasbubane commented Apr 30, 2020

@bquorning I have added autocorrect.

Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@bquorning
Copy link
Collaborator

I’d like a second review from @pirj or @Darhazer before merging.

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

Just in case maybe add a spec covering the case with semicolon?

@tejasbubane
Copy link
Contributor Author

@pirj Added spec for semicolon - it is a little ugly though - since it does not remove the semicolon.

@bquorning bquorning merged commit a0dadd6 into rubocop:master May 1, 2020
@tejasbubane tejasbubane deleted the empty-hooks-cop branch May 1, 2020 10:02
@pirj
Copy link
Member

pirj commented May 1, 2020

Added spec for semicolon - it is a little ugly though - since it does not remove the semicolon.

No worries, it's less ugly than before {}; after { delete_users } 😄

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.

Detect empty hooks (before, after, …)
4 participants