Skip to content

Commit

Permalink
rubocop: finalize remaining compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Aug 11, 2016
1 parent 66bb25c commit a37c3cb
Show file tree
Hide file tree
Showing 45 changed files with 202 additions and 406 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Style/DotPosition:
EnforcedStyle: trailing
Style/FormatString:
EnforcedStyle: percent
Style/IndentArray:
EnforcedStyle: consistent
Style/IndentHash:
EnforcedStyle: consistent

# Disable these until we know what to do with them
Style/AccessorMethodName: # this creates breaking changes in the API
Expand All @@ -40,6 +44,8 @@ Style/MethodMissing: # this doesn't exist in 1.8/1.9
Enabled: false
Style/Lambda: # not supported in 1.8
Enabled: false
Style/EachWithObject: # not supported in 1.8
Enabled: false
Style/AlignParameters: # does not work correctly with subsequent block
Enabled: false
Style/AlignArray: # does not support indentation
Expand Down
114 changes: 0 additions & 114 deletions .rubocop_todo.yml

This file was deleted.

5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ desc "Publish gem"
task :publish do
ver = ENV['VERSION']

if ver.nil? || ver.empty?
raise "missing VERSION=x.y.z"
elsif ver < YARD::VERSION
raise "missing VERSION=x.y.z" if ver.nil? || ver.empty?
if ver < YARD::VERSION
raise "invalid version `#{ver}' (must be >= `#{YARD::VERSION}')"
end

Expand Down
7 changes: 2 additions & 5 deletions lib/yard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ def self.load_plugins; YARD::Config.load_plugins end
def self.windows?
return @windows if defined? @windows
require 'rbconfig'
if ::RbConfig::CONFIG['host_os'] =~ /mingw|win32|cygwin/
@windows = true
else
@windows = false
end
@windows =
::RbConfig::CONFIG['host_os'] =~ /mingw|win32|cygwin/ ? true : false
ensure
@windows ||= false
end
Expand Down
12 changes: 5 additions & 7 deletions lib/yard/cli/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ def run(*args)
if @use_git
load_git_commit(gemfile)
all_objects
elsif load_gem_data(gemfile)
log.info "Found #{gemfile}"
all_objects
else
if load_gem_data(gemfile)
log.info "Found #{gemfile}"
all_objects
else
log.error "Cannot find gem #{gemfile}"
nil
end
log.error "Cannot find gem #{gemfile}"
nil
end
end.compact

Expand Down
8 changes: 3 additions & 5 deletions lib/yard/cli/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ def optparse(*args)

expression = "#{visibilities.uniq.inspect}.include?(object.visibility)"
options.verifier = Verifier.new(expression)
if args.first
@objects = args.map {|o| Registry.at(o) }.compact
else
@objects = [Registry.root]
end
@objects = args.first ?
args.map {|o| Registry.at(o) }.compact :
[Registry.root]
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/yard/cli/markup_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def run(*args) # rubocop:disable Lint/UnusedMethodArgument
types.sort_by {|name, _| name.to_s }.each do |name, providers|
log.puts "[#{name}]"
libs = providers.map {|p| p[:lib] }.compact
unless libs.empty?
log.puts " Providers: #{libs.join(" ")}"
end
log.puts " Providers: #{libs.join(" ")}" unless libs.empty?
if exts[name]
log.puts " Extensions: #{exts[name].map {|e| ".#{e}" }.join(" ")}"
end
Expand Down
4 changes: 1 addition & 3 deletions lib/yard/cli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ def optparse(*args)
# Generate doc for first time
# This is not necessary but makes for a better first-run experience
libver = libraries.empty? ? nil : libraries.values.first.first
if libver && !libver.ready?
generate_doc_for_first_time(libver)
end
generate_doc_for_first_time(libver) if libver && !libver.ready?
else
add_libraries(args)
options[:single_library] = false if libraries.size > 1
Expand Down
26 changes: 14 additions & 12 deletions lib/yard/cli/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ def print_statistics
end
meths.each {|m| send(m) }

if @undocumented == 0
total = 100
elsif @total == 0
total = 0
else
total = (@total - @undocumented).to_f / @total.to_f * 100
end
total =
if @undocumented == 0
100
elsif @total == 0
0
else
(@total - @undocumented).to_f / @total.to_f * 100
end
log.puts("% 3.2f%% documented" % total)
end

Expand Down Expand Up @@ -157,11 +158,12 @@ def stats_for_methods
def output(name, data, undoc = nil)
@total += data if data.is_a?(Integer) && undoc
@undocumented += undoc if undoc.is_a?(Integer)
if undoc
data = ("%5s (% 5d undocumented)" % [data, undoc])
else
data = "%5s" % data
end
data =
if undoc
("%5s (% 5d undocumented)" % [data, undoc])
else
"%5s" % data
end
log.puts("%-12s %s" % [name + ":", data])
end

Expand Down
4 changes: 1 addition & 3 deletions lib/yard/cli/yardoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ def add_api_verifier
no_api = true if apis.delete('')
exprs = []

unless apis.empty?
exprs << "#{apis.uniq.inspect}.include?(@api.text)"
end
exprs << "#{apis.uniq.inspect}.include?(@api.text)" unless apis.empty?

unless hidden_apis.empty?
exprs << "!#{hidden_apis.uniq.inspect}.include?(@api.text)"
Expand Down
14 changes: 4 additions & 10 deletions lib/yard/code_objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,8 @@ def docstring(locale = I18n::Locale.default)
# into a docstring and meta tags.
def docstring=(comments)
@docstrings.clear
if Docstring === comments
@docstring = comments
else
@docstring = Docstring.new(comments, self)
end
@docstring = Docstring === comments ?
comments : Docstring.new(comments, self)
end

# Default type is the lowercase class name without the "Object" suffix.
Expand Down Expand Up @@ -474,11 +471,8 @@ def relative_path(other)
common = [path, other].join(" ").match(/^(\S*)\S*(?: \1\S*)*$/)[1]
common = path unless common =~ /(\.|::|#)$/
common = common.sub(/(\.|::|#)[^:#\.]*?$/, '') if same_parent
if %w(. :).include?(common[-1, 1]) || other[common.size, 1] == '#'
suffix = ''
else
suffix = '(::|\.)'
end
suffix = %w(. :).include?(common[-1, 1]) || other[common.size, 1] == '#' ?
'' : '(::|\.)'
result = other.sub(/^#{Regexp.quote common}#{suffix}/, '')
result.empty? ? other : result
end
Expand Down
4 changes: 1 addition & 3 deletions lib/yard/code_objects/method_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def scope=(v)
YARD::Registry.delete(self)
@path = nil
@scope = v.to_sym
if @scope == :module
@scope = :class
end
@scope = :class if @scope == :module
YARD::Registry.register(self) if reregister
end

Expand Down
2 changes: 1 addition & 1 deletion lib/yard/code_objects/namespace_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def child(opts = {})
opts = SymbolHash[opts]
children.find do |obj|
opts.each do |meth, value|
break false if !(value.is_a?(Array) ? value.include?(obj[meth]) : obj[meth] == value)
break false unless value.is_a?(Array) ? value.include?(obj[meth]) : obj[meth] == value
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/yard/code_objects/root_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def path; @path ||= "" end
def inspect; @inspect ||= "#<yardoc root>" end
def root?; true end
def title; 'Top Level Namespace' end

def equal?(other)
other == :root ? true : super(other)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/yard/core_ext/insertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class Insertion
#
# @param [Array] list the list to perform the insertion on
# @param [Object] value the value to insert
def initialize(list, value) @list = list
@values = (Array === value ? value : [value]) end
def initialize(list, value)
@list = list
@values = (Array === value ? value : [value])
end

# Inserts the value before +val+
# @param [Object] val the object the value will be inserted before
Expand Down
6 changes: 1 addition & 5 deletions lib/yard/docstring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ def summary
when "\r", "\n"
next_char = stripped[index + 1, 1].to_s
if next_char =~ /^\s*$/
if stripped[index - 1, 1] == '.'
break index - 2
else
break index - 1
end
break stripped[index - 1, 1] == '.' ? index - 2 : index - 1
end
when "{", "(", "["
num_parens += 1
Expand Down
11 changes: 5 additions & 6 deletions lib/yard/docstring_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,11 @@ def call_after_parse_callbacks

parser.tags.each_with_index do |tag, i|
next unless tag.tag_name == "see"
if "#{tag.name}#{tag.text}" =~ /\A\{.*\}\Z/
infile_info = "\n in file `#{parser.object.file}' " \
"near line #{parser.object.line}"
log.warn "@see tag (##{i + 1}) should not be wrapped in {} " \
"(causes rendering issues): #{infile_info}"
end
next unless "#{tag.name}#{tag.text}" =~ /\A\{.*\}\Z/
infile_info = "\n in file `#{parser.object.file}' " \
"near line #{parser.object.line}"
log.warn "@see tag (##{i + 1}) should not be wrapped in {} " \
"(causes rendering issues): #{infile_info}"
end
end
end
Expand Down
9 changes: 3 additions & 6 deletions lib/yard/handlers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,9 @@ def ensure_loaded!(object, max_retries = 1)

retries = 0
while object.is_a?(Proxy)
if retries <= max_retries
log.debug "Missing object #{object} in file `#{parser.file}', moving it to the back of the line."
parser.parse_remaining_files
else
raise NamespaceMissingError, object
end
raise NamespaceMissingError, object if retries > max_retries
log.debug "Missing object #{object} in file `#{parser.file}', moving it to the back of the line."
parser.parse_remaining_files
retries += 1
end
object
Expand Down
Loading

0 comments on commit a37c3cb

Please sign in to comment.