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

Fix an infinite loop for Style/RaiseArgs with EnforcedStyle: compact when passing more than 2 arguments to raise #12774

Merged

Conversation

Earlopain
Copy link
Contributor

The following test causes the loop:

context 'with a raise with 3 args' do
it 'reports an offense' do
expect_offense(<<~RUBY)
raise RuntimeError, msg, caller
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Provide an exception object as an argument to `raise`.
RUBY
expect_no_corrections
end
end

This changes expect_no_corrections to always raise if there are correctors. In this case the corrector replaced nothing, resulting in the same cop being invocted again for the same reason.

Undoing the cop change while keeping the assertion change will produce a failure. The source assertion is left in because it produces nice diffs if there are actually changes.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@Earlopain Earlopain force-pushed the fix-infinite-loop-for-style-raise-args branch from 1d473ad to a7a1341 Compare March 10, 2024 19:44
@Earlopain Earlopain changed the title Fix an infinite loop for Style/RaiseArgs with EnforcedStyle: compact when passing than 2 arguments to raise Fix an infinite loop for Style/RaiseArgs with EnforcedStyle: compact when passing more than 2 arguments to raise Mar 10, 2024
…ct` when passing than 2 arguments to `raise`

The following test caused the loop: https://github.com/rubocop/rubocop/blob/5ee786dcadfa3c91096d9e81dcd16e4776ca6186/spec/rubocop/cop/style/raise_args_spec.rb#L130-L140

This changes `expect_no_corrections`  to always raise if there are correctors. In this case, the corrector replaced nothing, resulting in the same cop
being invocted again for the same reason.

The source assertion is left in because it produces nice diffs if there are actually changes.
@Earlopain Earlopain force-pushed the fix-infinite-loop-for-style-raise-args branch from a7a1341 to 601a526 Compare March 11, 2024 08:08
@bbatsov bbatsov merged commit 8d2ef48 into rubocop:master Mar 11, 2024
33 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 11, 2024

Thanks!

@Earlopain Earlopain deleted the fix-infinite-loop-for-style-raise-args branch March 11, 2024 09:05
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Mar 11, 2024
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Mar 15, 2024
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.

None yet

3 participants