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

Style/DocumentDynamicEvalDefinition error #9032

Closed
dreikanter opened this issue Nov 12, 2020 · 0 comments · Fixed by #9033
Closed

Style/DocumentDynamicEvalDefinition error #9032

dreikanter opened this issue Nov 12, 2020 · 0 comments · Fixed by #9033
Labels

Comments

@dreikanter
Copy link

dreikanter commented Nov 12, 2020

This code causes Style/DocumentDynamicEvalDefinition to throw an error:

stringio.instance_eval("def original_filename; 'stringio#{n}.txt'; end ")

I don't have any custom configuration for this cop.


Expected behavior

I would expect this cop to work with no errors.

Actual behavior

Here is the error log, you may notice "undefined method `heredoc_body'" error message:

~/a/amplifr (chore/rubocop130) (exit 1) > rubocop  --debug test.rb
For /Users/dreikanter/amplifr/amplifr: configuration from /Users/dreikanter/amplifr/amplifr/.rubocop.yml
configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.8.1/config/default.yml
configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.8.1/config/default.yml
Default configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/config/default.yml
configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-rspec-2.0.0.pre/config/default.yml
configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-rspec-2.0.0.pre/config/default.yml
configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.8.1/config/default.yml
configuration from /Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.8.1/config/default.yml
Inheriting configuration from /Users/dreikanter/amplifr/amplifr/.rubocop_todo.yml
Inspecting 1 file
Scanning /Users/dreikanter/amplifr/amplifr/test.rb
An error occurred while Style/DocumentDynamicEvalDefinition cop was inspecting /Users/dreikanter/amplifr/amplifr/test.rb:1:0.
undefined method `heredoc_body' for #<Parser::Source::Map::Collection:0x00007f7ffa742490>
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/style/document_dynamic_eval_definition.rb:101:in `comment_block_docs?'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/style/document_dynamic_eval_definition.rb:82:in `on_send'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:166:in `with_cop_error_handling'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.1.1/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/team.rb:157:in `investigate_partial'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:315:in `inspect_file'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:286:in `loop'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:131:in `file_offenses'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:122:in `process_file'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:100:in `each'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:100:in `reduce'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/runner.rb:47:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/lib/rubocop/cli.rb:41:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/exe/rubocop:13:in `block in <top (required)>'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.3.0/exe/rubocop:12:in `<top (required)>'
/Users/dreikanter/.rbenv/versions/2.7.0/bin/rubocop:23:in `load'
/Users/dreikanter/.rbenv/versions/2.7.0/bin/rubocop:23:in `<top (required)>'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/Users/dreikanter/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/Users/dreikanter/.rbenv/versions/2.7.0/bin/bundle:23:in `load'
/Users/dreikanter/.rbenv/versions/2.7.0/bin/bundle:23:in `<main>'
C

Offenses:

test.rb:1:1: C: Style/EvalWithLocation: Pass __FILE__ and __LINE__ to eval method, as they are used by backtraces.
stringio.instance_eval("def original_filename; 'stringio#{n}.txt'; end ")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

1 error occurred:
An error occurred while Style/DocumentDynamicEvalDefinition cop was inspecting /Users/dreikanter/amplifr/amplifr/test.rb:1:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
1.3.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.0 x86_64-darwin19)
Finished in 0.9276580000296235 seconds

Steps to reproduce the problem

I've upgraded rubocop to 1.3.0 and ran it on my codebase.

RuboCop version

$ rubocop -V
1.3.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.7.0 x86_64-darwin19)
  - rubocop-performance 1.8.1
  - rubocop-rails 2.8.1
  - rubocop-rspec 2.0.0.pre
@koic koic added the bug label Nov 12, 2020
koic added a commit to koic/rubocop that referenced this issue Nov 12, 2020
…ion`

Fixes rubocop#9032.

This PR fixes an error for `Style/DocumentDynamicEvalDefinition` when using
eval-type method with interpolated string that is not heredoc without comment doc.

It may be better to provide an option to accept non-heredoc interpolated-string in future.
bbatsov pushed a commit that referenced this issue Nov 13, 2020
Fixes #9032.

This PR fixes an error for `Style/DocumentDynamicEvalDefinition` when using
eval-type method with interpolated string that is not heredoc without comment doc.

It may be better to provide an option to accept non-heredoc interpolated-string in future.
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.

2 participants