Rubocop: Style/FormatStringToken unannotated - false negative for Date/Time format

Created on 12 Dec 2017  路  4Comments  路  Source: rubocop-hq/rubocop

Rubocop 0.52.0 introduced check for unannotated style, and now it throws error on every timestamp expression with default configuration. It makes sense for sting interpolation, but it does not for string to date conversion pattern.

Expected behavior

... not to warn about '%Y-%m-%dT%H:%M:%S.%L%z'

Actual behavior

It throws Style/FormatStringToken: Prefer annotated tokens (like %<foo>s) over unannotated tokens (like %s).

Steps to reproduce the problem

Code that causes warning:

Time.strptime('2017-10-13T12:56:33.000Z', '%Y-%m-%dT%H:%M:%S.%L%z')

RuboCop version

$ rubocop -V
0.52.0 (using Parser 2.4.0.2, running on ruby 2.4.2 x86_64-darwin17)

Most helpful comment

@nattfodd it's not just date strings, it's _any_ string that contains a percent sign. Unless the string is being used via % or printf or something like that, the string should be ignored.

Example of a current false positive:

class Foo
  def foo
    my_var = '%something%'
  end
end

All 4 comments

@nattfodd it's not just date strings, it's _any_ string that contains a percent sign. Unless the string is being used via % or printf or something like that, the string should be ignored.

Example of a current false positive:

class Foo
  def foo
    my_var = '%something%'
  end
end

Hey guys. I can see that it was merged into 0.52.1
Locally I still get Style/FormatStringToken: Prefer annotated tokens (like %<foo>s) over unannotated tokens (like %s) when calling:

Time.strptime("04:30-14/01/2018", "%H:%M-%d/%m/%Y")

Am I missing something?

bundle show rubocop
=> .bundle/gems/rubocop-0.52.1

@vinagrito #5398

@AlexWayfer I knew I was missing something :). Thx!

Was this page helpful?
0 / 5 - 0 ratings