-
-
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 new Rails/RelativeDateConstant
cop
#4003
Conversation
|
module RuboCop | ||
module Cop | ||
module Rails | ||
# This cop checks whether constant are relative date. |
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.
The description of cop should be extended here.
# end | ||
# end | ||
class RelativeDateConstant < Cop | ||
MSG = 'Do not use `%s` in constant variable, because they ' \ |
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.
Do not assign %s
to constants as it will be evaluated only once.
MSG = 'Do not use `%s` in constant variable, because they ' \ | ||
'are evaluated only once at system running.'.freeze | ||
|
||
BAD_METHODS = %i(ago from_now since until).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.
RELATIVE_DATE_METHODS
end | ||
end | ||
|
||
def bad_method_without_args?(node) |
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
I'd drop without_args
from the name of the method
Looks OK to me apart from my small remarks. I guess it can even have auto-correct. |
Thanks for review comments. I fixed it. |
👍 |
We probably do not use relative date from system startup time as constant. This cop checks it.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).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).