diff --git a/.rubocop.yml b/.rubocop.yml index 26ae7b5da..12c9957b4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -370,6 +370,9 @@ Rails/ActiveRecordCallbacksOrder: Rails/AddColumnIndex: Enabled: true +Rails/CompactBlank: + Enabled: true + Rails/CreateTableWithTimestamps: Enabled: true Exclude: @@ -391,6 +394,12 @@ Rails/DynamicFindBy: - find_by_slug_or_id! - find_by_manager_login +Rails/EnumHash: + Enabled: true + +Rails/EnumSyntax: + Enabled: true + Rails/EnumUniqueness: Enabled: true diff --git a/Gemfile b/Gemfile index b4a5f3158..806fcc58e 100644 --- a/Gemfile +++ b/Gemfile @@ -102,7 +102,7 @@ group :development do gem "rubocop-capybara", "~> 2.21.0", require: false gem "rubocop-factory_bot", "~> 2.26.1", require: false gem "rubocop-performance", "~> 1.22.1", require: false - gem "rubocop-rails", "~> 2.25.1", require: false + gem "rubocop-rails", "~> 2.26.2", require: false gem "rubocop-rspec", "~> 3.1.0", require: false gem "rubocop-rspec_rails", "~> 2.30.0", require: false gem "rvm1-capistrano3", "~> 1.4.0", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 579836807..78a3e2864 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -557,10 +557,10 @@ GEM rubocop-performance (1.22.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.25.1) + rubocop-rails (2.26.2) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rspec (3.1.0) rubocop (~> 1.61) @@ -772,7 +772,7 @@ DEPENDENCIES rubocop-capybara (~> 2.21.0) rubocop-factory_bot (~> 2.26.1) rubocop-performance (~> 1.22.1) - rubocop-rails (~> 2.25.1) + rubocop-rails (~> 2.26.2) rubocop-rspec (~> 3.1.0) rubocop-rspec_rails (~> 2.30.0) rvm1-capistrano3 (~> 1.4.0) diff --git a/app/components/concerns/header.rb b/app/components/concerns/header.rb index 25ca5b3ae..24b8a9216 100644 --- a/app/components/concerns/header.rb +++ b/app/components/concerns/header.rb @@ -7,7 +7,7 @@ module Header (t("#{namespace}.header.title", default: "") unless skip_section_title), strip_tags(title), setting["org_name"] - ].reject(&:blank?).join(" - ") + ].compact_blank.join(" - ") end heading_tag = if %w[admin management moderation sdg_management valuation].include?(namespace) diff --git a/app/components/sdg/goals/plain_tag_list_component.rb b/app/components/sdg/goals/plain_tag_list_component.rb index 5e8b4ff53..3cfa29868 100644 --- a/app/components/sdg/goals/plain_tag_list_component.rb +++ b/app/components/sdg/goals/plain_tag_list_component.rb @@ -4,7 +4,7 @@ class SDG::Goals::PlainTagListComponent < ApplicationComponent private def tags - [*goal_tags, see_more_link].select(&:present?) + [*goal_tags, see_more_link].compact_blank end def goal_tags diff --git a/app/components/sdg/targets/plain_tag_list_component.rb b/app/components/sdg/targets/plain_tag_list_component.rb index 78ccc4b42..46acd8e94 100644 --- a/app/components/sdg/targets/plain_tag_list_component.rb +++ b/app/components/sdg/targets/plain_tag_list_component.rb @@ -4,7 +4,7 @@ class SDG::Targets::PlainTagListComponent < ApplicationComponent private def tags - [*target_tags, see_more_link].select(&:present?) + [*target_tags, see_more_link].compact_blank end def target_tags diff --git a/app/components/shared/link_list_component.rb b/app/components/shared/link_list_component.rb index ccfc97b69..8009b5c4f 100644 --- a/app/components/shared/link_list_component.rb +++ b/app/components/shared/link_list_component.rb @@ -13,7 +13,7 @@ class Shared::LinkListComponent < ApplicationComponent private def present_links - links.select(&:present?) + links.compact_blank end def list_items diff --git a/app/models/dashboard/action.rb b/app/models/dashboard/action.rb index cfac18315..ca625a900 100644 --- a/app/models/dashboard/action.rb +++ b/app/models/dashboard/action.rb @@ -9,7 +9,7 @@ class Dashboard::Action < ApplicationRecord class_name: "Dashboard::ExecutedAction" has_many :proposals, through: :executed_actions - enum action_type: [:proposed_action, :resource] + enum :action_type, { proposed_action: 0, resource: 1 } validates :title, presence: true, allow_blank: false, length: { in: 4..80 } diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 452eb8b45..8bae96426 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -8,7 +8,7 @@ class Poll validates :date, presence: true, uniqueness: { scope: [:officer_id, :booth_id, :task] } validates :task, presence: true - enum task: { vote_collection: 0, recount_scrutiny: 1 } + enum :task, { vote_collection: 0, recount_scrutiny: 1 } scope :current, -> { where(date: Date.current) } diff --git a/app/models/progress_bar.rb b/app/models/progress_bar.rb index c966f6c9f..d79f61b8f 100644 --- a/app/models/progress_bar.rb +++ b/app/models/progress_bar.rb @@ -2,7 +2,7 @@ class ProgressBar < ApplicationRecord self.inheritance_column = nil RANGE = (0..100) - enum kind: %i[primary secondary] + enum :kind, { primary: 0, secondary: 1 } belongs_to :progressable, polymorphic: true diff --git a/app/models/sdg/phase.rb b/app/models/sdg/phase.rb index 3796dcf21..4a57fb531 100644 --- a/app/models/sdg/phase.rb +++ b/app/models/sdg/phase.rb @@ -1,6 +1,6 @@ class SDG::Phase < ApplicationRecord include Cardable - enum kind: %w[sensitization planning monitoring] + enum :kind, { sensitization: 0, planning: 1, monitoring: 2 } validates :kind, presence: true, uniqueness: true def self.[](kind) diff --git a/app/models/tenant.rb b/app/models/tenant.rb index e39d3cd9c..6c1bcac80 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -1,5 +1,5 @@ class Tenant < ApplicationRecord - enum schema_type: %w[subdomain domain] + enum :schema_type, { subdomain: 0, domain: 1 } validates :schema, presence: true, diff --git a/app/models/votation_type.rb b/app/models/votation_type.rb index 00fca0ecf..71d61c62d 100644 --- a/app/models/votation_type.rb +++ b/app/models/votation_type.rb @@ -3,7 +3,7 @@ class VotationType < ApplicationRecord QUESTIONABLE_TYPES = %w[Poll::Question].freeze - enum vote_type: %w[unique multiple] + enum :vote_type, { unique: 0, multiple: 1 } validates :questionable, presence: true validates :questionable_type, inclusion: { in: ->(*) { QUESTIONABLE_TYPES }}