Skip to content

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Lerner committed Sep 16, 2024
1 parent f497820 commit 8c3b4ab
Show file tree
Hide file tree
Showing 35 changed files with 162 additions and 134 deletions.
12 changes: 10 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require: rubocop-rails
require:
- rubocop-rails
- rubocop-capybara
- rubocop-factory_bot
- rubocop-graphql
AllCops:
NewCops: enable
Exclude:
Expand Down Expand Up @@ -47,6 +51,10 @@ Metrics/PerceivedComplexity:
Max: 13
Naming/PredicateName:
Enabled: false
Naming/BlockForwarding:
EnforcedStyle: explicit
Style/ArgumentsForwarding:
UseAnonymousForwarding: false
Metrics/ModuleLength:
Exclude:
- app/helpers/**/*
Expand All @@ -63,4 +71,4 @@ Style/WordArray:
Rails/EagerEvaluationLogMessage:
Enabled: false
Rails/I18nLocaleTexts:
Enabled: false
Enabled: false
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ group :development do
gem 'better_errors'

gem 'binding_of_caller'
gem 'rubocop-capybara'
gem 'rubocop-factory_bot'
gem 'rubocop-graphql'
gem 'rubocop-rails'
gem 'spring', '4.0.0'
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-graphql (1.5.4)
rubocop (>= 1.50, < 2)
rubocop-rails (2.26.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
Expand Down Expand Up @@ -411,6 +417,9 @@ DEPENDENCIES
puma (~> 6.4)
rails (~> 6.1)
react-rails
rubocop-capybara
rubocop-factory_bot
rubocop-graphql
rubocop-rails
rubyzip
selenium-webdriver
Expand Down
8 changes: 4 additions & 4 deletions app/channels/graphql_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def execute(data)
access_cache: {},
# Re-implement whatever context methods you need
# in this channel or ApplicationCable::Channel
current_user: current_user,
current_user:,
# Make sure the channel is in the context
channel: self,
}

result = HourglassSchema.execute(
query,
context: context,
variables: variables,
operation_name: operation_name,
context:,
variables:,
operation_name:,
)

payload = {
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/student/exams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def require_current_user_unique_session
user_id: e.user.id,
exam_id: params[:exam_id],
)
Anomaly.create(registration: registration, reason: e.message) if registration
Anomaly.create(registration:, reason: e.message) if registration
render json: { lockout: true, reason: e.message }
end

Expand Down Expand Up @@ -92,7 +92,7 @@ def start_exam!
start: @registration.start_time,
stop: @registration.effective_end_time,
},
answers: answers,
answers:,
}
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def execute
query = params[:query]
operation_name = params[:operationName]
context = {
current_user: current_user,
true_user: true_user,
current_user:,
true_user:,
impersonate_user: ->(user) { impersonate_user(user) },
stop_impersonating_user: -> { stop_impersonating_user },
bottlenose_api: bottlenose_api,
bottlenose_api:,
access_cache: {},
}
result = HourglassSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
result = HourglassSchema.execute(query, variables:, context:, operation_name:)
render json: result
end

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

def trigger_subscription
exam_id = HourglassSchema.id_from_object(exam, Types::ExamType, {})
HourglassSchema.subscriptions.trigger(:anomaly_was_created, { exam_id: exam_id }, self)
HourglassSchema.subscriptions.trigger(:anomaly_was_created, { exam_id: }, self)
end

def visible_to?(check_user, role_for_exam, _role_for_course)
Expand Down
58 changes: 29 additions & 29 deletions app/models/body_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def valid_file_refs_code_tag
before_save do
if rubrics.empty?
rubrics.build(
exam_version: exam_version,
question: question,
part: part,
exam_version:,
question:,
part:,
body_item: self,
type: 'None',
)
Expand Down Expand Up @@ -83,12 +83,12 @@ def as_json(format:)
else
if format == :graphql
return {
info: info,
info:,
id: HourglassSchema.id_from_object(self, Types::BodyItemType, {}),
}
end

send("as_json_#{info['type']}", format: format)
send("as_json_#{info['type']}", format:)
end
end

Expand All @@ -100,7 +100,7 @@ def rubric_as_json(format:)
if root_rubric.nil? || root_rubric.is_a?(None)
nil
else
root_rubric.as_json(format: format).deep_stringify_keys
root_rubric.as_json(format:).deep_stringify_keys
end
end

Expand All @@ -116,7 +116,7 @@ def as_json_AllThatApply(format:)
'options' => info['options'].zip(answer).map do |opt, ans|
{ BodyItem.html_val(format, opt) => ans }
end,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand All @@ -142,7 +142,7 @@ def as_json_Code(format:)
else
MarksProcessor.process_marks_reverse(answer['text'], answer['marks'])
end,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand Down Expand Up @@ -174,7 +174,7 @@ def as_json_CodeTag(format:)
'filename' => answer['selectedFile'],
'line' => answer['lineNumber'],
},
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand All @@ -188,7 +188,7 @@ def as_json_Matching(format:)
'prompts' => BodyItem.html_vals(format, info['prompts']),
'values' => BodyItem.html_vals(format, info['values']),
'correctAnswers' => answer,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand All @@ -199,7 +199,7 @@ def as_json_MultipleChoice(format:)
'prompt' => BodyItem.html_val(format, info['prompt']),
'options' => BodyItem.html_vals(format, info['options']),
'correctAnswer' => answer,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand All @@ -214,7 +214,7 @@ def as_json_Text(format:)
else
BodyItem.html_val(format, answer&.dig('text'))
end,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand All @@ -229,7 +229,7 @@ def as_json_YesNo(format:)
'YesNo' => {
'prompt' => BodyItem.html_val(format, info['prompt']),
'correctAnswer' => answer,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand All @@ -241,7 +241,7 @@ def as_json_YesNo(format:)
'TrueFalse' => {
'prompt' => BodyItem.html_val(format, info['prompt']),
'correctAnswer' => answer,
'rubric' => rubric_as_json(format: format),
'rubric' => rubric_as_json(format:),
}.compact,
}
end
Expand Down Expand Up @@ -281,7 +281,7 @@ def html_vals(format, val)
def from_yaml_AllThatApply(type, options:, prompt: nil)
BodyItem.new(
info: {
type: type,
type:,
prompt: html_val(:graphql, prompt),
options: html_vals(:graphql, options.map(&:keys).flatten),
}.compact,
Expand Down Expand Up @@ -311,12 +311,12 @@ def from_yaml_Code(type, initial: nil, prompt: nil, lang: nil, correct_answer: n
end
BodyItem.new(
info: {
type: type,
type:,
prompt: html_val(:graphql, prompt),
lang: lang,
initial: initial,
lang:,
initial:,
}.compact,
answer: answer,
answer:,
)
end

Expand All @@ -334,18 +334,18 @@ def from_yaml_CodeSnippet(type, initial: nil, lang: nil)
end
BodyItem.new(
info: {
type: type,
lang: lang,
initial: initial,
type:,
lang:,
initial:,
}.compact,
)
end

def from_yaml_CodeTag(type, choices:, correct_answer:, prompt: nil)
BodyItem.new(
info: {
type: type,
choices: choices,
type:,
choices:,
prompt: html_val(:graphql, prompt),
}.compact,
answer: {
Expand All @@ -367,7 +367,7 @@ def from_yaml_Matching(
)
BodyItem.new(
info: {
type: type,
type:,
prompt: html_val(:graphql, prompt),
promptsLabel: html_val(:graphql, prompts_label),
valuesLabel: html_val(:graphql, values_label),
Expand All @@ -382,7 +382,7 @@ def from_yaml_Matching(
def from_yaml_MultipleChoice(type, options:, correct_answer:, prompt: nil)
BodyItem.new(
info: {
type: type,
type:,
prompt: html_val(:graphql, prompt),
options: html_vals(:graphql, options),
}.compact,
Expand All @@ -393,7 +393,7 @@ def from_yaml_MultipleChoice(type, options:, correct_answer:, prompt: nil)
def from_yaml_Text(type, entire_value: nil, prompt: nil, correct_answer: nil)
BodyItem.new(
info: {
type: type,
type:,
prompt: html_val(:graphql, prompt || entire_value.to_s),
}.compact,
answer: correct_answer,
Expand All @@ -414,7 +414,7 @@ def from_yaml_TrueFalse(_type, entire_value: nil, prompt: nil, correct_answer: n
noLabel: 'False',
prompt: html_val(:graphql, prompt.to_s),
}.compact,
answer: answer,
answer:,
)
end

Expand All @@ -432,7 +432,7 @@ def from_yaml_YesNo(_type, entire_value: nil, prompt: nil, correct_answer: nil)
noLabel: 'No',
prompt: html_val(:graphql, prompt.to_s),
}.compact,
answer: answer,
answer:,
)
end
# rubocop:enable Naming/MethodName
Expand Down
6 changes: 3 additions & 3 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class Course < ApplicationRecord
validates :bottlenose_id, presence: true

def user_is_student?(user)
student_registrations.exists?(user: user)
student_registrations.exists?(user:)
end

def user_is_staff?(user)
staff_registrations.exists?(user: user)
staff_registrations.exists?(user:)
end

def user_is_professor?(user)
professor_course_registrations.exists?(user: user)
professor_course_registrations.exists?(user:)
end

def all_staff
Expand Down
Loading

0 comments on commit 8c3b4ab

Please sign in to comment.