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

Update Rubocop version and enforce all cops #617

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ group :development, :docker_development do
# 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 "rubocop", "~> 1.63", require: false
gem "rubocop-performance", "~> 1.21", require: false
gem "rubocop-rails", "~> 2.24", require: false
gem "spring"
gem "spring-watcher-listen", "~> 2.0.0"
# gem 'bullet'
Expand Down
33 changes: 17 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ GEM
js-routes (1.4.9)
railties (>= 4)
sprockets-rails
json (2.6.3)
json (2.7.2)
jsonapi-renderer (0.2.2)
kaminari (1.2.2)
activesupport (>= 4.1.0)
Expand Down Expand Up @@ -359,8 +359,8 @@ GEM
options (2.3.2)
orm_adapter (0.5.0)
pairing_heap (3.0.0)
parallel (1.23.0)
parser (3.2.2.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pdf-reader (2.11.0)
Expand Down Expand Up @@ -443,7 +443,7 @@ GEM
ffi (~> 1.0)
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.2)
regexp_parser (2.9.0)
request_store (1.5.1)
rack (>= 1.4)
responders (3.1.0)
Expand Down Expand Up @@ -484,26 +484,27 @@ GEM
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.12.0)
rubocop (1.57.2)
rubocop (1.63.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.22.1)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.24.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-graphviz (1.2.5)
rexml
ruby-progressbar (1.13.0)
Expand Down Expand Up @@ -701,9 +702,9 @@ DEPENDENCIES
rgl
rqrcode
rspec-rails
rubocop (~> 1.57)
rubocop-performance (~> 1.16)
rubocop-rails (~> 2.22, >= 2.22.1)
rubocop (~> 1.63)
rubocop-performance (~> 1.21)
rubocop-rails (~> 2.24)
rubyzip (~> 2.3.0)
sass-rails (>= 6)
selenium-webdriver
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/commontator/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def upvote

# PUT /comments/1/downvote
def downvote
security_transgression_unless(@comment.can_be_voted_on_by?(@commontator_user) && \
security_transgression_unless(@comment.can_be_voted_on_by?(@commontator_user) &&
@comment.thread.config.comment_voting.to_sym == :ld)

@comment.downvote_from(@commontator_user)
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/readers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def update_all
.map(&:commontator_thread)
existing_readers = Reader.where(user: current_user, thread: threads)
missing_thread_ids = threads.map(&:id) - existing_readers.pluck(:thread_id)
new_readers = []
missing_thread_ids.each do |t|
new_readers << Reader.new(thread_id: t, user: current_user)
new_readers = missing_thread_ids.map do |t|
Reader.new(thread_id: t, user: current_user)
end
Reader.import new_readers
Reader.where(user: current_user, thread: threads).touch_all
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/media_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ def edit_or_show_medium_path(medium)
def external_link_description_not_empty(medium)
# Uses link display name if not empty, otherwise falls back to the
# link url itself.
(medium.external_link_description.presence || medium.external_reference_link)
medium.external_link_description.presence || medium.external_reference_link
end
end
75 changes: 33 additions & 42 deletions app/models/manuscript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,16 @@ def create_or_update_chapter_items!
attrs = [:medium_id, :pdf_destination, :section_id, :sort, :page, :description, :ref_number,
:position, :quarantine]
item_details = items.pluck(*attrs).map { |i| attrs.zip(i).to_h }
contents = []
@chapters.each do |c|
contents.push(
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: nil,
sort: "chapter",
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: nil,
quarantine: nil }
)
contents = @chapters.map do |c|
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: nil,
sort: "chapter",
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: nil,
quarantine: nil }
end
create_or_update_items!(contents, item_details, item_destinations,
item_id_map)
Expand All @@ -176,21 +173,18 @@ def create_or_update_section_items!
attrs = [:medium_id, :pdf_destination, :section_id, :sort, :page, :description, :ref_number,
:position, :quarantine]
item_details = items.pluck(*attrs).map { |i| attrs.zip(i).to_h }
contents = []
# NOTE: that sections get a position -1 in order to place them ahead
# of all content items within themseleves in #script_items_by_position
@sections.each do |s|
contents.push(
{ medium_id: @medium.id,
pdf_destination: s["destination"],
section_id: s["mampf_section"].id,
sort: "section",
page: s["page"].to_i,
description: s["description"],
ref_number: s["label"],
position: -1,
quarantine: nil }
)
contents = @sections.map do |s|
{ medium_id: @medium.id,
pdf_destination: s["destination"],
section_id: s["mampf_section"].id,
sort: "section",
page: s["page"].to_i,
description: s["description"],
ref_number: s["label"],
position: -1,
quarantine: nil }
end
create_or_update_items!(contents, item_details, item_destinations,
item_id_map)
Expand All @@ -208,22 +202,19 @@ def create_or_update_content_items!(filter_boxes)
attrs = [:medium_id, :pdf_destination, :section_id, :sort, :page, :description, :ref_number,
:position, :hidden, :quarantine]
item_details = items.pluck(*attrs).map { |i| attrs.zip(i).to_h }
contents = []
@content.each do |c|
contents.push(
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: @sections.find do |s|
c["section"] == s["section"]
end ["mampf_section"]&.id,
sort: Item.internal_sort(c["sort"]),
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: c["counter"],
hidden: filter_boxes[c["counter"]].third == false,
quarantine: nil }
)
contents = @content.map do |c|
{ medium_id: @medium.id,
pdf_destination: c["destination"],
section_id: @sections.find do |s|
c["section"] == s["section"]
end ["mampf_section"]&.id,
sort: Item.internal_sort(c["sort"]),
page: c["page"].to_i,
description: c["description"],
ref_number: c["label"],
position: c["counter"],
hidden: filter_boxes[c["counter"]].third == false,
quarantine: nil }
end
create_or_update_items!(contents, item_details, item_destinations,
item_id_map)
Expand Down
11 changes: 5 additions & 6 deletions app/models/medium_publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ def realize_optional_stuff!
# to the medium's teachable's media_scope
def create_notifications!
@medium.teachable&.media_scope&.touch
notifications = []
@medium.teachable.media_scope.users.touch_all
@medium.teachable.media_scope.users.each do |u|
notifications << Notification.new(recipient: u,
notifiable_id: @medium.id,
notifiable_type: "Medium",
action: "create")
notifications = @medium.teachable.media_scope.users.map do |u|
Notification.new(recipient: u,
notifiable_id: @medium.id,
notifiable_type: "Medium",
action: "create")
end
Notification.import notifications
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/quiz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def preselected_hide_solution(vertex_id, crosses)

def questions
ids = quiz_graph&.vertices&.values&.select { |v| v[:type] == "Question" }
&.map { |v| v[:id] }
&.pluck(:id)
Question.where(id: ids)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/referral.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def vtt_time_span

# provide metadata for vtt file
def vtt_properties
link = (item.link.presence || item.medium_link)
link = item.link.presence || item.medium_link
# at the moment, relations between items can be only of the form
# script <-> video, which means that between them there will be at most
# one script, one manuscript and one video
Expand Down
2 changes: 1 addition & 1 deletion app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def correction_size
end

def preceding_tutorial(user)
assignment.previous&.map { |a| a.tutorial(user) }&.compact&.first
assignment.previous&.filter_map { |a| a.tutorial(user) }&.first
fosterfarrell9 marked this conversation as resolved.
Show resolved Hide resolved
end

def invited_users
Expand Down
8 changes: 3 additions & 5 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,11 @@ def self.select_by_title_except(excluded_tags)
# converts the subgraph of all tags of distance <= 2 to the given marked tag
# into a cytoscape array representing this subgraph
def self.to_cytoscape(tags, marked_tag, highlight_related_tags: true)
result = []
# add vertices
tags.each do |t|
result.push(data: t.cytoscape_vertex(marked_tag,
highlight_related_tags:
highlight_related_tags))
result = tags.map do |t|
{ data: t.cytoscape_vertex(marked_tag, highlight_related_tags: highlight_related_tags) }
end

# add edges
edges = []
tags.each do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20201002094500_change_submission_foreign_keys.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# rubocop:disable Rails/
# rubocop:disable Lint/SymbolConversion
class ChangeSubmissionForeignKeys < ActiveRecord::Migration[6.0]
def up
remove_index :user_submission_joins,
Expand Down Expand Up @@ -33,3 +34,4 @@ def id_to_uuid(table_name, relation_name, relation_class)
end
end
# rubocop:enable Rails/
# rubocop:enable Lint/SymbolConversion