Skip to content

Rails/TransactionExitStatement false positive with until loop #1495

@owst

Description

@owst

Similar to #658 but using a until loop rather than loop:

ApplicationRecord.transaction do
  until stop_looping?
    break if condition

    do_something
  end
end

has offence:

Inspecting 1 file
C

Offenses:

loop.rb:3:5: C: Rails/TransactionExitStatement: Exit statement break is not allowed. Use raise (rollback) or next (commit).
    break if condition
    ^^^^^

1 file inspected, 1 offense detected

Expected behavior

No offense - the break affects the until not the transaction.

Actual behavior

Offense found.

Steps to reproduce the problem

Code as above

RuboCop version

$ bundle exec rubocop -V
1.77.0 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 2.7, running on ruby 3.3.7) [arm64-darwin24]
  - rubocop-performance 1.24.0
  - rubocop-rails 2.32.0
  - rubocop-rspec 3.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions