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/ConditionalAssignment causes undefined method `column' for nil:NilClass #7165

Closed
znz opened this issue Jun 24, 2019 · 1 comment · Fixed by #7166
Closed

Style/ConditionalAssignment causes undefined method `column' for nil:NilClass #7165

znz opened this issue Jun 24, 2019 · 1 comment · Fixed by #7166
Labels

Comments

@znz
Copy link
Contributor

znz commented Jun 24, 2019

Expected behavior

Do not raise exception.

Actual behavior

When

  • EnforcedStyle: assign_inside_condition
  • condition without else
  • auto correction

causes error:

undefined method `column' for nil:NilClass

Steps to reproduce the problem

% cat .rubocop.yml
Style/ConditionalAssignment:
  EnforcedStyle: assign_inside_condition
% cat a.rb
foo ||=
  if foo1?
    foo1
  elsif foo2?
    foo2
  end
% rubocop -a --only Style/ConditionalAssignment a.rb
Inspecting 1 file


0 files inspected, no offenses detected
undefined method `column' for nil:NilClass

RuboCop version

0.71.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-darwin18)

@koic
Copy link
Member

koic commented Jun 24, 2019

Thanks for the feedback. I opened a PR #7166.

koic added a commit to koic/rubocop that referenced this issue Jun 24, 2019
Fixes rubocop#7165.

This PR fixes an auto-correct error for `Style/ConditionalAssignment` when without `else` branch'.

This error occurs when `EnforcedStyle: assign_inside_condition`.

```yaml
# .rubocop.yml
Style/ConditionalAssignment:
  EnforcedStyle: assign_inside_condition
```

```ruby
# example.rb
var = if foo
        bar
      elsif baz
        qux
      end
```

```console
% rubocop -a --only Style/ConditionalAssignment
Inspecting 1 file

0 files inspected, no offenses detected
undefined method `column' for nil:NilClass
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:600:in
`move_branch_'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:576:in
`block (2 lev'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:575:in
`each'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:575:in
`block in mov'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/corrector.rb:64:in
`block (2 levels) in rewrite'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/parser-2.6.3.0/lib/parser/source/tree_rewriter.rb:220:in
`transaction'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/corrector.rb:63:in
`block in rewrite'
```
bbatsov pushed a commit that referenced this issue Jun 25, 2019
Fixes #7165.

This PR fixes an auto-correct error for `Style/ConditionalAssignment` when without `else` branch'.

This error occurs when `EnforcedStyle: assign_inside_condition`.

```yaml
# .rubocop.yml
Style/ConditionalAssignment:
  EnforcedStyle: assign_inside_condition
```

```ruby
# example.rb
var = if foo
        bar
      elsif baz
        qux
      end
```

```console
% rubocop -a --only Style/ConditionalAssignment
Inspecting 1 file

0 files inspected, no offenses detected
undefined method `column' for nil:NilClass
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:600:in
`move_branch_'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:576:in
`block (2 lev'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:575:in
`each'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/style/conditional_assignment.rb:575:in
`block in mov'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/corrector.rb:64:in
`block (2 levels) in rewrite'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/parser-2.6.3.0/lib/parser/source/tree_rewriter.rb:220:in
`transaction'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/corrector.rb:63:in
`block in rewrite'
```
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