Skip to content

Commit

Permalink
Fix a false positive for Lint/IncompatibleIoSelectWithFiberScheduler
Browse files Browse the repository at this point in the history
This PR fixes a false positive for `Lint/IncompatibleIoSelectWithFiberScheduler`
when using excepts argument.

AFAIK, `IO.wait_readable` and `IO.wait_writable` cannot replace IO objects waiting for exceptions.
  • Loading branch information
koic authored and bbatsov committed May 13, 2023
1 parent 922501f commit 0970cc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11830](https://github.com/rubocop/rubocop/pull/11830): Fix a false positive for `Lint/IncompatibleIoSelectWithFiberScheduler`. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module Lint
#
# This cop checks for `IO.select` that is incompatible with Fiber Scheduler since Ruby 3.0.
#
# When an array of IO objects waiting for an exception (the third argument of `IO.select`)
# is used as an argument, there is no alternative API, so offenses are not registered.
#
# NOTE: When the method is successful the return value of `IO.select` is `[[IO]]`,
# and the return value of `io.wait_readable` and `io.wait_writable` are `self`.
# They are not autocorrected when assigning a return value because these types are different.
Expand Down Expand Up @@ -42,8 +45,8 @@ class IncompatibleIoSelectWithFiberScheduler < Base
PATTERN

def on_send(node)
read, write, _excepts, timeout = *io_select(node)
return unless read
read, write, excepts, timeout = *io_select(node)
return if excepts && !excepts.children.empty?
return unless scheduler_compatible?(read, write) || scheduler_compatible?(write, read)

preferred = preferred_method(read, write, timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@
RUBY
end

it 'does not register an offense when using `IO.select` with read and excepts arguments' do
expect_no_offenses(<<~RUBY)
IO.select([rp], [], [excepts])
RUBY
end

it 'does not register an offense when using `Enumerable#select`' do
expect_no_offenses(<<~RUBY)
collection.select { |item| item.do_something? }
Expand Down

0 comments on commit 0970cc1

Please sign in to comment.