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

More bugs in FormatParameterMismatch cop #2116

Closed
bquorning opened this issue Aug 6, 2015 · 23 comments
Closed

More bugs in FormatParameterMismatch cop #2116

bquorning opened this issue Aug 6, 2015 · 23 comments
Labels

Comments

@bquorning
Copy link
Contributor

@edmz

It looks like #2112 fixes the bug I reported in #2110, so now I noticed another two bugs:

# encoding: utf-8
puts 'foo %{bar} baz' % { bar: 42 }
puts 'duration: %10.fms' % 42
Offenses:

test.rb:2:23: W: Number arguments (1) to String#% mismatches expected fields (0).
puts 'foo %{bar} baz' % { bar: 42 }
                      ^
test.rb:3:26: W: Number arguments (1) to String#% mismatches expected fields (0).
puts 'duration: %10.fms' % 42
                         ^

1 file inspected, 2 offenses detected

This is on the latest master, including https://github.com/bbatsov/rubocop/pull/2112.patch. I’m sorry I didn’t notice these bugs previously.

@bquorning bquorning changed the title More bugs in FormatParameterMismatch cop? More bugs in FormatParameterMismatch cop Aug 6, 2015
@bbatsov bbatsov added the bug label Aug 7, 2015
@kytrinyx
Copy link

kytrinyx commented Aug 8, 2015

I also found this one, which generates the error Number arguments (3) to String#% mismatches expected fields (1).

puts '"%s" % "a b c".gsub(" ", "_")'

Here's a failing spec for it:

it 'does not register an offense for % when argument is the result of a message send' do
  inspect_source(cop, '"%s" % "a b c".gsub(" ", "_")')
  expect(cop.offenses).to be_empty
end

kytrinyx added a commit to exercism/ruby that referenced this issue Aug 8, 2015
There were some backwards incompatible changes that caused new offenses to be triggered
on CI, which in turn causes PRs to fail for reasons unrelated to the code they're changing.

I was going to fix the new offenses, but one of them is actually triggered by
a bug in the rubocop library (see rubocop/rubocop#2116), so this turned
out to require more time than I could spare for it today.
@edmz
Copy link
Contributor

edmz commented Aug 10, 2015

thank you for the spec. Working on a fix.

On Sat, Aug 8, 2015 at 3:43 PM Katrina Owen notifications@github.com
wrote:

I also found this one:

puts '"%s" % "a b c".gsub(" ", "_")'

Here's a failing spec for it:

it 'does not register an offense for % when argument is the result of a message send' do
inspect_source(cop, '"%s" % "a b c".gsub(" ", "_")')
expect(cop.offenses).to be_empty
end


Reply to this email directly or view it on GitHub
#2116 (comment).

@edmz
Copy link
Contributor

edmz commented Aug 10, 2015

@bbatsov, any ideas on how to deal with this one in particular?

On Mon, Aug 10, 2015 at 10:10 AM Eduardo Dominguez eduardodmz@gmail.com
wrote:

thank you for the spec. Working on a fix.

On Sat, Aug 8, 2015 at 3:43 PM Katrina Owen notifications@github.com
wrote:

I also found this one:

puts '"%s" % "a b c".gsub(" ", "_")'

Here's a failing spec for it:

it 'does not register an offense for % when argument is the result of a message send' do
inspect_source(cop, '"%s" % "a b c".gsub(" ", "_")')
expect(cop.offenses).to be_empty
end


Reply to this email directly or view it on GitHub
#2116 (comment).

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 10, 2015

The first case can be handled, although I'm guessing it will require a lot of work. The second should simply be ignored.

@edmz
Copy link
Contributor

edmz commented Aug 10, 2015

I think I have fixes for all reported issues.

How urgent are these? I would like to test a bit more if possible.

On Mon, Aug 10, 2015 at 10:14 AM Bozhidar Batsov notifications@github.com
wrote:

The first case can be handled, although I'm guessing it will require a lot
of work. The second should simply be ignored.


Reply to this email directly or view it on GitHub
#2116 (comment).

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 10, 2015

Not super urgent, so feel free to do as much testing as needed.

@bquorning
Copy link
Contributor Author

If you push your branch, I will happily run it against my project's code base.

@edmz
Copy link
Contributor

edmz commented Aug 10, 2015

@bquorning thank you, will do!

@edmz
Copy link
Contributor

edmz commented Aug 10, 2015

@bquorning My branch with the fixes is here: https://github.com/edmz/rubocop/tree/fix_params_mismatch_bug

Its not yet in shape for a PR, I just wanted to accept your offer to test it :)

@bquorning
Copy link
Contributor Author

Using your branch, I’m still getting one warning – when using a heredoc. Test file:

# encoding: utf-8
puts <<-TXT % { bar: 42 }
  foo %{bar} baz
TXT

@edmz
Copy link
Contributor

edmz commented Aug 10, 2015

@bbatsov could you help me? I don't know how to detect a heredoc.

I tried searching other cops for an example but failed to find one,
probably due to my inhability to grep correctly.

On Mon, Aug 10, 2015 at 1:43 PM Benjamin Quorning notifications@github.com
wrote:

Using your branch, I’m still getting one warning – when using a heredoc.
Test file:

encoding: utf-8

puts <<-TXT % { bar: 42 } foo %{bar} bazTXT


Reply to this email directly or view it on GitHub
#2116 (comment).

@edmz
Copy link
Contributor

edmz commented Aug 14, 2015

@bbatsov ping :)

On Monday, August 10, 2015, Eduardo Dominguez eduardodmz@gmail.com wrote:

@bbatsov could you help me? I don't know how to detect a heredoc.

I tried searching other cops for an example but failed to find one,
probably due to my inhability to grep correctly.

On Mon, Aug 10, 2015 at 1:43 PM Benjamin Quorning <
notifications@github.com
javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

Using your branch, I’m still getting one warning – when using a heredoc.
Test file:

encoding: utf-8

puts <<-TXT % { bar: 42 } foo %{bar} bazTXT


Reply to this email directly or view it on GitHub
#2116 (comment).

Eduardo

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 14, 2015

I tried searching other cops for an example but failed to find one,
probably due to my inhability to grep correctly.

A heredoc is just a string as far as the parser is concerned, so you can inspect loc.begin of string elements to see if they aren't heredocs. Alternatively you can tap into the tokenized version of the code.

@edmz
Copy link
Contributor

edmz commented Aug 14, 2015

I have that fixed too

On Friday, August 14, 2015, Bozhidar Batsov notifications@github.com
wrote:

@edmz https://github.com/edmz There's also this
https://github.com/bbatsov/rubocop/blob/4240ae468edbd1e1589ed3501cc16cbba3ab8513/lib/rubocop/cop/style/command_literal.rb#L82
:-)


Reply to this email directly or view it on GitHub
#2116 (comment).

Eduardo

@edmz
Copy link
Contributor

edmz commented Aug 17, 2015

@bquorning If you have the time and willingness, could you try my latest patch?

Thanks in advance

@bquorning
Copy link
Contributor Author

@edmz I tried your branch, and don’t see any offenses when running RuboCop against my code.

@kytrinyx
Copy link

I ran it against mine and was still seeing the warnings for

W: Number arguments (3) to String#% mismatches expected fields (1).
    'test_%s' % description.gsub(/[ -]/, '_')

(I wasn't sure if it was expected to be fixed, so I just wanted to comment, in case).

@edmz
Copy link
Contributor

edmz commented Aug 19, 2015

@kytrinyx thanks for your input, I will check that case.

@edmz
Copy link
Contributor

edmz commented Aug 19, 2015

@kytrinyx I just checked the following case:

'test_%s' % description.gsub(/[ -]/, '_')

and the only offense for that line is:

Favor format over String#%

Did you apply the latest PR?

That said, this could be something on my side that I am not seeing.

@kytrinyx
Copy link

Ah, latest PR--I thought it had been merged, and tested against master. I'll test again, thanks!

@edmz
Copy link
Contributor

edmz commented Aug 21, 2015

@kytrinyx did you have a chance to test it against your code? :)

@kytrinyx
Copy link

Sorry, things got out of hand. Yes, I have now tested it! (drumroll) no offenses detected.

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

4 participants