Skip to content

Commit

Permalink
Merge pull request #59 from sul-dlss/lint_remover
Browse files Browse the repository at this point in the history
Auto-correct rubocop lint issues
  • Loading branch information
jcoyne committed Aug 17, 2018
2 parents bfd00b7 + d621c8a commit ff55374
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 107 deletions.
60 changes: 0 additions & 60 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ Lint/AmbiguousOperator:
- 'lib/pre_assembly/digital_object.rb'
- 'spec/digital_object_spec.rb'

# Offense count: 27
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
Exclude:
- 'devel/add_and_update_files.rb'
- 'devel/dor_workspace_cleanup.rb'
- 'devel/examine_objects.rb'
- 'devel/mjf_transform.rb'
- 'devel/prepare_content.rb'
- 'devel/pub_purl.rb'
- 'devel/retrieve_content.rb'
- 'devel/upd_descMD_frda.rb'
- 'lib/pre_assembly/bundle.rb'
- 'lib/pre_assembly/reporting.rb'
- 'spec/bundle_spec.rb'
- 'spec/digital_object_spec.rb'

# Offense count: 2
Lint/DuplicateMethods:
Exclude:
Expand All @@ -56,55 +39,12 @@ Lint/RescueException:
- 'lib/pre_assembly/digital_object.rb'
- 'lib/pre_assembly/remediation/remediate.rb'

# Offense count: 3
# Cop supports --auto-correct.
Lint/ScriptPermission:
Exclude:
- 'devel/pub_purl.rb'
- 'devel/test_pf_file.rb'
- 'devel/upd_descMD_frda.rb'

# Offense count: 3
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'Rakefile'
- 'devel/prepare_content.rb'

# Offense count: 4
# Cop supports --auto-correct.
Lint/StringConversionInInterpolation:
Exclude:
- 'devel/pub_purl.rb'
- 'devel/upd_descMD_frda.rb'
- 'lib/pre_assembly/bundle.rb'
- 'lib/pre_assembly/digital_object.rb'

# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'Rakefile'
- 'bin/pre-assemble'
- 'devel/prepare_content.rb'
- 'devel/revs_get_druid_from_sourceid.rb'
- 'devel/revs_update_images.rb'
- 'devel/revs_update_metadata.rb'
- 'devel/salt_update_dates.rb'
- 'devel/salt_update_doc_types.rb'
- 'lib/pre_assembly.rb'
- 'lib/pre_assembly/bundle.rb'
- 'lib/pre_assembly/logging.rb'
- 'spec/digital_object_spec.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/pre_assembly/bundle.rb'
- 'lib/pre_assembly/digital_object.rb'

# Offense count: 25
Lint/UselessAssignment:
Enabled: false
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if ['test', 'development'].include? ENV['ROBOT_ENVIRONMENT']

namespace :repo do
desc "Load XML file(s) into repo (fedora and solr), default: contents of 'load_order' file. With a glob: rake repo:load[fedora_conf/data/*.xml]"
task :load, [:glob] do |task, args|
task :load, [:glob] do |_task, args|
require 'active_fedora'
puts "travis_fold:start:repo-load\r" if ENV['TRAVIS'] == 'true'

Expand All @@ -57,7 +57,7 @@ if ['test', 'development'].include? ENV['ROBOT_ENVIRONMENT']
file_list.each do |file|
i += 1

handler = proc do |e, attempt_number, total_delay|
handler = proc do |e, _attempt_number, _total_delay|
puts STDERR.puts "ERROR loading #{file}:\n#{e.message}\n#{e.backtrace.join "\n"}"
errors << file
end
Expand Down
2 changes: 1 addition & 1 deletion bin/pre-assemble
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ options = {}

OptionParser.new do |opts|
opts.banner = "Usage:\n pre-assemble YAML_CONFIG_FILE [--resume] [--limit 200]\n"
opts.on("-r", "--resume", "Resume") do |r|
opts.on("-r", "--resume", "Resume") do |_r|
options[:resume] = true
end
opts.on("-l [LIMIT]", "--limit [LIMIT]", "Limit") do |l|
Expand Down
6 changes: 3 additions & 3 deletions devel/add_and_update_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_or_replace_files(objects)
path_to_new_file = File.join(@base_path, file_path)
base_filename = File.basename(file_path)

unless File.exists? path_to_new_file
unless File.exist? path_to_new_file

puts "*****New file '#{path_to_new_file}' not found"
@log.error "*****New file '#{path_to_new_file}' not found"
Expand Down Expand Up @@ -184,9 +184,9 @@ def old_druid_tree_path(druid, root_dir)

# returns the location of a content file, which can be in the old location if not found in the new location, e.g. aa/111/bb/2222/aa111bb2222/content or aa/111/bb/2222/
def content_file(druid, root_dir, filename)
if File.exists?(path_to_content_file(druid, root_dir, filename))
if File.exist?(path_to_content_file(druid, root_dir, filename))
return path_to_content_file(druid, root_dir, filename)
elsif File.exists?(old_path_to_file(druid, root_dir, filename))
elsif File.exist?(old_path_to_file(druid, root_dir, filename))
return old_path_to_file(druid, root_dir, filename)
else
return nil
Expand Down
2 changes: 1 addition & 1 deletion devel/dor_workspace_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
if Assembly::Utils.updates_allowed?(druid)
paths_to_cleanup.each do |root_dir|
folder = DruidTools::Druid.new(druid, root_dir).path()
if Dir.exists?(folder)
if Dir.exist?(folder)
FileUtils.rm_r(folder)
deleted_from << root_dir
end
Expand Down
4 changes: 2 additions & 2 deletions devel/examine_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def old_druid_tree_path(druid, root_dir)
cm_file = File.join(druid_tree_path(druid, Dor::Config.content.content_base_dir), 'metadata', 'contentMetadata.xml')
tif_file = File.join(druid_tree_path(druid, Dor::Config.content.content_base_dir), 'content', tif_filename)
puts "Workspace folder exists = #{File.directory?(object_location)}"
puts "#{tif_file} exists = #{File.exists?(tif_file)}" unless (tif_filename.nil? || tif_filename == '')
puts "#{cm_file} exists = #{File.exists?(cm_file)}"
puts "#{tif_file} exists = #{File.exist?(tif_file)}" unless (tif_filename.nil? || tif_filename == '')
puts "#{cm_file} exists = #{File.exist?(cm_file)}"
# puts ''
# pp i.contentMetadata.ng_xml.to_s
puts '----'
Expand Down
4 changes: 2 additions & 2 deletions devel/mjf_transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
def file_cleanup(folder, existing_files_to_remove)
existing_files_to_remove.each do |filename|
full_path = File.join(folder, filename)
if File.exists?(full_path)
if File.exist?(full_path)
puts "...Deleting existing file #{full_path}"
File.delete(full_path)
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def file_cleanup(folder, existing_files_to_remove)
xml_file_params.merge!({ :preserve => 'yes', :publish => 'no', :shelve => 'no' })
end # end case file_type

if File.exists?(File.join(content_sub_folder, relative_path_to_file)) # this confirms the existence of the file on the original file system before adding the new node to the contentMetadata
if File.exist?(File.join(content_sub_folder, relative_path_to_file)) # this confirms the existence of the file on the original file system before adding the new node to the contentMetadata
xml.file(xml_file_params) {
xml.checksum(file.attributes['CHECKSUM'].value, :type => 'md5')
} # end builder file node
Expand Down
12 changes: 6 additions & 6 deletions devel/prepare_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
help = "Usage:\n ruby prepare_content.rb INPUT_CSV_FILE BASE_CONTENT_FOLDER [STAGING_FOLDER] [--no-object-folders] [--report] [--content_metadata] [--content_metadata_style STYLE]\n"
OptionParser.new do |opts|
opts.banner = help
opts.on("--report") do |dr|
opts.on("--report") do |_dr|
report = true
end
opts.on("--content_metadata") do |cm|
opts.on("--content_metadata") do |_cm|
content_metadata = true
end
opts.on("--content_metadata_style [STYLE]") do |st|
cm_style = st
end
opts.on("--no-object-folders") do |ob|
opts.on("--no-object-folders") do |_ob|
no_object_folders = true
end
end.parse!
Expand All @@ -63,9 +63,9 @@
staging_folder = ARGV[2]
end

abort "#{csv_in} not found" unless File.exists?(csv_in)
abort "#{csv_in} not found" unless File.exist?(csv_in)

unless File.exists?(csv_out) # if we don't already have a log file, write out the header row
unless File.exist?(csv_out) # if we don't already have a log file, write out the header row
CSV.open(csv_out, 'a') { |f|
output_row = ["Object", "Image", "Filename", "Sequence", "Label", "Druid", "Success", "Message", "Time"]
f << output_row
Expand Down Expand Up @@ -191,7 +191,7 @@
message = "found #{input_file}, symlink to object folder #{object_folder}"
output_file_full_path = no_object_folders ? File.join(staging_folder, input_filename) : (File.join(object_folder, input_filename))
input_file_full_path = Pathname.new(File.join(base_content_folder, input_file)).cleanpath(true).to_s
FileUtils.ln_s(input_file_full_path, output_file_full_path, :force => true) unless (report || File.exists?(output_file_full_path))
FileUtils.ln_s(input_file_full_path, output_file_full_path, :force => true) unless (report || File.exist?(output_file_full_path))
num_files_copied += 1
success = true
CSV.open(csv_out, 'a') { |f|
Expand Down
4 changes: 2 additions & 2 deletions devel/pub_purl.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def check_args(args)

if args.size != 1
return -1
elsif !File.exists?(get_file_path(args[0]))
elsif !File.exist?(get_file_path(args[0]))
return -1
else
return 0
Expand Down Expand Up @@ -59,7 +59,7 @@ def main() # Iterate over file of pid/druids to publish metadata for
# RUN YOUR CODE HERE
pid.chomp!
@log.info '====================='
@log.info "#{Time.now.to_s}"
@log.info "#{Time.now}"
@log.info "Processing pid #{pid}"
obj = Dor::Item.find(pid)
obj.publish_metadata
Expand Down
4 changes: 2 additions & 2 deletions devel/retrieve_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def metadata_folder(druid)

# write out content metadata from object unless a version already exists in the directory
cm_file = File.join(metadata_folder(druid), 'contentMetadata.xml')
unless File.exists?(cm_file)
unless File.exist?(cm_file)
File.open(cm_file, 'w') { |fh| fh.puts @fobj.contentMetadata.ng_xml.to_s }
puts 'write contentMetadata.xml'
end
Expand All @@ -54,5 +54,5 @@ def metadata_folder(druid)
source = File.join(base_content_directory, content_subfolder, filename)
dest = File.join(content_folder(druid), filename)

FileUtils.cp(source, dest) unless File.exists?(dest) && !File.exists?(source)
FileUtils.cp(source, dest) unless File.exist?(dest) && !File.exist?(source)
end
2 changes: 1 addition & 1 deletion devel/revs_get_druid_from_sourceid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
all_pids = []
all_filenames = []

@items.each_with_index do |row, x|
@items.each_with_index do |row, _x|
pids = Dor::SearchService.query_by_id("Revs:#{row.sourceid}")
if pids.size != 1
puts "cannot find single pid for source id #{row.sourceid}"
Expand Down
2 changes: 1 addition & 1 deletion devel/revs_update_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# read input manifest
@items = CsvMapper.import(csv_in) do read_attributes_from_file end

@items.each_with_index do |row, x|
@items.each_with_index do |row, _x|
pids = Dor::SearchService.query_by_id("Revs:#{row.sourceid}")
if pids.size != 1
puts "cannot find single pid for source id #{row.sourceid}"
Expand Down
2 changes: 1 addition & 1 deletion devel/revs_update_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# read input manifest
@items = CsvMapper.import(csv_in) do read_attributes_from_file end

@items.each_with_index do |row, x|
@items.each_with_index do |row, _x|
manifest_row = Hash[row.each_pair.to_a]
pids = Dor::SearchService.query_by_id("Revs:#{manifest_row[:sourceid]}")
if pids.size != 1
Expand Down
2 changes: 1 addition & 1 deletion devel/salt_update_dates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# read input manifest
@items = CsvMapper.import(csv_in) do read_attributes_from_file end

@items.each_with_index do |row, x|
@items.each_with_index do |row, _x|
manifest_row = Hash[row.each_pair.to_a]
pid = manifest_row[:druid]
done = completed_druids.include?(pid)
Expand Down
2 changes: 1 addition & 1 deletion devel/salt_update_doc_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# read input manifest
@items = CsvMapper.import(csv_in) do read_attributes_from_file end

@items.each_with_index do |row, x|
@items.each_with_index do |row, _x|
manifest_row = Hash[row.each_pair.to_a]
pid = manifest_row[:druid]
done = completed_druids.include?(pid)
Expand Down
Empty file modified devel/test_pf_file.rb
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions devel/upd_descMD_frda.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def check_args(args)

if args.size != 2
return -1
elsif !File.exists?(get_file_path(args[0])) &&
elsif !File.exist?(get_file_path(args[0])) &&
!File.exists(get_file_path(args[1]))
return -1
else
Expand Down Expand Up @@ -103,7 +103,7 @@ def main() # Iterate over file of pid/druids to change
File.open(get_file_path(ARGV[1])).each do |pid|
pid.chomp!
@log.info '====================='
@log.info "#{Time.now.to_s}"
@log.info "#{Time.now}"
@log.info "Processing pid #{pid}"

changes_made = 0
Expand All @@ -114,7 +114,7 @@ def main() # Iterate over file of pid/druids to change

# Get XML from file if available & use to change descMetadata and identityMetadata
# puts "Getting XML file ..."
if pid_to_file[pid] and File.exists?("#{@mods_path}#{pid_to_file[pid]}")
if pid_to_file[pid] and File.exist?("#{@mods_path}#{pid_to_file[pid]}")
xml_dm = read_xml(pid, pid_to_file)
xml_dm = cleanup_guill(xml_dm)
new_title = get_title(xml_dm) # get new_title here to use below for identityMetadata
Expand Down
2 changes: 1 addition & 1 deletion lib/pre_assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

module PreAssembly
def self.retry_handler(method_name, logger, params = {})
Proc.new do |exception, attempt_number, total_delay|
Proc.new do |_exception, attempt_number, _total_delay|
logger.send " ** #{method_name} FAILED **; with params of #{params.inspect}; and trying attempt #{attempt_number} of #{Dor::Config.dor.num_attempts}; delayed #{Dor::Config.dor.total_delay} seconds"
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def initialize(params = {})
cmc[:style] = cmc[:style].to_sym
params[:file_attr] ||= params[:publish_attr]
@user_params = params
YAML_PARAMS.each { |p| instance_variable_set "@#{p.to_s}", params[p] }
YAML_PARAMS.each { |p| instance_variable_set "@#{p}", params[p] }

# Other setup work.
setup_paths
Expand Down Expand Up @@ -115,7 +115,7 @@ def setup_other
@content_exclusion = Regexp.new(@content_exclusion) if @content_exclusion
@validate_bundle_dir ||= {}
@file_attr = {} if @file_attr.nil?
@file_attr.delete_if { |k, v| v.nil? }
@file_attr.delete_if { |_k, v| v.nil? }
@set_druid_id = [@set_druid_id] if @set_druid_id && @set_druid_id.class == String # convert set_druid_id to 1 element array if its single valued and exists
end

Expand Down Expand Up @@ -282,7 +282,7 @@ def validate_usage
validation_errors << "The project_style:get_druid_from value of '#{@project_style[:get_druid_from]}' is not valid." unless allowed_values[:project_style][:get_druid_from].include? @project_style[:get_druid_from]
validation_errors << "The content_md_creation:style value of '#{@content_md_creation[:style]}' is not valid." unless allowed_values[:content_md_creation][:style].include? @content_md_creation[:style]

validation_errors << "The SMPL manifest #{@content_md_creation[:smpl_manifest]} was not found in #{@bundle_dir}." if @content_md_creation[:style] == :smpl && !File.exists?(File.join(@bundle_dir, @content_md_creation[:smpl_manifest]))
validation_errors << "The SMPL manifest #{@content_md_creation[:smpl_manifest]} was not found in #{@bundle_dir}." if @content_md_creation[:style] == :smpl && !File.exist?(File.join(@bundle_dir, @content_md_creation[:smpl_manifest]))

unless validation_errors.blank?
validation_errors = ['Configuration errors found:'] + validation_errors
Expand Down Expand Up @@ -363,7 +363,7 @@ def object_files_exist?(dobj)
####
def cleanup(steps = [], dry_run = false)
log "cleanup()"
if File.exists?(@progress_log_file)
if File.exist?(@progress_log_file)
druids = Assembly::Utils.get_druids_from_log(@progress_log_file)
else
puts "#{@progress_log_file} not found! Cannot proceed"
Expand All @@ -377,7 +377,7 @@ def cleanup(steps = [], dry_run = false)
# validating code.
####

def bundle_directory_is_valid?(io = STDOUT)
def bundle_directory_is_valid?(_io = STDOUT)
# Do nothing if no validation code was supplied.
return true unless @validate_bundle_dir[:code]
# Run validations and return true/false accordingly.
Expand Down
4 changes: 2 additions & 2 deletions lib/pre_assembly/digital_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DigitalObject
####

def initialize(params = {})
INIT_PARAMS.each { |p| instance_variable_set "@#{p.to_s}", params[p] }
INIT_PARAMS.each { |p| instance_variable_set "@#{p}", params[p] }
@file_attr ||= params[:publish_attr]
setup
end
Expand Down Expand Up @@ -188,7 +188,7 @@ def query_dor_by_barcode(barcode)
Dor::SearchService.query_by_id :barcode => barcode
end

def get_dor_item_apos(pid)
def get_dor_item_apos(_pid)
get_dor_object
@dor_object.nil? ? [] : @dor_object.admin_policy_object
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pre_assembly/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.setup(project_root, environment)
@@log ||= Logger.new(log_file)
@@log.level = LEVELS[:info]

@@log.formatter = proc do |severity, datetime, progname, msg|
@@log.formatter = proc do |severity, datetime, _progname, msg|
LOG_FORMAT % [severity, datetime.strftime(TIME_FORMAT), msg]
end
end
Expand Down
Loading

0 comments on commit ff55374

Please sign in to comment.