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

Wrong number of arguments (given 2, expected 1) #10745

Closed
mbykovskyy opened this issue Jun 23, 2022 · 7 comments · Fixed by #10769
Closed

Wrong number of arguments (given 2, expected 1) #10745

mbykovskyy opened this issue Jun 23, 2022 · 7 comments · Fixed by #10769
Labels

Comments

@mbykovskyy
Copy link

Expected behavior

bundle exec rubocop should run successfully.

Actual behavior

Exists with an error:

❯ be rubocop -d
For /Users/maksymbykovskyy/dev/roskilde: configuration from /Users/maksymbykovskyy/dev/roskilde/.rubocop.yml
Inheriting configuration from /Users/maksymbykovskyy/dev/.rubocop.yml
Default configuration from /Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/config/default.yml
AllCops/Exclude configuration from /Users/maksymbykovskyy/dev/.rubocop.yml
Use parallel by default.
Running parallel inspection
Inspecting 50 files
Scanning /Users/maksymbykovskyy/dev/roskilde/Gemfile
Loading cache from /Users/maksymbykovskyy/.cache/rubocop_cache/0156023dc493a877ce3a036797e78dde696ff482/6d7a3b621ca1730e04accd938619e4bdab66cfb1/8af134f10501ae5d548c9381ac38f922d13743fc
.

0 files inspected, no offenses detected
wrong number of arguments (given 2, expected 1)
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/json-1.8.6/lib/json/common.rb:155:in `initialize'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/json-1.8.6/lib/json/common.rb:155:in `new'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cached_data.rb:14:in `from_json'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/result_cache.rb:119:in `load'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:145:in `file_offense_cache'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:120:in `process_file'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:100:in `each'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:100:in `reduce'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/runner.rb:47:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli/command.rb:11:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli/environment.rb:18:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli.rb:71:in `run_command'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/lib/rubocop/cli.rb:47:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/exe/rubocop:12:in `block in <top (required)>'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/exe/rubocop:12:in `<top (required)>'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/bin/rubocop:25:in `load'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/bin/rubocop:25:in `<top (required)>'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `load'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:58:in `kernel_load'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/cli/exec.rb:23:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:484:in `exec'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:31:in `dispatch'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/cli.rb:25:in `start'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:48:in `block in <top (required)>'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/friendly_errors.rb:103:in `with_friendly_errors'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.7/libexec/bundle:36:in `<top (required)>'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
/Users/maksymbykovskyy/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'
Finished in 0.8689230000018142 seconds

Steps to reproduce the problem

.rubocop.yml

inherit_from: ../.rubocop.yml

AllCops:
  TargetRubyVersion: 3.0.1
  NewCops: enable

../.rubocop.yml

AllCops:
  TargetRubyVersion: 2.7.2
  NewCops: enable

Layout/LineLength:
  Max: 120

Metrics/ClassLength:
  Max: 250

Metrics/MethodLength:
  Max: 25

Layout/FirstArrayElementIndentation:
  EnforcedStyle: consistent

Layout/FirstHashElementIndentation:
  EnforcedStyle: consistent

Layout/MultilineOperationIndentation:
  EnforcedStyle: indented

Layout/MultilineMethodCallIndentation:
  EnforcedStyle: indented

RuboCop version

❯ ruby --version && bundle --version && be rubocop --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
Bundler version 2.3.7
1.30.1
@mbykovskyy
Copy link
Author

Running it with bundle exec rubocop -C false works ok.

@dvandersluis
Copy link
Member

Probably something broken got stored in your cache try removing the /Users/maksymbykovskyy/.cache/rubocop_cache directory

@mbykovskyy
Copy link
Author

I removed everything from that dir and it still throws the same error. The cached file just has [] in it.

@edruder
Copy link

edruder commented Jun 25, 2022

I can't reproduce this issue, either.

> ruby --version && bundle --version && be rubocop --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
Bundler version 2.3.7
1.30.1
> ls
./             ../            .rubocop.yml   .ruby-version  Gemfile        Gemfile.lock
> ls ..
./            ../           .rubocop.yml  test/
> be rubocop -d
For /Users/edruder/code/rubocop/test: configuration from /Users/edruder/code/rubocop/test/.rubocop.yml
Inheriting configuration from /Users/edruder/code/rubocop/.rubocop.yml
Default configuration from /Users/edruder/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.30.1/config/default.yml
Use parallel by default.
Running parallel inspection
Inspecting 1 file
Scanning /Users/edruder/code/rubocop/test/Gemfile
Loading cache from /Users/edruder/.cache/rubocop_cache/7ae94859851c3f155eb908fe13b417bef395ef30/6d7a3b621ca1730e04accd938619e4bdab66cfb1/af910bc9f40649d6f2b7639f250b4b3c2983175c
.

1 file inspected, no offenses detected
Finished in 0.2418600000000879 seconds

@mjobin-mdsol
Copy link

json 1.8 with ruby 3.1 ?!? really?

probably a good time to bump your json gem to ~> 2.3

@koic
Copy link
Member

koic commented Jun 29, 2022

@mjobin-mdsol Great! I've confirmed it and opened #10769 to resolve the issue.

@koic koic added the bug label Jun 29, 2022
koic added a commit to koic/rubocop that referenced this issue Jun 29, 2022
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
bbatsov pushed a commit that referenced this issue Jun 29, 2022
Fixes #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
@mbykovskyy
Copy link
Author

json 1.8 with ruby 3.1 ?!? really?

probably a good time to bump your json gem to ~> 2.3

@mjobin-mdsol, good catch! Looks like we need to update some gems. @koic, thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants