DEV: Fix rubocop issues (#14715)

DEV: Fix rubocop issues (#14715)

diff --git a/app/models/locale_site_setting.rb b/app/models/locale_site_setting.rb
index f541a27..6843187 100644
--- a/app/models/locale_site_setting.rb
+++ b/app/models/locale_site_setting.rb
@@ -23,7 +23,7 @@ class LocaleSiteSetting < EnumSiteSetting
 
     @lock.synchronize do
       @language_names ||= begin
-        names = YAML.load(File.read(File.join(Rails.root, 'config', 'locales', 'names.yml')))
+        names = YAML.safe_load(File.read(File.join(Rails.root, 'config', 'locales', 'names.yml')))
 
         DiscoursePluginRegistry.locales.each do |locale, options|
           if !names.key?(locale) && options[:name] && options[:nativeName]
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb
index 502409d..2273913 100644
--- a/app/models/topic_embed.rb
+++ b/app/models/topic_embed.rb
@@ -117,8 +117,8 @@ class TopicEmbed < ActiveRecord::Base
       follow_canonical: true,
     )
 
-    url = fd.resolve
-    return if url.blank?
+    uri = fd.resolve
+    return if uri.blank?
 
     opts = {
       tags: %w[div p code pre h1 h2 h3 b em i strong a img ul li ol blockquote],
@@ -132,7 +132,7 @@ class TopicEmbed < ActiveRecord::Base
 
     response = FetchResponse.new
     begin
-      html = open(url, allow_redirections: :safe).read
+      html = uri.read(allow_redirections: :safe)
     rescue OpenURI::HTTPError, Net::OpenTimeout
       return
     end
@@ -256,10 +256,6 @@ class TopicEmbed < ActiveRecord::Base
       body
     end
   end
-
-  def self.open(uri, **kwargs)
-    URI.open(uri, **kwargs)
-  end
 end
 
 # == Schema Information
diff --git a/app/services/site_settings_task.rb b/app/services/site_settings_task.rb
index 64c8048..356d8ec 100644
--- a/app/services/site_settings_task.rb
+++ b/app/services/site_settings_task.rb
@@ -16,7 +16,7 @@ class SiteSettingsTask
     counts = { updated: 0, not_found: 0, errors: 0 }
     log = []
 
-    site_settings = YAML::load(yml)
+    site_settings = YAML::safe_load(yml)
     site_settings.each do |site_setting|
       key = site_setting[0]
       val = site_setting[1]
diff --git a/lib/cache.rb b/lib/cache.rb
index 7d69361..ca814c9 100644
--- a/lib/cache.rb
+++ b/lib/cache.rb
@@ -86,7 +86,7 @@ class Cache
 
       if raw
         begin
-          Marshal.load(raw)
+          Marshal.load(raw) # rubocop:disable Security/MarshalLoad
         rescue => e
           log_first_exception(e)
         end
@@ -113,7 +113,7 @@ class Cache
 
   def read_entry(key)
     if data = redis.get(key)
-      Marshal.load(data)
+      Marshal.load(data) # rubocop:disable Security/MarshalLoad
     end
   rescue => e
     # corrupt cache, this can happen if Marshal version
diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb
index fbc81aa..32afc2f 100644
--- a/lib/discourse_updates.rb
+++ b/lib/discourse_updates.rb
@@ -61,18 +61,34 @@ module DiscourseUpdates
       Discourse.redis.get last_installed_version_key
     end
 
+    def last_installed_version=(arg)
+      Discourse.redis.set(last_installed_version, arg)
+    end
+
     def latest_version
       Discourse.redis.get latest_version_key
     end
 
+    def latest_version=(arg)
+      Discourse.redis.set(latest_version, arg)
+    end
+
     def missing_versions_count
       Discourse.redis.get(missing_versions_count_key).try(:to_i)
     end
 
+    def missing_versions_count=(arg)
+      Discourse.redis.set(missing_versions_count, arg)
+    end
+
     def critical_updates_available?
       (Discourse.redis.get(critical_updates_available_key) || false) == 'true'
     end
 
+    def critical_updates_available=(arg)
+      Discourse.redis.set(critical_updates_available, arg)
+    end
+
     def updated_at
       t = Discourse.redis.get(updated_at_key)
       t ? Time.zone.parse(t) : nil
@@ -82,12 +98,6 @@ module DiscourseUpdates
       Discourse.redis.set updated_at_key, time_with_zone.as_json
     end
 
-    ['last_installed_version', 'latest_version', 'missing_versions_count', 'critical_updates_available'].each do |name|
-      eval "define_method :#{name}= do |arg|
-        Discourse.redis.set #{name}_key, arg
-      end"
-    end
-
     def missing_versions=(versions)
       # delete previous list from redis
       prev_keys = Discourse.redis.lrange(missing_versions_list_key, 0, 4)
diff --git a/lib/i18n/locale_file_checker.rb b/lib/i18n/locale_file_checker.rb
index e818823..757e9b9 100644
--- a/lib/i18n/locale_file_checker.rb
+++ b/lib/i18n/locale_file_checker.rb
@@ -165,7 +165,7 @@ class LocaleFileChecker
 
   def plural_keys
     @plural_keys ||= begin
-      eval(File.read("#{Rails.root}/#{PLURALS_FILE}")).map do |locale, value|
+      eval(File.read("#{Rails.root}/#{PLURALS_FILE}")).map do |locale, value| # rubocop:disable Security/Eval
         [locale.to_s, value[:i18n][:plural][:keys].map(&:to_s)]
       end.to_h
     end
diff --git a/lib/middleware/anonymous_cache.rb b/lib/middleware/anonymous_cache.rb
index a62fb01..8d605ae 100644
--- a/lib/middleware/anonymous_cache.rb
+++ b/lib/middleware/anonymous_cache.rb
@@ -29,7 +29,7 @@ module Middleware
         method << "|#{k}=#\{h.#{v}}"
       end
       method << "\"\nend"
-      eval(method)
+      eval(method) # rubocop:disable Security/Eval
       @@compiled = true
     end
 
diff --git a/lib/onebox/engine/github_actions_onebox.rb b/lib/onebox/engine/github_actions_onebox.rb
index cdb7e16..182fff4 100644
--- a/lib/onebox/engine/github_actions_onebox.rb
+++ b/lib/onebox/engine/github_actions_onebox.rb
@@ -71,7 +71,7 @@ module Onebox
           raw["head_commit"]["message"].lines.first
         elsif type == :pr_run
           pr_url = "https://api.github.com/repos/#{match[:org]}/#{match[:repo]}/pulls/#{match[:pr_id]}"
-          ::MultiJson.load(URI.open(pr_url, read_timeout: timeout))["title"]
+          ::MultiJson.load(URI.parse(pr_url).open(read_timeout: timeout))["title"]
         end
 
         {
diff --git a/lib/onebox/engine/json.rb b/lib/onebox/engine/json.rb
index 261dc03..204b09c 100644
--- a/lib/onebox/engine/json.rb
+++ b/lib/onebox/engine/json.rb
@@ -6,7 +6,7 @@ module Onebox
       private
 
       def raw
-        @raw ||= ::MultiJson.load(URI.open(url, read_timeout: timeout))
+        @raw ||= ::MultiJson.load(URI.parse(url).open(read_timeout: timeout))
       end
     end
   end
diff --git a/lib/onebox/engine/pubmed_onebox.rb b/lib/onebox/engine/pubmed_onebox.rb
index 1cf8a0a..366d5d5 100644
--- a/lib/onebox/engine/pubmed_onebox.rb
+++ b/lib/onebox/engine/pubmed_onebox.rb
@@ -12,7 +12,7 @@ module Onebox
 
       def xml
         return @xml if defined?(@xml)
-        doc = Nokogiri::XML(URI.open(URI.join(@url, "?report=xml&format=text")))
+        doc = Nokogiri::XML(URI.join(@url, "?report=xml&format=text").open)
         pre = doc.xpath("//pre")
         @xml = Nokogiri::XML("<root>" + pre.text + "</root>")
       end
diff --git a/lib/onebox/mixins/git_blob_onebox.rb b/lib/onebox/mixins/git_blob_onebox.rb
index cac7b2a..0c9b2bd 100644
--- a/lib/onebox/mixins/git_blob_onebox.rb
+++ b/lib/onebox/mixins/git_blob_onebox.rb
@@ -167,7 +167,7 @@ module Onebox
               @model_file = @lang.dup
               @raw = "https://render.githubusercontent.com/view/solid?url=" + self.raw_template(m)
             else
-              contents = URI.open(self.raw_template(m), read_timeout: timeout).read
+              contents = URI.parse(self.raw_template(m)).open(read_timeout: timeout).read
 
               contents_lines = contents.lines           #get contents lines
               contents_lines_size = contents_lines.size #get number of lines
diff --git a/lib/onebox/status_check.rb b/lib/onebox/status_check.rb
index 73b3bca..0980b8d 100644
--- a/lib/onebox/status_check.rb
+++ b/lib/onebox/status_check.rb
@@ -35,7 +35,7 @@ module Onebox
     private
 
     def check
-      res = URI.open(@url, read_timeout: (@options.timeout || Onebox.options.timeout))
+      res = URI.parse(@url).open(read_timeout: (@options.timeout || Onebox.options.timeout))

[... diff too long, it was truncated ...]

GitHub sha: 69f0f48dc084c1ac4d5d441094b15cf01790ac98

This commit appears in #14715 which was approved by ZogStriP and SamSaffron. It was merged by udan11.