-
-
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
New cop FormatParamterMismatch
checks format
for wrong parameter count
#2057
Conversation
This is a good idea for a cop, but you're only halfway done. You need to:
|
I agree. @bbatsov was going to comment on it first since I have never done Thanks for letting me know whsts missing. On Tuesday, July 21, 2015, Jonas Arvidsson [email protected] wrote:
Eduardo |
I've made some progress on the tests, but somehow, I cant run 'rake spec' without getting:
Any idea what could be wrong? |
Likely you didn't add it here - https://github.com/bbatsov/rubocop/blob/master/lib/rubocop.rb Grepping for the name of some cop is a good way to find all the changes you have to make when introducing a new one. |
module Cop | ||
module Lint | ||
# This lint sees if there is a mismatch between the number of | ||
# expected parameters for format and what is actually passed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class comment should also include some examples of the kind of code that would trigger the cop.
Thanks for the input. I am making progress but I think I hit a roadblock. Is there a way to access to contents of a const? This is the case I am concerned about:
|
That's doable, but it's pretty hard. Our policy so far has been to simply ignore such cases. |
Ok, sounds good. |
Please let me know if I am missing anything. |
@@ -2,6 +2,9 @@ | |||
|
|||
## master (unreleased) | |||
|
|||
* [#2057](https://github.com/bbatsov/rubocop/pull/2057): New cop `Lint/FormatParameterMismatch` checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in "New features". You should add yourself to the bottom of this file.
Apart from my small remarks the code looks good. Before we can merge the cop you'll also have to squash all commit together and ideally run this on a few bigger projects (e.g. Rails and Rubinius). This helps us be sure there aren't edge cases we missed. |
One more thing - I don't see support for: puts "%.4s\\%.2s\\%s" % ["1","2","3"] |
Good catch! On Wed, Jul 22, 2015 at 12:46 PM Bozhidar Batsov [email protected]
|
I will try to add more coverage and use cases, but it might be very hard to be exhaustive due to the flexibility of what sprintf() can receive. |
No problem. Take your time. |
@edmz Heads up - I plan to release 0.33 later this week. If you'd like this cop to get in you'll have to wrap it soon. |
25bacd4
to
da9de33
Compare
@bbatsov so I worked on this and:
|
You'll need to rebase your branch on top of the current |
da9de33
to
39e947c
Compare
@bbatsov Rebased! I've never done so much git-fu before :) |
I still see a merge conflict. Guess you'll have to rebase again. |
39e947c
to
fb3ebac
Compare
Rebased again. Its the changelog. I guess you merged something before merging this that created the conflict. Hopefully this time it will work. |
I've noticed a typo in your commit message. |
expect(cop.offenses).to be_empty | ||
end | ||
|
||
it 'registers an offense for %' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, String#%
instead of %
- it's more informative.
fb3ebac
to
77246e8
Compare
FormatParamterMismatch -> FormatParameterMismatch |
77246e8
to
b9d35f5
Compare
Ah, missed that. Hopefully I got it right this time. On Fri, Jul 31, 2015 at 11:02 AM Bozhidar Batsov [email protected]
|
New cop `FormatParamterMismatch` checks `format` for wrong parameter count
👍 We're good to go! Thanks! |
Currently works for
format
andsprintf
only.