Enable `Lint/ShadowingOuterLocalVariable` for Rubocop.
This commit is contained in:
parent
2f5c21e28c
commit
8dc1463ab3
|
@ -102,6 +102,9 @@ Layout/EndAlignment:
|
||||||
Lint/RequireParentheses:
|
Lint/RequireParentheses:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Lint/ShadowingOuterLocalVariable:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Layout/MultilineMethodCallIndentation:
|
Layout/MultilineMethodCallIndentation:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
EnforcedStyle: indented
|
EnforcedStyle: indented
|
||||||
|
|
|
@ -292,11 +292,11 @@ SQL
|
||||||
topic_id: topic.id
|
topic_id: topic.id
|
||||||
}
|
}
|
||||||
|
|
||||||
channels.each do |channel, user_ids|
|
channels.each do |channel, ids|
|
||||||
MessageBus.publish(
|
MessageBus.publish(
|
||||||
channel,
|
channel,
|
||||||
message.as_json,
|
message.as_json,
|
||||||
user_ids: user_ids
|
user_ids: ids
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,8 +54,8 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["
|
||||||
end
|
end
|
||||||
|
|
||||||
if (files = params[:files]) && files.respond_to?(:map)
|
if (files = params[:files]) && files.respond_to?(:map)
|
||||||
params[:files] = files.map do |file|
|
params[:files] = files.map do |f|
|
||||||
file.respond_to?(:headers) ? file.headers : file
|
f.respond_to?(:headers) ? f.headers : f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -106,14 +106,14 @@ module Email
|
||||||
.where(id: PostReply.where(reply_id: post_id).select(:post_id))
|
.where(id: PostReply.where(reply_id: post_id).select(:post_id))
|
||||||
.order(id: :desc)
|
.order(id: :desc)
|
||||||
|
|
||||||
referenced_post_message_ids = referenced_posts.map do |post|
|
referenced_post_message_ids = referenced_posts.map do |referenced_post|
|
||||||
if post.incoming_email&.message_id.present?
|
if referenced_post.incoming_email&.message_id.present?
|
||||||
"<#{post.incoming_email.message_id}>"
|
"<#{referenced_post.incoming_email.message_id}>"
|
||||||
else
|
else
|
||||||
if post.post_number == 1
|
if referenced_post.post_number == 1
|
||||||
"<topic/#{topic_id}@#{host}>"
|
"<topic/#{topic_id}@#{host}>"
|
||||||
else
|
else
|
||||||
"<topic/#{topic_id}/#{post.id}@#{host}>"
|
"<topic/#{topic_id}/#{referenced_post.id}@#{host}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,10 +38,17 @@ class FinalDestination
|
||||||
@opts[:lookup_ip] ||= lambda { |host| FinalDestination.lookup_ip(host) }
|
@opts[:lookup_ip] ||= lambda { |host| FinalDestination.lookup_ip(host) }
|
||||||
|
|
||||||
@ignored = @opts[:ignore_hostnames] || []
|
@ignored = @opts[:ignore_hostnames] || []
|
||||||
[Discourse.base_url_no_prefix].concat(@opts[:ignore_redirects] || []).each do |url|
|
|
||||||
url = uri(url)
|
ignore_redirects = [Discourse.base_url_no_prefix]
|
||||||
if url.present? && url.hostname
|
|
||||||
@ignored << url.hostname
|
if @opts[:ignore_redirects]
|
||||||
|
ignore_redirects.concat(@opts[:ignore_redirects])
|
||||||
|
end
|
||||||
|
|
||||||
|
ignore_redirects.each do |ignore_redirect|
|
||||||
|
ignore_redirect = uri(ignore_redirect)
|
||||||
|
if ignore_redirect.present? && ignore_redirect.hostname
|
||||||
|
@ignored << ignore_redirect.hostname
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@ module ActiveSupport
|
||||||
uncached = "#{method_name}_without_cache"
|
uncached = "#{method_name}_without_cache"
|
||||||
alias_method uncached, method_name
|
alias_method uncached, method_name
|
||||||
|
|
||||||
define_method(method_name) do |*args|
|
define_method(method_name) do |*arguments|
|
||||||
# this avoids recursive locks
|
# this avoids recursive locks
|
||||||
found = true
|
found = true
|
||||||
data = cache.fetch(args) { found = false }
|
data = cache.fetch(arguments) { found = false }
|
||||||
unless found
|
unless found
|
||||||
cache[args] = data = send(uncached, *args)
|
cache[arguments] = data = send(uncached, *arguments)
|
||||||
end
|
end
|
||||||
# so cache is never corrupted
|
# so cache is never corrupted
|
||||||
data.dup
|
data.dup
|
||||||
|
@ -45,9 +45,10 @@ module ActiveSupport
|
||||||
args.each do |method_name|
|
args.each do |method_name|
|
||||||
orig = "#{method_name}_without_clear_memoize"
|
orig = "#{method_name}_without_clear_memoize"
|
||||||
alias_method orig, method_name
|
alias_method orig, method_name
|
||||||
define_method(method_name) do |*args|
|
|
||||||
|
define_method(method_name) do |*arguments|
|
||||||
ActiveSupport::Inflector.clear_memoize!
|
ActiveSupport::Inflector.clear_memoize!
|
||||||
send(orig, *args)
|
send(orig, *arguments)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,9 +41,11 @@ module I18n
|
||||||
I18n.backend.load_translations(I18n.load_path.grep(/\.rb$/))
|
I18n.backend.load_translations(I18n.load_path.grep(/\.rb$/))
|
||||||
|
|
||||||
# load plural rules from plugins
|
# load plural rules from plugins
|
||||||
DiscoursePluginRegistry.locales.each do |locale, options|
|
DiscoursePluginRegistry.locales.each do |plugin_locale, options|
|
||||||
if options[:plural]
|
if options[:plural]
|
||||||
I18n.backend.store_translations(locale, i18n: { plural: options[:plural] })
|
I18n.backend.store_translations(plugin_locale,
|
||||||
|
i18n: { plural: options[:plural] }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,9 +97,14 @@ module ImportExport
|
||||||
topic_data[:posts] = []
|
topic_data[:posts] = []
|
||||||
|
|
||||||
topic.ordered_posts.find_each do |post|
|
topic.ordered_posts.find_each do |post|
|
||||||
h = POST_ATTRS.inject({}) { |h, a| h[a] = post.send(a); h; }
|
attributes = POST_ATTRS.inject({}) { |h, a| h[a] = post.send(a); h; }
|
||||||
h[:raw] = h[:raw].gsub('src="/uploads', "src=\"#{Discourse.base_url_no_prefix}/uploads")
|
|
||||||
topic_data[:posts] << h
|
attributes[:raw] = attributes[:raw].gsub(
|
||||||
|
'src="/uploads',
|
||||||
|
"src=\"#{Discourse.base_url_no_prefix}/uploads"
|
||||||
|
)
|
||||||
|
|
||||||
|
topic_data[:posts] << attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
data << topic_data
|
data << topic_data
|
||||||
|
|
|
@ -27,21 +27,21 @@ class Typepad < Thor
|
||||||
end
|
end
|
||||||
|
|
||||||
inside_block = true
|
inside_block = true
|
||||||
entry = ""
|
input = ""
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
File.open(options[:file]).each_line do |l|
|
File.open(options[:file]).each_line do |l|
|
||||||
l = l.scrub
|
l = l.scrub
|
||||||
|
|
||||||
if l =~ /^--------$/
|
if l =~ /^--------$/
|
||||||
parsed_entry = process_entry(entry)
|
parsed_entry = process_entry(input)
|
||||||
if parsed_entry
|
if parsed_entry
|
||||||
puts "Parsed #{parsed_entry[:title]}"
|
puts "Parsed #{parsed_entry[:title]}"
|
||||||
entries << parsed_entry
|
entries << parsed_entry
|
||||||
end
|
end
|
||||||
entry = ""
|
input = ""
|
||||||
else
|
else
|
||||||
entry << l
|
input << l
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class Typepad < Thor
|
||||||
SiteSetting.email_domains_blacklist = ""
|
SiteSetting.email_domains_blacklist = ""
|
||||||
|
|
||||||
puts "Importing #{entries.size} entries"
|
puts "Importing #{entries.size} entries"
|
||||||
|
|
||||||
entries.each_with_index do |entry, idx|
|
entries.each_with_index do |entry, idx|
|
||||||
puts "Importing (#{idx + 1}/#{entries.size})"
|
puts "Importing (#{idx + 1}/#{entries.size})"
|
||||||
next if entry[:body].blank?
|
next if entry[:body].blank?
|
||||||
|
@ -219,7 +220,7 @@ class Typepad < Thor
|
||||||
current << c
|
current << c
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
segments.delete_if { |s| s.nil? || s.size < 2 }
|
segments.delete_if { |segment| segment.nil? || segment.size < 2 }
|
||||||
segments << current
|
segments << current
|
||||||
|
|
||||||
comment[:author] = segments[0]
|
comment[:author] = segments[0]
|
||||||
|
|
|
@ -95,7 +95,7 @@ class DiscourseCLI < Thor
|
||||||
if !filename
|
if !filename
|
||||||
puts "You must provide a filename to restore. Did you mean one of the following?\n\n"
|
puts "You must provide a filename to restore. Did you mean one of the following?\n\n"
|
||||||
|
|
||||||
Dir["public/backups/default/*"].sort_by { |filename| File.mtime(filename) }.reverse.each do |f|
|
Dir["public/backups/default/*"].sort_by { |path| File.mtime(path) }.reverse.each do |f|
|
||||||
puts "#{discourse} restore #{File.basename(f)}"
|
puts "#{discourse} restore #{File.basename(f)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -393,12 +393,12 @@ class ImportScripts::DiscuzX < ImportScripts::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
if m['status'] & 1 == 1 || mapped[:raw].blank?
|
if m['status'] & 1 == 1 || mapped[:raw].blank?
|
||||||
mapped[:post_create_action] = lambda do |post|
|
mapped[:post_create_action] = lambda do |action_post|
|
||||||
PostDestroyer.new(Discourse.system_user, post).perform_delete
|
PostDestroyer.new(Discourse.system_user, action_post).perform_delete
|
||||||
end
|
end
|
||||||
elsif (m['status'] & 2) >> 1 == 1 # waiting for approve
|
elsif (m['status'] & 2) >> 1 == 1 # waiting for approve
|
||||||
mapped[:post_create_action] = lambda do |post|
|
mapped[:post_create_action] = lambda do |action_post|
|
||||||
PostAction.act(Discourse.system_user, post, 6, take_action: false)
|
PostAction.act(Discourse.system_user, action_post, 6, take_action: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
skip ? nil : mapped
|
skip ? nil : mapped
|
||||||
|
|
|
@ -355,10 +355,10 @@ class ImportScripts::Smf1 < ImportScripts::Base
|
||||||
post[:archetype] = Archetype.private_message
|
post[:archetype] = Archetype.private_message
|
||||||
post[:title] = title
|
post[:title] = title
|
||||||
post[:target_usernames] = User.where(id: recipients).pluck(:username)
|
post[:target_usernames] = User.where(id: recipients).pluck(:username)
|
||||||
post[:post_create_action] = proc do |p|
|
post[:post_create_action] = proc do |action_post|
|
||||||
@pm_mapping[users] ||= {}
|
@pm_mapping[users] ||= {}
|
||||||
@pm_mapping[users][title] ||= []
|
@pm_mapping[users][title] ||= []
|
||||||
@pm_mapping[users][title] << p.topic_id
|
@pm_mapping[users][title] << action_post.topic_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -201,15 +201,17 @@ class ImportScripts::Smf2 < ImportScripts::Base
|
||||||
SQL
|
SQL
|
||||||
skip = false
|
skip = false
|
||||||
ignore_quotes = false
|
ignore_quotes = false
|
||||||
|
|
||||||
post = {
|
post = {
|
||||||
id: message[:id_msg],
|
id: message[:id_msg],
|
||||||
user_id: user_id_from_imported_user_id(message[:id_member]) || -1,
|
user_id: user_id_from_imported_user_id(message[:id_member]) || -1,
|
||||||
created_at: Time.zone.at(message[:poster_time]),
|
created_at: Time.zone.at(message[:poster_time]),
|
||||||
post_create_action: ignore_quotes && proc do |post|
|
post_create_action: ignore_quotes && proc do |p|
|
||||||
post.custom_fields['import_rebake'] = 't'
|
p.custom_fields['import_rebake'] = 't'
|
||||||
post.save
|
p.save
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
if message[:id_msg] == message[:id_first_msg]
|
if message[:id_msg] == message[:id_first_msg]
|
||||||
post[:category] = category_id_from_imported_category_id(message[:id_board])
|
post[:category] = category_id_from_imported_category_id(message[:id_board])
|
||||||
post[:title] = decode_entities(message[:subject])
|
post[:title] = decode_entities(message[:subject])
|
||||||
|
|
|
@ -273,8 +273,8 @@ class ImportScripts::Telligent < ImportScripts::Base
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
created_at: row["DateCreated"],
|
created_at: row["DateCreated"],
|
||||||
closed: row["IsLocked"],
|
closed: row["IsLocked"],
|
||||||
post_create_action: proc do |post|
|
post_create_action: proc do |action_post|
|
||||||
topic = post.topic
|
topic = action_post.topic
|
||||||
Jobs.enqueue_at(topic.pinned_until, :unpin_topic, topic_id: topic.id) if topic.pinned_until
|
Jobs.enqueue_at(topic.pinned_until, :unpin_topic, topic_id: topic.id) if topic.pinned_until
|
||||||
url = "f/#{row['ForumId']}/t/#{row['ThreadId']}"
|
url = "f/#{row['ForumId']}/t/#{row['ThreadId']}"
|
||||||
Permalink.create(url: url, topic_id: topic.id) unless Permalink.exists?(url: url)
|
Permalink.create(url: url, topic_id: topic.id) unless Permalink.exists?(url: url)
|
||||||
|
|
|
@ -114,16 +114,16 @@ describe TopicTrackingState do
|
||||||
"/private-messages/group/#{group2.name}"
|
"/private-messages/group/#{group2.name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
message = messages.find do |message|
|
message = messages.find do |m|
|
||||||
message.channel == '/private-messages/inbox'
|
m.channel == '/private-messages/inbox'
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||||
expect(message.user_ids).to eq(private_message_topic.allowed_users.map(&:id))
|
expect(message.user_ids).to eq(private_message_topic.allowed_users.map(&:id))
|
||||||
|
|
||||||
[group1, group2].each do |group|
|
[group1, group2].each do |group|
|
||||||
message = messages.find do |message|
|
message = messages.find do |m|
|
||||||
message.channel == "/private-messages/group/#{group.name}"
|
m.channel == "/private-messages/group/#{group.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||||
|
@ -148,9 +148,7 @@ describe TopicTrackingState do
|
||||||
"/private-messages/group/#{group2.name}/archive",
|
"/private-messages/group/#{group2.name}/archive",
|
||||||
)
|
)
|
||||||
|
|
||||||
message = messages.find do |message|
|
message = messages.find { |m| m.channel == '/private-messages/inbox' }
|
||||||
message.channel == '/private-messages/inbox'
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||||
expect(message.user_ids).to eq(private_message_topic.allowed_users.map(&:id))
|
expect(message.user_ids).to eq(private_message_topic.allowed_users.map(&:id))
|
||||||
|
@ -162,10 +160,7 @@ describe TopicTrackingState do
|
||||||
group_channel,
|
group_channel,
|
||||||
"#{group_channel}/archive"
|
"#{group_channel}/archive"
|
||||||
].each do |channel|
|
].each do |channel|
|
||||||
message = messages.find do |message|
|
message = messages.find { |m| m.channel == channel }
|
||||||
message.channel == channel
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||||
expect(message.user_ids).to eq(group.users.map(&:id))
|
expect(message.user_ids).to eq(group.users.map(&:id))
|
||||||
end
|
end
|
||||||
|
@ -211,9 +206,7 @@ describe TopicTrackingState do
|
||||||
[user.id],
|
[user.id],
|
||||||
[group.users.first.id]
|
[group.users.first.id]
|
||||||
]).each do |channel, user_ids|
|
]).each do |channel, user_ids|
|
||||||
message = messages.find do |message|
|
message = messages.find { |m| m.channel == channel }
|
||||||
message.channel == channel
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||||
expect(message.user_ids).to eq(user_ids)
|
expect(message.user_ids).to eq(user_ids)
|
||||||
|
@ -239,10 +232,7 @@ describe TopicTrackingState do
|
||||||
expect(messages.map(&:channel)).to eq(expected_channels)
|
expect(messages.map(&:channel)).to eq(expected_channels)
|
||||||
|
|
||||||
expected_channels.each do |channel|
|
expected_channels.each do |channel|
|
||||||
message = messages.find do |message|
|
message = messages.find { |m| m.channel = channel }
|
||||||
message.channel = channel
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
expect(message.data["topic_id"]).to eq(private_message_topic.id)
|
||||||
expect(message.user_ids).to eq([private_message_post.user_id])
|
expect(message.user_ids).to eq([private_message_post.user_id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ describe TopicStatusUpdater do
|
||||||
topic = create_topic
|
topic = create_topic
|
||||||
|
|
||||||
called = false
|
called = false
|
||||||
updater = -> (topic) { called = true }
|
updater = -> (_) { called = true }
|
||||||
|
|
||||||
DiscourseEvent.on(:topic_closed, &updater)
|
DiscourseEvent.on(:topic_closed, &updater)
|
||||||
TopicStatusUpdater.new(topic, admin).update!("closed", true)
|
TopicStatusUpdater.new(topic, admin).update!("closed", true)
|
||||||
|
|
Loading…
Reference in New Issue