DEV: Update to lastest rubocop-discourse

This commit is contained in:
Loïc Guitaut
2024-05-27 12:27:13 +02:00
committed by Loïc Guitaut
parent 3b6d4c830f
commit 2a28cda15c
164 changed files with 269 additions and 263 deletions

View File

@@ -1,24 +1,24 @@
# frozen_string_literal: true
class ApplicationRequest < ActiveRecord::Base
enum req_type: %i[
http_total
http_2xx
http_background
http_3xx
http_4xx
http_5xx
page_view_crawler
page_view_logged_in
page_view_anon
page_view_logged_in_mobile
page_view_anon_mobile
api
user_api
page_view_anon_browser
page_view_anon_browser_mobile
page_view_logged_in_browser
page_view_logged_in_browser_mobile
]
enum req_type: {
http_total: 0,
http_2xx: 1,
http_background: 2,
http_3xx: 3,
http_4xx: 4,
http_5xx: 5,
page_view_crawler: 6,
page_view_logged_in: 7,
page_view_anon: 8,
page_view_logged_in_mobile: 9,
page_view_anon_mobile: 10,
api: 11,
user_api: 12,
page_view_anon_browser: 13,
page_view_anon_browser_mobile: 14,
page_view_logged_in_browser: 15,
page_view_logged_in_browser_mobile: 16,
}
include CachedCounting

View File

@@ -542,7 +542,7 @@ class Category < ActiveRecord::Base
end
def ensure_slug
return unless name.present?
return if name.blank?
self.name.strip!
@@ -948,7 +948,7 @@ class Category < ActiveRecord::Base
# If the name changes, try and update the category definition topic too if it's an exact match
def rename_category_definition
return unless topic.present?
return if topic.blank?
old_name = saved_changes.transform_values(&:first)["name"]
if topic.title == I18n.t("category.topic_prefix", category: old_name)
topic.update_attribute(:title, I18n.t("category.topic_prefix", category: name))

View File

@@ -49,7 +49,7 @@ class DirectoryColumn < ActiveRecord::Base
column.enabled = false
end
unless @@plugin_directory_columns.include?(directory_column.name)
if @@plugin_directory_columns.exclude?(directory_column.name)
@@plugin_directory_columns << directory_column.name
DirectoryItem.add_plugin_query(attrs[:query])
end

View File

@@ -24,10 +24,10 @@ class EmbeddableHost < ActiveRecord::Base
end
end
return false unless uri.present?
return false if uri.blank?
host = uri.host
return false unless host.present?
return false if host.blank?
host << ":#{uri.port}" if uri.port.present? && uri.port != 80 && uri.port != 443

View File

@@ -857,7 +857,7 @@ class Group < ActiveRecord::Base
end
def bulk_add(user_ids)
return unless user_ids.present?
return if user_ids.blank?
Group.transaction do
sql = <<~SQL

View File

@@ -33,13 +33,13 @@ class GroupHistory < ActiveRecord::Base
if !params.blank?
params = params.slice(*filters)
records = records.where(action: self.actions[params[:action].to_sym]) unless params[
records = records.where(action: self.actions[params[:action].to_sym]) if params[
:action
].blank?
records = records.where(subject: params[:subject]) unless params[:subject].blank?
].present?
records = records.where(subject: params[:subject]) if params[:subject].present?
%i[acting_user target_user].each do |filter|
unless params[filter].blank?
if params[filter].present?
id = User.where(username_lower: params[filter]).pluck(:id)
records = records.where("#{filter}_id" => id)
end

View File

@@ -3,7 +3,7 @@
class IncomingDomain < ActiveRecord::Base
def self.add!(uri)
name = uri.host
return unless name.present?
return if name.blank?
https = uri.scheme == "https"
port = uri.port

View File

@@ -60,7 +60,7 @@ class IncomingLink < ActiveRecord::Base
self.incoming_referer_id = nil
# will set incoming_referer_id
return unless referer.present?
return if referer.blank?
parsed = URI.parse(referer)

View File

@@ -129,7 +129,7 @@ class InviteRedeemer
field_val = field_params[f.id.to_s]
fields["#{User::USER_FIELD_PREFIX}#{f.id}"] = field_val[
0...UserField.max_length
] unless field_val.blank?
] if field_val.present?
end
user.custom_fields = fields
end

View File

@@ -1326,14 +1326,14 @@ class Post < ActiveRecord::Base
private
def parse_quote_into_arguments(quote)
return {} unless quote.present?
return {} if quote.blank?
args = HashWithIndifferentAccess.new
quote.first.scan(/([a-z]+)\:(\d+)/).each { |arg| args[arg[0]] = arg[1].to_i }
args
end
def add_to_quoted_post_numbers(num)
return unless num.present?
return if num.blank?
self.quoted_post_numbers ||= []
self.quoted_post_numbers << num
end

View File

@@ -13,7 +13,7 @@ class PostAnalyzer
end
def has_oneboxes?
return false unless @raw.present?
return false if @raw.blank?
cooked_stripped
found_oneboxes?
@@ -56,7 +56,7 @@ class PostAnalyzer
# How many images are present in the post
def embedded_media_count
return 0 unless @raw.present?
return 0 if @raw.blank?
# TODO - do we need to look for tags other than img, video and audio?
cooked_stripped
@@ -71,7 +71,7 @@ class PostAnalyzer
# How many attachments are present in the post
def attachment_count
return 0 unless @raw.present?
return 0 if @raw.blank?
attachments =
cooked_stripped.css("a.attachment[href^=\"#{Discourse.store.absolute_base_url}\"]")
@@ -119,7 +119,7 @@ class PostAnalyzer
# Returns an array of all links in a post excluding mentions
def raw_links
return [] unless @raw.present?
return [] if @raw.blank?
return @raw_links if @raw_links.present?
@raw_links = []

View File

@@ -676,7 +676,7 @@ class PostMover
end
def add_allowed_users(usernames)
return unless usernames.present?
return if usernames.blank?
names = usernames.split(",").flatten
User

View File

@@ -207,7 +207,7 @@ SQL
new_posts_read = timings.size - existing.size if is_regular
timings.each_with_index do |(post_number, time), index|
unless existing.include?(index)
if existing.exclude?(index)
PostTiming.record_new_timing(
topic_id: topic_id,
post_number: post_number,

View File

@@ -62,7 +62,7 @@ class Reviewable < ActiveRecord::Base
end
def self.valid_type?(type)
return false unless Reviewable.types.include?(type)
return false if Reviewable.types.exclude?(type)
type.constantize <= Reviewable
rescue NameError
false
@@ -383,7 +383,7 @@ class Reviewable < ActiveRecord::Base
end
def self.viewable_by(user, order: nil, preload: true)
return none unless user.present?
return none if user.blank?
result = self.order(order || "reviewables.score desc, reviewables.created_at desc")
@@ -732,7 +732,7 @@ class Reviewable < ActiveRecord::Base
private
def update_flag_stats(status:, user_ids:)
return unless %i[agreed disagreed ignored].include?(status)
return if %i[agreed disagreed ignored].exclude?(status)
# Don't count self-flags
user_ids -= [post&.user_id]

View File

@@ -29,7 +29,7 @@ class ScreenedIpAddress < ActiveRecord::Base
end
def check_for_match
unless self.errors[:ip_address].present?
if self.errors[:ip_address].blank?
matched = self.class.match_for_ip_address(self.ip_address)
if matched && matched.action_type == self.action_type
self.errors.add(:ip_address, :ip_address_already_screened)

View File

@@ -36,7 +36,7 @@ class SearchLog < ActiveRecord::Base
return [:error] if term.blank?
search_type = search_types[search_type]
return [:error] unless search_type.present? && ip_address.present?
return [:error] if search_type.blank? || ip_address.blank?
ip_address = nil if user_id
key = redis_key(user_id: user_id, ip_address: ip_address)

View File

@@ -233,10 +233,10 @@ class Tag < ActiveRecord::Base
def update_synonym_associations
if target_tag_id && saved_change_to_target_tag_id?
target_tag.tag_groups.each do |tag_group|
tag_group.tags << self unless tag_group.tags.include?(self)
tag_group.tags << self if tag_group.tags.exclude?(self)
end
target_tag.categories.each do |category|
category.tags << self unless category.tags.include?(self)
category.tags << self if category.tags.exclude?(self)
end
end
end

View File

@@ -23,7 +23,7 @@ class ThemeField < ActiveRecord::Base
scope :find_by_theme_ids,
->(theme_ids) do
return none unless theme_ids.present?
return none if theme_ids.blank?
where(theme_id: theme_ids).joins(
"JOIN (
@@ -34,7 +34,7 @@ class ThemeField < ActiveRecord::Base
scope :filter_locale_fields,
->(locale_codes) do
return none unless locale_codes.present?
return none if locale_codes.blank?
where(target_id: Theme.targets[:translations], name: locale_codes).joins(
DB.sql_fragment(
@@ -420,7 +420,7 @@ class ThemeField < ActiveRecord::Base
if basic_html_field? || translation_field?
self.value_baked, self.error =
translation_field? ? process_translation : process_html(self.value)
self.error = nil unless self.error.present?
self.error = nil if self.error.blank?
self.compiler_version = Theme.compiler_version
CSP::Extension.clear_theme_extensions_cache!
elsif extra_js_field? || js_tests_field?

View File

@@ -1372,7 +1372,7 @@ class Topic < ActiveRecord::Base
self.slug_computed_callbacks = []
def slug_for_topic(title)
return "" unless title.present?
return "" if title.blank?
slug = Slug.for(title)
# this is a hook for plugins that need to modify the generated slug
@@ -1384,7 +1384,7 @@ class Topic < ActiveRecord::Base
# Even if the slug column in the database is null, topic.slug will return something:
def slug
unless slug = read_attribute(:slug)
return "" unless title.present?
return "" if title.blank?
slug = slug_for_topic(title)
if new_record?
write_attribute(:slug, slug)
@@ -1445,12 +1445,12 @@ class Topic < ActiveRecord::Base
end
def clear_pin_for(user)
return unless user.present?
return if user.blank?
TopicUser.change(user.id, id, cleared_pinned_at: Time.now)
end
def re_pin_for(user)
return unless user.present?
return if user.blank?
TopicUser.change(user.id, id, cleared_pinned_at: nil)
end
@@ -2062,7 +2062,7 @@ class Topic < ActiveRecord::Base
def self.publish_stats_to_clients!(topic_id, type, opts = {})
topic = Topic.find_by(id: topic_id)
return unless topic.present?
return if topic.blank?
case type
when :liked, :unliked

View File

@@ -315,7 +315,7 @@ class TopicEmbed < ActiveRecord::Base
return result if result.size >= 100
end
end
return result unless result.blank?
return result if result.present?
# If there is no first paragraph, return the first div (onebox)
doc.css("div").first.to_s

View File

@@ -86,7 +86,7 @@ class TopicLinkClick < ActiveRecord::Base
).first
# If no link is found...
unless link.present?
if link.blank?
# ... return the url for relative links or when using the same host
return url if url =~ %r{\A/[^/]} || uri.try(:host) == Discourse.current_hostname

View File

@@ -45,7 +45,7 @@ class TranslationOverride < ActiveRecord::Base
validate :check_interpolation_keys
enum :status, %i[up_to_date outdated invalid_interpolation_keys deprecated]
enum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 }
def self.upsert!(locale, key, value)
params = { locale: locale, translation_key: key }

View File

@@ -898,7 +898,7 @@ class User < ActiveRecord::Base
def password=(password)
# special case for passwordless accounts
@raw_password = password unless password.blank?
@raw_password = password if password.present?
end
def password

View File

@@ -203,7 +203,7 @@ class UserProfile < ActiveRecord::Base
URI.parse(self.website).host
rescue URI::Error
end
unless allowed_domains.split("|").include?(domain)
if allowed_domains.split("|").exclude?(domain)
self.errors.add :base,
(
I18n.t(