Skip to content

Commit

Permalink
finished rubocop for app/ spec/ and lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
briri committed Jul 10, 2020
1 parent 3e7d68e commit ed4c019
Show file tree
Hide file tree
Showing 59 changed files with 85 additions and 204 deletions.
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,21 @@ Layout/LineLength:
# longer.
- 'spec/spec_helper.rb'

# Bumping the default ClassLength so we don't need to refactor everything
Metrics/ClassLength:
Max: 300

# Bumping the default AbcSize so we don't need to refactor everything
Metrics/AbcSize:
Max: 25

# Bumping the default CyclomaticComplexity so we don't need to refactor everything
Metrics/CyclomaticComplexity:
Max: 25

# Bumping the default PerceivedComplexity so we don't need to refactor everything
Metrics/PerceivedComplexity:
Max: 25

# Restrict the number of lines of code that may be within a block of code. This should
# force developers to break their code into smaller discrete methods or objects.
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class AnswersController < ApplicationController

respond_to :html
Expand All @@ -13,7 +12,6 @@ class AnswersController < ApplicationController
# `remote: true` in the <form> tag and just send back the ERB.
# Consider using ActionCable for the progress bar(s)
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def create_or_update
p_params = permitted_params

Expand Down Expand Up @@ -166,7 +164,7 @@ def create_or_update
# rubocop:enable Style/GuardClause
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

private

Expand Down Expand Up @@ -194,4 +192,3 @@ def check_answered(section, q_array, all_answers)
end

end
# rubocop:enable Metrics/ClassLength
7 changes: 3 additions & 4 deletions app/controllers/api/v0/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::V0::PlansController < Api::V0::BaseController

##
# Creates a new plan based on the information passed in JSON to the API
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def create
@template = Template.live(params[:template_id])
raise Pundit::NotAuthorizedError unless Api::V0::PlansPolicy.new(@user, @template).create?
Expand Down Expand Up @@ -54,10 +54,9 @@ def create
render json: _("Bad Parameters"), status: 400
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def index
raise Pundit::NotAuthorizedError unless Api::V0::PlansPolicy.new(@user, nil).index?

Expand Down Expand Up @@ -97,7 +96,7 @@ def index
respond_with @plans
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

private

Expand Down
11 changes: 3 additions & 8 deletions app/controllers/api/v0/statistics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class Api::V0::StatisticsController < Api::V0::BaseController

before_action :authenticate
Expand All @@ -14,7 +13,6 @@ class Api::V0::StatisticsController < Api::V0::BaseController
# against org_id param instead of user's org

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def users_joined
unless Api::V0::StatisticsPolicy.new(@user, :statistics).users_joined?
raise Pundit::NotAuthorizedError
Expand Down Expand Up @@ -58,13 +56,12 @@ def users_joined
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

# GET
# Returns the number of completed plans within the user's org for the data
# start_date and end_date specified
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def completed_plans
unless Api::V0::StatisticsPolicy.new(@user, :statistics).completed_plans?
raise Pundit::NotAuthorizedError
Expand Down Expand Up @@ -107,13 +104,12 @@ def completed_plans
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

# /api/v0/statistics/created_plans
# Returns the number of created plans within the user's org for the data
# start_date and end_date specified
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def created_plans
raise Pundit::NotAuthorizedError unless Api::V0::StatisticsPolicy.new(@user, :statistics).plans?

Expand Down Expand Up @@ -154,7 +150,7 @@ def created_plans
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

##
# Displays the number of DMPs using templates owned/create by the caller's Org
Expand Down Expand Up @@ -246,4 +242,3 @@ def dates_to_range(hash)
end

end
# rubocop:enable Metrics/ClassLength
3 changes: 1 addition & 2 deletions app/controllers/api/v0/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Api::V0::TemplatesController < Api::V0::BaseController
#
# Renders a list of templates ordered by organisation
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def index
# check if the user has permissions to use the templates API
unless Api::V0::TemplatePolicy.new(@user, :guidance_group).index?
Expand Down Expand Up @@ -54,6 +53,6 @@ def index
respond_with @org_templates
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

end
2 changes: 0 additions & 2 deletions app/controllers/api/v1/base_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Api
module V1

# Base API Controller
# rubocop:disable Metrics/ClassLength
class BaseApiController < ApplicationController

# Skipping the standard Rails authenticity tokens passed in UI
Expand Down Expand Up @@ -192,7 +191,6 @@ def host_permitted_params
end

end
# rubocop:enable Metrics/ClassLength

end

Expand Down
12 changes: 4 additions & 8 deletions app/controllers/api/v1/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ module Api

module V1

# rubocop:disable Metrics/ClassLength
class PlansController < BaseApiController

respond_to :json

# GET /api/v1/plans/:id
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def show
plans = Plan.where(id: params[:id]).limit(1)

Expand Down Expand Up @@ -42,11 +40,10 @@ def show
end
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

# POST /api/v1/plans
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockNesting
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def create
dmp = @json.with_indifferent_access.fetch(:items, []).first.fetch(:dmp, {})

Expand Down Expand Up @@ -90,7 +87,7 @@ def create
render_error(errors: [_("Invalid JSON")], status: :bad_request)
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockNesting
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

# GET /api/v1/plans
def index
Expand Down Expand Up @@ -133,7 +130,7 @@ def assign_roles(plan:)
end
end

# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
# rubocop:disable Metrics/AbcSize
def contributor_to_user(contributor:)
identifiers = contributor.identifiers.map do |id|
{ name: id.identifier_scheme&.name, value: id.value }
Expand All @@ -158,10 +155,9 @@ def contributor_to_user(contributor:)
end
user
end
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
# rubocop:enable Metrics/AbcSize

end
# rubocop:enable Metrics/ClassLength

end

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class ApplicationController < ActionController::Base

protect_from_forgery with: :exception
Expand Down Expand Up @@ -174,4 +173,3 @@ def configure_permitted_parameters
end

end
# rubocop:enable Metrics/ClassLength
3 changes: 1 addition & 2 deletions app/controllers/concerns/paginable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ module Paginable
# one approach to just include everything in the double splat `**options` param

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def paginable_renderise(partial: nil, controller: nil, action: nil,
path_params: {}, query_params: {}, scope: nil,
locals: {}, **options)
Expand Down Expand Up @@ -84,7 +83,7 @@ def paginable_renderise(partial: nil, controller: nil, action: nil,
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

# Returns the base url of the paginable route for a given page passed
def paginable_base_url(page = 1)
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/concerns/versionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_modifiable(obj)
# generated and returns a modifiable version of that object
# NOTE: the obj passed is still not saved however it should belongs to a
# parent already
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
def get_new(obj)
unless obj.respond_to?(:template)
raise ArgumentError,
Expand Down Expand Up @@ -76,14 +76,13 @@ def get_new(obj)
end
obj
end
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength

# Locates an object (e.g. phase, section, question, annotation) in a
# search_space
# (e.g. phases/sections/questions/annotations) by comparing either the number
# method or the org_id and text for annotations
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def find_in_space(obj, search_space)
unless search_space.respond_to?(:each)
raise ArgumentError, _("The search_space does not respond to each")
Expand Down Expand Up @@ -132,6 +131,6 @@ def find_in_space(obj, search_space)
nil
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

end
2 changes: 0 additions & 2 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class ContactUs::ContactsController < ApplicationController

# rubocop:disable Metrics/PerceivedComplexity
def create
@contact = ContactUs::Contact.new(params[:contact_us_contact])

Expand All @@ -20,7 +19,6 @@ def create
render_new_page
end
end
# rubocop:enable Metrics/PerceivedComplexity

def new
@contact = ContactUs::Contact.new
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/contributors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class ContributorsController < ApplicationController

include OrgSelectable
Expand Down Expand Up @@ -185,4 +184,3 @@ def save_orcid
end

end
# rubocop:enable Metrics/ClassLength
2 changes: 0 additions & 2 deletions app/controllers/guidances_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class GuidancesController < ApplicationController

after_action :verify_authorized
Expand Down Expand Up @@ -141,4 +140,3 @@ def ensure_default_group(org)
end

end
# rubocop:enable Metrics/ClassLength
2 changes: 0 additions & 2 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/ClassLength
class NotesController < ApplicationController

include ConditionalUserMailer
Expand Down Expand Up @@ -167,4 +166,3 @@ def note_params
end

end
# rubocop:enable Metrics/ClassLength
2 changes: 0 additions & 2 deletions app/controllers/org_admin/phases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module OrgAdmin

# rubocop:disable Metrics/ClassLength
class PhasesController < ApplicationController

include Versionable
Expand Down Expand Up @@ -197,4 +196,3 @@ def phase_params
end

end
# rubocop:enable Metrics/ClassLength
5 changes: 1 addition & 4 deletions app/controllers/org_admin/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module OrgAdmin

# rubocop:disable Metrics/ClassLength
class QuestionsController < ApplicationController

include AllowedQuestionFormats
Expand Down Expand Up @@ -110,7 +109,6 @@ def create

# PUT /org_admin/templates/:template_id/phases/:phase_id/sections/:section_id/questions/:id
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def update
question = Question.find(params[:id])
authorize question
Expand Down Expand Up @@ -185,7 +183,7 @@ def update
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable

# DELETE /org_admin/templates/:template_id/phases/:phase_id/sections/:section_id/questions/:id
# rubocop:disable Metrics/AbcSize
Expand Down Expand Up @@ -287,6 +285,5 @@ def transfer_associations(attrs, question)
end

end
# rubocop:enable Metrics/ClassLength

end
Loading

0 comments on commit ed4c019

Please sign in to comment.