Skip to content

Commit

Permalink
Merge pull request #10059 from saraycp/rubocop_autocorrect_IV_control…
Browse files Browse the repository at this point in the history
…lers

Correct Rubocop Style/ConditionalAssignment in controllers I
  • Loading branch information
saraycp committed Aug 25, 2020
2 parents cd70669 + 62bf42b commit 27c1ec4
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 101 deletions.
17 changes: 4 additions & 13 deletions src/api/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,12 @@ Naming/HeredocDelimiterNaming:
- 'test/functional/source_controller_test.rb'
- 'test/unit/project_test.rb'

# Offense count: 1
# Offense count: 2
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/lib/authenticator.rb'

# Offense count: 11
Expand Down Expand Up @@ -1236,22 +1237,12 @@ Style/CommentedKeyword:
- 'test/unit/user_ldap_strategy_test.rb'
- 'test/unit/user_test.rb'

# Offense count: 74
# Offense count: 42
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/message_controller.rb'
- 'app/controllers/person_controller.rb'
- 'app/controllers/search_controller.rb'
- 'app/controllers/statistics_controller.rb'
- 'app/controllers/status/checks_controller.rb'
- 'app/controllers/status/reports_controller.rb'
- 'app/controllers/webui/attribute_controller.rb'
- 'app/controllers/webui/project_controller.rb'
- 'app/controllers/webui/projects/pulse_controller.rb'
- 'app/models/branch_package.rb'
- 'app/models/bs_request.rb'
- 'app/models/bs_request/find_for/project.rb'
Expand Down Expand Up @@ -1412,7 +1403,7 @@ Style/SymbolArray:
Style/WordArray:
Enabled: false

# Offense count: 1935
# Offense count: 1936
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
30 changes: 15 additions & 15 deletions src/api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,19 @@ def gather_exception_defaults(opt)
@exception = opt[:exception]
@errorcode = opt[:errorcode]

if opt[:status]
@status = opt[:status].to_i
else
@status = 400
end
@status = if opt[:status]
opt[:status].to_i
else
400
end

if @status == 401
unless response.headers['WWW-Authenticate']
if CONFIG['kerberos_mode']
response.headers['WWW-Authenticate'] = 'Negotiate'
else
response.headers['WWW-Authenticate'] = 'basic realm="API login"'
end
response.headers['WWW-Authenticate'] = if CONFIG['kerberos_mode']
'Negotiate'
else
'basic realm="API login"'
end
end
end
if @status == 404
Expand All @@ -226,11 +226,11 @@ def gather_exception_defaults(opt)

@summary ||= 'Internal Server Error'

if @exception
@errorcode ||= 'uncaught_exception'
else
@errorcode ||= 'unknown'
end
@errorcode ||= if @exception
'uncaught_exception'
else
'unknown'
end
end

def render_error(opt = {})
Expand Down
14 changes: 7 additions & 7 deletions src/api/app/controllers/message_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def check_project_and_package
end

def list
if @package
@messages = @package.messages
elsif @project
@messages = @project.messages
else
@messages = Message.limit(params[:limit]).order('created_at DESC')
end
@messages = if @package
@package.messages
elsif @project
@project.messages
else
Message.limit(params[:limit]).order('created_at DESC')
end
render partial: 'messages'
end

Expand Down
10 changes: 5 additions & 5 deletions src/api/app/controllers/person_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class PersonController < ApplicationController
before_action :set_user, only: [:post_userinfo, :change_my_password]

def show
if params[:prefix]
@list = User.where('login LIKE ?', params[:prefix] + '%')
else
@list = User.all
end
@list = if params[:prefix]
User.where('login LIKE ?', params[:prefix] + '%')
else
User.all
end
end

def login
Expand Down
28 changes: 14 additions & 14 deletions src/api/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ def search(what, render_all)
output = "<collection matches=\"#{matches}\">\n"

xml = {} # filled by filter
if render_all
key_template = "xml_#{what}_%d"
else
key_template = "xml_id_#{what}_%d"
end
key_template = if render_all
"xml_#{what}_%d"
else
"xml_id_#{what}_%d"
end
search_items = filter_items_from_cache(items, xml, key_template)

includes = []
Expand Down Expand Up @@ -288,15 +288,15 @@ def find_attribute(namespace, name)
attrib = AttribType.find_by_namespace_and_name!(namespace, name)

# gather the relation for attributes depending on project/package combination
if params[:package] && params[:project]
attribs = Package.get_by_project_and_name(params[:project], params[:package]).attribs
elsif params[:package]
attribs = attrib.attribs.where(package_id: Package.where(name: params[:package]))
elsif params[:project]
attribs = attrib.attribs.where(package_id: Project.get_by_name(params[:project]).packages)
else
attribs = attrib.attribs
end
attribs = if params[:package] && params[:project]
Package.get_by_project_and_name(params[:project], params[:package]).attribs
elsif params[:package]
attrib.attribs.where(package_id: Package.where(name: params[:package]))
elsif params[:project]
attrib.attribs.where(package_id: Project.get_by_name(params[:project]).packages)
else
attrib.attribs
end

# get the values associated with the attributes and store them
attribs = attribs.pluck(:id, :package_id)
Expand Down
20 changes: 10 additions & 10 deletions src/api/app/controllers/statistics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def highest_rated
ratings = Rating.select('db_object_id, db_object_type, count(score) as count,' \
'sum(score)/count(score) as score_calculated').group('db_object_id, db_object_type').order('score_calculated DESC')
ratings = ratings.to_a.delete_if { |r| r.count.to_i < min_votes_for_rating }
if @limit
@ratings = ratings[0..@limit - 1]
else
@ratings = ratings
end
@ratings = if @limit
ratings[0..@limit - 1]
else
ratings
end
end

def rating
Expand Down Expand Up @@ -126,11 +126,11 @@ def latest_added
list.concat(packages)
list.sort! { |a, b| b.created_at <=> a.created_at }

if @limit
@list = list[0..@limit - 1]
else
@list = list
end
@list = if @limit
list[0..@limit - 1]
else
list
end
end

def added_timestamp
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/controllers/status/checks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def check_notify_params
end

def set_status_report
if params[:report_uuid]
@status_report = @checkable.status_reports.find_or_initialize_by(uuid: params[:report_uuid])
else
@status_report = @checkable.status_reports.first_or_initialize
end
@status_report = if params[:report_uuid]
@checkable.status_reports.find_or_initialize_by(uuid: params[:report_uuid])
else
@checkable.status_reports.first_or_initialize
end
end

def set_check
Expand Down
12 changes: 6 additions & 6 deletions src/api/app/controllers/status/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def show
private

def set_status_report
if params[:report_uuid]
@status_report = @checkable.status_reports.find_by!(uuid: params[:report_uuid])
else
# request reports don't have uuid
@status_report = @checkable.status_reports.first
end
@status_report = if params[:report_uuid]
@checkable.status_reports.find_by!(uuid: params[:report_uuid])
else
# request reports don't have uuid
@checkable.status_reports.first
end
end
end
10 changes: 5 additions & 5 deletions src/api/app/controllers/webui/attribute_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def index
end

def new
if @package
@attribute = Attrib.new(package_id: @package.id)
else
@attribute = Attrib.new(project_id: @project.id)
end
@attribute = if @package
Attrib.new(package_id: @package.id)
else
Attrib.new(project_id: @project.id)
end

authorize @attribute, :create?

Expand Down
31 changes: 16 additions & 15 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,16 @@ def monitor_buildresult

@name_filter = params[:pkgname]
@lastbuild_switch = params[:lastbuild]
if params[:defaults]
defaults = (begin
# FIXME: this code needs some love
defaults = if params[:defaults]
(begin
Integer(params[:defaults])
rescue ArgumentError
1
end).positive?
else
defaults = true
end
else
true
end
params['expansionerror'] = 1 if params['unresolvable']
monitor_set_filter(defaults)

Expand Down Expand Up @@ -474,11 +475,11 @@ def monitor_parse_result(result)

return unless result.key?('state')

if result.key?('dirty')
@repostatushash[repo][arch] = 'outdated_' + result['state']
else
@repostatushash[repo][arch] = result['state']
end
@repostatushash[repo][arch] = if result.key?('dirty')
'outdated_' + result['state']
else
result['state']
end

@repostatusdetailshash[repo][arch] = result['details'] if result.key?('details')
end
Expand Down Expand Up @@ -597,11 +598,11 @@ def filter_matches?(input, filter_string)
filter_string.gsub!(/\s*/, '')
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
result = if no_invert[1] == '!'
input.include?(no_invert[2]) ? result : true
else
input.include?(no_invert[2]) ? true : result
end
end
result
end
Expand Down
12 changes: 6 additions & 6 deletions src/api/app/controllers/webui/projects/pulse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def set_range
end

def set_pulse
case @range
when 'month'
range = 1.month.ago..Date.tomorrow
else
range = 1.week.ago..Date.tomorrow
end
range = case @range
when 'month'
1.month.ago..Date.tomorrow
else
1.week.ago..Date.tomorrow
end

pulse = @project.project_log_entries.where(datetime: range).order(datetime: :asc)
@builds = pulse.where(event_type: [:build_fail, :build_success]).where(datetime: 24.hours.ago..Time.zone.now)
Expand Down

0 comments on commit 27c1ec4

Please sign in to comment.