Skip to content

Commit

Permalink
Merge pull request #80 from MITLibraries/tco46-linting
Browse files Browse the repository at this point in the history
Tco46 linting
  • Loading branch information
JPrevost authored Aug 13, 2024
2 parents 96ffcaf + f2b0e7d commit b8a272d
Show file tree
Hide file tree
Showing 61 changed files with 506 additions and 194 deletions.
35 changes: 35 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-capybara
- rubocop-graphql
- rubocop-minitest
- rubocop-performance
- rubocop-rails

AllCops:
TargetRubyVersion: 3.2
NewCops: enable
Exclude:
- "db/**/*"
- "config/**/*"
- "bin/**"
- 'node_modules/**/*'
- 'tmp/**/*'
- 'vendor/**/*'
- '.git/**/*'
- 'Gemfile'
- 'Rakefile'
- 'config.ru'

Metrics/BlockLength:
Exclude:
- "test/**/*"

Metrics/ClassLength:
Exclude:
- "test/**/*"

Metrics/MethodLength:
Exclude:
- "test/**/*.rb"
126 changes: 126 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-08-12 20:10:38 UTC using RuboCop version 1.65.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
GraphQL/ArgumentDescription:
Exclude:
- 'app/graphql/types/query_type.rb'

# Offense count: 28
GraphQL/FieldDescription:
Exclude:
- 'app/graphql/types/details_type.rb'
- 'app/graphql/types/search_event_type.rb'
- 'app/graphql/types/standard_identifiers_type.rb'
- 'app/graphql/types/term_type.rb'

# Offense count: 1
# Configuration parameters: Include.
# Include: **/graphql/**/*_schema.rb
GraphQL/MaxComplexitySchema:
Exclude:
- 'app/graphql/tacos_schema.rb'

# Offense count: 1
# Configuration parameters: Include.
# Include: **/graphql/**/*_schema.rb
GraphQL/MaxDepthSchema:
Exclude:
- 'app/graphql/tacos_schema.rb'

# Offense count: 7
GraphQL/ObjectDescription:
Exclude:
- 'app/graphql/mutations/base_mutation.rb'
- 'app/graphql/tacos_schema.rb'
- 'app/graphql/types/base_argument.rb'
- 'app/graphql/types/base_connection.rb'
- 'app/graphql/types/base_edge.rb'
- 'app/graphql/types/base_enum.rb'
- 'app/graphql/types/base_field.rb'
- 'app/graphql/types/base_input_object.rb'
- 'app/graphql/types/base_interface.rb'
- 'app/graphql/types/base_object.rb'
- 'app/graphql/types/base_scalar.rb'
- 'app/graphql/types/base_union.rb'
- 'app/graphql/types/details_type.rb'
- 'app/graphql/types/mutation_type.rb'
- 'app/graphql/types/node_type.rb'
- 'app/graphql/types/query_type.rb'
- 'app/graphql/types/search_event_type.rb'
- 'app/graphql/types/standard_identifiers_type.rb'
- 'app/graphql/types/term_type.rb'

# Offense count: 1
Lint/DuplicateMethods:
Exclude:
- 'app/graphql/types/query_type.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Lint/UselessMethodDefinition:
Exclude:
- 'app/graphql/tacos_schema.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 18

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 60

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 16

# Offense count: 1
Minitest/AssertRaisesCompoundBody:
Exclude:
- 'test/tasks/suggested_resource_rake_test.rb'

# Offense count: 2
Minitest/MultipleAssertions:
Max: 5

# Offense count: 6
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'test/models/metrics/algorithms_test.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Performance/StringReplacement:
Exclude:
- 'lib/tasks/suggested_resources.rake'

# Offense count: 3
Rails/I18nLocaleTexts:
Exclude:
- 'app/controllers/admin/application_controller.rb'
- 'app/controllers/application_controller.rb'

# Offense count: 25
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 310
11 changes: 7 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ group :development do
gem 'annotate'

# RuboCop is a Ruby static code analyzer (a.k.a. linter) and code formatter.
gem 'rubocop'
gem 'rubocop-capybara'
gem 'rubocop-rails'
gem 'rubocop', require: false
gem 'rubocop-capybara', require: false
gem 'rubocop-graphql', require: false
gem 'rubocop-minitest', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rails', require: false

# Use console on exceptions pages [https://github.com/rails/web-console]
gem 'web-console'
Expand All @@ -112,4 +115,4 @@ group :test do
gem 'webmock'
end

gem "administrate", "~> 0.20.1"
gem 'administrate', '~> 0.20.1'
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ GEM
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-graphql (1.5.4)
rubocop (>= 1.50, < 2)
rubocop-minitest (0.35.1)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.25.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
Expand Down Expand Up @@ -477,6 +485,9 @@ DEPENDENCIES
rails (~> 7.1.2)
rubocop
rubocop-capybara
rubocop-graphql
rubocop-minitest
rubocop-performance
rubocop-rails
selenium-webdriver
simplecov
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ outdated: # List outdated dependencies
# Code quality and safety commands
####################################

# coming soon!
lint:
bundle exec rubocop

lint-models:
bundle exec rubocop app/models

lint-controllers:
bundle exec rubocop app/controllers
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# All Administrate controllers inherit from this
# `Administrate::ApplicationController`, making it the ideal place to put
# authentication logic or other before_actions.
Expand All @@ -13,7 +15,7 @@ class ApplicationController < Administrate::ApplicationController

def authorize_user
return if authorize_action?(resource_name, action_name)

redirect_to root_path, alert: 'Not authorized'
end

Expand All @@ -23,7 +25,7 @@ def authorize_action?(resource, action)

def require_user
return if current_user

redirect_to root_path, alert: 'Please sign in to continue'
end

Expand Down
12 changes: 7 additions & 5 deletions app/controllers/admin/detector/suggested_resources_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
module Detector
class SuggestedResourcesController < Admin::ApplicationController
Expand All @@ -8,17 +10,17 @@ class SuggestedResourcesController < Admin::ApplicationController
# super
# send_foo_updated_email(requested_resource)
# end

# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`
# actions.
#
# def find_resource(param)
# Foo.find_by!(slug: param)
# end

# The result of this lookup will be available as `requested_resource`

# Override this if you have certain roles that require a subset
# this will be used to set the records shown on the `index` action.
#
Expand All @@ -29,7 +31,7 @@ class SuggestedResourcesController < Admin::ApplicationController
# resource_class.with_less_stuff
# end
# end

# Override `resource_params` if you want to transform the submitted
# data before it's persisted. For example, the following would turn all
# empty values into nil values. It uses other APIs such as `resource_class`
Expand All @@ -40,7 +42,7 @@ class SuggestedResourcesController < Admin::ApplicationController
# permit(dashboard.permitted_attributes(action_name)).
# transform_values { |value| value == "" ? nil : value }
# end

# See https://administrate-demo.herokuapp.com/customizing_controller_actions
# for more information
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/search_events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class SearchEventsController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/terms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class TermsController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class UsersController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
helper Mitlibraries::Theme::Engine.helpers

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 @@ -44,10 +44,10 @@ def prepare_variables(variables_param)
end
end

def handle_error_in_development(e)
logger.error e.message
logger.error e.backtrace.join("\n")
def handle_error_in_development(error)
logger.error error.message
logger.error error.backtrace.join("\n")

render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
render json: { errors: [{ message: error.message, backtrace: error.backtrace }], data: {} }, status: :internal_server_error
end
end
2 changes: 2 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class StaticController < ApplicationController
def index; end
end
30 changes: 17 additions & 13 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# frozen_string_literal: true

# Handles authentication response from Omniauth. See
# [the Devise docs](https://www.rubydoc.info/gems/devise_token_auth/DeviseTokenAuth/OmniauthCallbacksController) for
# additional information about this controller.
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
include FakeAuthConfig
module Users
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
include FakeAuthConfig

def openid_connect
@user = User.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @user, event: :authentication
flash[:notice] = "Welcome, #{@user.email}!"
end
def openid_connect
@user = User.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @user, event: :authentication
flash[:notice] = "Welcome, #{@user.email}!"
end

# Developer authentication is used in local dev and PR builds.
def developer
raise 'Invalid Authentication' unless FakeAuthConfig.fake_auth_enabled?
# Developer authentication is used in local dev and PR builds.
def developer
raise 'Invalid Authentication' unless FakeAuthConfig.fake_auth_enabled?

@user = User.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @user, event: :authentication
flash[:notice] = "Welcome, #{@user.email}!"
@user = User.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @user, event: :authentication
flash[:notice] = "Welcome, #{@user.email}!"
end
end
end
Loading

0 comments on commit b8a272d

Please sign in to comment.