Skip to content

Commit

Permalink
[CHORE] Setup Rubocop-Rails and Rubocop-Rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Daivasmara committed Apr 7, 2021
1 parent 29c7d48 commit 7ee3672
Show file tree
Hide file tree
Showing 24 changed files with 214 additions and 163 deletions.
6 changes: 5 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn eslint
cowsay yarn eslint --fix
yarn eslint --fix

cowsay bundle exec rubocop -a
bundle exec rubocop -a
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
require:
- rubocop-rails
- rubocop-rspec

AllCops:
NewCops: enable
Style/FrozenStringLiteralComment:
Enabled: false
Metrics/BlockLength:
Enabled: false
Style/Documentation:
Enabled: false
Rails/RakeEnvironment:
Enabled: false
RSpec/ExampleLength:
Enabled: false
Layout/LineLength:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ end

gem 'annotate', '~> 3.1'
gem 'figaro', '~> 1.2'
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
gem 'simplecov', require: false, group: :test
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ GEM
annotate (3.1.1)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 14.0)
ast (2.4.2)
bcrypt (3.1.16)
bindex (0.8.1)
bootsnap (1.7.3)
Expand Down Expand Up @@ -101,6 +102,9 @@ GEM
nokogiri (1.11.2)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.1.0)
ast (~> 2.4.1)
pg (1.2.3)
puma (5.2.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -138,10 +142,13 @@ GEM
method_source
rake (>= 0.8.7)
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.1.1)
rexml (3.2.5)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand All @@ -159,6 +166,25 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubocop (1.12.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-rails (2.9.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-rspec (2.2.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
Expand Down Expand Up @@ -191,6 +217,7 @@ GEM
turbolinks-source (5.2.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
web-console (4.1.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -222,6 +249,8 @@ DEPENDENCIES
rack-mini-profiler (~> 2.0)
rails (~> 6.1.3, >= 6.1.3.1)
rspec-rails (~> 5.0.0)
rubocop-rails
rubocop-rspec
sass-rails (>= 6)
simplecov
spring
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,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_relative "config/application"
require_relative 'config/application'

Rails.application.load_tasks
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_email (email) UNIQUE
# index_users_on_username (username) UNIQUE
#
class User < ApplicationRecord
has_secure_password

Expand Down
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is used by Rack-based servers to start the application.

require_relative "config/environment"
require_relative 'config/environment'

run Rails.application
Rails.application.load_server
26 changes: 13 additions & 13 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require_relative "boot"
require_relative 'boot'

require "rails"
require 'rails'
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require 'active_model/railtie'
require 'active_job/railtie'
require 'active_record/railtie'
require 'active_storage/engine'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_mailbox/engine'
require 'action_text/engine'
require 'action_view/railtie'
require 'action_cable/engine'
require 'sprockets/railtie'
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
Expand Down
4 changes: 2 additions & 2 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations.
require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
2 changes: 1 addition & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Load the Rails application.
require_relative "application"
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!
4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "active_support/core_ext/integer/time"
require 'active_support/core_ext/integer/time'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
Expand All @@ -16,7 +16,7 @@

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

Expand Down
8 changes: 4 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "active_support/core_ext/integer/time"
require 'active_support/core_ext/integer/time'

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
Expand Down Expand Up @@ -53,7 +53,7 @@
config.log_level = :info

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand Down Expand Up @@ -88,8 +88,8 @@
# require "syslog/logger"
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "active_support/core_ext/integer/time"
require 'active_support/core_ext/integer/time'

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE']
4 changes: 2 additions & 2 deletions config/initializers/filter_parameter_logging.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.

# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
Rails.application.config.filter_parameters += %i[
passw secret token _key crypt salt certificate otp ssn
]
12 changes: 6 additions & 6 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `worker_timeout` threshold that Puma will use to wait before
# terminating a worker in development environments.
#
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
port ENV.fetch('PORT', 3000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
environment ENV.fetch('RAILS_ENV') { 'development' }

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
Expand Down
8 changes: 4 additions & 4 deletions config/spring.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Spring.watch(
".ruby-version",
".rbenv-vars",
"tmp/restart.txt",
"tmp/caching-dev.txt"
'.ruby-version',
'.rbenv-vars',
'tmp/restart.txt',
'tmp/caching-dev.txt'
)
6 changes: 4 additions & 2 deletions db/migrate/20210327141353_create_users.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users, id: :uuid do |t|
t.string :username, null: false, unique: true
t.string :email, null: false, unique: true
t.string :username, null: false
t.string :email, null: false
t.string :password_digest, null: false

t.timestamps
end
add_index :users, :username, unique: true
add_index :users, :email, unique: true
end
end
2 changes: 2 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ee3672

Please sign in to comment.