Faker: 2.2.0 triggers deprecation warnings from...inside the gem

Created on 30 Aug 2019  路  6Comments  路  Source: faker-ruby/faker

Describe the bug

Trying to update the gem to 2.2.0 and we get a lot of deprecation warnings from inside the gem:

/.../vendor/bundle/ruby/2.6.0/gems/faker-2.2.0/lib/helpers/unique_generator.rb:22: Passing `number` with the 1st argument of `Lorem.words` is deprecated. Use keyword argument like `Lorem.words(number: ...)` instead.

We've spend a significant amount of time trying to fix all these warnings, which also translated to errors in some places (which is highly unsual for a minor gem update). Now we're seeing warnings coming from the gem itself. I would recommend being a bit more careful when releasing changes like these, since they affect quite a big number of apps, which may or may not have the time to spend on something less then non-critical 馃槉

All 6 comments

@koic

@linkyndy which version were you using before? < 2?

We had 1.9.3.

We knew that switching from positional parameters to keywords parameters would be painful, but we believed that keyword parameters would help us by providing self documentation.

We also changed the Faker::Number generator and made it start returning integer instead of string.

Thanks for raising this issue. We've received other pieces of feedback, we consider all of them and are always happy to discuss and evolve Faker together 馃憤

FYI, I created RuboCop Faker gem.
https://github.com/koic/rubocop-faker

The following command can be used to check and auto-correct the Faker 2 argument style.

Check positional argument style before Faker 2.

% rubocop --require rubocop-faker --only Faker/DeprecatedArguments

Auto-correction to keyword argument style on Faker 2.

% rubocop --require rubocop-faker --only Faker/DeprecatedArguments --auto-correct

This is the approach that factory_bot used to change APIs. The migration command was displayed with a deprecation warning at runtime.
https://github.com/thoughtbot/factory_bot/commit/dabacdace6ccde067438a72b3336769c052fb621

Dear @koic , dear @vbrazo

I am having the same problem and it comes from a file within _Faker_, not in my own code. Not much I can do to fix it in my project.

/Users/adeynack/.rvm/gems/ruby-2.6.5/gems/faker-2.10.1/lib/helpers/unique_generator.rb:22: Passing `number` with the 1st argument of `sentences` is deprecated. Use keyword argument like `sentences(number: ...)` instead.

To automatically update from positional arguments to keyword arguments,
install rubocop-faker and run:

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
Was this page helpful?
0 / 5 - 0 ratings

Related issues

benpolinsky picture benpolinsky  路  5Comments

oyeanuj picture oyeanuj  路  5Comments

CJAdeszko picture CJAdeszko  路  6Comments

zyrthofar picture zyrthofar  路  6Comments

mhutter picture mhutter  路  5Comments