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

[Fix #10745] Fix an error when using old JSON gem #10769

Merged
merged 1 commit into from Jun 29, 2022

Conversation

koic
Copy link
Member

@koic koic commented Jun 29, 2022

Fixes #10745.

This PR fixes the following incompatible API error when using JSON 2.2 or lower.

% bunlde exec rspec  ./spec/rubocop/result_cache_spec.rb:45
Run options: include {:focus=>true,
:locations=>{"./spec/rubocop/result_cache_spec.rb"=>[45]}}

Randomized with seed 40926
FF

Failures:

  1) RuboCop::ResultCache cached result that was saved with no command
  line option when no option is given is valid and can be loaded
     Failure/Error: deserialize_offenses(JSON.parse(text))

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     Shared Example Group: "valid" called from
       ./spec/rubocop/result_cache_spec.rb:121
     # ./lib/rubocop/cached_data.rb:14:in `from_json'
     # ./lib/rubocop/result_cache.rb:119:in `load'
     # ./spec/rubocop/result_cache_spec.rb:45:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in
       <top (required)>'

  2) RuboCop::ResultCache cached result that was saved with no command
  line option when --format is given is valid and can be loaded
     Failure/Error: deserialize_offenses(JSON.parse(text))

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     Shared Example Group: "valid" called from
       ./spec/rubocop/result_cache_spec.rb:242
     # ./lib/rubocop/cached_data.rb:14:in `from_json'
     # ./lib/rubocop/result_cache.rb:119:in `load'
     # ./spec/rubocop/result_cache_spec.rb:45:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in
       <top (required)>'

Finished in 0.2064 seconds (files took 1.04 seconds to load)
2 examples, 2 failures

It resolves the error by requiring JSON 2.3 or higher.

NOTE: It's been a few years since JSON 2.3 was released. It's maybe widespread to some extent, so it's not expected to have a big impact.
https://rubygems.org/gems/json/versions/2.3.0


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

Fixes rubocop#10745.

This PR fixes the following incompatible API error
when using JSON 2.2 or lower.

```console
% bunlde exec rspec  ./spec/rubocop/result_cache_spec.rb:45
Run options: include {:focus=>true,
:locations=>{"./spec/rubocop/result_cache_spec.rb"=>[45]}}

Randomized with seed 40926
FF

Failures:

  1) RuboCop::ResultCache cached result that was saved with no command
  line option when no option is given is valid and can be loaded
     Failure/Error: deserialize_offenses(JSON.parse(text))

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     Shared Example Group: "valid" called from
       ./spec/rubocop/result_cache_spec.rb:121
     # ./lib/rubocop/cached_data.rb:14:in `from_json'
     # ./lib/rubocop/result_cache.rb:119:in `load'
     # ./spec/rubocop/result_cache_spec.rb:45:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in
       <top (required)>'

  2) RuboCop::ResultCache cached result that was saved with no command
  line option when --format is given is valid and can be loaded
     Failure/Error: deserialize_offenses(JSON.parse(text))

     ArgumentError:
       wrong number of arguments (given 2, expected 1)
     Shared Example Group: "valid" called from
       ./spec/rubocop/result_cache_spec.rb:242
     # ./lib/rubocop/cached_data.rb:14:in `from_json'
     # ./lib/rubocop/result_cache.rb:119:in `load'
     # ./spec/rubocop/result_cache_spec.rb:45:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in
       <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in
       <top (required)>'

Finished in 0.2064 seconds (files took 1.04 seconds to load)
2 examples, 2 failures
```

It resolves the error by requiring JSON 2.3 or higher.

NOTE: It's been a few years since JSON 2.3 was released. It's maybe
widespread to some extent, so it's not expected to have a big impact.
https://rubygems.org/gems/json/versions/2.3.0
@koic koic force-pushed the fix_an_error_when_using_old_json_gem branch from 5a1efbe to 8fa86bc Compare June 29, 2022 05:52
@bbatsov bbatsov merged commit 32b3991 into rubocop:master Jun 29, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 29, 2022

Thanks!

@koic koic deleted the fix_an_error_when_using_old_json_gem branch June 29, 2022 07:34
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

Successfully merging this pull request may close these issues.

Wrong number of arguments (given 2, expected 1)
2 participants