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

Prevent Layout/SpaceAroundBlockParameters from breaking on lambda #4441

Merged

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented May 29, 2017

Layout/SpaceAroundKeyword cop crashes on lambda literal that does not have parens.

-> a { puts a }
$ rubocop --debug
An error occurred while Layout/SpaceAroundBlockParameters cop was inspecting /tmp/tmp.OXikUmBqDF/test.rb:1:0.

1 error occurred:
An error occurred while Layout/SpaceAroundBlockParameters cop was inspecting /tmp/tmp.OXikUmBqDF/test.rb:1:0.
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.49.0 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-linux)
For /tmp/tmp.OXikUmBqDF: configuration from /home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/config/default.yml
Inheriting configuration from /home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/config/enabled.yml
Inheriting configuration from /home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/config/disabled.yml
Inspecting 1 file
Scanning /tmp/tmp.OXikUmBqDF/test.rb
undefined method `end_pos' for nil:NilClass
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/layout/space_around_block_parameters.rb:54:in `check_no_space_style_inside_pipes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/layout/space_around_block_parameters.rb:44:in `check_inside_pipes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/layout/space_around_block_parameters.rb:26:in `on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:44:in `block (2 levels) in on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:43:in `block in on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:42:in `each'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:42:in `on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/ast/traversal.rb:12:in `walk'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:60:in `investigate'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/team.rb:112:in `investigate'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/team.rb:100:in `offenses'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/team.rb:42:in `inspect_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:258:in `inspect_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:205:in `block in do_inspection_loop'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:237:in `block in iterate_until_no_changes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:230:in `loop'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:230:in `iterate_until_no_changes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:201:in `do_inspection_loop'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:111:in `block in file_offenses'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:121:in `file_offense_cache'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:109:in `file_offenses'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:100:in `process_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:75:in `each'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:75:in `reduce'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:75:in `each_inspected_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:67:in `inspect_files'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:39:in `run'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cli.rb:82:in `execute_runner'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cli.rb:28:in `run'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/bin/rubocop:13:in `block in <top (required)>'
/usr/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/bin/rubocop:12:in `<top (required)>'
/home/pocke/.gem/ruby/2.4.0/bin/rubocop:22:in `load'
/home/pocke/.gem/ruby/2.4.0/bin/rubocop:22:in `<main>'
C

Offenses:

test.rb:1:1: C: Layout/SpaceInLambdaLiteral: Do not use spaces between -> and opening brace in lambda literals
-> a { puts a }
^^^^^^^^^^^^^^^
test.rb:1:4: C: Style/StabbyLambdaParentheses: Wrap stabby lambda arguments with parentheses.
-> a { puts a }
   ^

1 file inspected, 2 offenses detected
Finished in 0.07601038400025573 seconds

This change fixes the problem, and adds specs for lambda literals.


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.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

@pocke pocke force-pushed the SpaceAroundBlockParameters-with-lambda branch from 67ea21b to b06de2c Compare May 29, 2017 11:03
`Layout/SpaceAroundKeyword` cop crashes on lambda literal that does not have parens.

```ruby
-> a { puts a }
```

```bash
$ rubocop --debug
An error occurred while Layout/SpaceAroundBlockParameters cop was inspecting /tmp/tmp.OXikUmBqDF/test.rb:1:0.

1 error occurred:
An error occurred while Layout/SpaceAroundBlockParameters cop was inspecting /tmp/tmp.OXikUmBqDF/test.rb:1:0.
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.49.0 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-linux)
For /tmp/tmp.OXikUmBqDF: configuration from /home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/config/default.yml
Inheriting configuration from /home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/config/enabled.yml
Inheriting configuration from /home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/config/disabled.yml
Inspecting 1 file
Scanning /tmp/tmp.OXikUmBqDF/test.rb
undefined method `end_pos' for nil:NilClass
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/layout/space_around_block_parameters.rb:54:in `check_no_space_style_inside_pipes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/layout/space_around_block_parameters.rb:44:in `check_inside_pipes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/layout/space_around_block_parameters.rb:26:in `on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:44:in `block (2 levels) in on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:43:in `block in on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:42:in `each'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:42:in `on_block'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/ast/traversal.rb:12:in `walk'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/commissioner.rb:60:in `investigate'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/team.rb:112:in `investigate'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/team.rb:100:in `offenses'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cop/team.rb:42:in `inspect_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:258:in `inspect_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:205:in `block in do_inspection_loop'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:237:in `block in iterate_until_no_changes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:230:in `loop'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:230:in `iterate_until_no_changes'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:201:in `do_inspection_loop'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:111:in `block in file_offenses'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:121:in `file_offense_cache'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:109:in `file_offenses'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:100:in `process_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:75:in `each'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:75:in `reduce'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:75:in `each_inspected_file'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:67:in `inspect_files'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/runner.rb:39:in `run'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cli.rb:82:in `execute_runner'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/lib/rubocop/cli.rb:28:in `run'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/bin/rubocop:13:in `block in <top (required)>'
/usr/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/home/pocke/.gem/ruby/2.4.0/gems/rubocop-0.49.0/bin/rubocop:12:in `<top (required)>'
/home/pocke/.gem/ruby/2.4.0/bin/rubocop:22:in `load'
/home/pocke/.gem/ruby/2.4.0/bin/rubocop:22:in `<main>'
C

Offenses:

test.rb:1:1: C: Layout/SpaceInLambdaLiteral: Do not use spaces between -> and opening brace in lambda literals
-> a { puts a }
^^^^^^^^^^^^^^^
test.rb:1:4: C: Style/StabbyLambdaParentheses: Wrap stabby lambda arguments with parentheses.
-> a { puts a }
   ^

1 file inspected, 2 offenses detected
Finished in 0.07601038400025573 seconds
```

This change fixes the problem, and adds specs for lambda literals.
@bbatsov bbatsov merged commit c670327 into rubocop:master May 29, 2017
@pocke pocke deleted the SpaceAroundBlockParameters-with-lambda branch May 29, 2017 11:56
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