Skip to content

Commit

Permalink
Update rubocop deps (#2254)
Browse files Browse the repository at this point in the history
* Update rubocop dependencies

* Update rubocop channel on .codeclimate.yml

* Run rubocop autocorrections
  • Loading branch information
julianguyen authored Oct 14, 2023
1 parent cf00157 commit 751b6ca
Show file tree
Hide file tree
Showing 72 changed files with 230 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins:
enabled: false
rubocop:
enabled: true
channel: rubocop-0-71
channel: rubocop-1-56-3
ratings:
paths:
- Gemfile.lock
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require:
- rubocop-rails
- rubocop-performance
- rubocop-rspec
- rubocop-capybara
- rubocop-factory_bot

AllCops:
NewCops: enable
Expand Down
43 changes: 27 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws_cf_signer (0.1.3)
base64 (0.1.1)
bcrypt (3.1.13)
better_errors (2.9.1)
coderay (>= 1.0.0)
Expand Down Expand Up @@ -215,7 +216,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.6.2)
json (2.6.3)
jwt (2.5.0)
kaminari (1.2.1)
activesupport (>= 4.1.0)
Expand All @@ -229,6 +230,7 @@ GEM
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
language_server-protocol (3.17.0.3)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
Expand All @@ -246,7 +248,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mini_mime (1.1.2)
minitest (5.19.0)
minitest (5.20.0)
mono_logger (1.1.0)
multi_json (1.15.0)
multi_xml (0.6.0)
Expand Down Expand Up @@ -295,9 +297,10 @@ GEM
omniauth (~> 2.0)
orm_adapter (0.5.0)
os (1.1.4)
parallel (1.22.1)
parser (3.1.2.1)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
pg (1.1.4)
premailer (1.18.0)
addressable
Expand Down Expand Up @@ -404,7 +407,7 @@ GEM
redis (4.8.0)
redis-namespace (1.9.0)
redis (>= 4)
regexp_parser (2.6.0)
regexp_parser (2.8.2)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
Expand Down Expand Up @@ -461,30 +464,38 @@ GEM
rspec-support (3.11.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.37.1)
rubocop (1.57.1)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.23.0, < 2.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.23.0)
parser (>= 3.1.1.0)
rubocop-performance (1.15.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.17.1)
rubocop-rails (2.21.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.14.2)
rubocop-rspec (2.24.1)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (1.3.0)
rufus-scheduler (3.8.2)
Expand Down Expand Up @@ -564,7 +575,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.3.0)
unicode-display_width (2.5.0)
uniform_notifier (1.16.0)
vegas (0.1.11)
rack (>= 1.0.0)
Expand Down
42 changes: 20 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,28 @@ end

desc 'Automate the Config Setup for New Environments'
task setup_workspace: :environment do
begin
SECRETS = {
SECRET_KEY_BASE: generate_secret,
DEVISE_SECRET_KEY: generate_secret
}.freeze

%w[development test].each do |environment|
example = Rails.root.join('config', 'env', "#{environment}.example.env")
target = Rails.root.join('config', 'env', "#{environment}.env")
FileUtils.cp(example, target)

# insert the secrets into the file
content = File.read(target)
%w[SECRET_KEY_BASE DEVISE_SECRET_KEY].each do |key|
content.sub!(%(#{key}=""), %(#{key}="#{SECRETS[key.to_sym]}"))
end
File.write(target, content)
SECRETS = {
SECRET_KEY_BASE: generate_secret,
DEVISE_SECRET_KEY: generate_secret
}.freeze

%w[development test].each do |environment|
example = Rails.root.join('config', 'env', "#{environment}.example.env")
target = Rails.root.join('config', 'env', "#{environment}.env")
FileUtils.cp(example, target)

# insert the secrets into the file
content = File.read(target)
%w[SECRET_KEY_BASE DEVISE_SECRET_KEY].each do |key|
content.sub!(%(#{key}=""), %(#{key}="#{SECRETS[key.to_sym]}"))
end

puts "Workspace setup completed successfully 🎉"
rescue StandardError => e
puts "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
Rails.logger.error "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
File.write(target, content)
end

puts 'Workspace setup completed successfully 🎉'
rescue StandardError => e
puts "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
Rails.logger.error "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
end

# Run the secret task, grab the output, strip the new lines
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/allies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def index

def add
AllyshipCreator.perform(ally_id: params[:ally_id],
current_user: current_user)
current_user:)
redirect_to_path(allies_path)
end

def remove
user_id = current_user.id
ally_id = params[:ally_id].to_i
Allyship.where(user_id: user_id, ally_id: ally_id).destroy_all
Allyship.where(user_id:, ally_id:).destroy_all
redirect_to_path(allies_path)
end
end
8 changes: 3 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ApplicationController < ActionController::Base

private

def with_timezone
def with_timezone(&)
timezone = Time.find_zone(cookies[:timezone])
Time.use_zone(timezone) { yield }
Time.use_zone(timezone, &)
end

def set_locale
Expand Down Expand Up @@ -64,9 +64,7 @@ def configure_for_accept_invitation
end

def after_sign_in_path_for(resource)
if resource.respond_to?(:pwned?) && resource.pwned?
cookies[:pwned] = { value: true, expires: Time.current + 10.minutes }
end
cookies[:pwned] = { value: true, expires: 10.minutes.from_now } if resource.respond_to?(:pwned?) && resource.pwned?

super
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def delete

def remove_meeting_notification!(comment_id)
CommentNotificationsService.remove(
comment_id: comment_id,
comment_id:,
model_name: 'Meeting'
)
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/concerns/moments_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def saving_as_draft?

def empty_array_for(*symbols)
symbols.each do |symbol|
if moment_params[symbol].nil? && @moment.has_attribute?(symbol)
@moment[symbol] = []
end
@moment[symbol] = [] if moment_params[symbol].nil? && @moment.has_attribute?(symbol)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def format_success(format, model_object, is_update)
path = show_path(model_object)
format.html { redirect_to path }
status = is_update ? :ok : :created
format.json { render :show, status: status, location: model_object }
format.json { render :show, status:, location: model_object }
end

def format_failure(format, model_object, is_update)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/concerns/strategies_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def render_errors(strategy)

def empty_array_for(*symbols)
symbols.each do |symbol|
if strategy_params[symbol].nil? && @strategy.has_attribute?(symbol)
@strategy[symbol] = []
end
@strategy[symbol] = [] if strategy_params[symbol].nil? && @strategy.has_attribute?(symbol)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/groups/memberships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create

flash[:notice] = t('groups.join.success')
redirect_to_group
rescue
rescue StandardError
flash[:alert] = t('groups.join.group_not_exists')
redirect_to groups_path
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def index
# GET /groups/1
# GET /groups/1.json
def show
if @group.members.include? current_user
@meetings = @group.meetings.includes(:leaders)
end
@meetings = @group.meetings.includes(:leaders) if @group.members.include? current_user

@page_new = t('meetings.new') if @group.led_by?(current_user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/medications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def add_refill(medication)
dosage = @medication&.dosage || medication[:dosage]
no_of_days = total.to_i / dosage.to_i
no_of_weeks = no_of_days.to_i / weekly_dosage.length
days = 7 * no_of_weeks + (no_of_days % weekly_dosage.length)
days = (7 * no_of_weeks) + (no_of_days % weekly_dosage.length)
Time.zone.now.strftime('%d/%m/%Y').to_date + days - 1
end

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def leave
# Cannot leave When you are the only leader
if meeting.led_by?(current_user) && meeting.leaders.count == 1
redirect_to(group_path(meeting.group_id),
alert: t('meetings.leave.error'))
alert: t('.error'))
else
# Remove user from meeting
meeting.meeting_members.find_by(user_id: current_user.id).destroy
redirect_to(group_path(meeting.group_id),
notice: t('meetings.leave.success', meeting: meeting.name))
notice: t('.success', meeting: meeting.name))
end
end

Expand Down Expand Up @@ -107,10 +107,10 @@ def meeting_params

def send_notification(meeting, members, type)
MeetingNotificationsService.handle_members(
current_user: current_user,
meeting: meeting,
type: type,
members: members
current_user:,
meeting:,
type:,
members:
)
end

Expand Down
6 changes: 2 additions & 4 deletions app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def show
show_with_comments(@moment)
resources_data = get_resources_data(@moment, current_user)
@resources = ResourceRecommendations.new(
moment: @moment, current_user: current_user
moment: @moment, current_user:
).call
@show_crisis_prevention = resources_data[:show_crisis_prevention]
@resources_tags = resources_data[:tags]
Expand All @@ -41,9 +41,7 @@ def new

# GET /moments/1/edit
def edit
unless @moment.user_id == current_user.id
redirect_to_path(moment_path(@moment))
end
redirect_to_path(moment_path(@moment)) unless @moment.user_id == current_user.id
set_association_variables!
end

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/profile_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def remove_ban
private

def update_and_email(user, banned)
user.update(banned: banned)
user.update(banned:)
if banned
BannedMailer.add_ban_email(user).deliver_now
else
Expand All @@ -53,8 +53,8 @@ def ban(banned)

def notice_or_alert(user, notice)
name = user&.name || params[:user_id]
return { notice: t("reports.#{notice}", name: name) } if user.present?
return { notice: t("reports.#{notice}", name:) } if user.present?

{ alert: t("reports.#{notice}_error", name: name) }
{ alert: t("reports.#{notice}_error", name:) }
end
end
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def posts
private

def search_by_email(email)
User.where(email: email)
User.where(email:)
.where.not(id: current_user.id)
.where.not(banned: true)
end
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/secret_shares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
class SecretSharesController < ApplicationController
skip_before_action :if_not_signed_in, only: [:show]

def show
@moment = Moment.find_secret_share!(params[:id])
@page_author = User.find(@moment.user_id)
render 'moments/show'
end

def create
# Authorisation check will automatically raise ActiveRecord::RecordNotFound
moment = Moment.where(user: current_user).friendly.find(params[:moment])
Expand All @@ -13,12 +19,6 @@ def create
redirect_to moment_path(moment, anchor: 'secretShare')
end

def show
@moment = Moment.find_secret_share!(params[:id])
@page_author = User.find(@moment.user_id)
render 'moments/show'
end

def destroy
moment = Moment.find_by!(user: current_user, id: params[:id])
moment.update!(secret_share_identifier: nil)
Expand Down
Loading

0 comments on commit 751b6ca

Please sign in to comment.