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

Error in Style/MethodCallWithArgsParentheses (with Autocorrect) #5951

Closed
pdobb opened this issue Jun 5, 2018 · 6 comments · May be fixed by perangusta/devise_security_extension#1
Closed
Assignees
Labels

Comments

@pdobb
Copy link
Contributor

pdobb commented Jun 5, 2018

When running rubocop --auto-correct with the following settings:

Style/MethodCallWithArgsParentheses:
  Enabled: true

I receive an exception:

undefined method `begin' for #Parser::Source::Map::Constant:0x00007f864827eb80


Expected behavior

I expect Style/MethodCallWithArgsParentheses cop to complete without exception, as per usual.

Actual behavior

I get a Parser error part way through the auto-correct procedure. That is, it fixes some number of issues and then at some point fails with:

 app/uploaders/part_photo_uploader.rb:141:5: C: [Corrected] Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments. (https://github.com/bbatsov/ruby-style-guide#method-invocation-parens)
    new_file.content_type.start_with? "application"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 33/1553 files |===>                                                                                                                                                                   |  ETA: 00:01:11
33 files inspected, 92 offenses detected, 92 offenses corrected
undefined method `begin' for #<Parser::Source::Map::Constant:0x00007f864827eb80>
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/ast/node.rb:468:in `parenthesized_call?'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/style/method_call_with_args_parentheses.rb:95:in `args_parenthesized?'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/style/method_call_with_args_parentheses.rb:85:in `args_begin'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/style/method_call_with_args_parentheses.rb:56:in `block in autocorrect'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/corrector.rb:61:in `block (2 levels) in rewrite'
/Users/pauld/.gem/ruby/2.3.7/gems/parser-2.5.1.0/lib/parser/source/tree_rewriter.rb:220:in `transaction'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/corrector.rb:60:in `block in rewrite'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/corrector.rb:58:in `each'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/corrector.rb:58:in `rewrite'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/team.rb:126:in `autocorrect_all_cops'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/team.rb:70:in `autocorrect'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/team.rb:98:in `block in offenses'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/team.rb:115:in `investigate'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/team.rb:94:in `offenses'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:265:in `inspect_file'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:212:in `block in do_inspection_loop'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:244:in `block in iterate_until_no_changes'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:237:in `loop'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:237:in `iterate_until_no_changes'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:208:in `do_inspection_loop'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:111:in `block in file_offenses'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:129:in `file_offense_cache'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:109:in `file_offenses'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:100:in `process_file'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:75:in `each'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:75:in `reduce'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:75:in `each_inspected_file'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:67:in `inspect_files'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/runner.rb:39:in `run'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cli.rb:160:in `execute_runner'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cli.rb:88:in `execute_runners'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/cli.rb:41:in `run'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/bin/rubocop:13:in `block in <top (required)>'
/Users/pauld/.rubies/ruby-2.3.7/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/bin/rubocop:12:in `<top (required)>'
/Users/pauld/.gem/ruby/2.3.7/bin/rubocop:23:in `load'
/Users/pauld/.gem/ruby/2.3.7/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

I'm actually not sure what is causing this, exactly. Each time I run rubocop --auto-correct in my project with Style/MethodCallWithArgsParentheses enabled I see the above exception, though. I don't see the exception if I don't use autocorrection.

Sorry, not sure how I can be more helpful here. Will report back if I find something of use.

RuboCop version

rubocop -V
0.56.0 (using Parser 2.5.1.0, running on ruby 2.3.7 x86_64-darwin17)
@Drenmi Drenmi added the bug label Jun 6, 2018
@Drenmi
Copy link
Collaborator

Drenmi commented Jun 6, 2018

@pdobb Could you run RuboCop with -d to pinpoint the file where the error happens, and post a redacted version of the code that causes it?

@pdobb
Copy link
Contributor Author

pdobb commented Jun 6, 2018

@Drenmi Thanks, that's a useful flag! It's caused by raise NotImplementedError in any method. For example, this class reproduces the issue:

class MyTestClass
  def my_method
    raise NotImplementedError
  end
end

Update:
raise StandardError also causes it.
raise ArgumentError does not.

@Drenmi Drenmi self-assigned this Jun 6, 2018
@pdobb
Copy link
Contributor Author

pdobb commented Jun 6, 2018

I also see

undefined method begin' for #<Parser::Source::Map::Variable:0x00007fcf68e263c0> /Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/ast/node.rb:468:in parenthesized_call?'

For e.g. build inside of a loop. For example:

class MyTestClass
  def my_method
    %w[a b].each do |letter|
      Object.new.build letter
    end
  end
end

If I remove the each loop and jsut do Object.new.build "a" it doesn't fail.

@Drenmi
Copy link
Collaborator

Drenmi commented Jun 6, 2018

Thanks @pdobb! I can reproduce both issues on master. Will start working on a fix.

@pdobb
Copy link
Contributor Author

pdobb commented Jun 6, 2018

Similar issue with:

undefined method begin' for #<Parser::Source::Map::Operator:0x00007ffa53f32028> /Users/pauld/.gem/ruby/2.3.7/gems/rubocop-0.56.0/lib/rubocop/ast/node.rb:468:in parenthesized_call?'

Given a sleep call:

class MyTestClass
  def my_method
    sleep 1
  end
end

I'll stop there unless you want me to keep on going. Thanks!

@Drenmi
Copy link
Collaborator

Drenmi commented Jun 6, 2018

Seems like they are all the same class of issue. I suspect any additional examples will point to the same root cause. 🙂

Drenmi added a commit to Drenmi/rubocop that referenced this issue Jun 9, 2018
…aising error in some cases

This cop would raise an error when auto-correcting certain
constructs, such as:

```
def foo
  sleep 1
end
```

This was happening because some of the Parser source maps are
missing the `begin` keyword.
@bbatsov bbatsov closed this as completed in aa6804e Jun 9, 2018
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