Skip to content

Commit

Permalink
Fix rubocop violations
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaeftekhar committed Jan 9, 2024
1 parent c73375e commit 5c7c970
Show file tree
Hide file tree
Showing 56 changed files with 235 additions and 233 deletions.
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ GEM
paper_trail (12.3.0)
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.23.0)
parallel (1.24.0)
parallel_tests (4.4.0)
parallel
parser (3.2.2.3)
parser (3.3.0.2)
ast (~> 2.4.1)
racc
pg (1.4.6)
Expand Down Expand Up @@ -593,7 +593,7 @@ GEM
ffi (~> 1.0)
redcarpet (3.6.0)
redis (4.8.1)
regexp_parser (2.8.1)
regexp_parser (2.9.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.1)
Expand Down Expand Up @@ -641,7 +641,7 @@ GEM
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
Expand All @@ -652,10 +652,11 @@ GEM
rubocop (>= 0.82.0)
rubocop-performance (1.6.1)
rubocop (>= 0.71.0)
rubocop-rails (2.22.1)
rubocop-rails (2.23.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
Expand Down Expand Up @@ -719,7 +720,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uber (0.1.0)
unicode-display_width (2.4.2)
unicode-display_width (2.5.0)
uniform_notifier (1.16.0)
valid_email2 (4.0.6)
activemodel (>= 3.2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def create_translations
TermCustomizer::Translation.create!(
translation_set: form.translation_set,
key: form.key,
value: value,
locale: locale
value:,
locale:
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def create_translations
items = form.keys.map do |key|
form.current_organization.available_locales.map do |locale|
attrs = {
key: key,
locale: locale
key:,
locale:
}
next unless form.translation_set.translations.find_by(attrs).nil?

attrs.merge(value: I18n.t(key, locale: locale, default: ""))
attrs.merge(value: I18n.t(key, locale:, default: ""))
end
end.flatten

Expand Down
10 changes: 5 additions & 5 deletions app/commands/decidim/term_customizer/admin/update_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ def update_translations!
l_translation = TermCustomizer::Translation.find_by(
translation_set: translation.translation_set,
key: translation.key,
locale: locale
locale:
)

if l_translation
l_translation.update!(
key: form.key,
value: value,
locale: locale
value:,
locale:
)
else
l_translation = TermCustomizer::Translation.create!(
translation_set: translation.translation_set,
key: form.key,
value: value,
locale: locale
value:,
locale:
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
enforce_permission_to :create, :translation
@form = form(TranslationKeyImportForm).from_params(
params,
current_organization: current_organization,
current_organization:,
translation_set: set
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ def new
)
end

def edit
enforce_permission_to :update, :translation_set, translation_set: set
@form = form(TranslationSetForm).from_model(set)
end

def create
enforce_permission_to :create, :translation_set
@form = form(TranslationSetForm).from_params(
params,
current_organization: current_organization
current_organization:
)

CreateTranslationSet.call(@form) do
Expand All @@ -41,16 +46,11 @@ def create
end
end

def edit
enforce_permission_to :update, :translation_set, translation_set: set
@form = form(TranslationSetForm).from_model(set)
end

def update
enforce_permission_to :update, :translation_set, translation_set: set
@form = form(TranslationSetForm).from_params(
params,
current_organization: current_organization
current_organization:
)

UpdateTranslationSet.call(@form, set) do
Expand Down Expand Up @@ -84,15 +84,15 @@ def duplicate
hash["name_#{locale}"] = I18n.t(
"translation_sets.duplicate.copied_set_name",
name: set.name[locale],
locale: locale,
locale:,
scope: "decidim.term_customizer.admin"
)
end
end

@form = form(TranslationSetForm).from_params(
params.merge(name_attrs),
current_organization: current_organization
current_organization:
)

DuplicateTranslationSet.call(@form, set) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ def new
@form = form(TranslationForm).from_model(Translation.new)
end

def edit
enforce_permission_to(:update, :translation, translation:)
@form = form(TranslationForm).from_model(translation)
end

def create
enforce_permission_to :create, :translation
@form = form(TranslationForm).from_params(
params,
current_organization: current_organization,
current_organization:,
translation_set: set
)

Expand All @@ -39,16 +44,11 @@ def create
end
end

def edit
enforce_permission_to :update, :translation, translation: translation
@form = form(TranslationForm).from_model(translation)
end

def update
enforce_permission_to :update, :translation, translation: translation
enforce_permission_to(:update, :translation, translation:)
@form = form(TranslationForm).from_params(
params,
current_organization: current_organization,
current_organization:,
translation_set: set
)

Expand All @@ -66,7 +66,7 @@ def update
end

def destroy
enforce_permission_to :destroy, :translation, translation: translation
enforce_permission_to(:destroy, :translation, translation:)

# Destroy all locales of the translation key
pfm = TermCustomizer::PluralFormsManager.new(current_organization)
Expand Down Expand Up @@ -104,7 +104,7 @@ def import

@import = form(Admin::TranslationsImportForm).from_params(
params,
current_organization: current_organization
current_organization:
)
ImportSetTranslations.call(@import, set) do
on(:ok) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def set_form
@form = form(Admin::TranslationsDestroyForm).from_params(
params
).with_context(
current_organization: current_organization,
current_organization:,
translation_set: set
)
end
Expand Down
6 changes: 3 additions & 3 deletions app/forms/decidim/term_customizer/admin/translation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TranslationForm < Decidim::Form
translatable_attribute :value, String

validates :key, presence: true
validates :key, format: { with: %r{\A([a-z0-9_/?\-]+\.)*[a-z0-9_/?\-]+\z} }, unless: -> { key.blank? }
validates :key, format: { with: %r{\A([a-z0-9_/?-]+\.)*[a-z0-9_/?-]+\z} }, unless: -> { key.blank? }
validates :value, translatable_presence: true
validate :key_uniqueness

Expand All @@ -30,8 +30,8 @@ def map_model(model)
def key_uniqueness
errors.add(:key, :taken) if translation_set && translation_set.translations.where(
locale: I18n.locale,
key: key
).where.not(id: id).exists?
key:
).where.not(id:).exists?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/decidim/term_customizer/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Translation < TermCustomizer::ApplicationRecord

validates :locale, presence: true
validates :key, presence: true
validates :key, format: { with: %r{\A([a-z0-9_/?\-]+\.)*[a-z0-9_/?\-]+\z} }, unless: -> { key.blank? }
validates :key, format: { with: %r{\A([a-z0-9_/?-]+\.)*[a-z0-9_/?-]+\z} }, unless: -> { key.blank? }
validates :key, uniqueness: { scope: [:translation_set, :locale] }, unless: -> { key.blank? }

class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/term_customizer/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AdminEngine < ::Rails::Engine
end
end

initializer "decidim_term_customizer.register_icons" do |_app|
initializer "decidim_term_customizer.register_icons" do |_app|
Decidim.icons.register(name: "Decidim::TermCustomizer", icon: "translate", category: "system", description: "Term Customizer", engine: :admin)
Decidim.icons.register(name: "git-branch-line", icon: "git-branch-line", category: "system", description: "fork icon", engine: :admin)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/decidim/term_customizer/context/job_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Decidim
module TermCustomizer
module Context
class JobContext < Base
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def resolve!
# Figure out the organization and user through the job arguments if
Expand All @@ -28,6 +29,7 @@ def resolve!
# it through the user (if the user was passed).
@organization ||= user.organization if user
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

protected
Expand Down
8 changes: 4 additions & 4 deletions lib/decidim/term_customizer/plural_forms_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def add_locales_for!(translation, target_key)
# Check that the translation is not already added in the set
next if translation.translation_set.translations.where(
key: target_key,
locale: locale
locale:
).any?

# Add the plural form
translation.translation_set.translations.create!(
key: target_key,
locale: locale,
value: I18n.t(target_key, locale: locale, default: "")
locale:,
value: I18n.t(target_key, locale:, default: "")
)
end
end
Expand All @@ -91,7 +91,7 @@ def destroy_locales_for!(translation, target_key)
# Find the plural form the plural form
target = translation.translation_set.translations.find_by(
key: target_key,
locale: locale
locale:
)
next unless target

Expand Down
8 changes: 4 additions & 4 deletions lib/decidim/term_customizer/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def constraints_add_organization_query(query)

query.or!(
TermCustomizer::Constraint.where(
organization: organization,
organization:,
subject_type: nil,
subject_id: nil
)
Expand All @@ -80,13 +80,13 @@ def constraints_add_space_query(query)

query.or!(
TermCustomizer::Constraint.where(
organization: organization,
organization:,
subject: space
)
)
query.or!(
TermCustomizer::Constraint.where(
organization: organization,
organization:,
subject_type: space.class.name,
subject_id: nil
)
Expand All @@ -98,7 +98,7 @@ def constraints_add_component_query(query)

query.or!(
TermCustomizer::Constraint.where(
organization: organization,
organization:,
subject: component
)
)
Expand Down
12 changes: 6 additions & 6 deletions lib/decidim/term_customizer/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FactoryBot.define do
# Create as a sequence to avoid key collisions
sequence :translation_key do |n|
"#{::Faker::Lorem.words(number: rand(1..3)).join(".").downcase}.tr#{n}"
"#{Faker::Lorem.words(number: rand(1..3)).join(".").downcase}.tr#{n}"
end

factory :translation_set, class: "Decidim::TermCustomizer::TranslationSet" do
Expand Down Expand Up @@ -31,13 +31,13 @@
factory :translation, class: "Decidim::TermCustomizer::Translation" do
locale { :en }
key { generate(:translation_key) }
value { ::Faker::Lorem.words(number: rand(1..10)).join(" ") }
translation_set { create(:translation_set) }
value { Faker::Lorem.words(number: rand(1..10)).join(" ") }
translation_set
end

factory :translation_set_constraint, class: "Decidim::TermCustomizer::Constraint" do
organization { create(:organization) }
translation_set { create(:translation_set) }
subject { create(:participatory_process, organization: organization) }
organization
translation_set
subject { association(:participatory_process, organization:) }
end
end
2 changes: 1 addition & 1 deletion lib/decidim/term_customizer/translation_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def translations_by_key(search) # rubocop:disable Rails/Delegate
end

def translations_by_term(search, case_sensitive: false)
translations.by_term(search, case_sensitive: case_sensitive)
translations.by_term(search, case_sensitive:)
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/decidim/term_customizer/translation_import_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def attributes_for_all_locales
# the found item to the final array.
if item.nil?
{
key: key,
key:,
locale: locale.to_s,
value: I18n.t(key, locale: locale, default: "")
value: I18n.t(key, locale:, default: "")
}
else
item
Expand Down
Loading

0 comments on commit 5c7c970

Please sign in to comment.