Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,41 @@ Lint/AmbiguousBlockAssociation:
Lint/ConstantDefinitionInBlock:
Enabled: false

Lint/EmptyBlock:
Exclude:
- 'spec/**/*'

# The Metrics limits below are deliberately more permissive than RuboCop's defaults.
# They were calibrated against the existing code base so that the cops flag genuine outliers.
Metrics/AbcSize:
Max: 20
Max: 35
# Rails code reads the same attribute repeatedly (`current_course`, `submission.assessment`);
# counting each read separately inflates the score without indicating real complexity.
CountRepeatedAttributes: false

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Metrics/ClassLength:
Max: 200
CountAsOne: ['array', 'hash', 'heredoc']
CountComments: false

Metrics/CyclomaticComplexity:
Max: 15

Metrics/MethodLength:
Max: 30
CountAsOne: ['array', 'hash', 'heredoc']
CountComments: false

Metrics/ModuleLength:
Max: 200
CountAsOne: ['array', 'hash', 'heredoc']
CountComments: false

Metrics/PerceivedComplexity:
Max: 15

Style/Alias:
EnforcedStyle: prefer_alias_method
Expand Down Expand Up @@ -78,6 +104,9 @@ Style/LambdaCall:
Style/NumericPredicate:
EnforcedStyle: comparison

Style/OneClassPerFile:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Expand Down
290 changes: 7 additions & 283 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ApplicationUserTimeZoneConcern
protected

# Set the time_zone for current request.
def set_time_zone(&block) # rubocop:disable Naming/AccessorMethodName
def set_time_zone(&block)
Time.use_zone(current_user.time_zone, &block)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def additional_answer_params(answer)
end
end

def update_specific_answer_type_params(answer) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
def update_specific_answer_type_params(answer)
answer_actable_class = answer.actable.class.name
scalar_params = []
array_params = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
# rubocop:disable Metrics/ModuleLength
module Course::Assessment::Question::KoditsuQuestionConcern
extend ActiveSupport::Concern
include Course::Assessment::KoditsuAssessmentConcern
Expand Down Expand Up @@ -146,4 +145,3 @@ def koditsu_programming_language_map
}
end
end
# rubocop:enable Metrics/ModuleLength
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Course::Assessment::Submission::MonitoringConcern
after_action :stop_monitoring_session_if_submitted, only: [:update]
end

def should_monitor? # rubocop:disable Metrics/CyclomaticComplexity
def should_monitor?
monitoring_component_enabled? &&
current_user.id == @submission.creator_id &&
current_course_user&.student? &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def lesson_plan_items_submission_time_hash(course_user)
# their submitted time, if relevant/available.
# @param [Float] alpha Alpha value used in exponential moving average computation.
# @return [Float|nil] Learning rate exponential moving average, if computable.
def compute_learning_rate_ema(course_user, items_affecting_personal_times, submitted_items, alpha = 0.4) # rubocop:disable Metrics/AbcSize
def compute_learning_rate_ema(course_user, items_affecting_personal_times, submitted_items, alpha = 0.4)
submitted_items_affecting_personal_times = items_affecting_personal_times.
select { |i| i.id.in? submitted_items.keys }.
select { |i| i.time_for(course_user).end_at.present? }
Expand Down Expand Up @@ -67,7 +67,7 @@ def compute_learning_rate_ema(course_user, items_affecting_personal_times, submi
# @param [Float] min_learning_rate The minimum overall learning rate.
# @param [Float] max_learning_rate The maximum overall learning rate.
# @return [Array<Float>] An array pair containing [min learning rate, max learning rate].
def compute_learning_rate_effective_limits(course_user, items, submitted_items, min_learning_rate, max_learning_rate) # rubocop:disable Metrics/AbcSize
def compute_learning_rate_effective_limits(course_user, items, submitted_items, min_learning_rate, max_learning_rate)
course_start = items.first.start_at
course_end = items.last.start_at
last_submitted_item = items.reverse_each.lazy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Course::LessonPlan::Strategies::BasePersonalizationStrategy
#
# @param [CourseUser] course_user The course user to compute data for.
# @return [Hash] Precomputed data to aid execution.
def precompute_data(course_user) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def precompute_data(course_user)
submitted_items = lesson_plan_items_submission_time_hash(course_user)
items = lesson_plan_items_with_sorted_times_for(course_user)
items_affecting_personal_times = items.select(&:affects_personal_times?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Course::LessonPlan::Strategies::FomoPersonalizationStrategy <
# @param [Hash] precomputed_data The default data precomputed by precompute_data.
# @param [Set<Number>|nil] items_to_shift Set of item ids to shift. If provided, only items with ids in this set will
# be shifted.
def execute(course_user, precomputed_data, items_to_shift = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def execute(course_user, precomputed_data, items_to_shift = nil)
return if precomputed_data[:learning_rate_ema].nil?

@course_tz = course_user.course.time_zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Course::LessonPlan::Strategies::OtotPersonalizationStrategy <
#
# @param [CourseUser] course_user The course user to compute data for.
# @return [Hash] Precomputed data to aid execution.
def precompute_data(course_user) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def precompute_data(course_user)
submitted_items = lesson_plan_items_submission_time_hash(course_user)
items = lesson_plan_items_with_sorted_times_for(course_user)
items_affecting_personal_times = items.select(&:affects_personal_times?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Course::LessonPlan::Strategies::StragglersPersonalizationStrategy <
# @param [Hash] precomputed_data The default data precomputed by precompute_data.
# @param [Set<Number>|nil] items_to_shift Set of item ids to shift. If provided, only items with ids in this set will
# be shifted.
def execute(course_user, precomputed_data, items_to_shift = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def execute(course_user, precomputed_data, items_to_shift = nil)
return if precomputed_data[:learning_rate_ema].nil?

@course_tz = course_user.course.time_zone
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/course/unread_counts_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def pending_assessment_submissions_count
end
end

def unread_comments_count # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def unread_comments_count
self.class.include Course::Discussion::TopicsHelper

is_staff_with_students = current_course_user&.staff? && !current_course_user.my_students.empty?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def edit
end
end

def update # rubocop:disable Metrics/AbcSize
def update
if @settings.update(settings_components_params) && current_course.save
is_koditsu_enabled = settings_components_params['enabled_component_ids'].
include?('course_koditsu_platform_component')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Assessment::Question::ForumPostResponsesController < Course::Assessment::Question::Controller # rubocop:disable Metrics/ClassLength
class Course::Assessment::Question::ForumPostResponsesController < Course::Assessment::Question::Controller
include Course::Assessment::Question::GradingContextParamsConcern

build_and_authorize_new_question :forum_post_response_question,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Assessment::Question::RubricBasedResponsesController < Course::Assessment::Question::Controller # rubocop:disable Metrics/ClassLength
class Course::Assessment::Question::RubricBasedResponsesController < Course::Assessment::Question::Controller
include Course::Assessment::Question::RubricBasedResponseControllerConcern
include Course::Assessment::Question::GradingContextParamsConcern

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def show
end
end

def create # rubocop:disable Metrics/MethodLength
def create
if file_is_pdf?
respond_to do |format|
if pdf_import_service.save
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course/assessment/rubrics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Assessment::RubricsController < Course::Assessment::QuestionsController # rubocop:disable Metrics/ClassLength
class Course::Assessment::RubricsController < Course::Assessment::QuestionsController
load_resource :rubric, class: 'Course::Rubric', through: :question,
except: [:index, :rubric_answers, :grading_contexts, :answer_grading_contexts]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def index
@course_users = current_course.course_users.order_phantom_user.order_alphabetically
end

def create # rubocop:disable Metrics/AbcSize
def create
authorize! :access, @assessment

existing_submission = @assessment.submissions.find_by(creator: current_user)
Expand Down Expand Up @@ -419,7 +419,7 @@ def download_job

# Check for zombie jobs, create new grading jobs if there's any zombie jobs.
# TODO: Remove this method after found the cause of the dead jobs.
def check_zombie_jobs # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def check_zombie_jobs
return unless @submission.attempting? || @submission.submitted?

submitted_answers = @submission.answers.where(workflow_state: 'submitted')
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/course/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def course_params
permit(:title, :description, :status, :start_at, :end_at, :logo)
end

def load_todos # rubocop:disable Metrics/AbcSize
def load_todos
return unless current_course_user&.student?

todos = Course::LessonPlan::Todo.pending_for(current_course_user).
Expand Down Expand Up @@ -89,7 +89,7 @@ def load_todos # rubocop:disable Metrics/AbcSize
to_h { |survey| [survey.survey_id, survey] }
end

def load_items_with_timeline # rubocop:disable Metrics/CyclomaticComplexity
def load_items_with_timeline
return unless current_course_user&.student?

item_ids = [*@video_todos&.map { |todo| todo.item.id },
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course/gradebook_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::GradebookController < Course::ComponentController # rubocop:disable Metrics/ClassLength
class Course::GradebookController < Course::ComponentController
include Course::Gradebook::WeightParsingConcern

before_action :authorize_read_gradebook!
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/course/learning_map_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def map_conditionals_to_nodes
generate_node_depths(nodes)
end

def generate_all_node_relations # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def generate_all_node_relations
relations = init_all_node_relations
node_ids_to_children = relations[:node_ids_to_children]
node_ids_to_parents = relations[:node_ids_to_parents]
Expand Down Expand Up @@ -131,7 +131,7 @@ def map_condition_to_parent(condition)
{ id: id, is_satisfied: typed_condition.satisfied_by?(current_course_user) }
end

def generate_nodes_from_conditionals(all_node_relations) # rubocop:disable Metrics/AbcSize
def generate_nodes_from_conditionals(all_node_relations)
node_ids_to_children = all_node_relations[:node_ids_to_children]
node_ids_to_parents = all_node_relations[:node_ids_to_parents]
node_ids_to_unlock_level = all_node_relations[:node_ids_to_unlock_level]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course/statistics/aggregate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def assessment_info_array
:start_at, :end_at)
end

def user_submission_array # rubocop:disable Metrics/AbcSize
def user_submission_array
submission_data_arr = Course::Assessment::Submission.joins(creator: :course_users).
where(assessment_id: assessment_info_array.map { |i| i[0] },
course_users: { course_id: current_course.id, role: :student }).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Statistics::AssessmentsController < Course::Statistics::Controller # rubocop:disable Metrics/ClassLength
class Course::Statistics::AssessmentsController < Course::Statistics::Controller
include Course::UsersHelper
include Course::Statistics::SubmissionsConcern
include Course::Statistics::UsersConcern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def search_param
params.permit(:search)[:search]
end

def preload_courses # rubocop:disable Metrics/AbcSize
def preload_courses
@courses = @instance.courses.search(search_param).calculated(:active_user_count, :user_count)
@courses = @courses.active_in_past_7_days if ActiveRecord::Type::Boolean.new.cast(params[:active])

Expand Down
2 changes: 0 additions & 2 deletions app/helpers/application_html_formatters_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true
# rubocop:disable Metrics/ModuleLength
module ApplicationHtmlFormattersHelper
# Constants that defines the size/lines limit of the code
MAX_CODE_SIZE = 50 * 1024 # 50 KB
Expand Down Expand Up @@ -285,4 +284,3 @@ def remove_internal_adjacent_code_tags(text)
end
end
end
# rubocop:enable Metrics/ModuleLength
2 changes: 1 addition & 1 deletion app/helpers/course/discussion/topics_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def my_students_unread_count

# This replaces what the `from_user` scopes in the specific models were doing when getting
# my_students_unread_count, for better performance.
def from_user(topic, my_student_ids) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
def from_user(topic, my_student_ids)
case topic.actable_type
when 'Course::Assessment::SubmissionQuestion'
my_student_ids.include?(topic&.actable&.submission&.creator_id)
Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/course/course_user_type_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def valid_course_user_type?(type)
end
end

# rubocop:disable Metrics/CyclomaticComplexity
def course_users_by_type(type, user)
case type
when COURSE_USER_TYPES[:my_students]
Expand All @@ -34,5 +33,4 @@ def course_users_by_type(type, user)
students.without_phantom_users # :students is the default type
end
end
# rubocop:enable Metrics/CyclomaticComplexity
end
2 changes: 1 addition & 1 deletion app/models/course/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def record_marketplace_adoption(duplicate, destination_course, current_user)
)
end

def initialize_duplicate(duplicator, other) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
def initialize_duplicate(duplicator, other) # rubocop:disable Metrics/AbcSize
copy_attributes(other, duplicator)
target_tab = initialize_duplicate_tab(duplicator, other)
self.folder = duplicator.duplicate(other.folder)
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/assessment/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def publish

private

def validate_session_and_client_version # rubocop:disable Metrics/CyclomaticComplexity
def validate_session_and_client_version
return if last_session_id.nil? || client_version.nil?
return if last_session_id_changed? || !client_version_changed?
return if client_version_change[0].nil?
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/assessment/question.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Assessment::Question < ApplicationRecord # rubocop:disable Metrics/ClassLength
class Course::Assessment::Question < ApplicationRecord
include Course::SanitizeDescriptionConcern

actable optional: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/assessment/question/programming.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Assessment::Question::Programming < ApplicationRecord # rubocop:disable Metrics/ClassLength
class Course::Assessment::Question::Programming < ApplicationRecord
enum :package_type, { zip_upload: 0, online_editor: 1 }

# The table name for this model is singular.
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/gradebook/level_config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Gradebook::LevelConfig < ApplicationRecord # rubocop:disable Metrics/ClassLength
class Course::Gradebook::LevelConfig < ApplicationRecord
belongs_to :course, inverse_of: :gradebook_level_config

validates :weight, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/learning_rate_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Course::LearningRateRecord < ApplicationRecord
default_scope { order(created_at: :desc) }

# Implicitly asserts that effective_min <= effective_max as well
def learning_rate_between_effective_min_and_max # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
def learning_rate_between_effective_min_and_max
# We return if any of the three attributes is nil, since that will be handled by the presence check
return if learning_rate.nil? || effective_min.nil? || effective_max.nil?
return if effective_min <= learning_rate && learning_rate <= effective_max
Expand Down
2 changes: 1 addition & 1 deletion app/models/course/rubric.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Rubric < ApplicationRecord # rubocop:disable Metrics/ClassLength
class Course::Rubric < ApplicationRecord
include DuplicationStateTrackingConcern
include Course::Rubric::CopyOnWriteConcern

Expand Down
2 changes: 1 addition & 1 deletion app/models/course/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def find_or_create_personal_time_for(_course_user)
PersonalTime.new(@course_user, @id, reference_time.start_at)
end

def has_personal_times? # rubocop:disable Naming/PredicateName
def has_personal_times?
true
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
class Course::Assessment::Answer::ProgrammingCodaveriAsyncFeedbackService # rubocop:disable Metrics/ClassLength
class Course::Assessment::Answer::ProgrammingCodaveriAsyncFeedbackService
CODAVERI_LANGUAGE_MAPPING = {
en: 'english',
zh: 'chinese'
Expand Down Expand Up @@ -116,7 +116,7 @@ def process_codaveri_feedback
end
end

def save_annotation(file, feedback_line) # rubocop:disable Metrics/AbcSize
def save_annotation(file, feedback_line)
feedback_id = feedback_line['id']
linenum = feedback_line['linenum'].to_i
feedback = feedback_line['feedback']
Expand Down
Loading