DEV: update rubocop to version 0.77

We like to stay as close as possible to latest with rubocop cause the cops
get better.

This update required some code changes, specifically the default is to avoid
explicit returns where implicit is done

Also this renames a few rules
This commit is contained in:
Sam Saffron 2019-12-10 11:48:27 +11:00
parent 8e489ec8f8
commit 0c52537f10
23 changed files with 39 additions and 39 deletions

View File

@ -86,7 +86,7 @@ Layout/Tab:
Enabled: true Enabled: true
# Blank lines should not have any spaces. # Blank lines should not have any spaces.
Layout/TrailingBlankLines: Layout/TrailingEmptyLines:
Enabled: true Enabled: true
# No trailing whitespace. # No trailing whitespace.
@ -116,7 +116,7 @@ Layout/MultilineMethodCallIndentation:
Enabled: true Enabled: true
EnforcedStyle: indented EnforcedStyle: indented
Layout/AlignHash: Layout/HashAlignment:
Enabled: true Enabled: true
Bundler/OrderedGems: Bundler/OrderedGems:

View File

@ -150,7 +150,7 @@ GEM
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
image_size (1.5.0) image_size (1.5.0)
in_threads (1.5.1) in_threads (1.5.1)
jaro_winkler (1.5.2) jaro_winkler (1.5.4)
jmespath (1.4.0) jmespath (1.4.0)
jquery-rails (4.3.3) jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
@ -257,7 +257,7 @@ GEM
parallel (1.19.1) parallel (1.19.1)
parallel_tests (2.29.2) parallel_tests (2.29.2)
parallel parallel
parser (2.6.3.0) parser (2.6.5.0)
ast (~> 2.4.0) ast (~> 2.4.0)
pg (1.1.4) pg (1.1.4)
progress (3.5.0) progress (3.5.0)
@ -344,7 +344,7 @@ GEM
rspec-support (~> 3.8) rspec-support (~> 3.8)
rspec-support (3.9.0) rspec-support (3.9.0)
rtlit (0.0.5) rtlit (0.0.5)
rubocop (0.69.0) rubocop (0.77.0)
jaro_winkler (~> 1.5.1) jaro_winkler (~> 1.5.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.6) parser (>= 2.6)
@ -355,7 +355,7 @@ GEM
rubocop (>= 0.69.0) rubocop (>= 0.69.0)
ruby-openid (2.9.2) ruby-openid (2.9.2)
ruby-prof (1.0.0) ruby-prof (1.0.0)
ruby-progressbar (1.10.0) ruby-progressbar (1.10.1)
ruby-readability (0.7.0) ruby-readability (0.7.0)
guess_html_encoding (>= 0.0.4) guess_html_encoding (>= 0.0.4)
nokogiri (>= 1.6.0) nokogiri (>= 1.6.0)

View File

@ -757,7 +757,7 @@ class ApplicationController < ActionController::Base
redirect_path = "#{GlobalSetting.relative_url_root}/u/#{current_user.username}/preferences/second-factor" redirect_path = "#{GlobalSetting.relative_url_root}/u/#{current_user.username}/preferences/second-factor"
if !request.fullpath.start_with?(redirect_path) if !request.fullpath.start_with?(redirect_path)
redirect_to path(redirect_path) redirect_to path(redirect_path)
return nil
end end
end end
end end

View File

@ -142,7 +142,7 @@ class CategoriesController < ApplicationController
render_serialized(@category, CategorySerializer) render_serialized(@category, CategorySerializer)
else else
return render_json_error(@category) render_json_error(@category)
end end
end end

View File

@ -31,7 +31,7 @@ class FinishInstallationController < ApplicationController
if @user.save if @user.save
@user.change_trust_level!(1) if @user.trust_level < 1 @user.change_trust_level!(1) if @user.trust_level < 1
send_signup_email send_signup_email
return redirect_confirm(@user.email) redirect_confirm(@user.email)
end end
end end

View File

@ -169,7 +169,7 @@ class ReviewablesController < ApplicationController
render_json_error(reviewable.errors) render_json_error(reviewable.errors)
end end
rescue Reviewable::UpdateConflict rescue Reviewable::UpdateConflict
return render_json_error(I18n.t('reviewables.conflict'), status: 409) render_json_error(I18n.t('reviewables.conflict'), status: 409)
end end
end end

View File

@ -492,7 +492,7 @@ class SessionController < ApplicationController
end end
if ScreenedIpAddress.block_admin_login?(user, request.remote_ip) if ScreenedIpAddress.block_admin_login?(user, request.remote_ip)
return admin_not_allowed_from_ip_address(user) admin_not_allowed_from_ip_address(user)
end end
end end

View File

@ -67,7 +67,7 @@ class Users::OmniauthCallbacksController < ApplicationController
if @auth_result.failed? if @auth_result.failed?
flash[:error] = @auth_result.failed_reason.html_safe flash[:error] = @auth_result.failed_reason.html_safe
return render('failure') render('failure')
else else
@auth_result.authenticator_name = authenticator.name @auth_result.authenticator_name = authenticator.name
complete_response_data complete_response_data

View File

@ -225,7 +225,7 @@ module Jobs
already_read = user.user_option.email_level != UserOption.email_level_types[:always] && PostTiming.exists?(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id) already_read = user.user_option.email_level != UserOption.email_level_types[:always] && PostTiming.exists?(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id)
if already_read if already_read
return SkippedEmailLog.reason_types[:user_email_already_read] SkippedEmailLog.reason_types[:user_email_already_read]
end end
else else
false false

View File

@ -2,7 +2,7 @@
class ColorScheme < ActiveRecord::Base class ColorScheme < ActiveRecord::Base
# rubocop:disable Layout/AlignHash # rubocop:disable Layout/HashAlignment
CUSTOM_SCHEMES = { CUSTOM_SCHEMES = {
'Dark': { 'Dark': {
@ -97,7 +97,7 @@ class ColorScheme < ActiveRecord::Base
} }
} }
# rubocop:enable Layout/AlignHash # rubocop:enable Layout/HashAlignment
LIGHT_THEME_ID = 'Light' LIGHT_THEME_ID = 'Light'

View File

@ -94,7 +94,7 @@ class TranslationOverride < ActiveRecord::Base
keys: invalid_keys.join(', ') keys: invalid_keys.join(', ')
)) ))
return false false
end end
end end
end end

View File

@ -59,7 +59,7 @@ class UserSilencer
silenced_till: @user.silenced_till, silenced_till: @user.silenced_till,
silenced_at: DateTime.now silenced_at: DateTime.now
) )
return true true
end end
else else
false false

View File

@ -10,7 +10,7 @@ class ResolveDuplicateGroupNames < ActiveRecord::Migration[4.2]
GROUP BY lower(name) GROUP BY lower(name)
HAVING count(*) > 1);' HAVING count(*) > 1);'
groups = Group.where id: results groups = Group.where id: results
groups.group_by { |g| g.name.downcase }.each do |key, value| groups.group_by { |g| g.name.downcase }.each do |key, value|
value.each_with_index do |dup, index| value.each_with_index do |dup, index|
dup.update! name: "#{dup.name[0..18]}_#{index + 1}" if index > 0 dup.update! name: "#{dup.name[0..18]}_#{index + 1}" if index > 0

View File

@ -934,7 +934,7 @@ module Email
return if message_ids.empty? return if message_ids.empty?
host = Email::Sender.host_for(Discourse.base_url) host = Email::Sender.host_for(Discourse.base_url)
post_id_regexp = Regexp.new "topic/\\d+/(\\d+)@#{Regexp.escape(host)}" post_id_regexp = Regexp.new "topic/\\d+/(\\d+)@#{Regexp.escape(host)}"
topic_id_regexp = Regexp.new "topic/(\\d+)@#{Regexp.escape(host)}" topic_id_regexp = Regexp.new "topic/(\\d+)@#{Regexp.escape(host)}"
post_ids = message_ids.map { |message_id| message_id[post_id_regexp, 1] }.compact.map(&:to_i) post_ids = message_ids.map { |message_id| message_id[post_id_regexp, 1] }.compact.map(&:to_i)

View File

@ -29,7 +29,7 @@ class BulkImport::Base
NOW ||= "now()".freeze NOW ||= "now()".freeze
PRIVATE_OFFSET ||= 2**30 PRIVATE_OFFSET ||= 2**30
# rubocop:disable Layout/AlignHash # rubocop:disable Layout/HashAlignment
CHARSET_MAP = { CHARSET_MAP = {
"armscii8" => nil, "armscii8" => nil,
@ -70,7 +70,7 @@ class BulkImport::Base
"utf8" => Encoding::UTF_8, "utf8" => Encoding::UTF_8,
} }
# rubocop:enable Layout/AlignHash # rubocop:enable Layout/HashAlignment
def initialize def initialize
charset = ENV["DB_CHARSET"] || "utf8" charset = ENV["DB_CHARSET"] || "utf8"

View File

@ -222,7 +222,7 @@ class ImportScripts::Base
if existing == import_ids.length if existing == import_ids.length
puts "Skipping #{import_ids.length} already imported #{type}" puts "Skipping #{import_ids.length} already imported #{type}"
return true true
end end
ensure ensure
connection.exec('DROP TABLE import_ids') unless connection.nil? connection.exec('DROP TABLE import_ids') unless connection.nil?

View File

@ -833,9 +833,9 @@ class ImportScripts::DiscuzX < ImportScripts::Base
file_name = "#{part_4}_avatar_big.jpg" file_name = "#{part_4}_avatar_big.jpg"
if absolute if absolute
return File.join(DISCUZX_BASE_DIR, AVATAR_DIR, part_1, part_2, part_3, file_name), file_name [File.join(DISCUZX_BASE_DIR, AVATAR_DIR, part_1, part_2, part_3, file_name), file_name]
else else
return File.join(AVATAR_DIR, part_1, part_2, part_3, file_name), file_name [File.join(AVATAR_DIR, part_1, part_2, part_3, file_name), file_name]
end end
end end

View File

@ -573,7 +573,7 @@ class ImportScripts::FMGP < ImportScripts::Base
# Also deal with 0x80 (really‽) and non-breaking spaces # Also deal with 0x80 (really‽) and non-breaking spaces
text = fragment[1].gsub(/(\u200d|\u0080)/, "").gsub(/\u00a0/, " ") text = fragment[1].gsub(/(\u200d|\u0080)/, "").gsub(/\u00a0/, " ")
if fragment[2].nil? if fragment[2].nil?
return text text
else else
if fragment[2]["italic"].present? if fragment[2]["italic"].present?
text = "<i>#{text}</i>" text = "<i>#{text}</i>"
@ -585,7 +585,7 @@ class ImportScripts::FMGP < ImportScripts::Base
# s more likely than del to represent user intent? # s more likely than del to represent user intent?
text = "<s>#{text}</s>" text = "<s>#{text}</s>"
end end
return text text
end end
elsif fragment[0] == 1 elsif fragment[0] == 1
"\n" "\n"
@ -604,17 +604,17 @@ class ImportScripts::FMGP < ImportScripts::Base
# G+ occasionally doesn't put proper spaces after users # G+ occasionally doesn't put proper spaces after users
if user = find_user_by_import_id(fragment[2]) if user = find_user_by_import_id(fragment[2])
# user was in this import's authors # user was in this import's authors
return "@#{user.username} " "@#{user.username} "
else else
if google_user_info = UserAssociatedAccount.find_by(provider_name: 'google_oauth2', provider_uid: fragment[2]) if google_user_info = UserAssociatedAccount.find_by(provider_name: 'google_oauth2', provider_uid: fragment[2])
# user was not in this import, but has logged in or been imported otherwise # user was not in this import, but has logged in or been imported otherwise
user = User.find(google_user_info.user_id) user = User.find(google_user_info.user_id)
return "@#{user.username} " "@#{user.username} "
else else
raise RuntimeError.new("Google user #{fragment[1]} (id #{fragment[2]}) not imported") if !@dryrun raise RuntimeError.new("Google user #{fragment[1]} (id #{fragment[2]}) not imported") if !@dryrun
# if you want to fall back to their G+ name, just erase the raise above, # if you want to fall back to their G+ name, just erase the raise above,
# but this should not happen # but this should not happen
return "<b>+#{fragment[1]}</b>" "<b>+#{fragment[1]}</b>"
end end
end end
elsif fragment[0] == 4 elsif fragment[0] == 4
@ -669,14 +669,14 @@ class ImportScripts::FMGP < ImportScripts::Base
end end
if text == url if text == url
# leave the URL bare and Discourse will do the right thing # leave the URL bare and Discourse will do the right thing
return url url
else else
# It turns out that the only place we get here, google has done its own text # It turns out that the only place we get here, google has done its own text
# interpolation that doesn't look good on Discourse, so while it looks like # interpolation that doesn't look good on Discourse, so while it looks like
# this should be: # this should be:
# return "[#{text}](#{url})" # return "[#{text}](#{url})"
# it actually looks better to throw away the google-provided text: # it actually looks better to throw away the google-provided text:
return url url
end end
end end
end end

View File

@ -190,14 +190,14 @@ class ImportScripts::MyBB < ImportScripts::Base
if quoted_post_id_from_imported if quoted_post_id_from_imported
begin begin
post = Post.find(quoted_post_id_from_imported) post = Post.find(quoted_post_id_from_imported)
return "post:#{post.post_number}, topic:#{post.topic_id}" "post:#{post.post_number}, topic:#{post.topic_id}"
rescue rescue
puts "Could not find migrated post #{quoted_post_id_from_imported} quoted by original post #{post_id} as #{quoted_post_id}" puts "Could not find migrated post #{quoted_post_id_from_imported} quoted by original post #{post_id} as #{quoted_post_id}"
return "" ""
end end
else else
puts "Original post #{post_id} quotes nonexistent post #{quoted_post_id}" puts "Original post #{post_id} quotes nonexistent post #{quoted_post_id}"
return "" ""
end end
end end

View File

@ -19,7 +19,7 @@ class ImportScripts::Ning < ImportScripts::Base
@discussions_json = load_ning_json("ning-discussions-local.json") @discussions_json = load_ning_json("ning-discussions-local.json")
# An example of a custom category from Ning: # An example of a custom category from Ning:
@blogs_json = load_ning_json("ning-blogs-local.json") @blogs_json = load_ning_json("ning-blogs-local.json")
@photos_json = load_ning_json("ning-photos-local.json") @photos_json = load_ning_json("ning-photos-local.json")
@pages_json = load_ning_json("ning-pages-local.json") @pages_json = load_ning_json("ning-pages-local.json")

View File

@ -54,7 +54,7 @@ describe ColorScheme do
it "creates a new color scheme" do it "creates a new color scheme" do
c = described_class.create_from_base(name: 'Yellow', colors: { first_one: 'FFFF00', third_one: 'F00D33' }) c = described_class.create_from_base(name: 'Yellow', colors: { first_one: 'FFFF00', third_one: 'F00D33' })
expect(c.colors.size).to eq base_colors.size expect(c.colors.size).to eq base_colors.size
first = c.colors.find { |x| x.name == 'first_one' } first = c.colors.find { |x| x.name == 'first_one' }
second = c.colors.find { |x| x.name == 'second_one' } second = c.colors.find { |x| x.name == 'second_one' }
third = c.colors.find { |x| x.name == 'third_one' } third = c.colors.find { |x| x.name == 'third_one' }
expect(first.hex).to eq 'FFFF00' expect(first.hex).to eq 'FFFF00'

View File

@ -204,7 +204,7 @@ describe TrustLevel3Requirements do
_not_a_reply = create_post(user: user) # user created the topic, so it doesn't count _not_a_reply = create_post(user: user) # user created the topic, so it doesn't count
topic1 = create_post.topic topic1 = create_post.topic
_reply1 = create_post(topic: topic1, user: user) _reply1 = create_post(topic: topic1, user: user)
_reply_again = create_post(topic: topic1, user: user) # two replies in one topic _reply_again = create_post(topic: topic1, user: user) # two replies in one topic
topic2 = create_post(created_at: 101.days.ago).topic topic2 = create_post(created_at: 101.days.ago).topic
@ -319,7 +319,7 @@ describe TrustLevel3Requirements do
UserActionManager.enable UserActionManager.enable
t = Fabricate(:topic, user: user, created_at: 102.days.ago) t = Fabricate(:topic, user: user, created_at: 102.days.ago)
old_post = create_post(topic: t, user: user, created_at: 102.days.ago) old_post = create_post(topic: t, user: user, created_at: 102.days.ago)
recent_post2 = create_post(topic: t, user: user, created_at: 10.days.ago) recent_post2 = create_post(topic: t, user: user, created_at: 10.days.ago)
recent_post1 = create_post(topic: t, user: user, created_at: 1.hour.ago) recent_post1 = create_post(topic: t, user: user, created_at: 1.hour.ago)

View File

@ -219,7 +219,7 @@ module Concurrency
previous_value, @in_transaction = @in_transaction, true previous_value, @in_transaction = @in_transaction, true
begin begin
return yield yield
ensure ensure
@in_transaction = previous_value @in_transaction = previous_value
end end