DEV: Fix various rubocop lints (#24749)

These (21 + 3 from previous PRs) are soon to be enabled in rubocop-discourse:

Capybara/VisibilityMatcher
Lint/DeprecatedOpenSSLConstant
Lint/DisjunctiveAssignmentInConstructor
Lint/EmptyConditionalBody
Lint/EmptyEnsure
Lint/LiteralInInterpolation
Lint/NonLocalExitFromIterator
Lint/ParenthesesAsGroupedExpression
Lint/RedundantCopDisableDirective
Lint/RedundantRequireStatement
Lint/RedundantSafeNavigation
Lint/RedundantStringCoercion
Lint/RedundantWithIndex
Lint/RedundantWithObject
Lint/SafeNavigationChain
Lint/SafeNavigationConsistency
Lint/SelfAssignment
Lint/UnreachableCode
Lint/UselessMethodDefinition
Lint/Void

Previous PRs:
Lint/ShadowedArgument
Lint/DuplicateMethods
Lint/BooleanSymbol
RSpec/SpecFilePathSuffix
This commit is contained in:
Jarek Radosz
2023-12-06 23:25:00 +01:00
committed by GitHub
parent 47f298b2f4
commit 694b5f108b
129 changed files with 196 additions and 274 deletions

View File

@@ -234,7 +234,7 @@ class Admin::SiteTextsController < Admin::AdminController
translations.each do |key, value|
next unless I18n.exists?(key, :en)
if value&.is_a?(Hash)
if value.is_a?(Hash)
fix_plural_keys(key, value, locale).each do |plural|
plural_key = plural[0]
plural_value = plural[1]

View File

@@ -463,7 +463,7 @@ class ApplicationController < ActionController::Base
return unless guardian.can_enable_safe_mode?
safe_mode = params[SAFE_MODE]
if safe_mode&.is_a?(String)
if safe_mode.is_a?(String)
safe_mode = safe_mode.split(",")
request.env[NO_THEMES] = safe_mode.include?(NO_THEMES) || safe_mode.include?(LEGACY_NO_THEMES)
request.env[NO_PLUGINS] = safe_mode.include?(NO_PLUGINS)

View File

@@ -92,7 +92,7 @@ class ListController < ApplicationController
# Note the first is the default and we don't add a title
if (filter.to_s != current_homepage) && use_crawler_layout?
filter_title = I18n.t("js.filters.#{filter.to_s}.title", count: 0)
filter_title = I18n.t("js.filters.#{filter}.title", count: 0)
if list_opts[:category] && @category
@title =

View File

@@ -121,7 +121,7 @@ class TopicsController < ApplicationController
deleted =
guardian.can_see_topic?(ex.obj, false) ||
(!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj.deleted_at)
(!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj&.deleted_at)
if SiteSetting.detailed_404
if deleted
@@ -975,7 +975,7 @@ class TopicsController < ApplicationController
rescue Discourse::InvalidAccess => ex
deleted =
guardian.can_see_topic?(ex.obj, false) ||
(!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj.deleted_at)
(!guardian.can_see_topic?(ex.obj) && ex.obj&.access_topic_via_group && ex.obj&.deleted_at)
raise Discourse::NotFound.new(
nil,

View File

@@ -225,7 +225,7 @@ class UsersController < ApplicationController
end
end
if params[:external_ids]&.is_a?(ActionController::Parameters) && current_user&.admin? && is_api?
if params[:external_ids].is_a?(ActionController::Parameters) && current_user&.admin? && is_api?
attributes[:user_associated_accounts] = []
params[:external_ids].each do |provider_name, provider_uid|
@@ -716,7 +716,7 @@ class UsersController < ApplicationController
# Handle associated accounts
associations = []
if params[:external_ids]&.is_a?(ActionController::Parameters) && current_user&.admin? && is_api?
if params[:external_ids].is_a?(ActionController::Parameters) && current_user&.admin? && is_api?
params[:external_ids].each do |provider_name, provider_uid|
authenticator = Discourse.enabled_authenticators.find { |a| a.name == provider_name }
raise Discourse::InvalidParameters.new(:external_ids) if !authenticator&.is_managed?

View File

@@ -192,10 +192,10 @@ class UsersEmailController < ApplicationController
if token
if type == :old
@change_request =
token.user&.email_change_requests.where(old_email_token_id: token.id).first
token.user&.email_change_requests&.where(old_email_token_id: token.id)&.first
elsif type == :new
@change_request =
token.user&.email_change_requests.where(new_email_token_id: token.id).first
token.user&.email_change_requests&.where(new_email_token_id: token.id)&.first
end
end