Commit 9f9132ff2ff91555300853e1f80bbbc13d34a79c
1 parent
48678934
Exists in
master
and in
1 other branch
Rubocop: eradicate a few more methods wrapped in guards
By returning early the flow is hoped to be a bit clearer.
Showing
5 changed files
with
21 additions
and
18 deletions
Show diff stats
.rubocop.yml
app/controllers/problems_controller.rb
| ... | ... | @@ -136,9 +136,9 @@ class ProblemsController < ApplicationController |
| 136 | 136 | # Redirect :back if no errors selected |
| 137 | 137 | # |
| 138 | 138 | protected def need_selected_problem |
| 139 | - if err_ids.empty? | |
| 140 | - flash[:notice] = I18n.t('controllers.problems.flash.no_select_problem') | |
| 141 | - redirect_to :back | |
| 142 | - end | |
| 139 | + return if err_ids.any? | |
| 140 | + | |
| 141 | + flash[:notice] = I18n.t('controllers.problems.flash.no_select_problem') | |
| 142 | + redirect_to :back | |
| 143 | 143 | end |
| 144 | 144 | end | ... | ... |
app/decorators/backtrace_line_decorator.rb
| ... | ... | @@ -66,9 +66,8 @@ private |
| 66 | 66 | end |
| 67 | 67 | |
| 68 | 68 | def link_to_hosted_javascript(app, text) |
| 69 | - if app.asset_host? | |
| 70 | - h.link_to(text, "#{app.asset_host}/#{file_relative}", target: '_blank') | |
| 71 | - end | |
| 69 | + return unless app.asset_host? | |
| 70 | + h.link_to(text, "#{app.asset_host}/#{file_relative}", target: '_blank') | |
| 72 | 71 | end |
| 73 | 72 | |
| 74 | 73 | def link_to_github(app, text = nil) | ... | ... |
app/helpers/problems_helper.rb
| ... | ... | @@ -4,10 +4,14 @@ module ProblemsHelper |
| 4 | 4 | end |
| 5 | 5 | |
| 6 | 6 | def truncated_problem_message(problem) |
| 7 | - unless (msg = problem.message).blank? | |
| 8 | - # Truncate & insert invisible chars so that firefox can emulate 'word-wrap: break-word' CSS rule | |
| 9 | - truncate(msg, length: 300, escape: false).scan(/.{1,5}/).map { |s| h(s) }.join("​").html_safe | |
| 10 | - end | |
| 7 | + msg = problem.message | |
| 8 | + return if msg.blank? | |
| 9 | + | |
| 10 | + # Truncate & insert invisible chars so that firefox can emulate | |
| 11 | + # 'word-wrap: break-word' CSS rule | |
| 12 | + truncate(msg, length: 300, escape: false). | |
| 13 | + scan(/.{1,5}/).map { |s| h(s) }. | |
| 14 | + join("​").html_safe | |
| 11 | 15 | end |
| 12 | 16 | |
| 13 | 17 | def gravatar_tag(email, options = {}) | ... | ... |
app/models/app.rb
| ... | ... | @@ -203,12 +203,12 @@ protected |
| 203 | 203 | end |
| 204 | 204 | |
| 205 | 205 | def check_issue_tracker |
| 206 | - if issue_tracker.present? | |
| 207 | - issue_tracker.valid? | |
| 208 | - issue_tracker.errors.full_messages.each do |error| | |
| 209 | - errors[:base] << error | |
| 210 | - end if issue_tracker.errors | |
| 211 | - end | |
| 206 | + return if issue_tracker.blank? | |
| 207 | + | |
| 208 | + issue_tracker.valid? | |
| 209 | + issue_tracker.errors.full_messages.each do |error| | |
| 210 | + errors[:base] << error | |
| 211 | + end if issue_tracker.errors | |
| 212 | 212 | end |
| 213 | 213 | |
| 214 | 214 | def normalize_github_repo | ... | ... |