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

Rails/TransactionExitStatement false positive when mixing transaction and other blocks #658

Closed
Tietew opened this issue Mar 15, 2022 · 0 comments · Fixed by #662
Closed
Labels
bug Something isn't working

Comments

@Tietew
Copy link
Contributor

Tietew commented Mar 15, 2022

Rails/TransactionExitStatement detected on following break but its false positive.

FooModel.transaction do
  loop do
    break if should_exit? # just exit loop, not transaction
    some_works
  end
  puts "This line is always shown!"
end

Expected behavior

No offences detected.

Actual behavior

Rails/TransactionExitStatement detected at break

Steps to reproduce the problem

$ cat test.rb
FooModel.transaction do
  loop do
    break if should_exit? # just exit loop, not transaction
    some_works
  end
end
$ bundle exec rubocop test.rb --only Rails
Inspecting 1 file
C

Offenses:

test.rb:3:5: C: Rails/TransactionExitStatement: Exit statement break is not allowed. Use raise (rollback) or next (commit).
    break if should_exit? # just exit loop, not transaction
    ^^^^^

1 file inspected, 1 offense detected

RuboCop version

1.26.0 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 2.7.5 x86_64-linux)
  - rubocop-rails 2.14.0
@koic koic added the bug Something isn't working label Mar 15, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Mar 16, 2022
…tement`

Fixes rubocop#658.

This PR fixes an false positive for `Rails/TransactionExitStatement`
when `raise` is used in `loop` in transactions.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 16, 2022
…ement`

Fixes rubocop#658.

This PR fixes a false positive for `Rails/TransactionExitStatement`
when `raise` is used in `loop` in transactions.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 16, 2022
…ement`

Fixes rubocop#658.

This PR fixes a false positive for `Rails/TransactionExitStatement`
when `raise` is used in `loop` in transactions.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 16, 2022
…ement`

Fixes rubocop#658.

This PR fixes a false positive for `Rails/TransactionExitStatement`
when `raise` is used in `loop` in transactions.
koic added a commit to koic/rubocop-rails that referenced this issue Mar 16, 2022
…ement`

Fixes rubocop#658.

This PR fixes a false positive for `Rails/TransactionExitStatement`
when `break` is used in `loop` in transactions.
@koic koic closed this as completed in #662 Mar 16, 2022
koic added a commit that referenced this issue Mar 16, 2022
…saction_exit_statement

[Fix #658] Fix a false positive for `Rails/TransactionExitStatement`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants