Skip to content

Commit

Permalink
Merge pull request #2800 from mschnitzer/rubocop_rescue_modifier
Browse files Browse the repository at this point in the history
Enable Rubocop Style/RescueModifier
  • Loading branch information
mschnitzer committed Mar 10, 2017
2 parents 1f754c7 + 3ffef9c commit 6481f75
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/api/.rubocop.yml
Expand Up @@ -149,6 +149,10 @@ Style/TernaryParentheses:
Style/ZeroLengthPredicate:
Enabled: true

# Checks for uses of rescue in its modifier form
Style/RescueModifier:
Enabled: true

##################### Metrics ##################################

# Checks if the length a class exceeds some maximum value
Expand Down
8 changes: 0 additions & 8 deletions src/api/.rubocop_todo.yml
Expand Up @@ -765,14 +765,6 @@ Style/RedundantParentheses:
Style/RegexpLiteral:
Enabled: false

# Offense count: 7
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
- 'app/controllers/webui/feeds_controller.rb'
- 'app/controllers/webui/project_controller.rb'
- 'test/functional/webui/owner_search_test.rb'

# Offense count: 20
# Cop supports --auto-correct.
Style/SelfAssignment:
Expand Down
12 changes: 10 additions & 2 deletions src/api/app/controllers/webui/feeds_controller.rb
Expand Up @@ -21,12 +21,20 @@ def commits
return
end
unless params[:starting_at].blank?
@start = (Time.zone.parse(params[:starting_at]) rescue nil)
@start = (begin
Time.zone.parse(params[:starting_at])
rescue
nil
end)
end
@start ||= 7.days.ago
@finish = nil
unless params[:ending_at].blank?
@finish = (Time.zone.parse(params[:ending_at]) rescue nil)
@finish = (begin
Time.zone.parse(params[:ending_at])
rescue
nil
end)
end
@commits = @project.project_log_entries.where(event_type: 'commit').where(["datetime >= ?", @start])
@commits = @commits.where(["datetime <= ?", @finish]) unless @finish.nil?
Expand Down
12 changes: 10 additions & 2 deletions src/api/app/controllers/webui/project_controller.rb
Expand Up @@ -435,7 +435,11 @@ def monitor
@name_filter = params[:pkgname]
@lastbuild_switch = params[:lastbuild]
if params[:defaults]
defaults = (Integer(params[:defaults]) rescue 1) > 0
defaults = (begin
Integer(params[:defaults])
rescue
1
end) > 0
else
defaults = true
end
Expand Down Expand Up @@ -874,7 +878,11 @@ def monitor_set_filter(defaults)
@avail_status_values.each { |s|
id = s.delete(' ')
if params.has_key?(id)
next unless (Integer(params[id]) rescue 1) > 0
next unless (begin
Integer(params[id])
rescue
1
end) > 0
else
next unless defaults
end
Expand Down
18 changes: 15 additions & 3 deletions src/api/test/functional/webui/owner_search_test.rb
Expand Up @@ -46,9 +46,21 @@ def search_results
raw_results = page.all("div.search_result")
raw_results.collect do |row|
{
project: (row.find("a.project").text rescue nil),
package: (row.find("a.package").text rescue nil),
owners: (row.find("p").text rescue nil)
project: (begin
row.find("a.project").text
rescue
nil
end),
package: (begin
row.find("a.package").text
rescue
nil
end),
owners: (begin
row.find("p").text
rescue
nil
end)
}
end
end
Expand Down

0 comments on commit 6481f75

Please sign in to comment.