Skip to content

Commit

Permalink
Add Rubocop to CircleCI configuration (#8)
Browse files Browse the repository at this point in the history
* Add rubocop to Gemfile

* Update bundler version in lockfile

* Add rubocop to circleci configuration

* Auto fix some rubocop offenses
  • Loading branch information
danielpeng2 authored and Daniel Williams committed Oct 8, 2019
1 parent 48762e5 commit d85069d
Show file tree
Hide file tree
Showing 41 changed files with 223 additions and 118 deletions.
30 changes: 29 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,40 @@ workflows:
deploy:
jobs:
- install
- lint:
requires:
- install
- deploy:
requires:
- lint
- install
jobs:
lint:
docker:
- image: circleci/ruby:2.5.1
environment:
RAILS_ENV: development
PGHOST: 127.0.0.1
PGUSER: root
steps:
- checkout
- run:
name: Install dependencies
command: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs 4 --retry 3
- run:
name: Run Rubocop
command: bundle exec rubocop
deploy:
executor: heroku/default
steps:
- heroku/install
- heroku/deploy-via-git:
only-branch: master
install:
docker:
- image: circleci/ruby:2.5.1
environment:
RAILS_ENV: test
RAILS_ENV: development
PGHOST: 127.0.0.1
PGUSER: root

Expand Down
14 changes: 8 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down Expand Up @@ -25,21 +27,21 @@ gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails', '~> 3.5'
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'database_cleaner'
gem 'rspec-rails', '~> 3.5'
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'rubocop'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'rubocop'
end

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

gem "pg", "~> 1.1"
gem 'pg', '~> 1.1'
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 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.

Expand Down
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
10 changes: 6 additions & 4 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class QuestionsController < ApplicationController
def index
@questions = Question.all
render json: @questions
end
def index
@questions = Question.all
render json: @questions
end
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
Expand Down
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
Expand Down
2 changes: 2 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
2 changes: 2 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class Question < ApplicationRecord
end
48 changes: 29 additions & 19 deletions bin/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,63 @@
# this file is here to facilitate running it.
#

require "rubygems"
require 'rubygems'

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
ENV['BUNDLER_VERSION']
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`

bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1 || ">= 0.a"
unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
next
end

bundler_version = Regexp.last_match(1) || '>= 0.a'
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
gemfile = ENV['BUNDLE_GEMFILE']
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../../Gemfile", __FILE__)
File.expand_path('../Gemfile', __dir__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)

lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
return
end

Regexp.last_match(1)
end

Expand All @@ -68,24 +76,28 @@ m = Module.new do
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile
ENV['BUNDLE_GEMFILE'] ||= gemfile

# must dup string for RG < 1.8 compatibility
activate_bundler(bundler_version.dup)
end

def activate_bundler(bundler_version)
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
bundler_version = "< 2"
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0')
bundler_version = '< 2'
end
gem_error = activation_error_handling do
gem "bundler", bundler_version
gem 'bundler', bundler_version
end
return if gem_error.nil?

require_error = activation_error_handling do
require "bundler/version"
require 'bundler/version'
end
if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
return
end
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))

warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
exit 42
end
Expand All @@ -100,6 +112,4 @@ end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
4 changes: 3 additions & 1 deletion bin/rails
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

begin
load File.expand_path('../spring', __FILE__)
load File.expand_path('spring', __dir__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
Expand Down
4 changes: 3 additions & 1 deletion bin/rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

begin
load File.expand_path('../spring', __FILE__)
load File.expand_path('spring', __dir__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
Expand Down
2 changes: 2 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'fileutils'

# path to your application root.
Expand Down
1 change: 1 addition & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# This file loads Spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.
Expand Down
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'
Expand Down
26 changes: 14 additions & 12 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# frozen_string_literal: true

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 '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 'rails/test_unit/railtie'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down
2 changes: 2 additions & 0 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require 'bundler/setup' # Set up gems listed in the Gemfile.
Expand Down
2 changes: 2 additions & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Load the Rails application.
require_relative 'application'

Expand Down
3 changes: 2 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down Expand Up @@ -42,7 +44,6 @@
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true


# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true

Expand Down
8 changes: 5 additions & 3 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand All @@ -11,7 +13,7 @@
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.consider_all_requests_local = false

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
Expand Down Expand Up @@ -44,7 +46,7 @@
config.log_level = :debug

# 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 @@ -73,7 +75,7 @@
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
Expand Down
4 changes: 3 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

config.cache_classes = false

# Do not eager load code on boot. This avoids loading your whole application
Expand Down
Loading

0 comments on commit d85069d

Please sign in to comment.