DEV: lint against Layout/EmptyLineBetweenDefs (#24914)

This commit is contained in:
Kelv 2023-12-15 23:46:04 +08:00 committed by GitHub
parent 15fc2a289a
commit 2477bcc32e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 124 additions and 0 deletions

View File

@ -14,8 +14,10 @@ class Admin::DashboardController < Admin::StaffController
def moderation def moderation
end end
def security def security
end end
def reports def reports
end end

View File

@ -123,6 +123,7 @@ class ApplicationController < ActionController::Base
class RenderEmpty < StandardError class RenderEmpty < StandardError
end end
class PluginDisabled < StandardError class PluginDisabled < StandardError
end end

View File

@ -112,8 +112,10 @@ module Jobs
class ImageTooLargeError < StandardError class ImageTooLargeError < StandardError
end end
class ImageBrokenError < StandardError class ImageBrokenError < StandardError
end end
class UploadCreateError < StandardError class UploadCreateError < StandardError
end end

View File

@ -206,6 +206,7 @@ module HasCustomFields
class NotPreloadedError < StandardError class NotPreloadedError < StandardError
end end
class PreloadedProxy class PreloadedProxy
def initialize(preloaded, klass_with_custom_fields) def initialize(preloaded, klass_with_custom_fields)
@preloaded = preloaded @preloaded = preloaded

View File

@ -3,6 +3,7 @@
class DiscourseConnect < DiscourseConnectBase class DiscourseConnect < DiscourseConnectBase
class BlankExternalId < StandardError class BlankExternalId < StandardError
end end
class BannedExternalId < StandardError class BannedExternalId < StandardError
end end

View File

@ -3,8 +3,10 @@
class Invite < ActiveRecord::Base class Invite < ActiveRecord::Base
class UserExists < StandardError class UserExists < StandardError
end end
class RedemptionFailed < StandardError class RedemptionFailed < StandardError
end end
class ValidationFailed < StandardError class ValidationFailed < StandardError
end end

View File

@ -250,6 +250,7 @@ class Tag < ActiveRecord::Base
def sanitize_description def sanitize_description
self.description = sanitize_field(self.description) if description_changed? self.description = sanitize_field(self.description) if description_changed?
end end
def name_validator def name_validator
errors.add(:name, :invalid) if name.present? && RESERVED_TAGS.include?(self.name.strip.downcase) errors.add(:name, :invalid) if name.present? && RESERVED_TAGS.include?(self.name.strip.downcase)
end end

View File

@ -3,6 +3,7 @@
class Topic < ActiveRecord::Base class Topic < ActiveRecord::Base
class UserExists < StandardError class UserExists < StandardError
end end
class NotAllowed < StandardError class NotAllowed < StandardError
end end
include RateLimiter::OnCreateRecord include RateLimiter::OnCreateRecord

View File

@ -9,6 +9,7 @@ class ApplicationSerializer < ActiveModel::Serializer
def initialize(json) def initialize(json)
@json = json @json = json
end end
def as_json(*_args) def as_json(*_args)
@json @json
end end

View File

@ -9,10 +9,13 @@ class ExternalUploadManager
class ChecksumMismatchError < StandardError class ChecksumMismatchError < StandardError
end end
class DownloadFailedError < StandardError class DownloadFailedError < StandardError
end end
class CannotPromoteError < StandardError class CannotPromoteError < StandardError
end end
class SizeMismatchError < StandardError class SizeMismatchError < StandardError
end end

View File

@ -7,6 +7,7 @@ class AddUsernameLowerToUsers < ActiveRecord::Migration[4.2]
add_index :users, [:username_lower], unique: true add_index :users, [:username_lower], unique: true
change_column :users, :username_lower, :string, limit: 20, null: false change_column :users, :username_lower, :string, limit: 20, null: false
end end
def down def down
remove_column :users, :username_lower remove_column :users, :username_lower
end end

View File

@ -16,6 +16,7 @@ class CreatePostActions < ActiveRecord::Migration[4.2]
execute "create unique index idx_unique_actions on execute "create unique index idx_unique_actions on
post_actions(user_id, post_action_type_id, post_id) where deleted_at is null" post_actions(user_id, post_action_type_id, post_id) where deleted_at is null"
end end
def down def down
drop_table :post_actions drop_table :post_actions
end end

View File

@ -4,6 +4,7 @@ class AddTrackingToTopicUsers < ActiveRecord::Migration[4.2]
def up def up
execute "update topic_users set notification_level = 3 where notification_level = 2" execute "update topic_users set notification_level = 3 where notification_level = 2"
end end
def down def down
execute "update topic_users set notification_level = 2 where notification_level = 3" execute "update topic_users set notification_level = 2 where notification_level = 3"
end end

View File

@ -4,6 +4,7 @@ class AddIpAddressToUsers < ActiveRecord::Migration[4.2]
def up def up
execute "alter table users add column ip_address inet" execute "alter table users add column ip_address inet"
end end
def down def down
execute "alter table users drop column ip_address" execute "alter table users drop column ip_address"
end end

View File

@ -6,6 +6,7 @@ class AddCustomEmailInToCategories < ActiveRecord::Migration[4.2]
add_column :categories, :email_in_allow_strangers, :boolean, default: false add_column :categories, :email_in_allow_strangers, :boolean, default: false
add_index :categories, :email_in, unique: true add_index :categories, :email_in, unique: true
end end
def down def down
remove_column :categories, :email_in remove_column :categories, :email_in
remove_column :categories, :email_in_allow_strangers remove_column :categories, :email_in_allow_strangers

View File

@ -5,6 +5,7 @@ class PrivateMessagesHaveNoCategoryId < ActiveRecord::Migration[4.2]
execute "UPDATE topics SET category_id = NULL WHERE category_id IS NOT NULL AND archetype = \'private_message\'" execute "UPDATE topics SET category_id = NULL WHERE category_id IS NOT NULL AND archetype = \'private_message\'"
execute "ALTER TABLE topics ADD CONSTRAINT pm_has_no_category CHECK (category_id IS NULL OR archetype <> 'private_message')" execute "ALTER TABLE topics ADD CONSTRAINT pm_has_no_category CHECK (category_id IS NULL OR archetype <> 'private_message')"
end end
def down def down
raise ActiveRecord::IrreversibleMigration raise ActiveRecord::IrreversibleMigration
end end

View File

@ -5,6 +5,7 @@ class FlushApplicationRequests < ActiveRecord::Migration[4.2]
# flush as enum changed # flush as enum changed
execute "TRUNCATE TABLE application_requests" execute "TRUNCATE TABLE application_requests"
end end
def down def down
end end
end end

View File

@ -4,6 +4,7 @@ class EnlargeUsersEmailField < ActiveRecord::Migration[4.2]
def up def up
change_column :users, :email, :string, limit: 513 change_column :users, :email, :string, limit: 513
end end
def down def down
change_column :users, :email, :string, limit: 128 change_column :users, :email, :string, limit: 128
end end

View File

@ -8,6 +8,7 @@ class ShortenTopicCustomFieldsIndex < ActiveRecord::Migration[4.2]
name: "topic_custom_fields_value_key_idx", name: "topic_custom_fields_value_key_idx",
where: "value IS NOT NULL AND char_length(value) < 400" where: "value IS NOT NULL AND char_length(value) < 400"
end end
def down def down
remove_index :topic_custom_fields, :value, name: "topic_custom_fields_value_key_idx" remove_index :topic_custom_fields, :value, name: "topic_custom_fields_value_key_idx"
add_index :topic_custom_fields, :value add_index :topic_custom_fields, :value

View File

@ -4,6 +4,7 @@ class AddSkippedCreatedAtUserIdIndexOnEmailLogs < ActiveRecord::Migration[5.1]
def up def up
execute "CREATE INDEX idx_email_logs_user_created_filtered ON email_logs(user_id, created_at) WHERE skipped = 'f'" execute "CREATE INDEX idx_email_logs_user_created_filtered ON email_logs(user_id, created_at) WHERE skipped = 'f'"
end end
def down def down
execute "DROP INDEX idx_email_logs_user_created_filtered" execute "DROP INDEX idx_email_logs_user_created_filtered"
end end

View File

@ -7,6 +7,7 @@ class AddSuppressFromLatestToCategories < ActiveRecord::Migration[5.1]
UPDATE categories SET suppress_from_latest = suppress_from_homepage UPDATE categories SET suppress_from_latest = suppress_from_homepage
SQL SQL
end end
def down def down
raise "can not be removed" raise "can not be removed"
end end

View File

@ -13,6 +13,7 @@ class AddIndexToTags < ActiveRecord::Migration[5.2]
add_index :tags, "lower(name)", unique: true add_index :tags, "lower(name)", unique: true
end end
def down def down
raise ActiveRecord::IrreversibleMigration raise ActiveRecord::IrreversibleMigration
end end

View File

@ -14,6 +14,7 @@ class AddThemeIdToJavascriptCache < ActiveRecord::Migration[5.2]
make_changes make_changes
execute "ALTER TABLE javascript_caches ADD CONSTRAINT enforce_theme_or_theme_field CHECK ((theme_id IS NOT NULL AND theme_field_id IS NULL) OR (theme_id IS NULL AND theme_field_id IS NOT NULL))" execute "ALTER TABLE javascript_caches ADD CONSTRAINT enforce_theme_or_theme_field CHECK ((theme_id IS NOT NULL AND theme_field_id IS NULL) OR (theme_id IS NULL AND theme_field_id IS NOT NULL))"
end end
def down def down
execute "ALTER TABLE javascript_caches DROP CONSTRAINT enforce_theme_or_theme_field" execute "ALTER TABLE javascript_caches DROP CONSTRAINT enforce_theme_or_theme_field"
revert { make_changes } revert { make_changes }

View File

@ -7,6 +7,7 @@ class RemoveCanonicalEmailFromUserEmails < ActiveRecord::Migration[6.0]
DROP COLUMN IF EXISTS canonical_email DROP COLUMN IF EXISTS canonical_email
SQL SQL
end end
def down def down
# nothing to do, we already nuke the migrations # nothing to do, we already nuke the migrations
end end

View File

@ -2,6 +2,7 @@
module Auth module Auth
end end
class Auth::CurrentUserProvider class Auth::CurrentUserProvider
# do all current user initialization here # do all current user initialization here
def initialize(env) def initialize(env)

View File

@ -6,6 +6,7 @@ module Autospec
def self.watch(pattern, &blk) def self.watch(pattern, &blk)
WATCHERS[pattern] = blk WATCHERS[pattern] = blk
end end
def watchers def watchers
WATCHERS WATCHERS
end end
@ -41,6 +42,7 @@ module Autospec
def self.reload(pattern) def self.reload(pattern)
RELOADERS << pattern RELOADERS << pattern
end end
def reloaders def reloaders
RELOADERS RELOADERS
end end

View File

@ -5,10 +5,13 @@ require "rbconfig"
class ChromeInstalledChecker class ChromeInstalledChecker
class ChromeError < StandardError class ChromeError < StandardError
end end
class ChromeVersionError < ChromeError class ChromeVersionError < ChromeError
end end
class ChromeNotInstalled < ChromeError class ChromeNotInstalled < ChromeError
end end
class ChromeVersionTooLow < ChromeError class ChromeVersionTooLow < ChromeError
end end

View File

@ -3,8 +3,10 @@
class DiscourseConnectProvider < DiscourseConnectBase class DiscourseConnectProvider < DiscourseConnectBase
class BlankSecret < RuntimeError class BlankSecret < RuntimeError
end end
class BlankReturnUrl < RuntimeError class BlankReturnUrl < RuntimeError
end end
class InvalidParameterValueError < RuntimeError class InvalidParameterValueError < RuntimeError
attr_reader :param attr_reader :param
def initialize(param) def initialize(param)

View File

@ -14,32 +14,46 @@ module DiscourseWebauthn
class InvalidOriginError < SecurityKeyError class InvalidOriginError < SecurityKeyError
end end
class InvalidRelyingPartyIdError < SecurityKeyError class InvalidRelyingPartyIdError < SecurityKeyError
end end
class UserVerificationError < SecurityKeyError class UserVerificationError < SecurityKeyError
end end
class UserPresenceError < SecurityKeyError class UserPresenceError < SecurityKeyError
end end
class ChallengeMismatchError < SecurityKeyError class ChallengeMismatchError < SecurityKeyError
end end
class InvalidTypeError < SecurityKeyError class InvalidTypeError < SecurityKeyError
end end
class UnsupportedPublicKeyAlgorithmError < SecurityKeyError class UnsupportedPublicKeyAlgorithmError < SecurityKeyError
end end
class UnsupportedAttestationFormatError < SecurityKeyError class UnsupportedAttestationFormatError < SecurityKeyError
end end
class CredentialIdInUseError < SecurityKeyError class CredentialIdInUseError < SecurityKeyError
end end
class MalformedAttestationError < SecurityKeyError class MalformedAttestationError < SecurityKeyError
end end
class KeyNotFoundError < SecurityKeyError class KeyNotFoundError < SecurityKeyError
end end
class MalformedPublicKeyCredentialError < SecurityKeyError class MalformedPublicKeyCredentialError < SecurityKeyError
end end
class OwnershipError < SecurityKeyError class OwnershipError < SecurityKeyError
end end
class PublicKeyError < SecurityKeyError class PublicKeyError < SecurityKeyError
end end
class UnknownCOSEAlgorithmError < SecurityKeyError class UnknownCOSEAlgorithmError < SecurityKeyError
end end

View File

@ -9,52 +9,76 @@ module Email
# * add text to server.en.yml (parent key: "emails.incoming.errors") # * add text to server.en.yml (parent key: "emails.incoming.errors")
class ProcessingError < StandardError class ProcessingError < StandardError
end end
class EmptyEmailError < ProcessingError class EmptyEmailError < ProcessingError
end end
class ScreenedEmailError < ProcessingError class ScreenedEmailError < ProcessingError
end end
class UserNotFoundError < ProcessingError class UserNotFoundError < ProcessingError
end end
class AutoGeneratedEmailError < ProcessingError class AutoGeneratedEmailError < ProcessingError
end end
class BouncedEmailError < ProcessingError class BouncedEmailError < ProcessingError
end end
class NoBodyDetectedError < ProcessingError class NoBodyDetectedError < ProcessingError
end end
class NoSenderDetectedError < ProcessingError class NoSenderDetectedError < ProcessingError
end end
class FromReplyByAddressError < ProcessingError class FromReplyByAddressError < ProcessingError
end end
class InactiveUserError < ProcessingError class InactiveUserError < ProcessingError
end end
class SilencedUserError < ProcessingError class SilencedUserError < ProcessingError
end end
class BadDestinationAddress < ProcessingError class BadDestinationAddress < ProcessingError
end end
class StrangersNotAllowedError < ProcessingError class StrangersNotAllowedError < ProcessingError
end end
class ReplyNotAllowedError < ProcessingError class ReplyNotAllowedError < ProcessingError
end end
class InsufficientTrustLevelError < ProcessingError class InsufficientTrustLevelError < ProcessingError
end end
class ReplyUserNotMatchingError < ProcessingError class ReplyUserNotMatchingError < ProcessingError
end end
class TopicNotFoundError < ProcessingError class TopicNotFoundError < ProcessingError
end end
class TopicClosedError < ProcessingError class TopicClosedError < ProcessingError
end end
class InvalidPost < ProcessingError class InvalidPost < ProcessingError
end end
class TooShortPost < ProcessingError class TooShortPost < ProcessingError
end end
class InvalidPostAction < ProcessingError class InvalidPostAction < ProcessingError
end end
class UnsubscribeNotAllowed < ProcessingError class UnsubscribeNotAllowed < ProcessingError
end end
class EmailNotAllowed < ProcessingError class EmailNotAllowed < ProcessingError
end end
class OldDestinationError < ProcessingError class OldDestinationError < ProcessingError
end end
class ReplyToDigestError < ProcessingError class ReplyToDigestError < ProcessingError
end end

View File

@ -10,6 +10,7 @@ require "url_helper"
class FinalDestination class FinalDestination
class SSRFError < SocketError class SSRFError < SocketError
end end
class UrlEncodingError < ArgumentError class UrlEncodingError < ArgumentError
end end

View File

@ -4,6 +4,7 @@ class FinalDestination
module SSRFDetector module SSRFDetector
class DisallowedIpError < SSRFError class DisallowedIpError < SSRFError
end end
class LookupFailedError < SSRFError class LookupFailedError < SSRFError
end end

View File

@ -28,51 +28,67 @@ class Guardian
def blank? def blank?
true true
end end
def admin? def admin?
false false
end end
def staff? def staff?
false false
end end
def moderator? def moderator?
false false
end end
def anonymous? def anonymous?
true true
end end
def approved? def approved?
false false
end end
def staged? def staged?
false false
end end
def silenced? def silenced?
false false
end end
def is_system_user? def is_system_user?
false false
end end
def bot? def bot?
false false
end end
def secure_category_ids def secure_category_ids
[] []
end end
def groups def groups
[] []
end end
def has_trust_level?(level) def has_trust_level?(level)
false false
end end
def has_trust_level_or_staff?(level) def has_trust_level_or_staff?(level)
false false
end end
def email def email
nil nil
end end
def whisperer? def whisperer?
false false
end end
def in_any_groups?(group_ids) def in_any_groups?(group_ids)
false false
end end

View File

@ -6,6 +6,7 @@
require "htmlentities" require "htmlentities"
module Import module Import
end end
module Import::Normalize module Import::Normalize
def self.normalize_code_blocks(code, lang = nil) def self.normalize_code_blocks(code, lang = nil)
coder = HTMLEntities.new coder = HTMLEntities.new

View File

@ -56,6 +56,7 @@ class Migration::SafeMigrate
def e.cause def e.cause
nil nil
end end
def e.backtrace def e.backtrace
super.reject do |frame| super.reject do |frame|
frame =~ /safe_migrate\.rb/ || frame =~ /schema_migration_details\.rb/ frame =~ /safe_migrate\.rb/ || frame =~ /schema_migration_details\.rb/

View File

@ -39,8 +39,10 @@ class MiniSqlMultisiteConnection < MiniSql::ActiveRecordPostgres::Connection
def before_committed!(*) def before_committed!(*)
end end
def rolledback!(*) def rolledback!(*)
end end
def trigger_transactional_callbacks? def trigger_transactional_callbacks?
true true
end end

View File

@ -5,10 +5,13 @@
class PresenceChannel class PresenceChannel
class NotFound < StandardError class NotFound < StandardError
end end
class InvalidAccess < StandardError class InvalidAccess < StandardError
end end
class ConfigNotLoaded < StandardError class ConfigNotLoaded < StandardError
end end
class InvalidConfig < StandardError class InvalidConfig < StandardError
end end

View File

@ -32,6 +32,7 @@ module Chat
class MessageMover class MessageMover
class NoMessagesFound < StandardError class NoMessagesFound < StandardError
end end
class InvalidChannel < StandardError class InvalidChannel < StandardError
end end

View File

@ -2,6 +2,7 @@
module ImportScripts module ImportScripts
end end
module ImportScripts::PhpBB3 module ImportScripts::PhpBB3
end end

View File

@ -585,6 +585,7 @@ class ImportScripts::Smf2 < ImportScripts::Base
class Options class Options
class Error < StandardError class Error < StandardError
end end
class SettingsError < Error class SettingsError < Error
end end

View File

@ -8,6 +8,7 @@ class ThreadDetective
def self.test_thread def self.test_thread
Thread.new { sleep 1 } Thread.new { sleep 1 }
end end
def self.start(max_threads) def self.start(max_threads)
@thread ||= Thread.new { self.new.monitor(max_threads) } @thread ||= Thread.new { self.new.monitor(max_threads) }

View File

@ -123,6 +123,7 @@ RSpec.describe Auth::ManagedAuthenticator do
def name def name
"myauth" "myauth"
end end
def can_connect_existing_user? def can_connect_existing_user?
false false
end end
@ -164,6 +165,7 @@ RSpec.describe Auth::ManagedAuthenticator do
def name def name
"myauth" "myauth"
end end
def match_by_email def match_by_email
false false
end end
@ -328,9 +330,11 @@ RSpec.describe Auth::ManagedAuthenticator do
def name def name
"myauth" "myauth"
end end
def match_by_email def match_by_email
false false
end end
def match_by_username def match_by_username
true true
end end
@ -395,6 +399,7 @@ RSpec.describe Auth::ManagedAuthenticator do
def name def name
"myauth" "myauth"
end end
def match_by_username def match_by_username
false false
end end

View File

@ -68,6 +68,7 @@ RSpec.describe Plugin::Instance do
"a trout" "a trout"
end end
end end
class TroutJuniorSerializer < TroutSerializer class TroutJuniorSerializer < TroutSerializer
attribute :i_am_child attribute :i_am_child

View File

@ -390,6 +390,7 @@ RSpec.describe SiteSettingExtension do
def self.valid_value?(v) def self.valid_value?(v)
true true
end end
def self.values def self.values
[1, 2, 3] [1, 2, 3]
end end
@ -409,9 +410,11 @@ RSpec.describe SiteSettingExtension do
def self.valid_value?(v) def self.valid_value?(v)
self.values.include?(v) self.values.include?(v)
end end
def self.values def self.values
["en"] ["en"]
end end
def self.translate_names? def self.translate_names?
false false
end end

View File

@ -136,9 +136,11 @@ RSpec.describe SiteSettings::TypeSupervisor do
def self.valid_value?(v) def self.valid_value?(v)
self.values.include?(v) self.values.include?(v)
end end
def self.values def self.values
["en"] ["en"]
end end
def self.translate_names? def self.translate_names?
false false
end end
@ -147,9 +149,11 @@ RSpec.describe SiteSettings::TypeSupervisor do
class TestSmallThanTenValidator class TestSmallThanTenValidator
def initialize(opts) def initialize(opts)
end end
def valid_value?(v) def valid_value?(v)
v < 10 v < 10
end end
def error_message def error_message
"" ""
end end
@ -408,9 +412,11 @@ RSpec.describe SiteSettings::TypeSupervisor do
def self.valid_value?(v) def self.valid_value?(v)
self.values.include?(v) self.values.include?(v)
end end
def self.values def self.values
%w[a b] %w[a b]
end end
def self.translate_names? def self.translate_names?
false false
end end

View File

@ -3,8 +3,10 @@
class MockedImapProvider < Imap::Providers::Gmail class MockedImapProvider < Imap::Providers::Gmail
def connect! def connect!
end end
def disconnect! def disconnect!
end end
def open_mailbox(mailbox_name, write: false) def open_mailbox(mailbox_name, write: false)
end end

View File

@ -11,6 +11,7 @@ module PageObjects
def user_badges_table def user_badges_table
page.find(:table, id: "user-badges", visible: true) page.find(:table, id: "user-badges", visible: true)
end end
def find_badge_row_by_granter(granter) def find_badge_row_by_granter(granter)
user_badges_table.find(:table_row, { "Granted By" => "#{granter.username}" }) user_badges_table.find(:table_row, { "Granted By" => "#{granter.username}" })
end end

View File

@ -8,6 +8,7 @@ module PageObjects
def modal def modal
find(".grant-badge-modal") find(".grant-badge-modal")
end end
def select_badge(badge_name) def select_badge(badge_name)
within(modal) do within(modal) do
grantable_badges_dropdown.expand grantable_badges_dropdown.expand

View File

@ -8,6 +8,7 @@ module PageObjects
def modal def modal
find(".change-ownership-modal") find(".change-ownership-modal")
end end
def select_new_owner(user) def select_new_owner(user)
within(modal) do within(modal) do
users_dropdown.expand users_dropdown.expand