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

False positive on Time.days_in_month inside Range.new #3474

Closed
Fustrate opened this issue Sep 5, 2016 · 0 comments
Closed

False positive on Time.days_in_month inside Range.new #3474

Fustrate opened this issue Sep 5, 2016 · 0 comments
Labels

Comments

@Fustrate
Copy link

Fustrate commented Sep 5, 2016

I'm getting the following false positive:

Do not use Time.new without zone. Use one of Time.zone.local, Time.current, Time.new.in_time_zone, Time.new.utc, Time.new.getlocal, Time.new.iso8601, Time.new.jisx0301, Time.new.rfc3339, Time.new.to_i, Time.new.to_f instead.

on this code:

def make_calendar_hash(date)
  Range.new(1, Time.days_in_month(date.month, date.year)).map do |day| # <-- Here
    {
      date:   Time.zone.local(date.year, date.month, day),
      events: []
    }
  end
end

Strangely, it goes away when I move the method out of Range.new:

def make_calendar_hash(date)
  days_in_month = Time.days_in_month(date.month, date.year)

  Range.new(1, days_in_month).map do |day|
    {
      date:   Time.zone.local(date.year, date.month, day),
      events: []
    }
  end
end

days_in_month is a class method that only exists on Time as far as I can tell, although I think it has more to do with it being inside another method call than being a false positive unto itself.


$ rubocop -V
0.42.0 (using Parser 2.3.1.2, running on ruby 2.3.1 x86_64-darwin15)

I tested with both the published version (0.42.0) and built from master at 19b7035

@bbatsov bbatsov added the bug label Sep 6, 2016
b-t-g pushed a commit to b-t-g/rubocop that referenced this issue Oct 2, 2016
…ver does not contain an element of the Time class.
b-t-g pushed a commit to b-t-g/rubocop that referenced this issue Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants