diff --git a/.rubocop.yml b/.rubocop.yml index 664911bc8..5d150784c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -391,12 +391,18 @@ Style/IdenticalConditionalBranches: Style/MethodDefParentheses: Enabled: true +Style/MutableConstant: + Enabled: true + Style/Not: Enabled: true Style/PercentLiteralDelimiters: Enabled: true +Style/RedundantFreeze: + Enabled: true + Style/SafeNavigation: Enabled: true diff --git a/app/helpers/embed_videos_helper.rb b/app/helpers/embed_videos_helper.rb index 08a3179f8..af4f23ac2 100644 --- a/app/helpers/embed_videos_helper.rb +++ b/app/helpers/embed_videos_helper.rb @@ -1,6 +1,6 @@ module EmbedVideosHelper - VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ - YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/.freeze + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/.freeze def embedded_video_code(resource) link = resource.video_url diff --git a/app/models/activity.rb b/app/models/activity.rb index a0c862c25..3accc495b 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -2,7 +2,7 @@ class Activity < ApplicationRecord belongs_to :actionable, -> { with_hidden }, polymorphic: true belongs_to :user, -> { with_hidden }, inverse_of: :activities - VALID_ACTIONS = %w[hide block restore valuate email] + VALID_ACTIONS = %w[hide block restore valuate email].freeze validates :action, inclusion: { in: VALID_ACTIONS } diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index 3e3d8b07d..51616c0a2 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -1,6 +1,6 @@ class Budget class Heading < ApplicationRecord - OSM_DISTRICT_LEVEL_ZOOM = 12.freeze + OSM_DISTRICT_LEVEL_ZOOM = 12 include Sluggable diff --git a/app/models/budget/reclassified_vote.rb b/app/models/budget/reclassified_vote.rb index 1e9053428..ea73d27c1 100644 --- a/app/models/budget/reclassified_vote.rb +++ b/app/models/budget/reclassified_vote.rb @@ -1,6 +1,6 @@ class Budget class ReclassifiedVote < ApplicationRecord - REASONS = %w[heading_changed unfeasible] + REASONS = %w[heading_changed unfeasible].freeze belongs_to :user belongs_to :investment diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index 144367559..83ab583f8 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -1,6 +1,6 @@ module Statisticable extend ActiveSupport::Concern - PARTICIPATIONS = %w[gender age geozone] + PARTICIPATIONS = %w[gender age geozone].freeze included do attr_reader :resource diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 1e079bb8e..93b65eb8f 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -1,5 +1,5 @@ class Legislation::DraftVersion < ApplicationRecord - VALID_STATUSES = %w[draft published] + VALID_STATUSES = %w[draft published].freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 359c31001..e11bc3b09 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -23,7 +23,7 @@ class Legislation::Process < ApplicationRecord proposals_phase people_proposals_phase draft_publication result_publication].freeze - CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i + CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i.freeze has_many :draft_versions, -> { order(:id) }, foreign_key: "legislation_process_id", diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index 02b6906b2..134cf377d 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -1,5 +1,5 @@ class Poll::PartialResult < ApplicationRecord - VALID_ORIGINS = %w[web booth] + VALID_ORIGINS = %w[web booth].freeze belongs_to :question, -> { with_hidden }, inverse_of: :partial_results belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_partial_results diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb index 6cf9e7cc6..5f5407bcc 100644 --- a/app/models/poll/question/answer/video.rb +++ b/app/models/poll/question/answer/video.rb @@ -1,8 +1,8 @@ class Poll::Question::Answer::Video < ApplicationRecord belongs_to :answer, class_name: "Poll::Question::Answer" - VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ - YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/.freeze + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/.freeze validates :title, presence: true validate :valid_url? diff --git a/app/models/progress_bar.rb b/app/models/progress_bar.rb index f60e4f2b3..3da9c072b 100644 --- a/app/models/progress_bar.rb +++ b/app/models/progress_bar.rb @@ -1,6 +1,6 @@ class ProgressBar < ApplicationRecord self.inheritance_column = nil - RANGE = 0..100 + RANGE = (0..100).freeze enum kind: %i[primary secondary] diff --git a/app/models/proposal.rb b/app/models/proposal.rb index c02e09bd1..ce223cdaa 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -26,7 +26,7 @@ class Proposal < ApplicationRecord acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - RETIRE_OPTIONS = %w[duplicated started unfeasible done other] + RETIRE_OPTIONS = %w[duplicated started unfeasible done other].freeze translates :title, touch: true translates :description, touch: true diff --git a/app/models/report.rb b/app/models/report.rb index 857cb462f..e8d26a829 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,5 +1,5 @@ class Report < ApplicationRecord - KINDS = %i[results stats advanced_stats] + KINDS = %i[results stats advanced_stats].freeze belongs_to :process, polymorphic: true end diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index cf67804b2..fae7b7a3c 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -2,7 +2,7 @@ class SignatureSheet < ApplicationRecord belongs_to :signable, polymorphic: true belongs_to :author, class_name: "User" - VALID_SIGNABLES = %w[Proposal Budget::Investment] + VALID_SIGNABLES = %w[Proposal Budget::Investment].freeze has_many :signatures diff --git a/app/models/site_customization/content_block.rb b/app/models/site_customization/content_block.rb index a96bc8b47..a41580e36 100644 --- a/app/models/site_customization/content_block.rb +++ b/app/models/site_customization/content_block.rb @@ -1,5 +1,5 @@ class SiteCustomization::ContentBlock < ApplicationRecord - VALID_BLOCKS = %w[top_links footer subnavigation_left subnavigation_right] + VALID_BLOCKS = %w[top_links footer subnavigation_left subnavigation_right].freeze validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) } validates :name, presence: true, uniqueness: { scope: :locale }, inclusion: { in: VALID_BLOCKS } diff --git a/app/models/site_customization/image.rb b/app/models/site_customization/image.rb index 0ebf1f929..77f0e16ab 100644 --- a/app/models/site_customization/image.rb +++ b/app/models/site_customization/image.rb @@ -7,7 +7,7 @@ class SiteCustomization::Image < ApplicationRecord "budget_execution_no_image" => [800, 600], "map" => [420, 500], "logo_email" => [400, 80] - } + }.freeze has_attached_file :image diff --git a/app/models/site_customization/page.rb b/app/models/site_customization/page.rb index be59d0dcd..03c4bcccc 100644 --- a/app/models/site_customization/page.rb +++ b/app/models/site_customization/page.rb @@ -1,5 +1,5 @@ class SiteCustomization::Page < ApplicationRecord - VALID_STATUSES = %w[draft published] + VALID_STATUSES = %w[draft published].freeze has_many :cards, class_name: "Widget::Card", foreign_key: "site_customization_page_id", diff --git a/app/models/widget/feed.rb b/app/models/widget/feed.rb index 3e52e81d6..d90cdee2d 100644 --- a/app/models/widget/feed.rb +++ b/app/models/widget/feed.rb @@ -1,7 +1,7 @@ class Widget::Feed < ApplicationRecord self.table_name = "widget_feeds" - KINDS = %w[proposals debates processes] + KINDS = %w[proposals debates processes].freeze def active? setting.value.present? diff --git a/lib/graph_ql/api_types_creator.rb b/lib/graph_ql/api_types_creator.rb index 0fca95f61..823e430a8 100644 --- a/lib/graph_ql/api_types_creator.rb +++ b/lib/graph_ql/api_types_creator.rb @@ -8,7 +8,7 @@ module GraphQL float: GraphQL::FLOAT_TYPE, double: GraphQL::FLOAT_TYPE, string: GraphQL::STRING_TYPE - } + }.freeze def self.create(api_types_definitions) created_types = {} diff --git a/lib/remote_translations/microsoft/client.rb b/lib/remote_translations/microsoft/client.rb index 5c4f33d34..d7e1bc5d9 100644 --- a/lib/remote_translations/microsoft/client.rb +++ b/lib/remote_translations/microsoft/client.rb @@ -3,7 +3,7 @@ include RemoteTranslations::Microsoft::SentencesParser class RemoteTranslations::Microsoft::Client CHARACTERS_LIMIT_PER_REQUEST = 5000 - PREVENTING_TRANSLATION_KEY = "notranslate" + PREVENTING_TRANSLATION_KEY = "notranslate".freeze def initialize api_key = Rails.application.secrets.microsoft_api_key diff --git a/lib/tag_sanitizer.rb b/lib/tag_sanitizer.rb index 4a15ab1b8..eedf1f5af 100644 --- a/lib/tag_sanitizer.rb +++ b/lib/tag_sanitizer.rb @@ -1,5 +1,5 @@ class TagSanitizer - DISALLOWED_STRINGS = %w[? < > = /] + DISALLOWED_STRINGS = %w[? < > = /].freeze def sanitize_tag(tag) tag = tag.dup diff --git a/lib/user_segments.rb b/lib/user_segments.rb index d6bd427fb..bf30f4416 100644 --- a/lib/user_segments.rb +++ b/lib/user_segments.rb @@ -7,7 +7,7 @@ class UserSegments feasible_and_undecided_investment_authors selected_investment_authors winner_investment_authors - not_supported_on_current_budget] + not_supported_on_current_budget].freeze def self.all_users User.active