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

2.2.0 triggers deprecation warnings from...inside the gem #1714

Closed
linkyndy opened this issue Aug 30, 2019 · 6 comments
Closed

2.2.0 triggers deprecation warnings from...inside the gem #1714

linkyndy opened this issue Aug 30, 2019 · 6 comments

Comments

@linkyndy
Copy link

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 😊

@vbrazo
Copy link
Member

vbrazo commented Aug 30, 2019

@koic

@vbrazo
Copy link
Member

vbrazo commented Aug 30, 2019

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

@linkyndy
Copy link
Author

We had 1.9.3.

@vbrazo
Copy link
Member

vbrazo commented Aug 31, 2019

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 👍

@vbrazo vbrazo closed this as completed Aug 31, 2019
@koic
Copy link
Member

koic commented Sep 2, 2019

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.
thoughtbot/factory_bot@dabacda

koic added a commit to koic/faker that referenced this issue Sep 4, 2019
Follow up faker-ruby#1714.

This is a proposal to make it easy to convert positional arguments to
keyword arguments.

This approach is based on the experience that factory_bot has provided
for upgrades.

- thoughtbot/factory_bot@dabacda
- thoughtbot/factory_bot#1135

First, I prepared rubocop-faker gem for upgrading with auto-correction.
https://github.com/koic/rubocop-faker

This PR includes rubocop-faker autocorrect in deprecation.
The following is an example.

```console
% cat example.rb
require 'faker'

Faker::Lorem.words(10000, true)
```

## Before

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `Lorem.words` is
deprecated. Use keyword argument like `Lorem.words(number: ...)`
instead.
example.rb:3: Passing `supplemental` with the 2nd argument of
`Lorem.words` is deprecated. Use keyword argument like
`Lorem.words(supplemental: ...)` instead.
```

## After

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `words` is
deprecated. Use keyword argument like `words(number: ...)` instead.
example.rb:3: Passing `supplemental` with the 2nd argument of `words` is
deprecated. Use keyword argument like `words(supplemental: ...)`
instead.

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

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```

Basically, users can update by copying and pasting the command displayed
in the warning, so the upgrade is easy.
koic added a commit to koic/faker that referenced this issue Sep 4, 2019
Follow up faker-ruby#1714.

This is a proposal to make it easy to convert positional arguments to
keyword arguments.

This approach is based on the experience that factory_bot has provided
for upgrades.

- thoughtbot/factory_bot@dabacda
- thoughtbot/factory_bot#1135

First, I prepared rubocop-faker gem for upgrading with auto-correction.
https://github.com/koic/rubocop-faker

This PR includes rubocop-faker autocorrect in deprecation.
The following is an example.

```console
% cat example.rb
require 'faker'

Faker::Lorem.words(10000, true)
```

## Before

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `Lorem.words` is
deprecated. Use keyword argument like `Lorem.words(number: ...)`
instead.
example.rb:3: Passing `supplemental` with the 2nd argument of
`Lorem.words` is deprecated. Use keyword argument like
`Lorem.words(supplemental: ...)` instead.
```

## After

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `words` is
deprecated. Use keyword argument like `words(number: ...)` instead.
example.rb:3: Passing `supplemental` with the 2nd argument of `words` is
deprecated. Use keyword argument like `words(supplemental: ...)`
instead.

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

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```

Basically, users can update by copying and pasting the command displayed
in the warning, so the upgrade is easy.
vbrazo pushed a commit that referenced this issue Sep 6, 2019
Follow up #1714.

This is a proposal to make it easy to convert positional arguments to
keyword arguments.

This approach is based on the experience that factory_bot has provided
for upgrades.

- thoughtbot/factory_bot@dabacda
- thoughtbot/factory_bot#1135

First, I prepared rubocop-faker gem for upgrading with auto-correction.
https://github.com/koic/rubocop-faker

This PR includes rubocop-faker autocorrect in deprecation.
The following is an example.

```console
% cat example.rb
require 'faker'

Faker::Lorem.words(10000, true)
```

## Before

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `Lorem.words` is
deprecated. Use keyword argument like `Lorem.words(number: ...)`
instead.
example.rb:3: Passing `supplemental` with the 2nd argument of
`Lorem.words` is deprecated. Use keyword argument like
`Lorem.words(supplemental: ...)` instead.
```

## After

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `words` is
deprecated. Use keyword argument like `words(number: ...)` instead.
example.rb:3: Passing `supplemental` with the 2nd argument of `words` is
deprecated. Use keyword argument like `words(supplemental: ...)`
instead.

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

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```

Basically, users can update by copying and pasting the command displayed
in the warning, so the upgrade is easy.
@Adeynack
Copy link

Adeynack commented Feb 4, 2020

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

michebble pushed a commit to michebble/faker that referenced this issue Feb 16, 2020
Follow up faker-ruby#1714.

This is a proposal to make it easy to convert positional arguments to
keyword arguments.

This approach is based on the experience that factory_bot has provided
for upgrades.

- thoughtbot/factory_bot@dabacda
- thoughtbot/factory_bot#1135

First, I prepared rubocop-faker gem for upgrading with auto-correction.
https://github.com/koic/rubocop-faker

This PR includes rubocop-faker autocorrect in deprecation.
The following is an example.

```console
% cat example.rb
require 'faker'

Faker::Lorem.words(10000, true)
```

## Before

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `Lorem.words` is
deprecated. Use keyword argument like `Lorem.words(number: ...)`
instead.
example.rb:3: Passing `supplemental` with the 2nd argument of
`Lorem.words` is deprecated. Use keyword argument like
`Lorem.words(supplemental: ...)` instead.
```

## After

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `words` is
deprecated. Use keyword argument like `words(number: ...)` instead.
example.rb:3: Passing `supplemental` with the 2nd argument of `words` is
deprecated. Use keyword argument like `words(supplemental: ...)`
instead.

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

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```

Basically, users can update by copying and pasting the command displayed
in the warning, so the upgrade is easy.
davidmorton0 pushed a commit to davidmorton0/faker that referenced this issue Jul 12, 2021
Follow up faker-ruby#1714.

This is a proposal to make it easy to convert positional arguments to
keyword arguments.

This approach is based on the experience that factory_bot has provided
for upgrades.

- thoughtbot/factory_bot@dabacda
- thoughtbot/factory_bot#1135

First, I prepared rubocop-faker gem for upgrading with auto-correction.
https://github.com/koic/rubocop-faker

This PR includes rubocop-faker autocorrect in deprecation.
The following is an example.

```console
% cat example.rb
require 'faker'

Faker::Lorem.words(10000, true)
```

## Before

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `Lorem.words` is
deprecated. Use keyword argument like `Lorem.words(number: ...)`
instead.
example.rb:3: Passing `supplemental` with the 2nd argument of
`Lorem.words` is deprecated. Use keyword argument like
`Lorem.words(supplemental: ...)` instead.
```

## After

```console
% bundle exec ruby example.rb
example.rb:3: Passing `number` with the 1st argument of `words` is
deprecated. Use keyword argument like `words(number: ...)` instead.
example.rb:3: Passing `supplemental` with the 2nd argument of `words` is
deprecated. Use keyword argument like `words(supplemental: ...)`
instead.

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

rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```

Basically, users can update by copying and pasting the command displayed
in the warning, so the upgrade is easy.
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

4 participants