When running rubocop --auto-correct with the following settings:
Style/MethodCallWithArgsParentheses:
Enabled: true
I receive an exception:
undefined method `begin' for #
I expect Style/MethodCallWithArgsParentheses cop to complete without exception, as per usual.
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>'
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 -V
0.56.0 (using Parser 2.5.1.0, running on ruby 2.3.7 x86_64-darwin17)
@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?
@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.
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:inparenthesized_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.
Thanks @pdobb! I can reproduce both issues on master. Will start working on a fix.
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:inparenthesized_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!
Seems like they are all the same class of issue. I suspect any additional examples will point to the same root cause. 馃檪