Autofix Rubocop Rails/EnumHash (#23737)

shrike
Nick Schonning 2023-02-19 23:00:36 -05:00 committed by GitHub
parent 44a7d87cb1
commit 63e6353886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 12 additions and 28 deletions

View File

@ -1871,22 +1871,6 @@ Rails/DuplicateAssociation:
- 'app/serializers/activitypub/collection_serializer.rb'
- 'app/serializers/activitypub/note_serializer.rb'
# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/EnumHash:
Exclude:
- 'app/models/account.rb'
- 'app/models/custom_filter.rb'
- 'app/models/domain_block.rb'
- 'app/models/import.rb'
- 'app/models/list.rb'
- 'app/models/media_attachment.rb'
- 'app/models/preview_card.rb'
- 'app/models/relay.rb'
- 'app/models/status.rb'
# Offense count: 76
# Configuration parameters: EnforcedStyle.
# SupportedStyles: slashes, arguments

View File

@ -78,8 +78,8 @@ class Account < ApplicationRecord
include DomainMaterializable
include AccountMerging
enum protocol: [:ostatus, :activitypub]
enum suspension_origin: [:local, :remote], _prefix: true
enum protocol: { ostatus: 0, activitypub: 1 }
enum suspension_origin: { local: 0, remote: 1 }, _prefix: true
validates :username, presence: true
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }

View File

@ -30,7 +30,7 @@ class CustomFilter < ApplicationRecord
include Expireable
include Redisable
enum action: [:warn, :hide], _suffix: :action
enum action: { warn: 0, hide: 1 }, _suffix: :action
belongs_to :account
has_many :keywords, class_name: 'CustomFilterKeyword', inverse_of: :custom_filter, dependent: :destroy

View File

@ -20,7 +20,7 @@ class DomainBlock < ApplicationRecord
include DomainNormalizable
include DomainMaterializable
enum severity: [:silence, :suspend, :noop]
enum severity: { silence: 0, suspend: 1, noop: 2 }
validates :domain, presence: true, uniqueness: true, domain: true

View File

@ -24,7 +24,7 @@ class Import < ApplicationRecord
belongs_to :account
enum type: [:following, :blocking, :muting, :domain_blocking, :bookmarks]
enum type: { following: 0, blocking: 1, muting: 2, domain_blocking: 3, bookmarks: 4 }
validates :type, presence: true
validates_with ImportValidator, on: :create

View File

@ -16,7 +16,7 @@ class List < ApplicationRecord
PER_ACCOUNT_LIMIT = 50
enum replies_policy: [:list, :followed, :none], _prefix: :show
enum replies_policy: { list: 0, followed: 1, none: 2 }, _prefix: :show
belongs_to :account, optional: true

View File

@ -33,8 +33,8 @@ class MediaAttachment < ApplicationRecord
include Attachmentable
enum type: [:image, :gifv, :video, :unknown, :audio]
enum processing: [:queued, :in_progress, :complete, :failed], _prefix: true
enum type: { :image => 0, :gifv => 1, :video => 2, :unknown => 3, :audio => 4 }
enum processing: { :queued => 0, :in_progress => 1, :complete => 2, :failed => 3 }, _prefix: true
MAX_DESCRIPTION_LENGTH = 1_500

View File

@ -44,8 +44,8 @@ class PreviewCard < ApplicationRecord
self.inheritance_column = false
enum type: [:link, :photo, :video, :rich]
enum link_type: [:unknown, :article]
enum type: { link: 0, photo: 1, video: 2, rich: 3 }
enum link_type: { unknown: 0, article: 1 }
has_and_belongs_to_many :statuses
has_one :trend, class_name: 'PreviewCardTrend', inverse_of: :preview_card, dependent: :destroy

View File

@ -14,7 +14,7 @@
class Relay < ApplicationRecord
validates :inbox_url, presence: true, uniqueness: true, url: true, if: :will_save_change_to_inbox_url?
enum state: [:idle, :pending, :accepted, :rejected]
enum state: { idle: 0, pending: 1, accepted: 2, rejected: 3 }
scope :enabled, -> { accepted }

View File

@ -48,7 +48,7 @@ class Status < ApplicationRecord
update_index('statuses', :proper)
enum visibility: [:public, :unlisted, :private, :direct, :limited], _suffix: :visibility
enum visibility: { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4 }, _suffix: :visibility
belongs_to :application, class_name: 'Doorkeeper::Application', optional: true