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/SoleNestedConditional should not trigger when variable is declared in condition. #9603

Closed
antondalgren opened this issue Mar 15, 2021 · 0 comments
Labels

Comments

@antondalgren
Copy link

@antondalgren antondalgren commented Mar 15, 2021

 irb
irb(main):001:0> a = { a: 12 }
=> {:a=>12}
irb(main):002:1* if b = a[:a] && b
irb(main):003:1*   puts b
irb(main):004:0> end
=> nil
irb(main):005:0> a = { a: 12 }
=> {:a=>12}
irb(main):006:1* if b = a[:a]
irb(main):007:1*   puts b if b
irb(main):008:0> end
12
=> nil
irb(main):009:0> 

I tried to adress this issue my self, but I had a hard time understanding the AST, it's methods etc.


Expected behavior

a = { a: 12 }
if b = a[:a]
  puts b if b
end

Actual behavior

a = { a: 12 }
if b = a[:a] && b
  puts b
end

Steps to reproduce the problem

Spec that fails:

  it 'does not register an offense when using nested modifier on value declared in condition' do
    expect_no_offenses(<<~RUBY)
    if foo && bar = something_else
      do_something if bar
    end
    RUBY
  end

RuboCop version

❯ rubocop -V
1.10.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 arm64-darwin20)
  - rubocop-minitest 0.10.3
  - rubocop-performance 1.10.1
@koic koic added the bug label Mar 15, 2021
koic added a commit to koic/rubocop that referenced this issue Mar 15, 2021
…nal`

Fixes rubocop#9603.

This PR fixes a false positive for `Style/SoleNestedConditional`
when using nested modifier on value assigned in condition.
koic added a commit to koic/rubocop that referenced this issue Mar 15, 2021
…nal`

Fixes rubocop#9603.

This PR fixes a false positive for `Style/SoleNestedConditional`
when using nested modifier on value assigned in condition.
koic added a commit to koic/rubocop that referenced this issue Mar 16, 2021
…nal`

Fixes rubocop#9603.

This PR fixes a false positive for `Style/SoleNestedConditional`
when using nested modifier on value assigned in condition.
bbatsov added a commit that referenced this issue Mar 16, 2021
Fixes #9603.

This PR fixes a false positive for `Style/SoleNestedConditional`
when using nested modifier on value assigned in condition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants