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 negative on Style/FormatString? #1512

Closed
kakutani opened this issue Dec 19, 2014 · 1 comment
Closed

False negative on Style/FormatString? #1512

kakutani opened this issue Dec 19, 2014 · 1 comment
Assignees

Comments

@kakutani
Copy link

Rubocop(master) looks make false nagative against typical sprintf/format cases.

Some example cases(picked from ruby-doc.org) will fail tests.

This patch will make the test suite is passing:

diff --git a/lib/rubocop/cop/style/format_string.rb b/lib/rubocop/cop/style/format_string.rb
index e75095a..37c12df 100644
--- a/lib/rubocop/cop/style/format_string.rb
+++ b/lib/rubocop/cop/style/format_string.rb
@@ -31,13 +31,13 @@ def offending_node?(node)
         end

         def format_method?(name, node)
-          receiver, method_name, args = *node
+          receiver, method_name, *args = *node

           # commands have no explicit receiver
           return false unless !receiver && method_name == name

           # we do an argument count check to reduce false positives
-          args && args.children.size >= 2
+          args.size >= 2
         end

         def format?(node)

I'm not sure why format(something, a, b) registers an offense in spec but format("%d %04x", 123, 123) does not.

It would be great if you guys look into it.

@eitoball
Copy link
Contributor

👍

@jonas054 jonas054 self-assigned this Dec 21, 2014
bbatsov added a commit that referenced this issue Dec 21, 2014
…rmat-string

[Fix #1512] Fix false negative for typical string formatting examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants