Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Add Rubocop and run Linters on Test Action (#56)
Browse files Browse the repository at this point in the history
Add Rubocup and Eslint runs on test
  • Loading branch information
FinnIckler authored May 31, 2023
1 parent 973d72e commit 1633cac
Show file tree
Hide file tree
Showing 42 changed files with 545 additions and 236 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@ jobs:
RACK_ENV: test
steps:
- uses: actions/checkout@v3
- name: Set up Ruby # Only install ruby to get Rubocop
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2.2'
- name: Lint with Rubocop
run: |
gem install rubocop
rubocop
- name: Lint with Eslint
run: |
cd ./Frontend
npm install
npm run lint
- name: Start containers
run: docker compose -f "docker-compose.test.yml" up wca_registration_handler --abort-on-container-exit
227 changes: 227 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
AllCops:
TargetRubyVersion: 3.2.2
DisplayCopNames: true
NewCops: enable
Exclude:
- 'node_modules/**/*'
- 'Frontend/**/*'
- 'bin/**/*'
- 'vendor/**/*'

Bundler/OrderedGems:
Enabled: false

Lint/EmptyWhen:
Enabled: false

Lint/UnusedBlockArgument:
Enabled: false

Lint/UnusedMethodArgument:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

Style/Alias:
Enabled: false

Style/EmptyMethod:
EnforcedStyle: expanded

Style/RedundantSelf:
Enabled: false

Style/SafeNavigation:
Enabled: false

Style/StringLiterals:
# EnforcedStyle: double_quotes
Enabled: false

Style/TrailingCommaInArguments:
# If `comma`, the cop requires a comma after the last argument, but only for
# parenthesized method calls where each argument is on its own line.
# If `consistent_comma`, the cop requires a comma after the last argument,
# for all parenthesized method calls with arguments.
EnforcedStyleForMultiline: comma

Style/TrailingCommaInArrayLiteral:
# If `comma`, the cop requires a comma after the last argument, but only for
# parenthesized method calls where each argument is on its own line.
# If `consistent_comma`, the cop requires a comma after the last argument,
# for all parenthesized method calls with arguments.
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
# If `comma`, the cop requires a comma after the last item in an array or
# hash, but only when each item is on its own line.
# If `consistent_comma`, the cop requires a comma after the last item of all
# non-empty array and hash literals.
EnforcedStyleForMultiline: comma

Style/GuardClause:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/BlockNesting:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/CyclomaticComplexity:
Max: 23

Metrics/ParameterLists:
Max: 5
CountKeywordArgs: false

Metrics/PerceivedComplexity:
Max: 25

Layout/LineLength:
Max: 245

Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Naming/MemoizedInstanceVariableName:
Enabled: false

Style/AccessModifierDeclarations:
Enabled: false

Style/AsciiComments:
Enabled: false

Style/BlockDelimiters:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/ClassVars:
Enabled: false

Style/ConditionalAssignment:
Enabled: false

Style/Documentation:
Enabled: false

Style/DoubleNegation:
Enabled: false

Style/EmptyElse:
EnforcedStyle: empty

Style/IfInsideElse:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Style/InverseMethods:
Enabled: false

Style/Lambda:
Enabled: false

Style/MultilineBlockChain:
Enabled: false

Style/NegatedIf:
Enabled: false

Style/Next:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/PercentLiteralDelimiters:
Enabled: false

Style/PerlBackrefs:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact

Style/RedundantParentheses:
Enabled: false

Style/SignalException:
EnforcedStyle: only_raise

Layout/SpaceAroundOperators:
Enabled: false

Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methods

Style/StringLiteralsInInterpolation:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/WordArray:
Enabled: false

Style/SymbolProc:
Enabled: false

Naming/PredicateName:
Enabled: false

Naming/BlockParameterName:
Enabled: false

Naming/MethodParameterName:
Enabled: false

Style/YodaCondition:
Enabled: false

Style/FormatStringToken:
Enabled: false

Layout/EmptyLineAfterGuardClause:
Enabled: false

Lint/EmptyFile:
Exclude:
- 'db/seeds.rb'

# We have too many event IDs and Comp Years with numbers in them
Naming/VariableNumber:
Enabled: false

# If an external library requires us to use terms like "blacklist",
# we have no choice but to follow their conventions until they update
Naming/InclusiveLanguage:
Exclude:
- 'config/**/*'

Style/OpenStructUse:
Exclude:
- 'spec/lib/middlewares/warden_user_logger_spec.rb'

Style/HashSyntax:
EnforcedShorthandSyntax: never

# These AWS Clients are set in the initializer
Style/GlobalVars:
AllowedVariables:
- $sqs
- $dynamodb
2 changes: 1 addition & 1 deletion Frontend/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import '@thewca/wca-components/dist/index.esm.css'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { createBrowserRouter, Link, RouterProvider } from 'react-router-dom'
import Registrations from './pages/registrations'
import Register from './pages/register'
import Registrations from './pages/registrations'

const router = createBrowserRouter([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function RegistrationPanel() {
handleEventSelection={handleEventSelection}
events={EVENTS}
initialSelected={[]}
size={'2x'}
size="2x"
/>
<button
onClick={(_) =>
Expand Down
30 changes: 16 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/thewca/wca-registration.git" }
# frozen_string_literal: true

ruby "3.2.2"
source 'https://rubygems.org'
git_source(:github) { |_repo| 'https://github.com/thewca/wca-registration.git' }

ruby '3.2.2'

# Gems that are only needed by the handler not the worker
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4", ">= 7.0.4.3"
gem 'rails', '~> 7.0.4', '>= 7.0.4.3'

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
gem 'sqlite3', '~> 1.4'

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
gem 'puma', '~> 5.0'

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"
gem 'jbuilder'

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem "rack-cors"
gem 'rack-cors'

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false
gem 'bootsnap', require: false

# Use Redis adapter to run Action Cable in production
gem "redis", "~> 4.0"
gem 'hiredis'
gem 'redis', '~> 4.0'

# DynamoDB for storing registrations
gem 'aws-sdk-dynamodb'
Expand All @@ -33,21 +35,21 @@ gem 'aws-sdk-dynamodb'
gem 'aws-sdk-sqs'

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
gem "kredis"
gem 'kredis'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

# vault for secrets management
gem 'vault-rails'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'rubocop', require: false
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# 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_relative "config/application"
require_relative 'config/application'

Rails.application.load_tasks
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
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::API
end
4 changes: 3 additions & 1 deletion app/controllers/healthcheck_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

class HealthcheckController < ApplicationController
def index
render json: { status: "ok" }, status: :ok
render json: { status: 'ok' }, status: :ok
end
end
14 changes: 8 additions & 6 deletions app/controllers/metrics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# frozen_string_literal: true

require 'securerandom'
class MetricsController < ApplicationController
def index
# Get the queue attributes
queue_url = $sqs.get_queue_url(queue_name: "registrations.fifo").queue_url
queue_url = $sqs.get_queue_url(queue_name: 'registrations.fifo').queue_url
response = $sqs.get_queue_attributes({
queue_url: queue_url,
attribute_names: ["ApproximateNumberOfMessages"]
})
queue_url: queue_url,
attribute_names: ['ApproximateNumberOfMessages'],
})

# Get the queue size
queue_size = response.attributes["ApproximateNumberOfMessages"].to_i
queue_size = response.attributes['ApproximateNumberOfMessages'].to_i

render json: { queue_size: queue_size}
render json: { queue_size: queue_size }
end
end
Loading

0 comments on commit 1633cac

Please sign in to comment.