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

Don't crash on a multiline empty brace in Style/MultilineMethodCallBraceLayout #3456

Merged

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented Aug 30, 2016

RuboCop crashes with the following code.

test.rb

x(
)
$ rubocop --cache false -d test.rb
An error occurred while Style/MultilineMethodCallBraceLayout cop was inspecting /home/pocke/ghq/github.com/bbatsov/rubocop/test.rb.

1 error occurred:
An error occurred while Style/MultilineMethodCallBraceLayout cop was inspecting /home/pocke/ghq/github.com/bbatsov/rubocop/test.rb.
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.42.0 (using Parser 2.3.1.2, running on ruby 2.3.1 x86_64-linux)
For /home/pocke/ghq/github.com/bbatsov/rubocop: configuration from /home/pocke/ghq/github.com/bbatsov/rubocop/.rubocop.yml
Inheriting configuration from /home/pocke/ghq/github.com/bbatsov/rubocop/.rubocop_todo.yml
Default configuration from /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/config/default.yml
Inheriting configuration from /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/config/enabled.yml
Inheriting configuration from /home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/config/disabled.yml
Inspecting 1 file
Scanning /home/pocke/ghq/github.com/bbatsov/rubocop/test.rb
undefined method `loc' for nil:NilClass
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb:105:in `opening_brace_on_same_line?'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb:60:in `check_symmetrical'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb:41:in `check'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb:18:in `check_brace_layout'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/multiline_method_call_brace_layout.rb:77:in `on_send'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:42:in `block (2 levels) in on_send'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:97:in `with_cop_error_handling'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:41:in `block in on_send'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:40:in `each'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:40:in `on_send'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/ast_node/traversal.rb:13:in `walk'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/commissioner.rb:59:in `investigate'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:121:in `investigate'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:109:in `offenses'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:52:in `inspect_file'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:228:in `inspect_file'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:198:in `block in do_inspection_loop'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:188:in `loop'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:188:in `do_inspection_loop'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:93:in `block in file_offenses'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:103:in `file_offense_cache'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:91:in `file_offenses'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:82:in `process_file'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `each'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `inspect_files'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:35:in `run'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cli.rb:72:in `execute_runner'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/lib/rubocop/cli.rb:28:in `run'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/bin/rubocop:14:in `block in <top (required)>'
/usr/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/home/pocke/.gem/ruby/2.3.0/gems/rubocop-0.42.0/bin/rubocop:13:in `<top (required)>'
/home/pocke/.gem/ruby/2.3.0/bin/rubocop:23:in `load'
/home/pocke/.gem/ruby/2.3.0/bin/rubocop:23:in `<main>'
C

Offenses:

test.rb:1:1: C: Style/Encoding: Missing utf-8 encoding comment.
x(
^^
test.rb:1:1: C: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
x(
^
test.rb:1:2: C: Style/MethodCallParentheses: Do not use parentheses for method calls with no arguments.
x(
 ^
test.rb:2:1: C: Style/ClosingParenthesisIndentation: Align ) with (.
)
^

1 file inspected, 4 offenses detected
Finished in 0.04562400601571426 seconds

So, I've fixed the bug, and I've added test cases.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.

@pocke pocke force-pushed the fix-crash-multiline_method_call_brace_layout branch from dda130f to 423f5d7 Compare August 30, 2016 15:07
@bbatsov bbatsov merged commit 3436956 into rubocop:master Aug 30, 2016
@pocke pocke deleted the fix-crash-multiline_method_call_brace_layout branch September 18, 2016 13:50
Neodelf pushed a commit to Neodelf/rubocop that referenced this pull request Oct 15, 2016
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

Successfully merging this pull request may close these issues.

2 participants