Skip to content

Commit

Permalink
fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfaller committed Mar 21, 2019
1 parent 0e333ae commit 4bd31e0
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AllCops:
Exclude:
- 'spec/dgit/sources/**/*'
- 'tmp/**/*'
- 'Vagrantfile'
TargetRubyVersion: 2.2

ModuleLength:
Expand Down
16 changes: 14 additions & 2 deletions lib/dgit/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def underscore
# @return [String]
def camel_case
return self if self !~ /_/ && self =~ /[A-Z]+.*/

split('_').map(&:capitalize).join
end

Expand Down Expand Up @@ -76,6 +77,7 @@ def initialize(url)

def full_url
return @url if @oid.eql?(DEFAULT_BRANCH)

"#{@url}|#{@oid}"
end

Expand All @@ -100,6 +102,7 @@ def clone

def load_repository
raise "Source not cloned #{url}." if @entry.new?

@repository = Rugged::Repository.new(folder)
@repository.checkout(@oid, { strategy: :force })
end
Expand All @@ -123,10 +126,12 @@ def sources_by_state(state, error = false)

def sources_by_ids(*ids)
return sources if ids.empty?

source_array = sources
result = []
ids.each do |id|
raise "No such source index #{id}." if id >= source_array.length

result << source_array[id]
end
result
Expand Down Expand Up @@ -184,6 +189,7 @@ def del_all_analyses

def get_analyses(*names)
return analyses if names.empty?

analyses.select { |a| names.include?(a.simple_name) }
end

Expand All @@ -208,6 +214,7 @@ def del_all_joins

def get_joins(*names)
return joins if names.empty?

joins.select { |j| joins.include?(j.simple_name) }
end

Expand Down Expand Up @@ -237,6 +244,7 @@ def load_plugin(name, type, instance = false)
plugin = search_plugin(name, type)
raise "Plugin #{name} not found." unless plugin
return plugin.new(Dig.it.options) if instance

plugin
end

Expand All @@ -261,6 +269,7 @@ def search_plugin(name, type)
plugins = ObjectSpace.each_object(Class).select { |c| c < base_class && c.simple_name == name }

raise "No plugin #{name} of kind #{type} found." if plugins.empty?

warn "Ambiguous plugin name: several plugins of kind #{type} named #{name} were found." if plugins.size > 1

@plugins[name] = plugins[0]
Expand Down Expand Up @@ -317,6 +326,7 @@ class Dig
# @return [Dig] the instance.
def self.it
raise "Diggit has not been initialized." if @diggit.nil?

@diggit
end

Expand Down Expand Up @@ -348,6 +358,7 @@ def self.init_dir(folder = '.')
end
FileUtils.mkdir(File.expand_path('sources', folder)) unless File.exist?(File.expand_path('sources', folder))
return if File.exist?(File.expand_path("plugins", folder))

FileUtils.mkdir_p(File.expand_path("plugins", folder))
FileUtils.mkdir_p(File.expand_path("plugins/analysis", folder))
FileUtils.mkdir_p(File.expand_path("plugins/addon", folder))
Expand All @@ -373,6 +384,7 @@ def file_path(name)
# @return [Dig] a diggit object.
def initialize(folder)
raise "Folder #{folder} is not a diggit folder." unless File.exist?(File.expand_path(DGIT_FOLDER, folder))

@plugin_loader = PluginLoader.instance
@folder = folder
end
Expand Down Expand Up @@ -471,11 +483,11 @@ def join(source_ids = [], joins = [], mode = :run)
private

def clean_mode?(mode)
mode == :rerun || mode == :clean
%i[rerun clean].include?(mode)
end

def run_mode?(mode)
mode == :rerun || mode == :run
%i[rerun run].include?(mode)
end

def clean(runnable, placeholder)
Expand Down
1 change: 1 addition & 0 deletions lib/dgit/entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def clean(runnable_or_string)

def retrieve_name(runnable_or_string)
return runnable_or_string if runnable_or_string.is_a? String

runnable_or_string.name
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/dgit/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def self.name
# @return [Object]
def read_option(namespace, opt, default)
return @options[namespace][opt] if @options.key?(namespace) && @options[namespace].key?(opt)

default
end
end
Expand Down Expand Up @@ -102,6 +103,7 @@ def self.require_addons(*names)
def self.required_addons
base_addons = superclass < Runnable ? superclass.required_addons : []
return base_addons if @required_addons.nil?

base_addons + @required_addons
end
end
Expand Down Expand Up @@ -149,6 +151,7 @@ def self.require_analyses(*names)

def self.required_analyses
return [] if @required_analyses.nil?

@required_analyses
end
end
Expand Down
1 change: 1 addition & 0 deletions plugins/analysis/cloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def run
repo.checkout(c.oid, { strategy: %i[force remove_untracked] })
cloc = `cloc #{@source.folder} --progress-rate=0 --quiet --yaml`
next if cloc.empty?

yaml = YAML.safe_load(cloc.lines[2..-1].join)
yaml.delete('header')
output = { source: @source.url, commit: c.oid, cloc: yaml }
Expand Down
1 change: 1 addition & 0 deletions plugins/analysis/cloc_per_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def run
folder = File.expand_path(@source.folder)
cloc = `cloc #{folder} --progress-rate=0 --quiet --by-file --yaml --script-lang=Python,python`
return if cloc.empty?

yaml = YAML.safe_load(cloc.lines[2..-1].join)
yaml.delete('header')
yaml.delete('SUM')
Expand Down
4 changes: 4 additions & 0 deletions plugins/analysis/conflict_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ def run
out_dir = out.out_path_for_analysis(self, commit.oid)
parents = commit.parents
next unless parents.size > 1

left = parents[0]
right = parents[1]
base_oid = repo.merge_base(left, right)
next if base_oid.nil?

base = repo.lookup(base_oid)
%w[m b l r].each { |p| FileUtils.mkdir_p(File.join(out_dir, p)) }
populate_merge_directory(out_dir, commit, base, left, right)
Expand All @@ -52,6 +54,7 @@ def run
def populate_merge_directory(out_dir, commit, base, left, right)
commit.tree.walk_blobs(:preorder) do |r, e|
next if base.tree.get_entry_by_oid(e[:oid])

oids = find_oids(r, e[:name], base, left, right)
next if oids[:left].nil? || oids[:right].nil? # This would result in a trivial merge

Expand Down Expand Up @@ -92,6 +95,7 @@ def find_oids(root, name, base, left, right)
def find_oid(tree, components, name)
components.each { |c| tree = repo.lookup(tree[c][:oid]) unless tree.nil? || tree[c].nil? }
return nil if tree.nil? || tree[name].nil?

tree[name][:oid]
end

Expand Down
6 changes: 4 additions & 2 deletions plugins/analysis/diff_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class DiffExtractor < Diggit::Analysis
require_addons 'out'

ALLOWED_EXTENSIONS = ['.java']
ALLOWED_EXTENSIONS = ['.java'].freeze

def initialize(options)
super(options)
Expand All @@ -35,17 +35,19 @@ def run
out_dir = out.out_path_for_analysis(self, commit.oid)
parents = commit.parents
next unless parents.size == 1

parent = parents[0]
populate_diff_directory(out_dir, commit, parent)
end
end

def populate_diff_directory(out_dir, commit, parent)
directory_created = false
directory_created = false
diff = parent.diff(commit)
diff.each_delta do |delta_entry|
next unless delta_entry.status == :modified
next unless ALLOWED_EXTENSIONS.include?(File.extname(delta_entry.new_file[:path]))

unless directory_created
FileUtils.mkdir_p(out_dir)
directory_created = true
Expand Down
2 changes: 2 additions & 0 deletions plugins/analysis/javadoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def index_methods(doc)

m.xpath("MarkerAnnotation/SimpleName/@label").each do |k|
next unless k.to_s.casecmp("override")

javadoc['override'] = true
override_count += 1

Expand Down Expand Up @@ -117,6 +118,7 @@ def type(element)
return element.at_xpath('SimpleType/@label').to_s unless element.at_xpath('SimpleType').nil?
return element.at_xpath('PrimitiveType/@label').to_s unless element.at_xpath('PrimitiveType').nil?
return element.at_xpath('ArrayType/@label').to_s unless element.at_xpath('ArrayType').nil?

""
end

Expand Down
2 changes: 2 additions & 0 deletions plugins/analysis/yard_dup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def run
insert_to_map("@main #{obj.docstring}", doc_hash, obj) unless obj.docstring.empty?
obj.tags.each do |tag|
next if tag.nil?

tag_tokens = []
tag_tokens << "@#{tag.tag_name}" unless tag.tag_name.nil?
tag_tokens << tag.types.join(',') unless tag.types.nil? || tag.types.empty?
Expand Down Expand Up @@ -98,6 +99,7 @@ def plot_duplications(file, doc_hash)
def write_near_miss(file, doc_hash)
keys = doc_hash.each_key.to_a
return if keys.size < 2

File.open(file, 'w') do |f|
(0..(keys.size - 2)).each do |i|
key1 = keys[i]
Expand Down

0 comments on commit 4bd31e0

Please sign in to comment.