DEV: Enable unless cops

We discussed the use of `unless` internally and decided to enforce
available rules from rubocop to restrict its most problematic uses.
This commit is contained in:
Loïc Guitaut
2023-02-16 10:40:11 +01:00
committed by Loïc Guitaut
parent 87de3c2319
commit f7c57fbc19
56 changed files with 137 additions and 142 deletions

View File

@ -116,7 +116,7 @@ class ImportScripts::Base
def reset_site_settings
@old_site_settings.each do |key, value|
current_value = SiteSetting.get(key)
SiteSetting.set(key, value) unless current_value != @site_settings_during_import[key]
SiteSetting.set(key, value) if current_value == @site_settings_during_import[key]
end
RateLimiter.enable

View File

@ -178,11 +178,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
topic = topics[post[:topic_id]]
unless topic[:post_id]
mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
mapped[:title] = post[:title]
topic[:post_id] = post[:id]
else
if topic[:post_id]
parent = topic_lookup_from_imported_post_id(topic[:post_id])
next unless parent
@ -195,6 +191,10 @@ class ImportScripts::Bespoke < ImportScripts::Base
mapped[:reply_to_post_number] = reply_to_post_number
end
end
else
mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
mapped[:title] = post[:title]
topic[:post_id] = post[:id]
end
next if topic[:deleted] || post[:deleted]

View File

@ -887,7 +887,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
LIMIT 1",
)
return discuzx_link unless results.size > 0
return discuzx_link if results.size.zero?
linked_post_id = results.first["pid"]
lookup = topic_lookup_from_imported_post_id(linked_post_id)

View File

@ -225,11 +225,7 @@ class ImportScripts::Jive < ImportScripts::Base
next
end
unless topic[:post_id]
mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
mapped[:title] = post[:title]
topic[:post_id] = post[:id]
else
if topic[:post_id]
parent = topic_lookup_from_imported_post_id(topic[:post_id])
next unless parent
@ -242,6 +238,10 @@ class ImportScripts::Jive < ImportScripts::Base
mapped[:reply_to_post_number] = reply_to_post_number
end
end
else
mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
mapped[:title] = post[:title]
topic[:post_id] = post[:id]
end
next if topic[:deleted] || post[:deleted]

View File

@ -95,7 +95,7 @@ class ImportScripts::Kunena < ImportScripts::Base
cache_rows: false,
)
results.each do |u|
next unless u["userid"].to_i > 0
next if u["userid"].to_i <= 0
user = @users[u["userid"].to_i]
if user
user[:bio] = u["signature"]

View File

@ -114,7 +114,7 @@ class ImportScripts::Kunena < ImportScripts::Base
cache_rows: false,
)
results.each do |u|
next unless u["userid"].to_i > 0
next if u["userid"].to_i <= 0
user = @users[u["userid"].to_i]
if user
user[:bio] = u["signature"]

View File

@ -803,12 +803,12 @@ class ImportScripts::Lithium < ImportScripts::Base
import_mode: true,
}
unless topic_id
if topic_id
msg[:topic_id] = topic_id
else
msg[:title] = @htmlentities.decode(topic["subject"]).strip[0...255]
msg[:archetype] = Archetype.private_message
msg[:target_usernames] = usernames.join(",")
else
msg[:topic_id] = topic_id
end
msg

View File

@ -382,7 +382,9 @@ FROM #{TABLE_PREFIX}discuss_users
title_username_of_pm_first_post[[title, participants]] ||= m["pmtextid"]
end
unless topic_id
if topic_id
mapped[:topic_id] = topic_id
else
mapped[:title] = title
mapped[:archetype] = Archetype.private_message
mapped[:target_usernames] = target_usernames.join(",")
@ -392,8 +394,6 @@ FROM #{TABLE_PREFIX}discuss_users
mapped[:target_usernames] = "system"
puts "pm-#{m["pmtextid"]} has no target (#{m["touserarray"]})"
end
else
mapped[:topic_id] = topic_id
end
skip ? nil : mapped

View File

@ -378,7 +378,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
AttachmentPatterns.each do |p|
pattern, emitter = *p
body.gsub!(pattern) do |s|
next s unless (num = $~[:num].to_i - 1) >= 0
next s if (num = $~[:num].to_i - 1) < 0
next s unless (upload = attachments[num]).present?
use_count[num] += 1
instance_exec(upload, &emitter)

View File

@ -586,7 +586,9 @@ class ImportScripts::VBulletin < ImportScripts::Base
title_username_of_pm_first_post[[title, participants]] ||= m["pmtextid"]
end
unless topic_id
if topic_id
mapped[:topic_id] = topic_id
else
mapped[:title] = title
mapped[:archetype] = Archetype.private_message
mapped[:target_usernames] = target_usernames.join(",")
@ -596,8 +598,6 @@ class ImportScripts::VBulletin < ImportScripts::Base
mapped[:target_usernames] = "system"
puts "pm-#{m["pmtextid"]} has no target (#{m["touserarray"]})"
end
else
mapped[:topic_id] = topic_id
end
skip ? nil : mapped

View File

@ -335,7 +335,15 @@ class ImportScripts::XenForo < ImportScripts::Base
created_at: Time.zone.at(post["message_date"].to_i),
import_mode: true,
}
unless post["topic_id"] > 0
if post["topic_id"] <= 0
topic_id = post["topic_id"]
if t = topic_lookup_from_imported_post_id("pm_#{topic_id}")
msg[:topic_id] = t[:topic_id]
else
puts "Topic ID #{topic_id} not found, skipping post #{post["message_id"]} from #{post["user_id"]}"
next
end
else
msg[:title] = post["title"]
msg[:archetype] = Archetype.private_message
to_user_array = PHP.unserialize(post["recipients"])
@ -344,14 +352,6 @@ class ImportScripts::XenForo < ImportScripts::Base
usernames = User.where(id: [discourse_user_ids]).pluck(:username)
msg[:target_usernames] = usernames.join(",")
end
else
topic_id = post["topic_id"]
if t = topic_lookup_from_imported_post_id("pm_#{topic_id}")
msg[:topic_id] = t[:topic_id]
else
puts "Topic ID #{topic_id} not found, skipping post #{post["message_id"]} from #{post["user_id"]}"
next
end
end
msg
else