Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce new RuboCop cops for all Ruby files #566

Merged
merged 56 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b067b2f
Let RuboCop autocorrect all Ruby files (safe)
Splines Nov 25, 2023
4bb1d27
Revert "Let RuboCop autocorrect all Ruby files (safe)"
Splines Dec 3, 2023
3036172
Force use of explicit hash literal value (HashSyntax)
Splines Dec 3, 2023
ba78285
Only correct string literals to double quotes (safe)
Splines Dec 3, 2023
63443df
Allow use of method ".touch"
Splines Dec 3, 2023
e4f4bad
Autocorrect all other specified cops (safe)
Splines Dec 3, 2023
2758444
Fix Layout/IndentationConsistency (manual)
Splines Dec 3, 2023
51880ec
Fix (or disable) Layout/LineLength
Splines Dec 3, 2023
5081aaa
Fix all Style/ cops
Splines Dec 3, 2023
be71912
Fix Lint/ cops (3 still left open)
Splines Dec 3, 2023
9907630
Rename `get_votes_count` to `votes_count`
Splines Dec 3, 2023
6c4f737
Fix other Naming/ cops (1 still left open)
Splines Dec 3, 2023
dfd8b36
Disable `Rails/HelperInstanceVariable` in `quizzes_helper.rb`
Splines Dec 3, 2023
2b4a33f
Fix all Rails/InverseOf cops
Splines Dec 3, 2023
ee50c57
Disable Rails/ cops in existing db migrations
Splines Dec 3, 2023
accc5c9
Fix Rails/SkipsModelValidations (1 left open)
Splines Dec 3, 2023
6d0b455
Disable Rails/OutputSafety for one line
Splines Dec 3, 2023
611c73a
Fix Rails/I18n related cops
Splines Dec 3, 2023
f469316
Add custom env variable to rubocop
Splines Dec 3, 2023
3b48087
Disable Performance/CollectionLiteralInLoop in some tests
Splines Dec 3, 2023
3809c1b
Merge two duplicates groups in Gemfile together
Splines Dec 3, 2023
fa98d4a
Automatically autocorrect cops (unsafe)
Splines Dec 3, 2023
bdbba5c
Fix missing `Time.zone.now`
Splines Dec 3, 2023
f15424b
Add Style/MethodCallWithArgsParentheses and autofix (safe)
Splines Dec 3, 2023
4f1378c
Fix Layout/ cops
Splines Dec 3, 2023
f283b71
Fix or disable Style/ cops
Splines Dec 3, 2023
bc3c6b5
Delete weird random character
Splines Dec 3, 2023
e5a4fac
Fix Security/ cops
Splines Dec 3, 2023
9bf3662
Fix Performance/ cops
Splines Dec 3, 2023
66a7062
Fix wrong namespace for a cop
Splines Dec 3, 2023
de74556
Manually ignore more db/ cop violations
Splines Dec 3, 2023
64c503f
Delete empty test files
Splines Dec 3, 2023
2c52305
Fix line to long
Splines Dec 3, 2023
eb2189b
Temporarily disable Rails/LexicallyScopedActionFilter
Splines Dec 3, 2023
cb2fa14
Fix <= logical bug (registration threshold)
Splines Dec 5, 2023
84ad08f
remove duplicated restricted? method
fosterfarrell9 Dec 6, 2023
8cee213
change private methods to non-private methods
fosterfarrell9 Dec 7, 2023
a6565e1
remove duplicate method
fosterfarrell9 Dec 8, 2023
120e7dd
fix typo
fosterfarrell9 Dec 8, 2023
c3abe9f
change inverse_of relation
fosterfarrell9 Dec 8, 2023
2a730ff
fix existing inverse_of associations
fosterfarrell9 Dec 8, 2023
2c43ba1
rename duplicate announcements method
fosterfarrell9 Dec 8, 2023
329d8e2
undo premature change
fosterfarrell9 Dec 8, 2023
a9bd956
add namespace to constant
fosterfarrell9 Dec 8, 2023
0560c5e
remove unnecessary logging
fosterfarrell9 Dec 9, 2023
581cacf
remove non existing action from before filter
fosterfarrell9 Dec 9, 2023
c5b624e
Rewrite new registrations query with timeframe
Splines Dec 11, 2023
4616974
Allow touch_all method and replace problematic update calls
Splines Dec 11, 2023
82c572e
Disable Rails/HasManyOrHasOneDependent rule
Splines Dec 11, 2023
3ae975d
Fix unwanted "," character
Splines Dec 11, 2023
df44b9d
Get rid of weird "foo" check
Splines Dec 11, 2023
9fa990a
remove unused restricted? methods
fosterfarrell9 Dec 12, 2023
58874f7
Replace problematic touch_all by touch
Splines Dec 14, 2023
c8addbf
Fix wrong manual Style/ correction of 5081aaa
Splines Dec 14, 2023
b26b11f
Fix Rails/OutputSafety
Splines Dec 14, 2023
eb92c86
Remove duplicate dates before save
Splines Dec 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
124 changes: 62 additions & 62 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.4'
ruby "3.1.4"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "rails", "~> 7.0.4.3"
Expand Down Expand Up @@ -32,113 +32,113 @@ gem "jbuilder"
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem "active_model_serializers"
gem "bootsnap", ">= 1.4.2", require: false
gem "rack"
gem "active_model_serializers"
# Use CoffeeScript for .coffee assets and views
gem "coffee-rails", "~> 5.0.0"

# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
gem "shrine"
gem "fastimage"
gem "streamio-ffmpeg"
gem "pdf-reader"
gem "mini_magick"
gem "image_processing"
gem "mini_magick"
gem "pdf-reader"
gem "shrine"
gem "streamio-ffmpeg"
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem "filesize"
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem "rgl"
gem "responders"
gem "pg"
gem "devise"
gem "erubis"
gem "cancancan"
gem "jquery-rails"
gem "jquery-ui-rails"
gem "js-routes", '1.4.9'
gem "activerecord-import",
git: "https://github.com/zdennis/activerecord-import.git",
branch: "master"
gem "acts_as_list"
gem "acts_as_tree"
gem "acts_as_votable"
gem "barby"
gem "bootstrap", "~>5"
gem "bootstrap_form"
gem "cancancan"
gem "clipboard-rails"
gem "commontator"
gem "coveralls", require: false
gem "devise"
gem "devise-bootstrap-views"
gem "erubis"
gem "exception_handler", "~> 0.8.0.0"
gem "faraday", "~> 1.8"
gem "fuzzy-string-match"
gem "coveralls", require: false
gem "globalize"
gem "globalize-accessors"
gem "jquery-rails"
gem "jquery-ui-rails"
gem "js-routes", "1.4.9"
gem "kaminari"
gem "acts_as_list"
gem "acts_as_tree"
gem "activerecord-import",
git: "https://github.com/zdennis/activerecord-import.git",
branch: "master"
gem "thredded"
gem "kramdown-parser-gfm"
gem "thredded-markdown_katex",
git: "https://github.com/thredded/thredded-markdown_katex.git",
branch: "main"
gem "rails-i18n"
gem "kaminari-i18n"
gem "trix-rails", require: "trix"
gem "sunspot_rails",
github: 'sunspot/sunspot',
glob: 'sunspot_rails/*.gemspec'
gem "sunspot_solr"
gem "kramdown-parser-gfm"
gem "net-smtp"
gem "pg"
gem "premailer-rails"
gem "progress_bar"
gem "barby"
gem "rails-i18n"
gem "responders"
gem "rgl"
gem "rqrcode"
gem "rubyzip", "~> 2.3.0"
gem "sidekiq"
gem "sidekiq-cron", "~> 1.1"
gem "faraday", "~> 1.8"
gem "globalize"
gem "globalize-accessors"
gem "commontator"
gem "acts_as_votable"
gem "sprockets-rails",
git: "https://github.com/rails/sprockets-rails",
branch: "master"
gem "premailer-rails"
gem "clipboard-rails"
gem "rubyzip", "~> 2.3.0"
gem "exception_handler", "~> 0.8.0.0"
gem 'webpacker', '~> 5.x'
gem 'net-smtp'
git: "https://github.com/rails/sprockets-rails",
branch: "master"
gem "sunspot_rails",
github: "sunspot/sunspot",
glob: "sunspot_rails/*.gemspec"
gem "sunspot_solr"
gem "thredded"
gem "thredded-markdown_katex",
git: "https://github.com/thredded/thredded-markdown_katex.git",
branch: "main"
gem "trix-rails", require: "trix"
gem "webpacker", "~> 5.x"

group :development, :docker_development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
gem "rspec-rails"
gem "factory_bot_rails"
gem "rspec-rails"
end

group :development, :docker_development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "web-console", ">= 3.3.0"
gem "listen", ">= 3.0.5", "< 3.2"
gem "rails-erd"
gem "web-console", ">= 3.3.0"
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "marcel"
gem "pgreset"
gem "rubocop", "~> 1.57", require: false
gem "rubocop-performance", "~> 1.16", require: false
gem "rubocop-rails", "~> 2.22", ">= 2.22.1", require: false
gem "spring"
gem "spring-watcher-listen", "~> 2.0.0"
gem "rubocop", "~> 1.57", require: false
gem 'rubocop-performance', '~> 1.16', require: false
gem 'rubocop-rails', '~> 2.22', '>= 2.22.1', require: false
gem "pgreset"
gem "marcel"
# gem 'bullet'
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem "selenium-webdriver"
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
gem 'faker'
gem 'database_cleaner'
gem 'launchy'
gem 'simplecov', require: false
gem "database_cleaner"
gem "faker"
gem "launchy"
gem "simplecov", require: false
gem "webdrivers"
end

group :test, :development, :docker_development do
gem 'cypress-on-rails', '~> 1.0'
gem 'simplecov-cobertura'
group :test, :development, :docker_development do # rubocop:todo Bundler/DuplicatedGroup
gem "cypress-on-rails", "~> 1.0"
gem "simplecov-cobertura"
end
gem 'prometheus_exporter'
gem "prometheus_exporter"
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'
require_relative "config/application"

Rails.application.load_tasks
2 changes: 1 addition & 1 deletion app/abilities/main_ability.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MainAbility
include CanCan::Ability

def initialize(user)
def initialize(_user)
can :start, :main
end
end
4 changes: 2 additions & 2 deletions app/abilities/medium_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(user)

can [:show, :show_comments], Medium do |medium|
medium.visible_for_user?(user) &&
!(medium.sort.in?(['Question', 'Remark']) && !user.can_edit?(medium))
!(medium.sort.in?(["Question", "Remark"]) && !user.can_edit?(medium))
end

can :inspect, Medium do |medium|
Expand Down Expand Up @@ -46,7 +46,7 @@ def initialize(user)
!user.generic? && user.can_edit?(medium)
end

can [:register_download], Medium do |medium|
can [:register_download], Medium do |_medium|
!user.new_record?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/abilities/profile_ability.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ProfileAbility
include CanCan::Ability

def initialize(user)
def initialize(_user)
clear_aliased_actions

can [:edit, :update, :check_for_consent, :add_consent,
Expand Down
2 changes: 1 addition & 1 deletion app/abilities/search_ability.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SearchAbility
include CanCan::Ability

def initialize(user)
def initialize(_user)
clear_aliased_actions

can :index, :search
Expand Down
4 changes: 2 additions & 2 deletions app/abilities/tutorial_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def initialize(user)
user.can_update_personell?(tutorial.lecture)
end

can :overview, Tutorial do |tutorial, lecture|
can :overview, Tutorial do |_tutorial, lecture|
user.editor_or_teacher_in?(lecture)
end

can :index, Tutorial do |tutorial, lecture|
can :index, Tutorial do |_tutorial, lecture|
user.in?(lecture.tutors) || user.editor_or_teacher_in?(lecture)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/administration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AdministrationController < ApplicationController
# tell cancancan there is no model for this controller, but authorize
# nevertheless
authorize_resource class: false
layout 'administration'
layout "administration"

def current_ability
@current_ability ||= AdministrationAbility.new(current_user)
Expand All @@ -26,6 +26,6 @@ def classification
end

def search
@tags = params[:sort] == 'tag'
@tags = params[:sort] == "tag"
end
end
24 changes: 12 additions & 12 deletions app/controllers/announcements_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AnnouncementsController
class AnnouncementsController < ApplicationController
layout 'administration'
layout "administration"
before_action :set_announcement, except: [:new, :create, :index]
authorize_resource except: [:new, :create, :index]

Expand All @@ -17,7 +17,7 @@
end

def new
@lecture = Lecture.find_by_id(params[:lecture])

Check failure on line 20 in app/controllers/announcements_controller.rb

View workflow job for this annotation

GitHub Actions / RuboCop

Rails/DynamicFindBy: Use `find_by` instead of dynamic `find_by_id`.
@announcement = Announcement.new(announcer: current_user, lecture: @lecture)
authorize! :new, @announcement
end
Expand All @@ -33,14 +33,14 @@
# send notification email
send_notification_email
# redirection depending from where the announcement was created
unless @announcement.lecture.present?

Check failure on line 36 in app/controllers/announcements_controller.rb

View workflow job for this annotation

GitHub Actions / RuboCop

Rails/Blank: Use `if @announcement.lecture.blank?` instead of `unless @announcement.lecture.present?`.
redirect_to announcements_path
return
end
redirect_to edit_lecture_path(@announcement.lecture)
return
end
@errors = @announcement.errors[:details].join(', ')
@errors = @announcement.errors[:details].join(", ")
end

def propagate
Expand All @@ -66,12 +66,12 @@
User
end
notifications = []
users_to_notify.update_all(updated_at: Time.now)
users_to_notify.update_all(updated_at: Time.now) # rubocop:todo Rails/SkipsModelValidations

Check failure on line 69 in app/controllers/announcements_controller.rb

View workflow job for this annotation

GitHub Actions / RuboCop

Rails/TimeZone: Do not use `Time.now` without zone. Use one of `Time.zone.now`, `Time.current`, `Time.now.in_time_zone`, `Time.now.utc`, `Time.now.getlocal`, `Time.now.xmlschema`, `Time.now.iso8601`, `Time.now.jisx0301`, `Time.now.rfc3339`, `Time.now.httpdate`, `Time.now.to_i`, `Time.now.to_f` instead.
users_to_notify.find_each do |u|
notifications << Notification.new(recipient: u,
notifiable_id: @announcement.id,
notifiable_type: 'Announcement',
action: 'create')
notifiable_type: "Announcement",
action: "create")
end
# use activerecord-import gem to use only one SQL instruction
Notification.import notifications
Expand All @@ -86,19 +86,19 @@
end
I18n.available_locales.each do |l|
local_recipients = recipients.where(locale: l)
if local_recipients.any?
NotificationMailer.with(recipients: local_recipients.pluck(:id),
locale: l,
announcement: @announcement)
.announcement_email.deliver_later
end
next unless local_recipients.any?

NotificationMailer.with(recipients: local_recipients.pluck(:id),
locale: l,
announcement: @announcement)
.announcement_email.deliver_later
end
end

def set_announcement
@announcement = Announcement.find_by_id(params[:id])

Check failure on line 99 in app/controllers/announcements_controller.rb

View workflow job for this annotation

GitHub Actions / RuboCop

Rails/DynamicFindBy: Use `find_by` instead of dynamic `find_by_id`.
return if @announcement.present?

redirect_to :root, alert: I18n.t('controllers.no_announcement')
redirect_to :root, alert: I18n.t("controllers.no_announcement")
end
end
6 changes: 3 additions & 3 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
end

def new
question = Question.find_by_id(params[:question_id])

Check failure on line 11 in app/controllers/answers_controller.rb

View workflow job for this annotation

GitHub Actions / RuboCop

Rails/DynamicFindBy: Use `find_by` instead of dynamic `find_by_id`.
@answer = Answer.new(value: true, question: question)
@answer = Answer.new(value: true, question:)
authorize! :new, @answer
Splines marked this conversation as resolved.
Show resolved Hide resolved
I18n.locale = question&.locale_with_inheritance
end
Expand All @@ -36,16 +36,16 @@

def update_answer_box
@answer_id = params[:answer_id].to_i
@value = params[:value] == 'true'
@value = params[:value] == "true"
end

private

def set_answer
@answer = Answer.find_by_id(params[:id])

Check failure on line 45 in app/controllers/answers_controller.rb

View workflow job for this annotation

GitHub Actions / RuboCop

Rails/DynamicFindBy: Use `find_by` instead of dynamic `find_by_id`.
return if @answer.present?

redirect_to root_path, alert: I18n.t('controllers.no_answer')
redirect_to root_path, alert: I18n.t("controllers.no_answer")
end

def answer_params
Expand Down
Loading