Skip to content

Commit 69f0f48

Browse files
authored
DEV: Fix rubocop issues (#14715)
1 parent 6aa6275 commit 69f0f48

File tree

27 files changed

+65
-69
lines changed

27 files changed

+65
-69
lines changed

app/models/locale_site_setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.language_names
2323

2424
@lock.synchronize do
2525
@language_names ||= begin
26-
names = YAML.load(File.read(File.join(Rails.root, 'config', 'locales', 'names.yml')))
26+
names = YAML.safe_load(File.read(File.join(Rails.root, 'config', 'locales', 'names.yml')))
2727

2828
DiscoursePluginRegistry.locales.each do |locale, options|
2929
if !names.key?(locale) && options[:name] && options[:nativeName]

app/models/topic_embed.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ def self.find_remote(url)
117117
follow_canonical: true,
118118
)
119119

120-
url = fd.resolve
121-
return if url.blank?
120+
uri = fd.resolve
121+
return if uri.blank?
122122

123123
opts = {
124124
tags: %w[div p code pre h1 h2 h3 b em i strong a img ul li ol blockquote],
@@ -132,7 +132,7 @@ def self.find_remote(url)
132132

133133
response = FetchResponse.new
134134
begin
135-
html = open(url, allow_redirections: :safe).read
135+
html = uri.read(allow_redirections: :safe)
136136
rescue OpenURI::HTTPError, Net::OpenTimeout
137137
return
138138
end
@@ -256,10 +256,6 @@ def self.expanded_for(post)
256256
body
257257
end
258258
end
259-
260-
def self.open(uri, **kwargs)
261-
URI.open(uri, **kwargs)
262-
end
263259
end
264260

265261
# == Schema Information

app/services/site_settings_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def self.import(yml)
1616
counts = { updated: 0, not_found: 0, errors: 0 }
1717
log = []
1818

19-
site_settings = YAML::load(yml)
19+
site_settings = YAML::safe_load(yml)
2020
site_settings.each do |site_setting|
2121
key = site_setting[0]
2222
val = site_setting[1]

lib/cache.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def fetch(name, expires_in: nil, force: nil, &blk)
8686

8787
if raw
8888
begin
89-
Marshal.load(raw)
89+
Marshal.load(raw) # rubocop:disable Security/MarshalLoad
9090
rescue => e
9191
log_first_exception(e)
9292
end
@@ -113,7 +113,7 @@ def log_first_exception(e)
113113

114114
def read_entry(key)
115115
if data = redis.get(key)
116-
Marshal.load(data)
116+
Marshal.load(data) # rubocop:disable Security/MarshalLoad
117117
end
118118
rescue => e
119119
# corrupt cache, this can happen if Marshal version

lib/discourse_updates.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,34 @@ def last_installed_version
6161
Discourse.redis.get last_installed_version_key
6262
end
6363

64+
def last_installed_version=(arg)
65+
Discourse.redis.set(last_installed_version, arg)
66+
end
67+
6468
def latest_version
6569
Discourse.redis.get latest_version_key
6670
end
6771

72+
def latest_version=(arg)
73+
Discourse.redis.set(latest_version, arg)
74+
end
75+
6876
def missing_versions_count
6977
Discourse.redis.get(missing_versions_count_key).try(:to_i)
7078
end
7179

80+
def missing_versions_count=(arg)
81+
Discourse.redis.set(missing_versions_count, arg)
82+
end
83+
7284
def critical_updates_available?
7385
(Discourse.redis.get(critical_updates_available_key) || false) == 'true'
7486
end
7587

88+
def critical_updates_available=(arg)
89+
Discourse.redis.set(critical_updates_available, arg)
90+
end
91+
7692
def updated_at
7793
t = Discourse.redis.get(updated_at_key)
7894
t ? Time.zone.parse(t) : nil
@@ -82,12 +98,6 @@ def updated_at=(time_with_zone)
8298
Discourse.redis.set updated_at_key, time_with_zone.as_json
8399
end
84100

85-
['last_installed_version', 'latest_version', 'missing_versions_count', 'critical_updates_available'].each do |name|
86-
eval "define_method :#{name}= do |arg|
87-
Discourse.redis.set #{name}_key, arg
88-
end"
89-
end
90-
91101
def missing_versions=(versions)
92102
# delete previous list from redis
93103
prev_keys = Discourse.redis.lrange(missing_versions_list_key, 0, 4)

lib/i18n/locale_file_checker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def reference_value_pluralized?(value)
165165

166166
def plural_keys
167167
@plural_keys ||= begin
168-
eval(File.read("#{Rails.root}/#{PLURALS_FILE}")).map do |locale, value|
168+
eval(File.read("#{Rails.root}/#{PLURALS_FILE}")).map do |locale, value| # rubocop:disable Security/Eval
169169
[locale.to_s, value[:i18n][:plural][:keys].map(&:to_s)]
170170
end.to_h
171171
end

lib/middleware/anonymous_cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.compile_key_builder
2929
method << "|#{k}=#\{h.#{v}}"
3030
end
3131
method << "\"\nend"
32-
eval(method)
32+
eval(method) # rubocop:disable Security/Eval
3333
@@compiled = true
3434
end
3535

lib/onebox/engine/github_actions_onebox.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def data
7171
raw["head_commit"]["message"].lines.first
7272
elsif type == :pr_run
7373
pr_url = "https://api.github.com/repos/#{match[:org]}/#{match[:repo]}/pulls/#{match[:pr_id]}"
74-
::MultiJson.load(URI.open(pr_url, read_timeout: timeout))["title"]
74+
::MultiJson.load(URI.parse(pr_url).open(read_timeout: timeout))["title"]
7575
end
7676

7777
{

lib/onebox/engine/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module JSON
66
private
77

88
def raw
9-
@raw ||= ::MultiJson.load(URI.open(url, read_timeout: timeout))
9+
@raw ||= ::MultiJson.load(URI.parse(url).open(read_timeout: timeout))
1010
end
1111
end
1212
end

lib/onebox/engine/pubmed_onebox.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PubmedOnebox
1212

1313
def xml
1414
return @xml if defined?(@xml)
15-
doc = Nokogiri::XML(URI.open(URI.join(@url, "?report=xml&format=text")))
15+
doc = Nokogiri::XML(URI.join(@url, "?report=xml&format=text").open)
1616
pre = doc.xpath("//pre")
1717
@xml = Nokogiri::XML("<root>" + pre.text + "</root>")
1818
end

0 commit comments

Comments
 (0)