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

Cop for checking empty raise #10

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Cop for checking empty raise #10

wants to merge 12 commits into from

Conversation

adip1818
Copy link
Contributor

Implemented a cop to check that every "raise" has some arguments.

@adip1818
Copy link
Contributor Author

Addded rspec test case for the cop.

lib/cops/readme.md Outdated Show resolved Hide resolved
@rparjun rparjun marked this pull request as ready for review August 3, 2022 05:15
@adip1818 adip1818 requested a review from rparjun August 3, 2022 05:16
return unless node.command?(:raise)
# If the raise encountered does not have any arguments, add the offense
# It ensures that raise is always accompanied with an argument.
if node.arguments.size<1
Copy link

Choose a reason for hiding this comment

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

i guess raise without argument is valid inside an exception handler block. In that case, it will raise the exception which it just caught, can you verify it?

Copy link
Contributor Author

@adip1818 adip1818 Aug 3, 2022

Choose a reason for hiding this comment

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

For exception handler cases, raise will return a "RunTime" error if given without argument by default, if we want to raise an Exception, we need to pass it as an argument.

With no arguments, raises the exception in "$!" or raises a RuntimeError if "$!" is nil.

https://stackoverflow.com/questions/4800698/what-is-the-difference-between-raise-foo-and-raise-exception-newfoo

Copy link

Choose a reason for hiding this comment

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

I was talking about this case: https://stackoverflow.com/a/23771227

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.

4 participants