From 3988f2dade8a75cb642db8c239097bfcf8943a0d Mon Sep 17 00:00:00 2001 From: yhirano Date: Mon, 1 May 2017 23:31:02 +0900 Subject: [PATCH] Fix Rubocop offences (#2630) * disable Bundler/OrderedGems * fix rubocop Lint/UselessAssignment * fix rubocop Style/BlockDelimiters * fix rubocop Style/AlignHash * fix rubocop Style/AlignParameters, Style/EachWithObject * fix rubocop Style/SpaceInLambdaLiteral --- .rubocop.yml | 3 +++ app/controllers/auth/sessions_controller.rb | 2 +- app/controllers/concerns/localized.rb | 4 ++-- app/mailers/notification_mailer.rb | 10 +++++----- app/models/account.rb | 14 +++++++------- app/models/concerns/paginable.rb | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index bc43fee81a0..674865c4685 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -77,6 +77,9 @@ Style/Lambda: Rails/HasAndBelongsToMany: Enabled: false +Bundler/OrderedGems: + Enabled: false + AllCops: TargetRubyVersion: 2.3 Exclude: diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 09e67ec593c..4a5e0da6ef8 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -51,7 +51,7 @@ class Auth::SessionsController < Devise::SessionsController def valid_otp_attempt?(user) user.validate_and_consume_otp!(user_params[:otp_attempt]) || user.invalidate_otp_backup_code!(user_params[:otp_attempt]) - rescue OpenSSL::Cipher::CipherError => error + rescue OpenSSL::Cipher::CipherError => _error false end diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb index 44762df2af2..5501b6793be 100644 --- a/app/controllers/concerns/localized.rb +++ b/app/controllers/concerns/localized.rb @@ -17,9 +17,9 @@ module Localized end def default_locale - ENV.fetch('DEFAULT_LOCALE') { + ENV.fetch('DEFAULT_LOCALE') do user_supplied_locale || I18n.default_locale - } + end end def user_supplied_locale diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index a163edd3c0e..2bfc7772119 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -60,11 +60,11 @@ class NotificationMailer < ApplicationMailer I18n.with_locale(@me.user.locale || I18n.default_locale) do mail to: @me.user.email, - subject: I18n.t( - :subject, - scope: [:notification_mailer, :digest], - count: @notifications.size - ) + subject: I18n.t( + :subject, + scope: [:notification_mailer, :digest], + count: @notifications.size + ) end end end diff --git a/app/models/account.rb b/app/models/account.rb index 798042b3b4d..03584b4e645 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -75,12 +75,12 @@ class Account < ApplicationRecord scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') } delegate :email, - :current_sign_in_ip, - :current_sign_in_at, - :confirmed?, - to: :user, - prefix: true, - allow_nil: true + :current_sign_in_ip, + :current_sign_in_at, + :confirmed?, + to: :user, + prefix: true, + allow_nil: true def follow!(other_account) active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account) @@ -329,7 +329,7 @@ class Account < ApplicationRecord private def follow_mapping(query, field) - query.pluck(field).inject({}) { |mapping, id| mapping[id] = true; mapping } + query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true } end def avatar_styles(file) diff --git a/app/models/concerns/paginable.rb b/app/models/concerns/paginable.rb index b3df081c0c3..9e95cd649e4 100644 --- a/app/models/concerns/paginable.rb +++ b/app/models/concerns/paginable.rb @@ -4,7 +4,7 @@ module Paginable extend ActiveSupport::Concern included do - scope :paginate_by_max_id, -> (limit, max_id = nil, since_id = nil) { + scope :paginate_by_max_id, ->(limit, max_id = nil, since_id = nil) { query = order(arel_table[:id].desc).limit(limit) query = query.where(arel_table[:id].lt(max_id)) unless max_id.blank? query = query.where(arel_table[:id].gt(since_id)) unless since_id.blank?