Skip to content

Commit

Permalink
Rubocop updates (#1118)
Browse files Browse the repository at this point in the history
* Minimal code style enforcement

* Formatting and lint code updates (no change in functionality)
  • Loading branch information
zachgoll committed Aug 23, 2024
1 parent 359bceb commit eef4c26
Show file tree
Hide file tree
Showing 41 changed files with 533 additions and 523 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
25 changes: 14 additions & 11 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Omakase Ruby styling for Rails
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
inherit_gem:
rubocop-rails-omakase: rubocop.yml

Layout/IndentationWidth:
Enabled: true

# Overwrite or add rules to create your own house style
#
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
# Layout/SpaceInsideArrayLiteralBrackets:
# Enabled: false
Layout/ElseAlignment:
Enabled: false
Layout/EndAlignment:
Enabled: false
Layout/IndentationStyle:
EnforcedStyle: spaces
IndentationWidth: 2

Layout/IndentationConsistency:
Enabled: true

Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: true
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ gem "inline_svg"
gem "octokit"
gem "pagy"
gem "rails-settings-cached"
gem "tzinfo-data", platforms: %i[ windows jruby ]
gem "tzinfo-data", platforms: %i[windows jruby]
gem "csv"
gem "redcarpet"

group :development, :test do
gem "debug", platforms: %i[ mri windows ]
gem "debug", platforms: %i[mri windows]
gem "brakeman", require: false
gem "rubocop-rails-omakase", require: false
gem "i18n-tasks"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/account/entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Account::EntriesController < ApplicationController
layout :with_sidebar

before_action :set_account
before_action :set_entry, only: %i[ edit update show destroy ]
before_action :set_entry, only: %i[edit update show destroy]

def edit
render entryable_view_path(:edit)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/account/trades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def new
end

def index
@entries = @account.entries.reverse_chronological.where(entryable_type: %w[ Account::Trade Account::Transaction ])
@entries = @account.entries.reverse_chronological.where(entryable_type: %w[Account::Trade Account::Transaction])
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AccountsController < ApplicationController
layout :with_sidebar

include Filterable
before_action :set_account, only: %i[ edit show destroy sync update ]
before_action :set_account, only: %i[edit show destroy sync update]

def index
@institutions = Current.family.institutions
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CategoriesController < ApplicationController
layout :with_sidebar

before_action :set_category, only: %i[ edit update ]
before_action :set_category, only: %i[edit update]
before_action :set_transaction, only: :create

def index
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/category/dropdowns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ def show
end

private
def set_from_params
if params[:category_id]
@selected_category = categories_scope.find(params[:category_id])
end
def set_from_params
if params[:category_id]
@selected_category = categories_scope.find(params[:category_id])
end

if params[:transaction_id]
@transaction = Current.family.transactions.find(params[:transaction_id])
if params[:transaction_id]
@transaction = Current.family.transactions.find(params[:transaction_id])
end
end
end

def categories_scope
Current.family.categories.alphabetically
end
def categories_scope
Current.family.categories.alphabetically
end
end
38 changes: 19 additions & 19 deletions app/controllers/concerns/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ def skip_authentication(**options)

private

def authenticate_user!
if user = User.find_by(id: session[:user_id])
Current.user = user
else
redirect_to new_session_url
def authenticate_user!
if user = User.find_by(id: session[:user_id])
Current.user = user
else
redirect_to new_session_url
end
end
end

def login(user)
Current.user = user
reset_session
session[:user_id] = user.id
set_last_login_at
end
def login(user)
Current.user = user
reset_session
session[:user_id] = user.id
set_last_login_at
end

def logout
Current.user = nil
reset_session
end
def logout
Current.user = nil
reset_session
end

def set_last_login_at
Current.user.update(last_login_at: DateTime.now)
end
def set_last_login_at
Current.user.update(last_login_at: DateTime.now)
end
end
8 changes: 4 additions & 4 deletions app/controllers/concerns/filterable.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Filterable
extend ActiveSupport::Concern
extend ActiveSupport::Concern

included do
before_action :set_period
end
included do
before_action :set_period
end

private

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/imports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "ostruct"

class ImportsController < ApplicationController
before_action :set_import, except: %i[ index new create ]
before_action :set_import, except: %i[index new create]

def index
@imports = Current.family.imports
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/institutions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class InstitutionsController < ApplicationController
before_action :set_institution, except: %i[ new create ]
before_action :set_institution, except: %i[new create]

def new
@institution = Institution.new
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MerchantsController < ApplicationController
layout :with_sidebar

before_action :set_merchant, only: %i[ edit update destroy ]
before_action :set_merchant, only: %i[edit update destroy]

def index
@merchants = Current.family.merchants.alphabetically
Expand Down Expand Up @@ -31,11 +31,11 @@ def destroy

private

def set_merchant
@merchant = Current.family.merchants.find(params[:id])
end
def set_merchant
@merchant = Current.family.merchants.find(params[:id])
end

def merchant_params
params.require(:merchant).permit(:name, :color)
end
def merchant_params
params.require(:merchant).permit(:name, :color)
end
end
16 changes: 8 additions & 8 deletions app/controllers/password_resets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PasswordResetsController < ApplicationController

layout "auth"

before_action :set_user_by_token, only: %i[ edit update ]
before_action :set_user_by_token, only: %i[edit update]

def new
end
Expand Down Expand Up @@ -33,12 +33,12 @@ def update

private

def set_user_by_token
@user = User.find_by_token_for(:password_reset, params[:token])
redirect_to new_password_reset_path, alert: t("password_resets.update.invalid_token") unless @user.present?
end
def set_user_by_token
@user = User.find_by_token_for(:password_reset, params[:token])
redirect_to new_password_reset_path, alert: t("password_resets.update.invalid_token") unless @user.present?
end

def password_params
params.require(:user).permit(:password, :password_confirmation)
end
def password_params
params.require(:user).permit(:password, :password_confirmation)
end
end
6 changes: 3 additions & 3 deletions app/controllers/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def update

private

def password_params
params.require(:user).permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
end
def password_params
params.require(:user).permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
end
end
20 changes: 10 additions & 10 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def create

private

def set_user
@user = User.new user_params.except(:invite_code)
end
def set_user
@user = User.new user_params.except(:invite_code)
end

def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :invite_code)
end
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :invite_code)
end

def claim_invite_code
unless InviteCode.claim! params[:user][:invite_code]
redirect_to new_registration_path, alert: t("registrations.create.invalid_invite_code")
def claim_invite_code
unless InviteCode.claim! params[:user][:invite_code]
redirect_to new_registration_path, alert: t("registrations.create.invalid_invite_code")
end
end
end
end
8 changes: 4 additions & 4 deletions app/controllers/settings/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def destroy

private

def user_params
params.require(:user).permit(:first_name, :last_name, :profile_image,
family_attributes: [ :name, :id ])
end
def user_params
params.require(:user).permit(:first_name, :last_name, :profile_image,
family_attributes: [ :name, :id ])
end
end
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class TagsController < ApplicationController
layout :with_sidebar

before_action :set_tag, only: %i[ edit update ]
before_action :set_tag, only: %i[edit update]

def index
@tags = Current.family.tags.alphabetically
Expand Down
16 changes: 8 additions & 8 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class ApplicationMailer < ActionMailer::Base

private

def set_self_host_settings
mail.from = Setting.email_sender
mail.delivery_method.settings.merge!({ address: Setting.smtp_host,
port: Setting.smtp_port,
user_name: Setting.smtp_username,
password: Setting.smtp_password,
tls: ENV.fetch("SMTP_TLS_ENABLED", "true") == "true" })
end
def set_self_host_settings
mail.from = Setting.email_sender
mail.delivery_method.settings.merge!({ address: Setting.smtp_host,
port: Setting.smtp_port,
user_name: Setting.smtp_username,
password: Setting.smtp_password,
tls: ENV.fetch("SMTP_TLS_ENABLED", "true") == "true" })
end
end
12 changes: 6 additions & 6 deletions app/models/account/balance.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Account::Balance < ApplicationRecord
include Monetizable
include Monetizable

belongs_to :account
validates :account, :date, :balance, presence: true
monetize :balance
scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }
scope :chronological, -> { order(:date) }
belongs_to :account
validates :account, :date, :balance, presence: true
monetize :balance
scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }
scope :chronological, -> { order(:date) }
end
2 changes: 1 addition & 1 deletion app/models/account/entry_builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Account::EntryBuilder
include ActiveModel::Model

TYPES = %w[ income expense buy sell interest transfer_in transfer_out ].freeze
TYPES = %w[income expense buy sell interest transfer_in transfer_out].freeze

attr_accessor :type, :date, :qty, :ticker, :price, :amount, :currency, :account, :transfer_account_id

Expand Down
2 changes: 1 addition & 1 deletion app/models/account/entryable.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Account::Entryable
extend ActiveSupport::Concern

TYPES = %w[ Account::Valuation Account::Transaction Account::Trade ]
TYPES = %w[Account::Valuation Account::Transaction Account::Trade]

def self.from_type(entryable_type)
entryable_type.presence_in(TYPES).constantize
Expand Down
2 changes: 1 addition & 1 deletion app/models/account/trade_builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Account::TradeBuilder < Account::EntryBuilder
include ActiveModel::Model

TYPES = %w[ buy sell ].freeze
TYPES = %w[buy sell].freeze

attr_accessor :type, :qty, :price, :ticker, :date, :account

Expand Down
2 changes: 1 addition & 1 deletion app/models/account/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def requires_search?(params)
private

def searchable_keys
%i[ categories merchants ]
%i[categories merchants]
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/account/transaction_builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Account::TransactionBuilder
include ActiveModel::Model

TYPES = %w[ income expense interest transfer_in transfer_out ].freeze
TYPES = %w[income expense interest transfer_in transfer_out].freeze

attr_accessor :type, :amount, :date, :account, :transfer_account_id

Expand Down
Loading

0 comments on commit eef4c26

Please sign in to comment.