-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
Addded rspec test case for the cop. |
lib/cops/raise_message_cop.rb
Outdated
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 |
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.
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?
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.
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.
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.
I was talking about this case: https://stackoverflow.com/a/23771227
Implemented a cop to check that every "raise" has some arguments.