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

Regression in FormatParameterMismatch? #3869

Closed
backus opened this issue Jan 6, 2017 · 6 comments
Closed

Regression in FormatParameterMismatch? #3869

backus opened this issue Jan 6, 2017 · 6 comments

Comments

@backus
Copy link
Contributor

backus commented Jan 6, 2017

After looking at @pocke's findings for #3868 I ran the latest rubocop build on rubyspec. This file seems to have found an error with FormatParameterMismatch: https://github.com/ruby/spec/blob/cee95712953b1b913b7a4933ac07816a39a7acd8/core/string/modulo_spec.rb

An error occurred while Lint/FormatParameterMismatch cop was inspecting /Users/johnbackus/Projects/rubyspec/core/string/modulo_spec.rb.
undefined method `type' for nil:NilClass
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:139:in `arguments_count'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:107:in `count_matches'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:46:in `offending_node?'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:36:in `on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:41:in `block (2 levels) in on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:100:in `with_cop_error_handling'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:40:in `block in on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:39:in `each'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:39:in `on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:154:in `on_block'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_block'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:101:in `block in on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:99:in `each'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:99:in `each_with_index'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:99:in `on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_send'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:154:in `on_block'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:154:in `on_block'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_block'
(eval):2:in `block in on_begin'
(eval):2:in `each'
(eval):2:in `on_begin'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:45:in `on_begin'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:12:in `walk'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:58:in `investigate'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/team.rb:121:in `investigate'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/team.rb:109:in `offenses'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/team.rb:51:in `inspect_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:248:in `inspect_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:195:in `block in do_inspection_loop'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:227:in `block in iterate_until_no_changes'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:220:in `loop'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:220:in `iterate_until_no_changes'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:191:in `do_inspection_loop'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:101:in `block in file_offenses'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:111:in `file_offense_cache'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:99:in `file_offenses'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:90:in `process_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:68:in `block in each_inspected_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:65:in `each'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:65:in `reduce'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:65:in `each_inspected_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:57:in `inspect_files'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:36:in `run'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cli.rb:72:in `execute_runner'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cli.rb:27:in `run'
bin/rubocop:13:in `block in <main>'
/Users/johnbackus/.rubies/ruby-2.3.1/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
bin/rubocop:12:in `<main>'
@backus
Copy link
Contributor Author

backus commented Jan 6, 2017

I can try to whittle down the code causing the error later

@backus
Copy link
Contributor Author

backus commented Jan 7, 2017

Minimal reproduction

$ echo "'%' % []" | bin/rubocop --only FormatParameterMismatch --stdin - --debug
For /Users/johnbackus/Projects/rubocop: configuration from /Users/johnbackus/Projects/rubocop/.rubocop.yml
Inheriting configuration from /Users/johnbackus/Projects/rubocop/.rubocop_todo.yml
Default configuration from /Users/johnbackus/Projects/rubocop/config/default.yml
Inheriting configuration from /Users/johnbackus/Projects/rubocop/config/enabled.yml
Inheriting configuration from /Users/johnbackus/Projects/rubocop/config/disabled.yml
Inspecting 1 file
Scanning /Users/johnbackus/Projects/rubocop/-
An error occurred while Lint/FormatParameterMismatch cop was inspecting /Users/johnbackus/Projects/rubocop/-.
undefined method `type' for nil:NilClass
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:139:in `arguments_count'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:107:in `count_matches'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:46:in `offending_node?'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/lint/format_parameter_mismatch.rb:36:in `on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:41:in `block (2 levels) in on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:100:in `with_cop_error_handling'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:40:in `block in on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:39:in `each'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:39:in `on_send'
/Users/johnbackus/Projects/rubocop/lib/rubocop/ast/traversal.rb:12:in `walk'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/commissioner.rb:58:in `investigate'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/team.rb:121:in `investigate'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/team.rb:109:in `offenses'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cop/team.rb:51:in `inspect_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:248:in `inspect_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:195:in `block in do_inspection_loop'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:227:in `block in iterate_until_no_changes'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:220:in `loop'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:220:in `iterate_until_no_changes'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:191:in `do_inspection_loop'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:101:in `block in file_offenses'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:111:in `file_offense_cache'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:99:in `file_offenses'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:90:in `process_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:68:in `block in each_inspected_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:65:in `each'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:65:in `reduce'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:65:in `each_inspected_file'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:57:in `inspect_files'
/Users/johnbackus/Projects/rubocop/lib/rubocop/runner.rb:36:in `run'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cli.rb:72:in `execute_runner'
/Users/johnbackus/Projects/rubocop/lib/rubocop/cli.rb:27:in `run'
bin/rubocop:13:in `block in <main>'
/Users/johnbackus/.rubies/ruby-2.3.1/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
bin/rubocop:12:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/FormatParameterMismatch cop was inspecting /Users/johnbackus/Projects/rubocop/-.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.46.0 (using Parser 2.3.3.1, running on ruby 2.3.1 x86_64-darwin16)
Finished in 0.06896200001938269 seconds

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 7, 2017

^^ @zverok

Drenmi added a commit to Drenmi/rubocop that referenced this issue Jan 7, 2017
…ng when `#%` is passed an empty array

This cop would break if `#%` was passed an empty array, as it attempted
to check the type of the last element of the array (which would be
`nil`.)

This change fixes that.
@Drenmi
Copy link
Collaborator

Drenmi commented Jan 7, 2017

This was amazingly not a regression from the huge refactoring PR (it was introduced earlier in #3858), which both of @pocke's findings were.

But I submitted a fix anyhow. 😀

On a side note, I should have thought of running the refactored code against rubyspec ... 🤔

@zverok
Copy link
Contributor

zverok commented Jan 7, 2017

Sorry :( And thanks @Drenmi for the fix.

@Drenmi
Copy link
Collaborator

Drenmi commented Jan 7, 2017

No worries. Ruby has so many edge cases, it would be strange if we didn't have these now and then. 😊

@bbatsov bbatsov closed this as completed in 44c0052 Jan 8, 2017
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