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
This commit is contained in:
Gabriel Jablonski 2025-02-14 11:45:12 -03:00 committed by gabrieljablonski
parent 1d6b15b23d
commit 52a55827c3
32 changed files with 54 additions and 51 deletions

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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?

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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),

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -18,7 +18,7 @@ class ChatwootCaptcha
secret: @server_key
})
return unless response.success?
return false unless response.success?
response.parsed_response['success']
end

View File

@ -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

View File

@ -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

View File

@ -160,8 +160,7 @@
},
"lint-staged": {
"app/**/*.{js,vue}": [
"eslint --fix",
"git add"
"eslint --fix"
],
"*.scss": [
"scss-lint"