Skip to content

Commit

Permalink
rubocop: Style/TernaryParentheses, Style/RedundantParentheses
Browse files Browse the repository at this point in the history
[skip-stages=Flakey]

Change-Id: I8d860eedd8b199ed3adf0e2bf9162b43096c5347
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/315130
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Aaron Ogata <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
Product-Review: Cody Cutrer <[email protected]>
Build-Review: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Apr 12, 2023
1 parent 47ba763 commit b2b0bff
Show file tree
Hide file tree
Showing 219 changed files with 369 additions and 369 deletions.
4 changes: 2 additions & 2 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def courses_api
end

if params[:sort] && params[:order]
order += (params[:order] == "desc" ? " DESC, id DESC" : ", id")
order += ((params[:order] == "desc") ? " DESC, id DESC" : ", id")
end

opts = { include_crosslisted_courses: value_to_boolean(params[:include_crosslisted_courses]) }
Expand Down Expand Up @@ -1727,7 +1727,7 @@ def account_calendar_settings
end

def format_avatar_count(count = 0)
count > 99 ? "99+" : count
(count > 99) ? "99+" : count
end
private :format_avatar_count

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def use_new_math_equation_handling?
end

def user_url(*opts)
opts[0] == @current_user ? user_profile_url(@current_user) : super
(opts[0] == @current_user) ? user_profile_url(@current_user) : super
end

protected
Expand Down Expand Up @@ -1913,7 +1913,7 @@ def verified_file_request?
# Retrieving wiki pages needs to search either using the id or
# the page title.
def get_wiki_page
GuardRail.activate(params[:action] == "edit" ? :primary : :secondary) do
GuardRail.activate((params[:action] == "edit") ? :primary : :secondary) do
@wiki = @context.wiki

@page_name = params[:wiki_page_id] || params[:id] || (params[:wiki_page] && params[:wiki_page][:title])
Expand All @@ -1937,7 +1937,7 @@ def get_wiki_page
end

def content_tag_redirect(context, tag, error_redirect_symbol, tag_type = nil)
url_params = tag.tag_type == "context_module" ? { module_item_id: tag.id } : {}
url_params = (tag.tag_type == "context_module") ? { module_item_id: tag.id } : {}
if tag.content_type == "Assignment"
use_edit_url = params[:build].nil? &&
Account.site_admin.feature_enabled?(:new_quizzes_modules_support) &&
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/assignments_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ def render_create_or_update_result(result, opts = {})
if [:created, :ok].include?(result)
render json: assignment_json(@assignment, @current_user, session, opts), status: result
else
status = result == :forbidden ? :forbidden : :bad_request
status = (result == :forbidden) ? :forbidden : :bad_request
errors = @assignment.errors.as_json[:errors]
errors["published"] = errors.delete(:workflow_state) if errors.key?(:workflow_state)
render json: { errors: errors }, status: status
Expand All @@ -1486,7 +1486,7 @@ def invalid_bucket_error
def require_user_visibility
return render_unauthorized_action unless @current_user.present?

@user = params[:user_id] == "self" ? @current_user : api_find(User, params[:user_id])
@user = (params[:user_id] == "self") ? @current_user : api_find(User, params[:user_id])
# teacher, ta
return if @context.grants_right?(@current_user, :view_all_grades) && @context.students_visible_to(@current_user).include?(@user)

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/brand_configs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def save_to_user_session
def save_to_account
old_md5 = @account.brand_config_md5
session_config = session.delete(:brand_config)
new_md5 = session_config.nil? || session_config[:type] == :default ? nil : session_config[:md5]
new_md5 = (session_config.nil? || session_config[:type] == :default) ? nil : session_config[:md5]
new_brand_config = new_md5 && BrandConfig.find(new_md5)
progress = BrandConfigRegenerator.process(@account, @current_user, new_brand_config)

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/calendar_events_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def update_from_series(target_event, params_for_update, which)
end

all_events = find_which_series_events(target_event: target_event, which: "all", for_update: true)
events = which == "following" ? all_events.where("start_at >= ?", target_event.start_at) : all_events
events = (which == "following") ? all_events.where("start_at >= ?", target_event.start_at) : all_events
if events.blank?
# i don't believe we can get here, but cya
render json: { message: t("No events were found to update") }, status: :bad_request
Expand Down Expand Up @@ -1293,7 +1293,7 @@ def set_course_timetable
updated_section_ids = []
timetable_data.each do |section_id, timetables|
timetable_data[section_id] = Array(timetables)
section = section_id == "all" ? nil : api_find(@context.active_course_sections, section_id)
section = (section_id == "all") ? nil : api_find(@context.active_course_sections, section_id)
updated_section_ids << section.id if section

builder = Courses::TimetableEventBuilder.new(course: @context, course_section: section)
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def get_options(codes, user = @current_user)
@end_date = @start_date.end_of_day if @end_date < @start_date
end

@type ||= params[:type] == "assignment" ? :assignment : :event
@type ||= (params[:type] == "assignment") ? :assignment : :event

@context ||= user
include_accounts = Account.site_admin.feature_enabled?(:account_calendar_events)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def show
can_update_todo_date: context.grants_any_right?(@current_user, session, :manage_content, :manage_course_content_edit),
can_update_discussion_topic: context.grants_right?(@current_user, session, :moderate_forum),
can_update_wiki_page: context.grants_right?(@current_user, session, :update),
concluded: (context.is_a? Course) ? context.concluded? : false,
concluded: context.is_a?(Course) ? context.concluded? : false,
k5_course: context.is_a?(Course) && context.elementary_enabled?,
course_pacing_enabled: context.is_a?(Course) && @domain_root_account.feature_enabled?(:course_paces) && context.enable_course_paces,
user_is_observer: context.is_a?(Course) && context.enrollments.where(user_id: @current_user).first&.observer?,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/communication_channels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def confirm
@merge_opportunities.last.last.sort! { |a, b| Canvas::ICU.compare(a.account.name, b.account.name) }
end
end
@merge_opportunities.sort_by! { |a| [a.first == @current_user ? CanvasSort::First : CanvasSort::Last, Canvas::ICU.collation_key(a.first.name)] }
@merge_opportunities.sort_by! { |a| [(a.first == @current_user) ? CanvasSort::First : CanvasSort::Last, Canvas::ICU.collation_key(a.first.name)] }
else
@merge_opportunities = []
end
Expand Down Expand Up @@ -599,7 +599,7 @@ def bulk_confirm
protected

def account
@account ||= params[:account_id] == "self" ? @domain_root_account : Account.find(params[:account_id])
@account ||= (params[:account_id] == "self") ? @domain_root_account : Account.find(params[:account_id])
end

def bulk_action_args
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/conferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def create
end
user_ids = member_ids
@conference.add_initiator(@current_user)
user_ids.count > WebConference.max_invitees_sync_size ? @conference.delay.invite_users_from_context(user_ids) : @conference.invite_users_from_context(user_ids)
(user_ids.count > WebConference.max_invitees_sync_size) ? @conference.delay.invite_users_from_context(user_ids) : @conference.invite_users_from_context(user_ids)
@conference.save
format.html { redirect_to named_context_url(@context, :context_conference_url, @conference.id) }
format.json do
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/conversations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def create

shard.activate do
if batch_private_messages || batch_group_messages
mode = params[:mode] == "async" ? :async : :sync
mode = (params[:mode] == "async") ? :async : :sync
message.relativize_attachment_ids(from_shard: message.shard, to_shard: shard)
message.shard = shard
batch = ConversationBatch.generate(message, @recipients, mode,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/course_paces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def authorize_action

def latest_progress
progress = Progress.order(created_at: :desc).find_by(context: @course_pace, tag: "course_pace_publish")
progress&.workflow_state == "completed" ? nil : progress
(progress&.workflow_state == "completed") ? nil : progress
end

def load_and_run_progress
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ def check_enrollment(ignore_restricted_courses = false)
if (enrollment = fetch_enrollment)
if enrollment.state_based_on_date == :inactive && !ignore_restricted_courses
flash[:notice] = t("notices.enrollment_not_active", "Your membership in the course, %{course}, is not yet activated", course: @context.name)
return !!redirect_to(enrollment.workflow_state == "invited" ? courses_url : dashboard_url)
return !!redirect_to((enrollment.workflow_state == "invited") ? courses_url : dashboard_url)
end

if enrollment.rejected?
Expand Down Expand Up @@ -3177,7 +3177,7 @@ def update
if (mc_restrictions_by_type = params[:course][:blueprint_restrictions_by_object_type])
parsed_restrictions_by_type = {}
mc_restrictions_by_type.to_unsafe_h.each do |type, restrictions|
class_name = type == "quiz" ? "Quizzes::Quiz" : type.camelcase
class_name = (type == "quiz") ? "Quizzes::Quiz" : type.camelcase
parsed_restrictions_by_type[class_name] = restrictions.to_h { |k, v| [k.to_sym, value_to_boolean(v)] }
end
template.default_restrictions_by_type = parsed_restrictions_by_type
Expand Down Expand Up @@ -3954,7 +3954,7 @@ def courses_for_user(user, paginate_url: api_v1_courses_url)
def require_user_or_observer
return render_unauthorized_action unless @current_user.present?

@user = params[:user_id] == "self" ? @current_user : api_find(User, params[:user_id])
@user = (params[:user_id] == "self") ? @current_user : api_find(User, params[:user_id])
authorized_action(@user, @current_user, :read)
end

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/discussion_topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def index
when Course
context_url(@context, :context_settings_url, anchor: "tab-features")
when Group
(@context.context&.is_a? Course) || (@context.context&.is_a? Account) ? context_url(@context.context, :context_settings_url, anchor: "tab-features") : nil
((@context.context&.is_a? Course) || (@context.context&.is_a? Account)) ? context_url(@context.context, :context_settings_url, anchor: "tab-features") : nil
else
nil
end
Expand Down Expand Up @@ -504,7 +504,7 @@ def new
js_env({ is_announcement: params[:is_announcement] })
js_bundle :discussion_topic_edit_v2
css_bundle :discussions_index, :learning_outcomes
render html: "", layout: params[:embed] == "true" ? "mobile_embed" : true
render html: "", layout: (params[:embed] == "true") ? "mobile_embed" : true
return
end
edit
Expand Down Expand Up @@ -661,7 +661,7 @@ def edit

set_master_course_js_env_data(@topic, @context)
conditional_release_js_env(@topic.assignment)
render :edit, layout: params[:embed] == "true" ? "mobile_embed" : true
render :edit, layout: (params[:embed] == "true") ? "mobile_embed" : true
end

def show
Expand Down Expand Up @@ -816,7 +816,7 @@ def show

js_bundle :discussion_topics_post
css_bundle :discussions_index, :learning_outcomes
render html: "", layout: params[:embed] == "true" ? "mobile_embed" : true
render html: "", layout: (params[:embed] == "true") ? "mobile_embed" : true
return
end

Expand Down Expand Up @@ -1369,7 +1369,7 @@ def process_discussion_topic_runner(is_new:)
only_pinning = discussion_topic_hash.except(*%w[pinned]).blank?

# allow pinning/unpinning if a subtopic and we can update the root
topic_to_check = only_pinning && @topic.root_topic ? @topic.root_topic : @topic
topic_to_check = (only_pinning && @topic.root_topic) ? @topic.root_topic : @topic
return unless authorized_action(topic_to_check, @current_user, (is_new ? :create : :update))

process_podcast_parameters(discussion_topic_hash)
Expand Down Expand Up @@ -1732,7 +1732,7 @@ def handle_assignment_edit_params(hash)

unless hash[:assignment].nil?
if params[:due_at]
hash[:assignment][:due_at] = params[:due_at].empty? || params[:due_at] == "null" ? nil : params[:due_at]
hash[:assignment][:due_at] = (params[:due_at].empty? || params[:due_at] == "null") ? nil : params[:due_at]
end
hash[:assignment][:points_possible] = params[:points_possible] if params[:points_possible]
hash[:assignment][:assignment_group_id] = params[:assignment_group_id] if params[:assignment_group_id]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def require_view_error_reports
end

def index
params[:page] = params[:page].to_i > 0 ? params[:page].to_i : 1
params[:page] = (params[:page].to_i > 0) ? params[:page].to_i : 1
@reports = ErrorReport.preload(:user, :account)

@message = params[:message]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def api_index
Attachment.display_name_order_by_clause("attachments")
end
order_clause += " DESC" if params[:order] == "desc"
scope = scope.order(Arel.sql(order_clause)).order(id: params[:order] == "desc" ? :desc : :asc)
scope = scope.order(Arel.sql(order_clause)).order(id: (params[:order] == "desc") ? :desc : :asc)

if params[:content_types].present?
scope = scope.by_content_types(Array(params[:content_types]))
Expand Down Expand Up @@ -403,7 +403,7 @@ def react_files

{
asset_string: context.asset_string,
name: context == @current_user ? t("my_files", "My Files") : context.name,
name: (context == @current_user) ? t("my_files", "My Files") : context.name,
usage_rights_required: tool_context.respond_to?(:usage_rights_required?) && tool_context.usage_rights_required?,
permissions: {
manage_files_add: context.grants_right?(@current_user, session, :manage_files_add),
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/folders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def copy_file
@attachment = @source_file.clone_for(@context, @attachment, force_copy: true)
if @attachment.save
# default to rename on race condition (if a file happened to be created after the check above, and on_duplicate was not given)
@attachment.handle_duplicates(on_duplicate == "overwrite" ? :overwrite : :rename, duplicate_options)
@attachment.handle_duplicates((on_duplicate == "overwrite") ? :overwrite : :rename, duplicate_options)
render json: attachment_json(@attachment, @current_user, {}, { omit_verifier_in_app: true })
else
render json: @attachment.errors
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gradebooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ def gradebook_version
def requested_gradebook_view
return nil if params[:view].blank?

params[:view] == "learning_mastery" ? "learning_mastery" : "gradebook"
(params[:view] == "learning_mastery") ? "learning_mastery" : "gradebook"
end

def preferred_gradebook_view
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def render_deep_json(critical, secondary, status_code)
components = HealthChecks.process_readiness_checks(true)
readiness_response = render_readiness_json(components, true)

status = readiness_response[:status] == 503 ? readiness_response[:status] : status_code
status = (readiness_response[:status] == 503) ? readiness_response[:status] : status_code

response = {
readiness: components,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/login/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def successful_login(user, pseudonym, otp_passed = false)
redirect_to(registration_confirmation_path(session.delete(:confirm),
enrollment: session.delete(:enrollment),
login_success: 1,
confirm: (user.id == session.delete(:expected_user_id) ? 1 : nil)))
confirm: ((user.id == session.delete(:expected_user_id)) ? 1 : nil)))
end
else
# the URL to redirect back to is stored in the session, so it's
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lti/feature_flags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def lti_service_context

def context_from_id(context_type, context_id)
# If the id is an integer, it's a Canvas id, not an LTI id
column_name = context_id.to_i.to_s == context_id ? :id : :lti_context_id
column_name = (context_id.to_i.to_s == context_id) ? :id : :lti_context_id
context_type.find_by(column_name => context_id)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def apply_role_filter(scope)

enrollment_types = queryable_roles(role)
if enrollment_types.present? && group_role?(enrollment_types)
enrollment_types == [:group_leader] ? scope.where(user: context.leader_id) : scope
(enrollment_types == [:group_leader]) ? scope.where(user: context.leader_id) : scope
else
scope.none
end
Expand Down Expand Up @@ -92,7 +92,7 @@ def group
end

def lti_roles
@_lti_roles ||= user.id == context.leader_id ? group_leader_role_urns : group_member_role_urns
@_lti_roles ||= (user.id == context.leader_id) ? group_leader_role_urns : group_member_role_urns
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lti/ims/scores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def score_submission
submission_hash = { grader_id: -tool.id }
if line_item.assignment.grading_type == "pass_fail"
# This reflects behavior/logic in Basic Outcomes.
submission_hash[:grade] = scores_params[:result_score].to_f > 0 ? "pass" : "fail"
submission_hash[:grade] = (scores_params[:result_score].to_f > 0) ? "pass" : "fail"
else
submission_hash[:score] = submission_score
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lti/ims/tool_setting_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def lti2_service_name
def tool_setting_json(tool_setting, bubble)
if %w[all distinct].include?(bubble)
graph = []
distinct = bubble == "distinct" ? [] : nil
distinct = (bubble == "distinct") ? [] : nil
while tool_setting
graph << collect_tool_settings(tool_setting, distinct)
distinct |= graph.last.custom.keys if distinct
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lti/message_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def assignment
(tag&.context_type == "Assignment" && tag.context.context == @context) ? tag.context : nil
elsif params[:secure_params].present?
assignment = Assignment.from_secure_lti_params(params[:secure_params])
assignment&.root_account == @context.root_account ? assignment : nil
(assignment&.root_account == @context.root_account) ? assignment : nil
end
end

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

remaining_count = max_records - items.size
condition = klass == "ContentTag" ? "#{ContentTag.quoted_table_name}.updated_at>?" : "updated_at>?"
condition = (klass == "ContentTag") ? "#{ContentTag.quoted_table_name}.updated_at>?" : "updated_at>?"
items += item_scope.where(condition, cutoff_time).order(:id).limit(remaining_count).to_a
break if items.size >= max_records
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/media_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def index
url = api_v1_media_objects_url
end

order_dir = params[:order] == "desc" ? "desc" : "asc"
order_dir = (params[:order] == "desc") ? "desc" : "asc"
order_by = params[:sort] || "title"
if order_by == "title"
order_by = MediaObject.best_unicode_collation_key("COALESCE(user_entered_title, title)")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/oauth2_provider_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def old_silly_behavior(exception)

def grant_type
@grant_type ||= params[:grant_type] || (
!params[:grant_type] && params[:code] ? "authorization_code" : "__UNSUPPORTED_PLACEHOLDER__"
(!params[:grant_type] && params[:code]) ? "authorization_code" : "__UNSUPPORTED_PLACEHOLDER__"
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/outcome_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def user_rollups_sorted_by_score_json
# (sorting by name for duplicate scores), then reorder users
# from those rollups, then paginate those users, and finally
# only include rollups for those users
missing_score_sort = params[:sort_order] == "desc" ? CanvasSort::First : CanvasSort::Last
missing_score_sort = (params[:sort_order] == "desc") ? CanvasSort::First : CanvasSort::Last
rollups = user_rollups.sort_by do |r|
score = r.scores.find { |s| s.outcome.id.to_s == params[:sort_outcome_id] }&.score
[score || missing_score_sort, Canvas::ICU.collation_key(r.context.sortable_name)]
Expand Down
Loading

0 comments on commit b2b0bff

Please sign in to comment.