-
-
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
Style/FormatStringToken false positive #5245
Comments
Another instance of this is the use of
[Tagging #4539 for x-ref.] |
We ran into this with |
@pegasd Thanks for your bug report! I'll fix it. @jeremywadsack @envygeeks |
We ran into this with select like
|
@davidhrbac Yeah, I think that particular case is discussed in #5230 |
|
@pocke Thanks for linking that fix for |
Thanks for the quick fix! |
I see this as a false positive for |
Also in this spec: context 'something' do
let(:content) { template % address }
^^
let(:expected) { template % something(address) }
let(:address) { '[email protected]' }
context 'text' do
let(:template) { 'prefix %s suffix' }
it 'yields encoded content' do
expect(subject.run(content)).to eq(expected)
end
end
end |
This appeared when we recently upgraded RuboCop: I don't think it's a style we should enforce. The named tokens in format strings can be useful in very complicated cases, but those cases are not the norm, and the check's suggested style makes simple cases *less* readable. In 0.52.0 it also has bugs leading to many false positives where changing the code as suggested would result in incorrect behavior: rubocop/rubocop#5245.
This appeared when we recently upgraded RuboCop: I don't think it's a style we should enforce. The named tokens in format strings can be useful in very complicated cases, but those cases are not the norm, and the check's suggested style makes simple cases *less* readable. In 0.52.0 it also has bugs leading to many false positives where changing the code as suggested would result in incorrect behavior: rubocop/rubocop#5245.
Hi guys, I using the rubocop version rubocop-0.52.1 and rails 5.1.1 ruby version is 2.4.2p198 How can I solve this issue? |
@lionel218 the cop wants you to use something like: format('%<day>s %<start>s-%<end>s', day: starts_at.strftime('%a'), start: starts_at.strftime('%l%P'), end: ends_at.strftime('%l%P').strip) |
Hi @mikegee , Just solved this issue. Thanks for your kindness. |
Hi @mikegee , How can I solve this issue?
|
Please help me for this issue. |
@lionel218 I failed to duplicate the issue with the example you provided. Please open a new issue with all the details if you think this bug is still in Rubocop. Thanks! |
@mikegee , Thanks for your kindness. Please check for my code and rubocop issue. def event_date(open_house) app/helpers/open_houses_helper.rb:3:77: C: Style/FormatStringToken: Prefer annotated tokens (like %s) over unannotated tokens (like %s). |
@lionel218 I confirmed with that code and opened another issue for you: #5630 |
Thanks so much @mikegee |
Sorry for bumping an old issue, but since it shows up in first page of Google if you search for: My code: [...]
when /RedHat|CentOS|Fedora|SLES/
installed_packages = Facter::Core::Execution.exec('rpm -qa --qf "%{NAME} %{VERSION}\n"').split('\n')
when /Debian|Ubuntu/
...
[...] Was throwing an error: Disabling [...]
when /RedHat|CentOS|Fedora|SLES/
# rubocop:disable Style/FormatStringToken
installed_packages = Facter::Core::Execution.exec('rpm -qa --qf "%{NAME} %{VERSION}\n"').split('\n')
# rubocop:enable Style/FormatStringToken
when /Debian|Ubuntu/
[...] It may not be the correct/best way to solve it, but it was the quickest for someone like me who has little knowledge about |
I came across the following false positive while doing rspec-puppet testing on an sshd module.
Sometimes contents of a file can include valid string tokens that look like unannotated Ruby tokens.
These are usually wrapped inside a RegEx for testing.
For example,
sshd_config
can include%u
which is a valid username reference.Expected behavior
The following code shouldn't be flagged as offensive:
Actual behavior
RuboCop triggers
Style/FormatStringToken
error:Steps to reproduce the problem
The snippet above triggers the described offense.
RuboCop version
The text was updated successfully, but these errors were encountered: