mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
rubocop: fix offences of the Performance/RedundantBlockCall cop
This commit is contained in:
parent
985e448351
commit
bd25747bb7
5 changed files with 9 additions and 18 deletions
|
@ -169,15 +169,6 @@ Naming/MemoizedInstanceVariableName:
|
||||||
Naming/UncommunicativeMethodParamName:
|
Naming/UncommunicativeMethodParamName:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 6
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Performance/RedundantBlockCall:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/pry/commands/code_collector.rb'
|
|
||||||
- 'lib/pry/input_lock.rb'
|
|
||||||
- 'lib/pry/slop.rb'
|
|
||||||
- 'spec/command_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Performance/RedundantMatch:
|
Performance/RedundantMatch:
|
||||||
|
|
|
@ -122,13 +122,13 @@ class Pry
|
||||||
!args.empty?].count(true) > 1
|
!args.empty?].count(true) > 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def pry_array_content_as_string(array, ranges, &block)
|
def pry_array_content_as_string(array, ranges)
|
||||||
all = ''
|
all = ''
|
||||||
ranges.each do |range|
|
ranges.each do |range|
|
||||||
raise CommandError, "Minimum value for range is 1, not 0." if convert_to_range(range).first == 0
|
raise CommandError, "Minimum value for range is 1, not 0." if convert_to_range(range).first == 0
|
||||||
|
|
||||||
ranged_array = Array(array[range]) || []
|
ranged_array = Array(array[range]) || []
|
||||||
ranged_array.compact.each { |v| all << block.call(v) }
|
ranged_array.compact.each { |v| all << yield(v) }
|
||||||
end
|
end
|
||||||
|
|
||||||
all
|
all
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Pry
|
||||||
|
|
||||||
# Adds ourselves to the ownership list. The last one in the list may access
|
# Adds ourselves to the ownership list. The last one in the list may access
|
||||||
# the input through interruptible_region().
|
# the input through interruptible_region().
|
||||||
def __with_ownership(&block)
|
def __with_ownership
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
# Three cases:
|
# Three cases:
|
||||||
# 1) There are no owners, in this case we are good to go.
|
# 1) There are no owners, in this case we are good to go.
|
||||||
|
@ -56,7 +56,7 @@ class Pry
|
||||||
@owners << Thread.current
|
@owners << Thread.current
|
||||||
end
|
end
|
||||||
|
|
||||||
block.call
|
yield
|
||||||
ensure
|
ensure
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
# We are releasing any desire to have the input ownership by removing
|
# We are releasing any desire to have the input ownership by removing
|
||||||
|
@ -73,7 +73,7 @@ class Pry
|
||||||
def with_ownership(&block)
|
def with_ownership(&block)
|
||||||
# If we are in a nested with_ownership() call (nested pry context), we do nothing.
|
# If we are in a nested with_ownership() call (nested pry context), we do nothing.
|
||||||
nested = @mutex.synchronize { @owners.include?(Thread.current) }
|
nested = @mutex.synchronize { @owners.include?(Thread.current) }
|
||||||
nested ? block.call : __with_ownership(&block)
|
nested ? yield : __with_ownership(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enter_interruptible_region
|
def enter_interruptible_region
|
||||||
|
@ -103,13 +103,13 @@ class Pry
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
def interruptible_region(&block)
|
def interruptible_region
|
||||||
enter_interruptible_region
|
enter_interruptible_region
|
||||||
|
|
||||||
# XXX Note that there is a chance that we get the interrupt right after
|
# XXX Note that there is a chance that we get the interrupt right after
|
||||||
# the readline call succeeded, but we'll never know, and we will retry the
|
# the readline call succeeded, but we'll never know, and we will retry the
|
||||||
# call, discarding that piece of input.
|
# call, discarding that piece of input.
|
||||||
block.call
|
yield
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
# We were asked to back off. The one requesting the interrupt will be
|
# We were asked to back off. The one requesting the interrupt will be
|
||||||
# waiting on the conditional for the interruptible flag to change to false.
|
# waiting on the conditional for the interruptible flag to change to false.
|
||||||
|
|
|
@ -496,7 +496,7 @@ class Pry::Slop
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@unknown_options << item if strict? && item =~ /\A--?/
|
@unknown_options << item if strict? && item =~ /\A--?/
|
||||||
block.call(item) if block && !@trash.include?(index)
|
yield(item) if block && !@trash.include?(index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -605,7 +605,7 @@ describe "Pry::Command" do
|
||||||
it "should NOT expose &block in create_command's process method" do
|
it "should NOT expose &block in create_command's process method" do
|
||||||
@set.create_command "walking-spanish", "down the hall", takes_block: true do
|
@set.create_command "walking-spanish", "down the hall", takes_block: true do
|
||||||
def process(&block)
|
def process(&block)
|
||||||
block.call
|
block.call # rubocop:disable Performance/RedundantBlockCall
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@out = StringIO.new
|
@out = StringIO.new
|
||||||
|
|
Loading…
Reference in a new issue