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

Add rubocop settings and run safe autocorrect #1395

Merged
merged 5 commits into from
Oct 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
178 changes: 173 additions & 5 deletions .rubocop.yml
@@ -1,8 +1,11 @@
require: rubocop-rails
AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
- 'spec/factories/*.rb'
- 'app/controllers/*.rb'
- 'app/models/*.rb'
Exclude:
- 'assessmentConfig/**/*'
- 'attachments/**/*'
Expand All @@ -16,7 +19,7 @@ AllCops:
Rails:
Enabled: true

Metrics/LineLength:
Layout/LineLength:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the linelength stuff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, does removing "Enabled: false" introduce further changes if linting is run again? I'm not sure whether all lines are below 100 right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will probably introduce more things to be manually fixed, but not things that can be automatically fixed. I ran it again and there was nothing else that can be safely autofixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then let's not run it again for now.

Max: 100
# To make it possible to copy or click on URIs in the code, we allow lines
# contaning a URI to be longer than Max.
Expand All @@ -25,10 +28,6 @@ Metrics/LineLength:
- http
- https

Metrics/MethodLength:
CountComments: false # count full line comments?
Max: 20

# Indent private/protected/public as deep as method definitions
Layout/AccessModifierIndentation:
EnforcedStyle: outdent
Expand All @@ -41,3 +40,172 @@ Style/StringLiterals:
SupportedStyles:
- single_quotes
- double_quotes

# Frozen string literals will introduce breaking changes to existing ruby files.
Style/FrozenStringLiteralComment:
EnforcedStyle: never

Lint/RaiseException:
Enabled: false

Lint/StructNewOverride:
Enabled: false

Style/HashEachMethods:
Enabled: false

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Enabled: false

Naming/VariableName:
Enabled: false

Style/Alias:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylealias

Style/AsciiComments:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleasciicomments

Style/BeginBlock:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylebeginblock

Style/BlockDelimiters:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters

Style/CommentAnnotation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylecommentannotation

Style/Documentation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styledocumentation

Layout/DotPosition:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutdotposition

Style/DoubleNegation:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styledoublenegation

Style/EndBlock:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleendblock

Style/FormatString:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleformatstring

Style/IfUnlessModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier

Style/Lambda:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylelambda

Style/ModuleFunction:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylemodulefunction

Style/MultilineBlockChain:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain

Style/NegatedIf:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenegatedif

Style/NegatedWhile:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile

Style/NumericPredicate:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate

Style/ParallelAssignment:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment

Style/PercentLiteralDelimiters:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters

Style/PerlBackrefs:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs

Style/Semicolon:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesemicolon

Style/SignalException:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesignalexception

Style/SingleLineBlockParams:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams

Style/SingleLineMethods:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods

Layout/SpaceBeforeBlockBraces:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces

Layout/SpaceInsideParens:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens

Style/SpecialGlobalVars:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars

Style/StringLiterals:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylestringliterals

Style/TrailingCommaInArguments:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments

Style/TrailingCommaInArrayLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral

Style/TrailingCommaInHashLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral

Style/SymbolArray:
Enabled: false
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray

Style/WhileUntilModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier

Style/WordArray:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#stylewordarray

Lint/AmbiguousRegexpLiteral:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral

Lint/AssignmentInCondition:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition

Metrics:
Enabled: false
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -2,6 +2,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 File.expand_path("../config/application", __FILE__)
require File.expand_path("config/application", __dir__)

Autolab3::Application.load_tasks
12 changes: 6 additions & 6 deletions app/controllers/admins_controller.rb
Expand Up @@ -2,29 +2,29 @@
# this controller contains methods for system-wise
# admin functionality
class AdminsController < ApplicationController
rescue_from ActionView::MissingTemplate do |exception|
rescue_from ActionView::MissingTemplate do |_exception|
redirect_to("/home/error_404")
end

skip_before_action :set_course

action_auth_level :show, :administrator
def show
end
def show; end

action_auth_level :email_instructors, :administrator
def email_instructors
@cuds = CourseUserDatum.select(:user_id).distinct.joins(:course).joins(:user)
.where(instructor: true)
.order("users.email ASC")
.where(instructor: true)
.order("users.email ASC")

return unless request.post?

@email = CourseMailer.system_announcement(
params[:from],
make_dlist(@cuds),
params[:subject],
params[:body])
params[:body]
)
@email.deliver
end
end
14 changes: 7 additions & 7 deletions app/controllers/annotations_controller.rb
Expand Up @@ -8,9 +8,9 @@ class AnnotationsController < ApplicationController
before_action :set_assessment
before_action :set_submission
before_action :set_annotation, except: [:create]
rescue_from ActionView::MissingTemplate do |exception|
redirect_to("/home/error_404")
end
rescue_from ActionView::MissingTemplate do |_exception|
redirect_to("/home/error_404")
end

respond_to :json

Expand All @@ -21,7 +21,7 @@ def create

ActiveRecord::Base.transaction do
annotation.save
annotation.update_non_autograded_score()
annotation.update_non_autograded_score
end

respond_with(@course, @assessment, @submission, annotation)
Expand All @@ -32,7 +32,7 @@ def create
def update
ActiveRecord::Base.transaction do
@annotation.update(annotation_params)
@annotation.update_non_autograded_score()
@annotation.update_non_autograded_score
end

respond_with(@course, @assessment, @submission, @annotation) do |format|
Expand All @@ -45,7 +45,7 @@ def update
def destroy
ActiveRecord::Base.transaction do
@annotation.destroy
@annotation.update_non_autograded_score()
@annotation.update_non_autograded_score
end

head :no_content
Expand All @@ -58,7 +58,7 @@ def annotation_params
params[:annotation].delete(:created_at)
params[:annotation].delete(:updated_at)
params.require(:annotation).permit(:filename, :position, :line, :submitted_by,
:comment, :value, :problem_id,:submission_id, :coordinate)
:comment, :value, :problem_id, :submission_id, :coordinate)
end

def set_annotation
Expand Down
26 changes: 13 additions & 13 deletions app/controllers/announcements_controller.rb
@@ -1,19 +1,19 @@
# Extend the Rails ApplicationController to define some RESTful endpoints for
# dealing with Announcements.
class AnnouncementsController < ApplicationController
before_action :set_announcement, except: [:index, :new, :create]
before_action :set_announcement, except: %i[index new create]

rescue_from ActionView::MissingTemplate do |exception|
redirect_to("/home/error_404")
rescue_from ActionView::MissingTemplate do |_exception|
redirect_to("/home/error_404")
end

action_auth_level :index, :instructor
def index
if @cud.user.administrator?
@announcements = Announcement.where("course_id=? or system", @course.id)
else
@announcements = @course.announcements
end
@announcements = if @cud.user.administrator?
Announcement.where("course_id=? or system", @course.id)
else
@course.announcements
end
end

action_auth_level :new, :instructor
Expand All @@ -35,8 +35,7 @@ def create
end

action_auth_level :edit, :instructor
def edit
end
def edit; end

action_auth_level :update, :instructor
def update
Expand All @@ -63,9 +62,9 @@ def destroy
private

def set_announcement
@announcement = @course.announcements.find_by_id(params[:id])
if @announcement.nil? # May be system announcement / from another course
@announcement = Announcement.find_by_id(params[:id])
@announcement = @course.announcements.find_by(id: params[:id])
if @announcement.nil? # May be system announcement / from another course
@announcement = Announcement.find_by(id: params[:id])
if @announcement.nil?
flash[:error] = "Announcement not found."
redirect_to(action: :index) && return
Expand All @@ -76,6 +75,7 @@ def set_announcement
end
# Sanity check
return unless @announcement.system && !@cud.user.administrator?

flash[:error] = "You don't have permission to access system announcements."
redirect_to(action: :index) && return
end
Expand Down