Skip to content

Commit

Permalink
Rubocop update
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminSchaaf committed Jun 18, 2024
1 parent 50b1b31 commit 5542884
Show file tree
Hide file tree
Showing 58 changed files with 147 additions and 138 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ require: rubocop-rails

Rails:
Enabled: true
Rails/ActionOrder:
Enabled: false
Rails/I18nLocaleTexts:
Enabled: false
Rails/UniqueValidationWithoutIndex:
Enabled: false
Rails/ApplicationRecord:
Exclude:
- 'lib/**/*'
Expand Down Expand Up @@ -45,6 +51,8 @@ Style/FormatStringToken:
EnforcedStyle: template
Style/StringConcatenation:
Enabled: false
Style/NegatedIfElseCondition:
Enabled: false
Style/MixinUsage:
Exclude:
- 'bin/setup'
Expand All @@ -56,6 +64,8 @@ Naming/MethodParameterName:
MinNameLength: 2
AllowedNames:
- _
Naming/VariableNumber:
Enabled: false

# 'old' style
Style/EmptyMethod:
Expand Down
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'

gem 'rails', '~> 7.1.0'
gem 'sprockets-rails'
gem 'rake', '~> 12.0'
gem 'sprockets-rails'
# Use postgres
gem 'pg', '~> 1.0'
# Fast loading
Expand Down Expand Up @@ -79,9 +79,9 @@ group :test do
# Keep codebase clean
gem 'haml_lint', require: false
gem 'rails_best_practices', require: false
gem 'reek', '~> 5', require: false
gem 'rubocop', '~> 0.58', require: false
gem 'rubocop-rails', '~> 2.2.1', require: false
gem 'reek', '~> 6', require: false
gem 'rubocop', '~> 1.64.1', require: false
gem 'rubocop-rails', '~> 2.25.0', require: false

gem 'codecov', require: false
end
Expand Down
75 changes: 52 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ GEM
cocoon (1.2.15)
code_analyzer (0.5.5)
sexp_processor
codeclimate-engine-rb (0.4.2)
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
coffee-rails (5.0.0)
Expand Down Expand Up @@ -176,6 +175,33 @@ GEM
diff-lcs (1.5.1)
docile (1.4.0)
drb (2.2.1)
dry-configurable (1.1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-core (1.0.1)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-initializer (3.1.1)
dry-logic (1.5.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-schema (1.13.4)
concurrent-ruby (~> 1.0)
dry-configurable (~> 1.0, >= 1.0.1)
dry-core (~> 1.0, < 2)
dry-initializer (~> 3.0)
dry-logic (>= 1.4, < 2)
dry-types (>= 1.7, < 2)
zeitwerk (~> 2.6)
dry-types (1.7.2)
bigdecimal (~> 3.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
erubi (1.12.0)
erubis (2.7.0)
execjs (2.9.1)
Expand Down Expand Up @@ -224,7 +250,7 @@ GEM
thor (>= 0.14, < 2.0)
json (2.7.2)
jsonapi-renderer (0.2.2)
kwalify (0.7.2)
language_server-protocol (3.17.0.3)
launchy (3.0.1)
addressable (~> 2.8)
childprocess (~> 5.0)
Expand Down Expand Up @@ -283,11 +309,11 @@ GEM
parallel (1.24.0)
parallel_tests (4.7.1)
parallel
parser (2.7.2.0)
parser (3.3.3.0)
ast (~> 2.4.1)
racc
pg (1.5.6)
popper_js (1.16.1)
psych (3.1.0)
public_suffix (5.0.5)
racc (1.8.0)
rack (2.2.9)
Expand Down Expand Up @@ -342,12 +368,11 @@ GEM
rake (12.3.3)
rdoc (6.3.4.1)
redcarpet (3.6.0)
reek (5.6.0)
codeclimate-engine-rb (~> 0.4.0)
kwalify (~> 0.7.0)
parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
psych (~> 3.1.0)
reek (6.3.0)
dry-schema (~> 1.13.0)
parser (~> 3.3.0)
rainbow (>= 2.0, < 4.0)
rexml (~> 3.1)
regexp_parser (2.9.2)
reline (0.5.7)
io-console (~> 0.5)
Expand Down Expand Up @@ -378,20 +403,24 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (0.93.1)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-rails (2.2.1)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-rails (2.25.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.72.0)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-openid (2.9.2)
ruby-progressbar (1.13.0)
ruby-vips (2.2.1)
Expand Down Expand Up @@ -444,7 +473,7 @@ GEM
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.8.0)
unicode-display_width (2.5.0)
uniform_notifier (1.16.0)
warden (1.2.9)
rack (>= 2.0.9)
Expand Down Expand Up @@ -501,10 +530,10 @@ DEPENDENCIES
rails_best_practices
rake (~> 12.0)
redcarpet
reek (~> 5)
reek (~> 6)
rspec-rails (~> 6)
rubocop (~> 0.58)
rubocop-rails (~> 2.2.1)
rubocop (~> 1.64.1)
rubocop-rails (~> 2.25.0)
sass-rails (~> 6)
scanf
shoulda-matchers
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ begin
RuboCop::RakeTask.new
Reek::Rake::Task.new

task :rbp do
task rbp: [:environment] do
require 'rails_best_practices'

app_root = Rake.application.original_dir
Expand All @@ -34,7 +34,7 @@ rescue LoadError
puts 'Test tasks not available'
end

task :log do
task log: [:environment] do
ActiveRecord::Base.logger = Logger.new($stdout)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/forums/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def user_can_manage_topic?(topic = nil)

return user_can_manage_forums? unless topic

user_signed_in? && (topic.not_isolated? && user_can_manage_forums? ||
user_signed_in? && ((topic.not_isolated? && user_can_manage_forums?) ||
user_can_manage_topics?(topic.ancestors) ||
current_user.can?(:manage, topic))
end
Expand Down Expand Up @@ -41,7 +41,7 @@ def user_can_manage_thread?(thread = nil)

return user_can_manage_forums? unless thread

user_signed_in? && (thread.not_isolated? && user_can_manage_forums? ||
user_signed_in? && ((thread.not_isolated? && user_can_manage_forums?) ||
user_can_manage_topics?(thread.ancestors) ||
current_user.can?(:manage, thread))
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concerns/leagues/match_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def user_can_either_teams?
def user_can_confirm_score?
status = @match.status

user_can_home_team? && status == 'submitted_by_away_team' ||
user_can_away_team? && status == 'submitted_by_home_team'
(user_can_home_team? && status == 'submitted_by_away_team') ||
(user_can_away_team? && status == 'submitted_by_home_team')
end

def user_can_submit_team_score?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/leagues/roster_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def user_can_edit_roster?(roster = nil)
disbanded = roster&.disbanded?

user_can_edit_league?(roster.league) ||
user_signed_in? && current_user.can?(:edit, roster.team) && user_not_banned? && !disbanded
(user_signed_in? && current_user.can?(:edit, roster.team) && user_not_banned? && !disbanded)
end

def user_can_disband_roster?(roster = nil)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/team_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def user_can_create_team?
def user_can_edit_team?(team = nil)
team ||= @team

user_signed_in? && current_user.can?(:edit, team) && current_user.can?(:use, :teams) ||
(user_signed_in? && current_user.can?(:edit, team) && current_user.can?(:use, :teams)) ||
user_can_edit_teams?
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/users_permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module UsersPermissions
extend ActiveSupport::Concern

def user_can_edit_user?
user_signed_in? && current_user == @user && current_user.can?(:use, :users) ||
(user_signed_in? && current_user == @user && current_user.can?(:use, :users)) ||
user_can_edit_users?
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/leagues/transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def index
def update
Transfers::ApprovalService.call(@transfer_request, current_user)

flash[:error] = @transfer_request.errors.full_messages.first
flash.now[:error] = @transfer_request.errors.full_messages.first
index
render :index
end

def destroy
Transfers::DenialService.call(@transfer_request, current_user)

flash[:error] = @transfer_request.errors.full_messages.first
flash.now[:error] = @transfer_request.errors.full_messages.first
index
render :index
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/permissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def users

excluded_users = users_which_can.select(:id)
@users_without_permission = target_users.search(params[:q])
.where('users.id NOT IN (?)', excluded_users)
.where.not(users: { id: excluded_users })
.paginate(page: params[:page])
end

Expand Down Expand Up @@ -85,10 +85,10 @@ def user_can_edit_permissions?
end

def ensure_valid_target
redirect_back if subject? && ![:team, :forums_topic].include?(@subject)
redirect_back if subject? && [:team, :forums_topic].exclude?(@subject)
end

def redirect_back(options = {})
super(**{ fallback_location: permissions_path }.merge(options))
super(fallback_location: permissions_path, **options)
end
end
6 changes: 3 additions & 3 deletions app/helpers/forums/topics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module Forums
module TopicsHelper
include Forums::Permissions

ISOLATE_CONFIRM_MESSAGE = "Are you sure you want to unisolate this Topic?\n"\
ISOLATE_CONFIRM_MESSAGE = "Are you sure you want to unisolate this Topic?\n" \
'This means any admin will be able to manage this Topic.'.freeze

UNISOLATE_CONFIRM_MESSAGE = "Are you sure you want to isolate this Topic?\n"\
'This means only you and anyone you give access '\
UNISOLATE_CONFIRM_MESSAGE = "Are you sure you want to isolate this Topic?\n" \
'This means only you and anyone you give access ' \
'to will be able to manage this Topic.'.freeze
end
end
2 changes: 1 addition & 1 deletion app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class APIKey < ApplicationRecord
belongs_to :user, optional: true

validates :name, allow_blank: true, length: { maximum: 64 }
validates :user, allow_nil: true, uniqueness: true
# validates :user, allow_nil: true, uniqueness: true
validates :key, presence: true

before_validation :generate_unique_key, on: :create
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def paths
class_methods do
attr_reader :paths_class

# rubocop:disable Metrics/MethodLength, Lint/MissingSuper
# rubocop:disable Metrics/MethodLength
def paths(&block)
@paths_class = Class.new do
include Rails.application.routes.url_helpers
Expand Down Expand Up @@ -40,6 +40,6 @@ def method_missing(method, *args, &block)

@paths_class.class_eval(&block)
end
# rubocop:enable Metrics/MethodLength, Lint/MissingSuper
# rubocop:enable Metrics/MethodLength
end
end
2 changes: 1 addition & 1 deletion app/models/forums/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.page_of(post)
return 1 unless post

post_index = post.thread.posts.where('created_at < ?', post.created_at).count
post_index / Post.per_page + 1
(post_index / Post.per_page) + 1
end
end
end
5 changes: 2 additions & 3 deletions app/models/forums/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ class Thread < ApplicationRecord
'forums_threads.hidden' => nil,
}

after_initialize :set_defaults, unless: :persisted?
before_create :update_depth
before_update :update_depth, if: :topic_id_changed?

after_initialize :set_defaults, unless: :persisted?

before_update do
if hidden_changed?
sign = hidden? ? :- : :+
ActiveRecord::Base.connection.exec_update(<<-SQL, 'SQL', [id])
ActiveRecord::Base.connection.exec_update(<<-SQL.squish, 'SQL', [id])
UPDATE users
SET public_forums_posts_count = public_forums_posts_count #{sign} (
SELECT COUNT(1) FROM forums_posts WHERE thread_id = $1 AND created_by_id = users.id)
Expand Down
Loading

0 comments on commit 5542884

Please sign in to comment.