From 52a55827c3a7ee059273a8c59e0679f1fea5c5a8 Mon Sep 17 00:00:00 2001 From: Gabriel Jablonski Date: Fri, 14 Feb 2025 11:45:12 -0300 Subject: [PATCH] chore: lint files (#2) * chore: lint files * chore: suppress warning * chore: disable suggest extensions * chore: do not stage changes in pre-commit * chore: remove git add from FE lint and `-a` flag from rubocop on husky --- .husky/pre-commit | 4 ++-- .rubocop.yml | 4 ++++ Gemfile | 2 +- app/actions/contact_identify_action.rb | 2 +- app/builders/messages/instagram/message_builder.rb | 2 +- .../api/v1/accounts/automation_rules_controller.rb | 1 - .../api/v1/widget/conversations_controller.rb | 2 +- app/controllers/api_controller.rb | 2 +- .../super_admin/account_users_controller.rb | 2 +- app/helpers/reporting_event_helper.rb | 4 ++-- app/helpers/timezone_helper.rb | 2 +- app/jobs/webhooks/whatsapp_events_job.rb | 2 +- app/listeners/agent_bot_listener.rb | 4 ++-- app/listeners/automation_rule_listener.rb | 2 +- app/mailers/conversation_reply_mailer.rb | 4 ++-- app/models/attachment.rb | 4 ++-- app/models/concerns/content_attribute_validator.rb | 2 +- app/models/concerns/featurable.rb | 8 ++++---- app/models/conversation.rb | 3 ++- app/models/message.rb | 6 +++--- app/models/user.rb | 4 ++-- .../auto_assignment/inbox_round_robin_service.rb | 2 +- app/services/line/incoming_message_service.rb | 2 +- .../message_templates/hook_execution_service.rb | 4 ++-- db/migrate/20230515051424_update_article_image_keys.rb | 4 ++-- .../services/internal/reconcile_plan_config_service.rb | 4 ++-- enterprise/lib/captain/agent.rb | 2 +- lib/chatwoot_app.rb | 2 +- lib/chatwoot_captcha.rb | 2 +- lib/config_loader.rb | 4 ++-- lib/integrations/bot_processor_service.rb | 10 +++++----- package.json | 3 +-- 32 files changed, 54 insertions(+), 51 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index adda426ad..9c350db88 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -5,7 +5,7 @@ npx --no-install lint-staged # lint only staged ruby files -git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --force-exclusion -a +git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --force-exclusion # stage rubocop changes to files -git diff --name-only --cached | xargs git add +# git diff --name-only --cached | xargs git add diff --git a/.rubocop.yml b/.rubocop.yml index 1cdfbc713..679531c66 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -154,6 +154,7 @@ CustomCopLocation: AllCops: NewCops: enable + SuggestExtensions: false Exclude: - 'bin/**/*' - 'db/schema.rb' @@ -166,3 +167,6 @@ AllCops: - 'tmp/**/*' - 'storage/**/*' - 'db/migrate/20230426130150_init_schema.rb' + +Layout/LeadingCommentSpace: + Enabled: false diff --git a/Gemfile b/Gemfile index 1e8605379..92c2d8e72 100644 --- a/Gemfile +++ b/Gemfile @@ -40,7 +40,7 @@ gem 'down' # authentication type to fetch and send mail over oauth2.0 gem 'gmail_xoauth' # Lock net-smtp to 0.3.4 to avoid issues with gmail_xoauth2 -gem 'net-smtp', '~> 0.3.4' +gem 'net-smtp', '~> 0.3.4' # Prevent CSV injection gem 'csv-safe' diff --git a/app/actions/contact_identify_action.rb b/app/actions/contact_identify_action.rb index a88d3535b..8e7e1bf2d 100644 --- a/app/actions/contact_identify_action.rb +++ b/app/actions/contact_identify_action.rb @@ -69,7 +69,7 @@ class ContactIdentifyAction end def merge_contacts?(existing_contact, key) - return if existing_contact.blank? + return false if existing_contact.blank? return true if params[:identifier].blank? diff --git a/app/builders/messages/instagram/message_builder.rb b/app/builders/messages/instagram/message_builder.rb index 7f1b9cab2..a36d6f018 100644 --- a/app/builders/messages/instagram/message_builder.rb +++ b/app/builders/messages/instagram/message_builder.rb @@ -166,7 +166,7 @@ class Messages::Instagram::MessageBuilder < Messages::Messenger::MessageBuilder end def all_unsupported_files? - return if attachments.empty? + return false if attachments.empty? attachments_type = attachments.pluck(:type).uniq.first unsupported_file_type?(attachments_type) diff --git a/app/controllers/api/v1/accounts/automation_rules_controller.rb b/app/controllers/api/v1/accounts/automation_rules_controller.rb index 3d894808d..05d3cb1ab 100644 --- a/app/controllers/api/v1/accounts/automation_rules_controller.rb +++ b/app/controllers/api/v1/accounts/automation_rules_controller.rb @@ -24,7 +24,6 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont ActiveRecord::Base.transaction do automation_rule_update process_attachments - rescue StandardError => e Rails.logger.error e render json: { error: @automation_rule.errors.messages }.to_json, status: :unprocessable_entity diff --git a/app/controllers/api/v1/widget/conversations_controller.rb b/app/controllers/api/v1/widget/conversations_controller.rb index fe5facc1a..64b32db3c 100644 --- a/app/controllers/api/v1/widget/conversations_controller.rb +++ b/app/controllers/api/v1/widget/conversations_controller.rb @@ -82,7 +82,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController end def render_not_found_if_empty - return head :not_found if conversation.nil? + head :not_found if conversation.nil? end def permitted_params diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index eb6f776f1..769bb1b18 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -12,7 +12,7 @@ class ApiController < ApplicationController def redis_status r = Redis.new(Redis::Config.app) - return 'ok' if r.ping + 'ok' if r.ping rescue Redis::CannotConnectError 'failing' end diff --git a/app/controllers/super_admin/account_users_controller.rb b/app/controllers/super_admin/account_users_controller.rb index b210dea19..057128c98 100644 --- a/app/controllers/super_admin/account_users_controller.rb +++ b/app/controllers/super_admin/account_users_controller.rb @@ -6,7 +6,7 @@ class SuperAdmin::AccountUsersController < SuperAdmin::ApplicationController resource = resource_class.new(resource_params) authorize_resource(resource) - notice = resource.save ? translate_with_resource('create.success') : resource.errors.full_messages.first + notice = resource.save ? translate_with_resource('create.success') : resource.errors.full_messages.first redirect_back(fallback_location: [namespace, resource.account], notice: notice) end diff --git a/app/helpers/reporting_event_helper.rb b/app/helpers/reporting_event_helper.rb index e08b5691c..94c7f8cde 100644 --- a/app/helpers/reporting_event_helper.rb +++ b/app/helpers/reporting_event_helper.rb @@ -52,8 +52,8 @@ module ReportingEventHelper end def format_time(hour, minute) - hour = hour < 10 ? "0#{hour}" : hour - minute = minute < 10 ? "0#{minute}" : minute + hour = "0#{hour}" if hour < 10 + minute = "0#{minute}" if minute < 10 "#{hour}:#{minute}" end end diff --git a/app/helpers/timezone_helper.rb b/app/helpers/timezone_helper.rb index b016cc9d9..7b88ceae6 100644 --- a/app/helpers/timezone_helper.rb +++ b/app/helpers/timezone_helper.rb @@ -14,6 +14,6 @@ module TimezoneHelper zone.now.utc_offset == offset_in_seconds end - return matching_zone.name if matching_zone + matching_zone&.name end end diff --git a/app/jobs/webhooks/whatsapp_events_job.rb b/app/jobs/webhooks/whatsapp_events_job.rb index cd2dad167..b130161de 100644 --- a/app/jobs/webhooks/whatsapp_events_job.rb +++ b/app/jobs/webhooks/whatsapp_events_job.rb @@ -47,6 +47,6 @@ class Webhooks::WhatsappEventsJob < ApplicationJob phone_number_id = wb_params[:entry].first[:changes].first.dig(:value, :metadata, :phone_number_id) channel = Channel::Whatsapp.find_by(phone_number: phone_number) # validate to ensure the phone number id matches the whatsapp channel - return channel if channel && channel.provider_config['phone_number_id'] == phone_number_id + channel if channel && channel.provider_config['phone_number_id'] == phone_number_id end end diff --git a/app/listeners/agent_bot_listener.rb b/app/listeners/agent_bot_listener.rb index 12e8c6570..5b8ac6cc5 100644 --- a/app/listeners/agent_bot_listener.rb +++ b/app/listeners/agent_bot_listener.rb @@ -53,8 +53,8 @@ class AgentBotListener < BaseListener private def connected_agent_bot_exist?(inbox) - return if inbox.agent_bot_inbox.blank? - return unless inbox.agent_bot_inbox.active? + return false if inbox.agent_bot_inbox.blank? + return false unless inbox.agent_bot_inbox.active? true end diff --git a/app/listeners/automation_rule_listener.rb b/app/listeners/automation_rule_listener.rb index 5dabda47e..e0a4ef523 100644 --- a/app/listeners/automation_rule_listener.rb +++ b/app/listeners/automation_rule_listener.rb @@ -70,7 +70,7 @@ class AutomationRuleListener < BaseListener end def rule_present?(event_name, account) - return if account.blank? + return false if account.blank? current_account_rules(event_name, account).any? end diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index f9d1faf3d..7c00d92d0 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -72,8 +72,8 @@ class ConversationReplyMailer < ApplicationMailer def conversation_already_viewed? # whether contact already saw the message on widget - return unless @conversation.contact_last_seen_at - return unless last_outgoing_message&.created_at + return false unless @conversation.contact_last_seen_at + return false unless last_outgoing_message&.created_at @conversation.contact_last_seen_at > last_outgoing_message&.created_at end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 0bfd9a978..c603edb4d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -123,9 +123,9 @@ class Attachment < ApplicationRecord end def should_validate_file? - return unless file.attached? + return false unless file.attached? # we are only limiting attachment types in case of website widget - return unless message.inbox.channel_type == 'Channel::WebWidget' + return false unless message.inbox.channel_type == 'Channel::WebWidget' true end diff --git a/app/models/concerns/content_attribute_validator.rb b/app/models/concerns/content_attribute_validator.rb index bad93c913..8a15ad4a1 100644 --- a/app/models/concerns/content_attribute_validator.rb +++ b/app/models/concerns/content_attribute_validator.rb @@ -37,7 +37,7 @@ class ContentAttributeValidator < ActiveModel::Validator end def validate_item_actions!(record) - if record.items.select { |item| item[:actions].blank? }.present? + if record.items.select { |item| item[:actions].blank? }.present? # rubocop:disable Style/RedundantFilterChain record.errors.add(:content_attributes, 'contains items missing actions') && return end diff --git a/app/models/concerns/featurable.rb b/app/models/concerns/featurable.rb index daa0b4bf6..ff4aa961b 100644 --- a/app/models/concerns/featurable.rb +++ b/app/models/concerns/featurable.rb @@ -25,8 +25,8 @@ module Featurable end end - def enable_features!(*names) - enable_features(*names) + def enable_features!(*) + enable_features(*) save end @@ -36,8 +36,8 @@ module Featurable end end - def disable_features!(*names) - disable_features(*names) + def disable_features!(*) + disable_features(*) save end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 2a7a49223..e09e6efaf 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -290,8 +290,9 @@ class Conversation < ApplicationRecord def conversation_status_changed_to_open? return false unless open? + # saved_change_to_status? method only works in case of update - return true if previous_changes.key?(:id) || saved_change_to_status? + true if previous_changes.key?(:id) || saved_change_to_status? end def create_label_change(user_name) diff --git a/app/models/message.rb b/app/models/message.rb index 20dad7403..c6c737fe6 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -359,9 +359,9 @@ class Message < ApplicationRecord end def can_notify_via_mail? - return unless email_notifiable_message? - return unless email_notifiable_channel? - return if conversation.contact.email.blank? + return false unless email_notifiable_message? + return false unless email_notifiable_channel? + return false if conversation.contact.email.blank? true end diff --git a/app/models/user.rb b/app/models/user.rb index 5594b0ca6..d1907362a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -109,8 +109,8 @@ class User < ApplicationRecord self.email = email.try(:downcase) end - def send_devise_notification(notification, *args) - devise_mailer.with(account: Current.account).send(notification, self, *args).deliver_later + def send_devise_notification(notification, *) + devise_mailer.with(account: Current.account).send(notification, self, *).deliver_later end def set_password_and_uid diff --git a/app/services/auto_assignment/inbox_round_robin_service.rb b/app/services/auto_assignment/inbox_round_robin_service.rb index 7f5a5fb6c..e121ada43 100644 --- a/app/services/auto_assignment/inbox_round_robin_service.rb +++ b/app/services/auto_assignment/inbox_round_robin_service.rb @@ -49,7 +49,7 @@ class AutoAssignment::InboxRoundRobinService end def validate_queue? - return true if inbox.inbox_members.map(&:user_id).sort == queue.map(&:to_i).sort + true if inbox.inbox_members.map(&:user_id).sort == queue.map(&:to_i).sort end def queue diff --git a/app/services/line/incoming_message_service.rb b/app/services/line/incoming_message_service.rb index 4761292d0..a9344d660 100644 --- a/app/services/line/incoming_message_service.rb +++ b/app/services/line/incoming_message_service.rb @@ -30,7 +30,7 @@ class Line::IncomingMessageService end def message_created?(event) - return unless event_type_message?(event) + return false unless event_type_message?(event) @message = @conversation.messages.build( content: message_content(event), diff --git a/app/services/message_templates/hook_execution_service.rb b/app/services/message_templates/hook_execution_service.rb index bc161d885..53e2e3a7e 100644 --- a/app/services/message_templates/hook_execution_service.rb +++ b/app/services/message_templates/hook_execution_service.rb @@ -66,10 +66,10 @@ class MessageTemplates::HookExecutionService end def should_send_csat_survey? - return unless csat_enabled_conversation? + return false unless csat_enabled_conversation? # only send CSAT once in a conversation - return if conversation.messages.where(content_type: :input_csat).present? + return false if conversation.messages.where(content_type: :input_csat).present? true end diff --git a/db/migrate/20230515051424_update_article_image_keys.rb b/db/migrate/20230515051424_update_article_image_keys.rb index db208470f..b80e6c86e 100644 --- a/db/migrate/20230515051424_update_article_image_keys.rb +++ b/db/migrate/20230515051424_update_article_image_keys.rb @@ -12,8 +12,8 @@ class ArticleKeyConverter def convert_key(id) verifier_name = 'ActiveStorage' - key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000, - hash_digest_class: OpenSSL::Digest::SHA1) + key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000, + hash_digest_class: OpenSSL::Digest::SHA1) key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator) secret = key_generator.generate_key(verifier_name.to_s) verifier = ActiveSupport::MessageVerifier.new(secret) diff --git a/enterprise/app/services/internal/reconcile_plan_config_service.rb b/enterprise/app/services/internal/reconcile_plan_config_service.rb index 3dcb4ba12..7934a5be6 100644 --- a/enterprise/app/services/internal/reconcile_plan_config_service.rb +++ b/enterprise/app/services/internal/reconcile_plan_config_service.rb @@ -16,7 +16,7 @@ class Internal::ReconcilePlanConfigService end def premium_config - @premium_config ||= YAML.safe_load(File.read("#{config_path}/premium_installation_config.yml")).freeze + @premium_config ||= YAML.safe_load_file("#{config_path}/premium_installation_config.yml").freeze end def remove_premium_config_reset_warning @@ -46,7 +46,7 @@ class Internal::ReconcilePlanConfigService end def premium_features - @premium_features ||= YAML.safe_load(File.read("#{config_path}/premium_features.yml")).freeze + @premium_features ||= YAML.safe_load_file("#{config_path}/premium_features.yml").freeze end def reconcile_premium_features diff --git a/enterprise/lib/captain/agent.rb b/enterprise/lib/captain/agent.rb index f0b511115..b548cede1 100644 --- a/enterprise/lib/captain/agent.rb +++ b/enterprise/lib/captain/agent.rb @@ -63,7 +63,7 @@ class Captain::Agent "Tool execution failed: #{e.message}" end - def construct_prompt(config) + def construct_prompt(config) # rubocop:disable Metrics/MethodLength return config[:prompt] if config[:prompt] <<~PROMPT diff --git a/lib/chatwoot_app.rb b/lib/chatwoot_app.rb index 37c90c19d..d4b614615 100644 --- a/lib/chatwoot_app.rb +++ b/lib/chatwoot_app.rb @@ -12,7 +12,7 @@ module ChatwootApp end def self.enterprise? - return if ENV.fetch('DISABLE_ENTERPRISE', false) + return false if ENV.fetch('DISABLE_ENTERPRISE', false) @enterprise ||= root.join('enterprise').exist? end diff --git a/lib/chatwoot_captcha.rb b/lib/chatwoot_captcha.rb index 37e852868..d2da7aabd 100644 --- a/lib/chatwoot_captcha.rb +++ b/lib/chatwoot_captcha.rb @@ -18,7 +18,7 @@ class ChatwootCaptcha secret: @server_key }) - return unless response.success? + return false unless response.success? response.parsed_response['success'] end diff --git a/lib/config_loader.rb b/lib/config_loader.rb index aa393067e..f637c4588 100644 --- a/lib/config_loader.rb +++ b/lib/config_loader.rb @@ -28,13 +28,13 @@ class ConfigLoader def general_configs @config_path ||= Rails.root.join('config') - @general_configs ||= YAML.safe_load(File.read("#{@config_path}/installation_config.yml")).freeze + @general_configs ||= YAML.safe_load_file("#{@config_path}/installation_config.yml").freeze end private def account_features - @account_features ||= YAML.safe_load(File.read("#{@config_path}/features.yml")).freeze + @account_features ||= YAML.safe_load_file("#{@config_path}/features.yml").freeze end def reconcile_general_config diff --git a/lib/integrations/bot_processor_service.rb b/lib/integrations/bot_processor_service.rb index 600ee4305..401c519ce 100644 --- a/lib/integrations/bot_processor_service.rb +++ b/lib/integrations/bot_processor_service.rb @@ -14,9 +14,9 @@ class Integrations::BotProcessorService private def should_run_processor?(message) - return if message.private? - return unless processable_message?(message) - return unless conversation.pending? + return false if message.private? + return false unless processable_message?(message) + return false unless conversation.pending? true end @@ -43,8 +43,8 @@ class Integrations::BotProcessorService def processable_message?(message) # TODO: change from reportable and create a dedicated method for this? - return unless message.reportable? - return if message.outgoing? && !processable_outgoing_message?(message) + return false unless message.reportable? + return false if message.outgoing? && !processable_outgoing_message?(message) true end diff --git a/package.json b/package.json index 4c30829f7..0111fe49b 100644 --- a/package.json +++ b/package.json @@ -160,8 +160,7 @@ }, "lint-staged": { "app/**/*.{js,vue}": [ - "eslint --fix", - "git add" + "eslint --fix" ], "*.scss": [ "scss-lint"