summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-03-02 02:48:37 +0200
committerKyrylo Silin <silin@kyrylo.org>2019-03-02 02:48:37 +0200
commita5b6a7371a6c3a9475d920032764db58255817e9 (patch)
tree63c621508525f4b304fdc3c02b0a6474de08665c
parentf21279cffc1ad401f52ab2b5f2b35990b4930d73 (diff)
downloadpry-rubocop-fixes.tar.gz
rubocop: fix offences of the Style/InverseMethods coprubocop-fixes
-rw-r--r--.rubocop_todo.yml10
-rw-r--r--lib/pry/code.rb10
-rw-r--r--lib/pry/command.rb2
-rw-r--r--lib/pry/commands/hist.rb4
-rw-r--r--lib/pry/commands/ls/jruby_hacks.rb2
-rw-r--r--lib/pry/commands/ls/ls_entity.rb2
-rw-r--r--spec/code_spec.rb15
7 files changed, 30 insertions, 15 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 845d1e36..70db2ce3 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -274,16 +274,6 @@ Style/IfInsideElse:
- 'lib/pry/slop/commands.rb'
- 'lib/pry/slop/option.rb'
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: InverseMethods, InverseBlocks.
-Style/InverseMethods:
- Exclude:
- - 'lib/pry/command.rb'
- - 'lib/pry/commands/hist.rb'
- - 'lib/pry/commands/ls/jruby_hacks.rb'
- - 'lib/pry/commands/ls/ls_entity.rb'
-
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
diff --git a/lib/pry/code.rb b/lib/pry/code.rb
index 037b5c45..7e08c76a 100644
--- a/lib/pry/code.rb
+++ b/lib/pry/code.rb
@@ -117,6 +117,16 @@ class Pry
end
end
+ # Filter the lines using the given block.
+ #
+ # @yield [LOC]
+ # @return [Code]
+ def reject(&block)
+ alter do
+ @lines = @lines.reject(&block)
+ end
+ end
+
# Remove all lines that aren't in the given range, expressed either as a
# `Range` object or a first and last line number (inclusive). Negative
# indices count from the end of the array of lines.
diff --git a/lib/pry/command.rb b/lib/pry/command.rb
index b6cbd8f1..23830927 100644
--- a/lib/pry/command.rb
+++ b/lib/pry/command.rb
@@ -418,7 +418,7 @@ class Pry
def call_safely(*args)
unless dependencies_met?
gems_needed = Array(command_options[:requires_gem])
- gems_not_installed = gems_needed.select { |g| !Rubygem.installed?(g) }
+ gems_not_installed = gems_needed.reject { |g| Rubygem.installed?(g) }
output.puts(<<WARN)
The command #{Helpers::Text.bold(command_name)} is unavailable because it requires the following
gems to be installed: #{(gems_not_installed.join(", "))}
diff --git a/lib/pry/commands/hist.rb b/lib/pry/commands/hist.rb
index 3f14fb5c..a11e2ada 100644
--- a/lib/pry/commands/hist.rb
+++ b/lib/pry/commands/hist.rb
@@ -52,8 +52,8 @@ class Pry
end
if opts.present?(:'exclude-pry')
- @history = @history.select do |loc|
- !command_set.valid_command?(loc.line)
+ @history = @history.reject do |loc|
+ command_set.valid_command?(loc.line)
end
end
diff --git a/lib/pry/commands/ls/jruby_hacks.rb b/lib/pry/commands/ls/jruby_hacks.rb
index 1e393baf..5b79d558 100644
--- a/lib/pry/commands/ls/jruby_hacks.rb
+++ b/lib/pry/commands/ls/jruby_hacks.rb
@@ -28,7 +28,7 @@ class Pry
found = []
values.select do |x|
- (!found.any? { |y| x == y }) && found << x
+ (found.none? { |y| x == y }) && found << x
end
end
end
diff --git a/lib/pry/commands/ls/ls_entity.rb b/lib/pry/commands/ls/ls_entity.rb
index f600cd99..e2e62911 100644
--- a/lib/pry/commands/ls/ls_entity.rb
+++ b/lib/pry/commands/ls/ls_entity.rb
@@ -24,7 +24,7 @@ class Pry
end
def entities_table
- entities.map(&:write_out).reject { |o| !o }.join('')
+ entities.map(&:write_out).select { |o| o }.join('')
end
private
diff --git a/spec/code_spec.rb b/spec/code_spec.rb
index 06430634..9c427ca9 100644
--- a/spec/code_spec.rb
+++ b/spec/code_spec.rb
@@ -259,4 +259,19 @@ describe Pry::Code do
end
end
end
+
+ describe "#reject" do
+ let(:code) do
+ Pry::Code(Pry::Helpers::CommandHelpers.unindent <<-STR)
+ puts 'This line will be rejected'
+ puts 'This line will remain'
+ puts 'This line will be rejected'
+ STR
+ end
+
+ it "selects lines based" do
+ filtered_code = code.reject { |loc| loc.line =~ /will be rejected/ }
+ expect(filtered_code).to eq("puts 'This line will remain'\n")
+ end
+ end
end