-
-
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
Add a new Style/EvalWithLocation
cop
#5173
Conversation
0da4c4d
to
ffc8e1a
Compare
module RuboCop | ||
module Cop | ||
module Style | ||
# TODO |
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 you forgot about this. :-)
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'll update it!
# RUBY | ||
class EvalWithLocation < Cop | ||
MSG = 'Pass `__FILE__` and `__LINE__` to `eval` method ' \ | ||
'to display actual backtrace.'.freeze |
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 think this should be reworded to something mentioning "source location metadata (that's used by backtraces)."
MSG = 'Pass `__FILE__` and `__LINE__` to `eval` method ' \ | ||
'to display actual backtrace.'.freeze | ||
MSG_INCORRECT_LINE = 'Use `%<expected>s` instead of `%<actual>s` ' \ | ||
'to display actual backtrace.'.freeze |
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.
Same here.
ffc8e1a
to
39b9cf4
Compare
I added the documentation and updated the messages.
Sorry, I'm not sure what you meant. I updated the message to |
I'd only replace the second sentence with |
This has to be rebased, btw. |
I understand. Thanks! I'll update the messages, and rebase. |
39b9cf4
to
26f56cb
Compare
👍 |
@pocke Why does the example in the PR description pass |
It is my mistake, |
🤔 I don't think I understand why the offset is necessary? Perhaps the reasoning/instructions should be documented and/or included in part of the offense message? I imagine people will frequently look at the documentation and include the offset when they don't need to and/or not include the offset when they do need to. |
Wow, this is the first time that RuboCop actually signals a genuine error for me, thanks to this cop 🎉 |
eval
can receive a file name and a line number to display actual backtrace.For example:
If we pass
__FILE__
and__LINE__
to aneval
method, an exception that occurs in the eval method has a backtrace with actual file name and line number. But sometimes we forget writing__FILE__
and__LINE__
.This cop detects this problem. This cop adds an offense for an
eval
method call without a location.Note: I think we can implement auto-correction for this cop in the next step.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).rake spec
) are passing.rake internal_investigation
.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).