From 29cbbd6b3108e74b60288ff8bc7f09a8c087a2ac Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 27 Mar 2025 13:50:24 +0100 Subject: [PATCH] DEV: Fix `Lint/ShadowingOuterLocalVariable` (#32036) unblocks a rubocop update --- app/models/concerns/category_hashtag.rb | 4 +--- lib/middleware/discourse_public_exceptions.rb | 2 +- lib/svg_sprite.rb | 11 +++++++---- lib/tasks/plugin.rake | 4 +--- lib/topics_filter.rb | 3 +-- .../automation/lib/discourse_automation/scriptable.rb | 6 +++--- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/models/concerns/category_hashtag.rb b/app/models/concerns/category_hashtag.rb index d8044399a8e..c17bbe6ee29 100644 --- a/app/models/concerns/category_hashtag.rb +++ b/app/models/concerns/category_hashtag.rb @@ -18,9 +18,7 @@ module CategoryHashtag slug_path = split_slug_path(slug) next if slug_path.blank? - if SiteSetting.slug_generation_method == "encoded" - slug_path.map! { |slug| CGI.escape(slug) } - end + slug_path.map! { CGI.escape(_1) } if SiteSetting.slug_generation_method == "encoded" parent_slug, child_slug = slug_path.last(2) # Category slugs can be in the parent:child format, if there diff --git a/lib/middleware/discourse_public_exceptions.rb b/lib/middleware/discourse_public_exceptions.rb index dd82b0afd58..8f117f8b684 100644 --- a/lib/middleware/discourse_public_exceptions.rb +++ b/lib/middleware/discourse_public_exceptions.rb @@ -68,7 +68,7 @@ module Middleware body = response.body body = [body] if String === body rack_response = [response.status, response.headers, body] - app = lambda { |env| rack_response } + app = lambda { |_| rack_response } EXCEPTION_RESPONSE_MIDDLEWARES.each { |middleware| app = middleware.new(app) } return app.call(env) end diff --git a/lib/svg_sprite.rb b/lib/svg_sprite.rb index 4cfc9597331..4d0041189fb 100644 --- a/lib/svg_sprite.rb +++ b/lib/svg_sprite.rb @@ -324,7 +324,7 @@ module SvgSprite cache .defer_get_set_bulk( Theme.transform_ids(theme_id), - lambda { |theme_id| "theme_svg_sprites_#{theme_id}" }, + lambda { |_theme_id| "theme_svg_sprites_#{_theme_id}" }, ) do |theme_ids| theme_field_uploads = ThemeField.where( @@ -344,12 +344,15 @@ module SvgSprite end theme_sprites - .map do |(theme_id, upload_id, sprite)| + .map do |(_theme_id, upload_id, sprite)| begin - [theme_id, symbols_for("theme_#{theme_id}_#{upload_id}.svg", sprite, strict: false)] + [ + _theme_id, + symbols_for("theme_#{_theme_id}_#{upload_id}.svg", sprite, strict: false), + ] rescue => e Rails.logger.warn( - "Bad XML in custom sprite in theme with ID=#{theme_id}. Error info: #{e.inspect}", + "Bad XML in custom sprite in theme with ID=#{_theme_id}. Error info: #{e.inspect}", ) end end diff --git a/lib/tasks/plugin.rake b/lib/tasks/plugin.rake index e580c37fa06..dc92bcf4f3e 100644 --- a/lib/tasks/plugin.rake +++ b/lib/tasks/plugin.rake @@ -325,7 +325,6 @@ task "plugin:create", [:name] do |t, args| abort("Plugin directory, " + plugin_path + ", already exists.") if File.directory?(plugin_path) - failures = [] repo = "https://github.com/discourse/discourse-plugin-skeleton" begin attempts ||= 1 @@ -333,7 +332,7 @@ task "plugin:create", [:name] do |t, args| system("git clone --quiet #{repo} #{plugin_path}", exception: true) rescue StandardError if attempts == 3 - failures << repo + STDOUT.puts "Failed to clone #{repo}" abort end @@ -341,7 +340,6 @@ task "plugin:create", [:name] do |t, args| attempts += 1 retry end - failures.each { |repo| STDOUT.puts "Failed to clone #{repo}" } if failures.present? Dir.chdir(plugin_path) do # rubocop:disable Discourse/NoChdir puts "Initializing git repository..." diff --git a/lib/topics_filter.rb b/lib/topics_filter.rb index fc0eb179614..f5b280cdc8b 100644 --- a/lib/topics_filter.rb +++ b/lib/topics_filter.rb @@ -83,8 +83,7 @@ class TopicsFilter when "views-max" filter_by_number_of_views(max: filter_values) else - if custom_filter = - DiscoursePluginRegistry.custom_filter_mappings.find { |hash| hash.key?(filter) } + if custom_filter = DiscoursePluginRegistry.custom_filter_mappings.find { _1.key?(filter) } @scope = custom_filter[filter].call(@scope, filter_values, @guardian) || @scope end end diff --git a/plugins/automation/lib/discourse_automation/scriptable.rb b/plugins/automation/lib/discourse_automation/scriptable.rb index 9aaf4cf2701..cf34202f312 100644 --- a/plugins/automation/lib/discourse_automation/scriptable.rb +++ b/plugins/automation/lib/discourse_automation/scriptable.rb @@ -73,14 +73,14 @@ module DiscourseAutomation end end - def placeholder(name = nil, triggerable: nil, &block) + def placeholder(placeholder_name = nil, triggerable: nil, &block) if block_given? result = yield(@automation.serialized_fields, @automation) Array(result).each do |name| @placeholders << { name: name.to_sym, triggerable: triggerable&.to_sym } end - elsif name - @placeholders << { name: name.to_sym, triggerable: triggerable&.to_sym } + elsif placeholder_name + @placeholders << { name: placeholder_name.to_sym, triggerable: triggerable&.to_sym } end end