Skip to content

Commit

Permalink
Tweak offense message for Rails/RelativeDateConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed Mar 27, 2021
1 parent 9469931 commit 442f612
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/relative_date_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RelativeDateConstant < Base
include RangeHelp
extend AutoCorrector

MSG = 'Do not assign %<method_name>s to constants as it ' \
MSG = 'Do not assign `%<method_name>s` to constants as it ' \
'will be evaluated only once.'
RELATIVE_DATE_METHODS = %i[since from_now after ago until before yesterday tomorrow].freeze

Expand Down
22 changes: 11 additions & 11 deletions spec/rubocop/cop/rails/relative_date_constant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SomeClass
expect_offense(<<~RUBY)
class SomeClass
EXPIRED_AT = 1.week.since
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign since to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `since` to constants as it will be evaluated only once.
end
RUBY

Expand All @@ -47,7 +47,7 @@ def self.expired_at
expect_offense(<<~RUBY)
class SomeClass
RECENT_DATE = Date.yesterday
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign yesterday to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `yesterday` to constants as it will be evaluated only once.
end
RUBY

Expand All @@ -64,7 +64,7 @@ def self.recent_date
expect_offense(<<~RUBY)
class SomeClass
FUTURE_DATE = Time.zone.tomorrow
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign tomorrow to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `tomorrow` to constants as it will be evaluated only once.
end
RUBY

Expand All @@ -81,7 +81,7 @@ def self.future_date
expect_offense(<<~RUBY)
class SomeClass
START_DATE = 2.weeks.ago.to_date
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign ago to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `ago` to constants as it will be evaluated only once.
end
RUBY

Expand All @@ -98,7 +98,7 @@ def self.start_date
expect_offense(<<~RUBY)
class SomeClass
TRIAL_PERIOD = DateTime.current..1.day.since
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign since to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `since` to constants as it will be evaluated only once.
end
RUBY

Expand All @@ -115,7 +115,7 @@ def self.trial_period
expect_offense(<<~RUBY)
class SomeClass
TRIAL_PERIOD = DateTime.current...1.day.since
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign since to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `since` to constants as it will be evaluated only once.
end
RUBY
end
Expand All @@ -124,7 +124,7 @@ class SomeClass
expect_offense(<<~RUBY)
class SomeClass
TRIAL_PERIOD = 1.day.ago..DateTime.current
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign ago to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `ago` to constants as it will be evaluated only once.
end
RUBY
end
Expand All @@ -133,7 +133,7 @@ class SomeClass
expect_offense(<<~RUBY)
class SomeClass
TRIAL_PERIOD = 1.day.ago...DateTime.current
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign ago to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `ago` to constants as it will be evaluated only once.
end
RUBY
end
Expand All @@ -144,7 +144,7 @@ class SomeClass
expect_offense(<<~RUBY)
class SomeClass
EXPIRED_AT ||= 1.week.since
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign since to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `since` to constants as it will be evaluated only once.
end
RUBY
end
Expand All @@ -155,8 +155,8 @@ class SomeClass
expect_offense(<<~RUBY)
class SomeClass
START, A, x = 2.weeks.ago, 1.week.since, 5
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign ago to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign since to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `ago` to constants as it will be evaluated only once.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not assign `since` to constants as it will be evaluated only once.
end
RUBY
end
Expand Down

0 comments on commit 442f612

Please sign in to comment.