Skip to content

Commit

Permalink
[frontend] Fix Style/BlockDelimiters offenses
Browse files Browse the repository at this point in the history
Mob-programming with @DavidKang
  • Loading branch information
bgeuken authored and DavidKang committed Dec 15, 2017
1 parent 061bc72 commit dd9cf5d
Show file tree
Hide file tree
Showing 39 changed files with 239 additions and 247 deletions.
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Expand Up @@ -329,16 +329,6 @@ Rails/SkipsModelValidations:
Rails/TimeZone:
Enabled: false

# Offense count: 130
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Enabled: false

# Offense count: 200
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
24 changes: 12 additions & 12 deletions src/api/app/controllers/webui/project_controller.rb
Expand Up @@ -673,9 +673,9 @@ def status
@develprojects.insert(1, no_project)

respond_to do |format|
format.json {
format.json do
render json: Yajl::Encoder.encode(@packages)
}
end
format.html
end
end
Expand Down Expand Up @@ -868,7 +868,7 @@ def monitor_set_filter(defaults)
@avail_status_values = Buildresult.avail_status_values
@filter_out = %w(disabled excluded unknown)
@status_filter = []
@avail_status_values.each { |s|
@avail_status_values.each do |s|
id = s.delete(' ')
if params.has_key?(id)
next unless (begin
Expand All @@ -881,46 +881,46 @@ def monitor_set_filter(defaults)
end
next if defaults && @filter_out.include?(s)
@status_filter << s
}
end

@avail_arch_values = []
@avail_repo_values = []

@project.api_obj.repositories.each { |r|
@project.api_obj.repositories.each do |r|
@avail_repo_values << r.name
@avail_arch_values << r.architectures.pluck(:name)
}
end
@avail_arch_values = @avail_arch_values.flatten.uniq.sort
@avail_repo_values = @avail_repo_values.flatten.uniq.sort

@arch_filter = []
@avail_arch_values.each { |s|
@avail_arch_values.each do |s|
archid = valid_xml_id('arch_' + s)
if defaults || (params.has_key?(archid) && params[archid])
@arch_filter << s
end
}
end

@repo_filter = []
@avail_repo_values.each { |s|
@avail_repo_values.each do |s|
repoid = valid_xml_id('repo_' + s)
if defaults || (params.has_key?(repoid) && params[repoid])
@repo_filter << s
end
}
end
end

def filter_matches?(input, filter_string)
result = false
filter_string.gsub!(/\s*/, '')
filter_string.split(',').each { |filter|
filter_string.split(',').each do |filter|
no_invert = filter.match(/(^!?)(.+)/)
if no_invert[1] == '!'
result = input.include?(no_invert[2]) ? result : true
else
result = input.include?(no_invert[2]) ? true : result
end
}
end
result
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/app/helpers/webui/project_helper.rb
Expand Up @@ -116,10 +116,10 @@ def map_request_state_to_flag(state)
def escape_list(list)
# The input list is not html_safe because it's
# user input which we should never trust!!!
list.map { |p|
list.map do |p|
"['".html_safe +
escape_javascript(p) +
"']".html_safe
}.join(',').html_safe
end.join(',').html_safe
end
end
4 changes: 2 additions & 2 deletions src/api/app/helpers/webui/webui_helper.rb
Expand Up @@ -383,13 +383,13 @@ def can_register
def escape_nested_list(list)
# The input list is not html_safe because it's
# user input which we should never trust!!!
list.map { |item|
list.map do |item|
"['".html_safe +
escape_javascript(item[0]) +
"', '".html_safe +
escape_javascript(item[1]) +
"']".html_safe
}.join(",\n").html_safe
end.join(",\n").html_safe
end

def replace_jquery_meta_characters(input)
Expand Down
8 changes: 4 additions & 4 deletions src/api/app/mixins/request_source_diff.rb
Expand Up @@ -4,9 +4,9 @@ class ActionSourceDiffer
attr_accessor :action

def perform(opts)
gather_source_packages.map { |spkg|
gather_source_packages.map do |spkg|
diff_for_source(spkg, opts)
}.join
end.join
end

def gather_source_packages
Expand All @@ -19,10 +19,10 @@ def gather_source_packages
prj = Project.find_by_name(action.source_project)
return [] unless prj

return prj.packages.map { |p|
return prj.packages.map do |p|
p.check_source_access!
p.name
}
end
end
end

Expand Down
24 changes: 12 additions & 12 deletions src/api/app/models/channel.rb
Expand Up @@ -7,20 +7,20 @@ class Channel < ApplicationRecord

def self.verify_xml!(xmlhash)
xmlhash = Xmlhash.parse(xmlhash) if xmlhash.is_a? String
xmlhash.elements('target') { |p|
xmlhash.elements('target') do |p|
prj = Project.get_by_name(p['project'])
unless prj.repositories.find_by_name(p['repository'])
raise UnknownRepository, "Repository does not exist #{prj.name}/#{p['repository']}"
end
}
xmlhash.elements('binaries').each { |p|
end
xmlhash.elements('binaries').each do |p|
project = p['project']
if project.present?
prj = Project.get_by_name(p['project'])
prj.repositories.find_by_name!(p['repository']) if p['repository']
end
Architecture.find_by_name!(p['arch']) if p['arch']
p.elements('binary') { |b|
p.elements('binary') do |b|
Architecture.find_by_name!(b['arch']) if b['arch']
project = b['project']
if project
Expand All @@ -33,8 +33,8 @@ def self.verify_xml!(xmlhash)
raise UnknownRepository, "Repository does not exist #{prj.name}/#{b['repository']}"
end
end
}
}
end
end
end

def name
Expand All @@ -46,7 +46,7 @@ def name
def _update_from_xml_targets(xmlhash)
# sync channel targets
hasharray = []
xmlhash.elements('target').each { |p|
xmlhash.elements('target').each do |p|
prj = Project.find_by_name(p['project'])
next unless prj
r = prj.repositories.find_by_name(p['repository'])
Expand All @@ -55,14 +55,14 @@ def _update_from_xml_targets(xmlhash)
repository: r, id_template: p['id_template'],
requires_issue: p['requires_issue'],
disabled: (p.has_key? 'disabled') }
}
end
sync_hash_with_model(ChannelTarget, channel_targets, hasharray)
end

def _update_from_xml_binary_lists(xmlhash)
# sync binary lists
hasharray = []
xmlhash.elements('binaries').each { |p|
xmlhash.elements('binaries').each do |p|
repository = nil
project = p['project']
if project.present?
Expand All @@ -75,7 +75,7 @@ def _update_from_xml_binary_lists(xmlhash)
arch = Architecture.find_by_name!(p['arch']) if p['arch']
hasharray << { project: project, architecture: arch,
repository: repository }
}
end
sync_hash_with_model(ChannelBinaryList, channel_binary_lists, hasharray)
end

Expand Down Expand Up @@ -110,7 +110,7 @@ def update_from_xml(xmlhash)
end

# sync binaries for all lists
channel_binary_lists.each { |cbl|
channel_binary_lists.each do |cbl|
hasharray = Array.new
# search the right xml binaries group for this cbl
xmlhash.elements('binaries') do |b|
Expand All @@ -127,7 +127,7 @@ def update_from_xml(xmlhash)
raise "Unable to find binary list #{cbl.project.name} #{cbl.repository.name} #{cbl.architecture.name}" if hasharray.empty?
# update...
_update_from_xml_binaries(cbl, hasharray)
}
end
save
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/owner.rb
Expand Up @@ -244,7 +244,7 @@ def self.find_containers(rootproject, owner, devel = true, filter = %w(maintaine
def self.find_maintainers(container, filter)
maintainers = []
sql = _build_rolefilter_sql(filter)
add_owners = Proc.new { |cont|
add_owners = Proc.new do |cont|
m = Owner.new
m.rootproject = ''
if cont.is_a? Package
Expand All @@ -256,7 +256,7 @@ def self.find_maintainers(container, filter)
m.filter = filter
_extract_from_container(m, cont.relationships, sql, nil)
maintainers << m unless m.users.nil? && m.groups.nil?
}
end
project = container
if container.is_a? Package
add_owners.call container
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/package.rb
Expand Up @@ -103,9 +103,9 @@ class PutFileNoPermission < APIException; setup 403; end
# which would produce a query like
# WHERE (packages.project_id not in (0))
# because we assumes that there are more allowed projects than forbidden ones.
default_scope {
default_scope do
where.not(id: Package.where(project_id: Relationship.forbidden_project_ids))
}
end

scope :order_by_name, -> { order('LOWER(name)') }

Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/service.rb
Expand Up @@ -77,10 +77,10 @@ def addKiwiImport
end

def fill_params(element, parameters)
parameters.each { |parameter|
parameters.each do |parameter|
param = element.add_element('param', name: parameter[:name])
param.text = parameter[:value]
}
end
true
end

Expand Down
8 changes: 4 additions & 4 deletions src/api/lib/memory_dumper.rb
Expand Up @@ -6,21 +6,21 @@ def initialize(app)
@toexit = 0

Memprof.start
old_handler = trap('URG') {
old_handler = trap('URG') do
@toexit = 1
old_handler.call if old_handler
}
end
end

def call(env)
ret = @app.call(env)
if @toexit == 1
pid = Process.pid
fork {
fork do
GC.start
Memprof.dump_all("/tmp/memprof-#{pid}.json")
exit!
}
end
# in case it did not work
Process.kill('USR1', $$)
@toexit = 0
Expand Down
4 changes: 2 additions & 2 deletions src/api/lib/tasks/databases.rake
Expand Up @@ -39,11 +39,11 @@ namespace :db do

sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"

structure = con.select_all(sql, 'SCHEMA').map { |table|
structure = con.select_all(sql, 'SCHEMA').map do |table|
table.delete('Table_type')
sql = "SHOW CREATE TABLE #{con.quote_table_name(table.to_a.first.last)}"
con.exec_query(sql, 'SCHEMA').first['Create Table'] + ";\n\n"
}.join
end.join
else
raise "Task not supported by '#{abcs[Rails.env]['adapter']}'"
end
Expand Down
8 changes: 4 additions & 4 deletions src/api/lib/tasks/delayed_job.rake
Expand Up @@ -33,18 +33,18 @@ namespace :jobs do
task(issuetrackers: :environment) { IssueTracker.first.try(:save!) }

desc 'Update all changed issues from remote IssueTrackers now'
task(updateissues: :environment) {
task(updateissues: :environment) do
IssueTracker.all.each do |t|
next unless t.enable_fetch
t.update_issues
end
}
end

desc 'Import all issues from remote IssueTrackers now'
task(enforceissuesupdate: :environment) {
task(enforceissuesupdate: :environment) do
IssueTracker.all.each do |t|
next unless t.enable_fetch
t.enforced_update_all_issues
end
}
end
end
4 changes: 2 additions & 2 deletions src/api/script/import_database.rb
Expand Up @@ -92,9 +92,9 @@ def import_dump
filename = @params[:path] || options['backup_filename']

cmds = ["bzcat #{File.join(@data_path, filename)}"]
cmds << TABLES_TO_REMOVE.map { |table|
cmds << TABLES_TO_REMOVE.map do |table|
"sed '/-- Dumping data for table `#{table}`/,/-- Table structure for table/{//!d}'"
}.join(' | ') unless TABLES_TO_REMOVE.empty?
end.join(' | ') unless TABLES_TO_REMOVE.empty?
cmds << "#{File.exist?(@vagrant_path) ? 'vagrant exec' : ''} mysql -u#{username} -p#{password} #{database}"

puts "Extracting and importing data from #{filename}..."
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/controllers/person_controller_spec.rb
Expand Up @@ -56,14 +56,14 @@
end

describe 'PUT #put_userinfo' do
let(:xml) {
let(:xml) do
<<-XML_DATA
<userinfo>
<realname>test name</realname>
<email>test@test.de</email>
</userinfo>
XML_DATA
}
end

context 'when in LDAP mode' do
before do
Expand Down
4 changes: 2 additions & 2 deletions src/api/spec/controllers/webui/attributes_controller_spec.rb
Expand Up @@ -181,9 +181,9 @@
end

it 'deletes the attrib' do
expect {
expect do
delete :destroy, params: { id: attrib.id }
}.to change { Attrib.count }.by(-1)
end.to change { Attrib.count }.by(-1)
expect(response).to redirect_to(root_path)
expect(flash[:notice]).to eq 'Attribute sucessfully deleted!'
end
Expand Down

0 comments on commit dd9cf5d

Please sign in to comment.