Skip to content

Commit

Permalink
rubocop: fix offences regarding spaces
Browse files Browse the repository at this point in the history
Fixes offences of the following cops:

* Layout/SpaceAroundEqualsInParameterDefault
* Layout/SpaceAroundOperators
* Layout/SpaceBeforeBlockBraces
* Layout/SpaceInsideBlockBraces
  • Loading branch information
kyrylo committed Nov 4, 2018
1 parent d2e306c commit 04d4f42
Show file tree
Hide file tree
Showing 55 changed files with 207 additions and 236 deletions.
29 changes: 0 additions & 29 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,27 +394,6 @@ Layout/SpaceAfterSemicolon:
- 'spec/commands/show_source_spec.rb'
- 'spec/commands/whereami_spec.rb'

# Offense count: 73
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: false

# Offense count: 38
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Layout/SpaceAroundOperators:
Enabled: false

# Offense count: 117
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
Enabled: false

# Offense count: 8
# Cop supports --auto-correct.
Layout/SpaceBeforeComma:
Expand Down Expand Up @@ -460,14 +439,6 @@ Layout/SpaceInsideArrayPercentLiteral:
Exclude:
- 'spec/helpers/table_spec.rb'

# Offense count: 80
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Enabled: false

# Offense count: 44
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def reset
self.option_processors = nil
end

def parse_options(args=ARGV)
def parse_options(args = ARGV)
unless options
raise NoOptionsError, "No command line options defined! Use Pry::CLI.add_options to add command line options."
end
Expand Down
6 changes: 3 additions & 3 deletions lib/pry/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def from_method(meth, start_line = nil)
# @param [Integer, nil] start_line The line number to start on, or nil to
# use the method's original line numbers.
# @return [Code]
def from_module(mod, candidate_rank = 0, start_line=nil)
def from_module(mod, candidate_rank = 0, start_line = nil)
candidate = Pry::WrappedModule(mod).candidate(candidate_rank)
start_line ||= candidate.line
new(candidate.source, start_line, :ruby)
Expand Down Expand Up @@ -266,7 +266,7 @@ def highlighted

# Writes a formatted representation (based on the configuration of the
# object) to the given output, which must respond to `#<<`.
def print_to_output(output, color=false)
def print_to_output(output, color = false)
@lines.each do |loc|
loc = loc.dup
loc.colorize(@code_type) if color
Expand Down Expand Up @@ -338,7 +338,7 @@ def method_missing(name, *args, &block)
undef =~

# Check whether String responds to missing methods.
def respond_to_missing?(name, include_all=false)
def respond_to_missing?(name, include_all = false)
''.respond_to?(name, include_all)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pry/code/loc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def indent(distance)

def handle_multiline_entries_from_edit_command(line, max_width)
line.split("\n").map.with_index do |inner_line, i|
i.zero? ? inner_line : "#{' '* (max_width + 2)}#{inner_line}"
i.zero? ? inner_line : "#{' ' * (max_width + 2)}#{inner_line}"
end.join("\n")
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def c_module?
include Pry::Helpers::CommandHelpers

class << self
def lookup(str, _pry_, options={})
def lookup(str, _pry_, options = {})
co = new(str, _pry_, options)

co.default_lookup || co.method_or_class_lookup ||
Expand All @@ -76,7 +76,7 @@ def lookup(str, _pry_, options={})
attr_accessor :_pry_
attr_accessor :super_level

def initialize(str, _pry_, options={})
def initialize(str, _pry_, options = {})
options = {
super: 0,
}.merge!(options)
Expand Down
12 changes: 6 additions & 6 deletions lib/pry/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class << self
attr_writer :command_options
attr_writer :match

def match(arg=nil)
def match(arg = nil)
if arg
@command_options ||= default_options(arg)
@command_options[:listing] = arg.is_a?(String) ? arg : arg.inspect
Expand All @@ -33,13 +33,13 @@ def match(arg=nil)
end

# Define or get the command's description
def description(arg=nil)
def description(arg = nil)
@description = arg if arg
@description ||= nil
end

# Define or get the command's options
def command_options(arg=nil)
def command_options(arg = nil)
@command_options ||= default_options(match)
@command_options.merge!(arg) if arg
@command_options
Expand All @@ -49,7 +49,7 @@ def command_options(arg=nil)
alias_method :options=, :command_options=

# Define or get the command's banner
def banner(arg=nil)
def banner(arg = nil)
@banner = arg if arg
@banner ||= description
end
Expand Down Expand Up @@ -194,7 +194,7 @@ def convert_to_regex(obj)
# This is usually auto-generated from directory naming, but it can be
# manually overridden if necessary.
# Group should not be changed once it is initialized.
def group(name=nil)
def group(name = nil)
@group ||= if name
name
else
Expand Down Expand Up @@ -274,7 +274,7 @@ def void

# Instantiate a command, in preparation for calling it.
# @param [Hash] context The runtime context to use with this command.
def initialize(context={})
def initialize(context = {})
self.context = context
self.target = context[:target]
self.output = context[:output]
Expand Down
16 changes: 8 additions & 8 deletions lib/pry/command_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def initialize(*imported_sets, &block)
# # hello john, nice number: 10
# # pry(main)> help number
# # number-N regex command
def block_command(match, description="No description.", options={}, &block)
def block_command(match, description = "No description.", options = {}, &block)
description, options = ["No description.", description] if description.is_a?(Hash)
options = Pry::Command.default_options(match).merge!(options)

Expand Down Expand Up @@ -107,7 +107,7 @@ def block_command(match, description="No description.", options={}, &block)
# end
# end
#
def create_command(match, description="No description.", options={}, &block)
def create_command(match, description = "No description.", options = {}, &block)
description, options = ["No description.", description] if description.is_a?(Hash)
options = Pry::Command.default_options(match).merge!(options)

Expand Down Expand Up @@ -210,7 +210,7 @@ def alias_command(match, action, options = {})
# command description to be passed this way too.
# @example Renaming the `ls` command and changing its description.
# Pry.config.commands.rename "dir", "ls", :description => "DOS friendly ls"
def rename_command(new_match, search, options={})
def rename_command(new_match, search, options = {})
cmd = find_command_by_match_or_listing(search)

options = {
Expand All @@ -225,7 +225,7 @@ def rename_command(new_match, search, options={})
@commands.delete(cmd.match)
end

def disabled_command(name_of_disabled_command, message, matcher=name_of_disabled_command)
def disabled_command(name_of_disabled_command, message, matcher = name_of_disabled_command)
create_command name_of_disabled_command do
match matcher
description ""
Expand All @@ -247,7 +247,7 @@ def disabled_command(name_of_disabled_command, message, matcher=name_of_disabled
# end
# @example Getting
# Pry.config.commands.desc "amend-line"
def desc(search, description=nil)
def desc(search, description = nil)
cmd = find_command_by_match_or_listing(search)
return cmd.description if !description

Expand Down Expand Up @@ -359,7 +359,7 @@ def valid_command?(val)
# @param [String] val The line to execute
# @param [Hash] context The context to execute the commands with
# @return [CommandSet::Result]
def process_line(val, context={})
def process_line(val, context = {})
if (command = find_command(val))
context = context.merge(command_set: self)
retval = command.new(context).process_line(val)
Expand All @@ -379,13 +379,13 @@ def run_command(context, match, *args)
# @param [String] search The line to search for
# @param [Hash] context The context to create the command with
# @return [Array<String>]
def complete(search, context={})
def complete(search, context = {})
if (command = find_command(search))
command.new(context).complete(search)
else
@commands.keys.select do |key|
String === key && key.start_with?(search)
end.map{ |key| key + " " }
end.map { |key| key + " " }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def never_reload?
opts.present?(:'no-reload') || _pry_.config.disable_auto_reload
end

def reload?(file_name="")
def reload?(file_name = "")
(reloadable? || file_name.end_with?(".rb")) && !never_reload?
end

Expand Down
8 changes: 4 additions & 4 deletions lib/pry/commands/find_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def search_class
# @param [Array<Method>] matches
def print_matches(matches)
grouped = matches.group_by(&:owner)
order = grouped.keys.sort_by{ |x| x.name || x.to_s }
order = grouped.keys.sort_by { |x| x.name || x.to_s }

order.each do |klass|
print_matches_for_class(klass, grouped)
Expand All @@ -102,7 +102,7 @@ def additional_info(header, method)
end

def matched_method_lines(header, method)
method.source.split(/\n/).select {|x| x =~ pattern }.join("\n#{' ' * header.length}")
method.source.split(/\n/).select { |x| x =~ pattern }.join("\n#{' ' * header.length}")
end

# Run the given block against every constant in the provided namespace.
Expand All @@ -111,7 +111,7 @@ def matched_method_lines(header, method)
# @param [Hash<Module,Boolean>] done The namespaces we've already visited (private)
# @yieldparam klass Each class/module in the namespace.
#
def recurse_namespace(klass, done={}, &block)
def recurse_namespace(klass, done = {}, &block)
return if !(Module === klass) || done[klass]

done[klass] = true
Expand Down Expand Up @@ -142,7 +142,7 @@ def recurse_namespace(klass, done={}, &block)
# @return [Array<Method>]
#
def search_all_methods(namespace)
done = Hash.new{ |h,k| h[k] = {} }
done = Hash.new { |h,k| h[k] = {} }
matches = []

recurse_namespace(namespace) do |klass|
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/commands/gem_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def process(str)

private
def list_as_string(gems, limit = 10)
gems[0..limit-1].map do |gem|
gems[0..limit - 1].map do |gem|
name, version, info = gem.values_at 'name', 'version', 'info'
"#{bold(name)} #{bold('v'+version)} \n#{info}\n\n"
"#{bold(name)} #{bold('v' + version)} \n#{info}\n\n"
end.join
end
Pry::Commands.add_command(self)
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def sorted_group_names(groups)
# @param [Array<Pry::Command>] commands The commands to sort
# @return [Array<Pry::Command>] commands sorted by listing name.
def sorted_commands(commands)
commands.sort_by{ |command| command.options[:listing].to_s }
commands.sort_by { |command| command.options[:listing].to_s }
end

# Display help for an individual command or group.
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/commands/show_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def content_and_headers_for_all_module_candidates(mod)
mod.number_of_candidates.times do |v|
candidate = mod.candidate(v)
begin
result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{candidate.source_file} @ line #{candidate.source_line}:\n"
result << "\nCandidate #{v + 1}/#{mod.number_of_candidates}: #{candidate.source_file} @ line #{candidate.source_line}:\n"
content = content_for(candidate)

result << "Number of lines: #{content.lines.count}\n\n" << content
Expand Down
6 changes: 3 additions & 3 deletions lib/pry/commands/watch_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def expressions

def delete(index)
if index
output.puts "Deleting watch expression ##{index}: #{expressions[index-1]}"
expressions.delete_at(index-1)
output.puts "Deleting watch expression ##{index}: #{expressions[index - 1]}"
expressions.delete_at(index - 1)
else
output.puts "Deleting all watched expressions"
expressions.clear
Expand All @@ -70,7 +70,7 @@ def list
pager.puts "Listing all watched expressions:"
pager.puts ""
expressions.each_with_index do |expr, index|
pager.print with_line_numbers(expr.to_s, index+1)
pager.print with_line_numbers(expr.to_s, index + 1)
end
pager.puts ""
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/config/behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def keys
def eager_load!
default = @default
while default
default.memoized_methods.each {|method| self[key] = default.public_send(key)} if default.respond_to?(:memoized_methods)
default.memoized_methods.each { |method| self[key] = default.public_send(key) } if default.respond_to?(:memoized_methods)
default = @default.default
end
end
Expand Down Expand Up @@ -208,7 +208,7 @@ def method_missing(name, *args, &block)
end
end

def respond_to_missing?(key, include_all=false)
def respond_to_missing?(key, include_all = false)
key = key.to_s.chomp(ASSIGNMENT)
key?(key) or @default.respond_to?(key) or super(key, include_all)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/config/memoization.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Pry
class Config < Pry::BasicObject
module Memoization
MEMOIZED_METHODS = Hash.new {|h,k| h[k] = [] }
MEMOIZED_METHODS = Hash.new { |h,k| h[k] = [] }

module ClassMethods
#
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/core_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Object
# end
# my_method()
# @see Pry.start
def pry(object=nil, hash={})
def pry(object = nil, hash = {})
if object.nil? || Hash === object
Pry.start(self, object || {})
else
Expand Down Expand Up @@ -81,7 +81,7 @@ def __binding__
# This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
# 1) ./spec/pry_spec.rb:360:in `block in (root)'
# 2) ./spec/pry_spec.rb:366:in `block in (root)'
return class_eval {binding} if Pry::Helpers::Platform.jruby? and self.name == nil
return class_eval { binding } if Pry::Helpers::Platform.jruby? and self.name == nil

# class_eval sets both self and the default definee to this class.
return class_eval("binding")
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(_pry_)
@_pry_ = _pry_
end

def edit_tempfile_with_content(initial_content, line=1)
def edit_tempfile_with_content(initial_content, line = 1)
temp_file do |f|
f.puts(initial_content)
f.flush
Expand All @@ -18,7 +18,7 @@ def edit_tempfile_with_content(initial_content, line=1)
end
end

def invoke_editor(file, line, blocking=true)
def invoke_editor(file, line, blocking = true)
raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless _pry_.config.editor

editor_invocation = build_editor_invocation_string(file, line, blocking)
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/helpers/base_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def colorize_code(code)
CodeRay.scan(code, :ruby).term
end

def highlight(string, regexp, highlight_color=:bright_yellow)
def highlight(string, regexp, highlight_color = :bright_yellow)
string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
end

Expand Down
Loading

0 comments on commit 04d4f42

Please sign in to comment.