Skip to content

Commit 6b96925

Browse files
mxygemseanmarcia
authored andcommitted
Railscop (#170)
* Add Rubocop * Fix Layout/AlignHash & Create Rubocop.yml - Offense count: 4 * Fix Layout/AlignParameters - Offense count: 5 * Fix Layout/BlockEndNewline - Offense count: 4 * Fix Layout/ClosingParenthesisIndentation - Offense count: 1 * Fix Layout/CommentIndentation - Offense count: 1 * Fix Layout/EmptyLineBetweenDefs - Offense count: 2 * Fix Layout/EmptyLines - Offense count: 23 * Fix Layout/EmptyLinesAroundAccessModifier - Offense count: 7 * Fix Layout/EmptyLinesAroundBlockBody - Offense count: 14 * Fix Layout/ExtraSpacing - Offense count: 1 * Fix Layout/IndentArray - Offense count: 8 * Fix Layout/IndentationConsistency - Offense count: 25 - 31 offenses detected, 31 offenses corrected * Fix Layout/IndentationWidth - Offense count: 1 - 3 offenses detected, 3 offenses corrected * Fix Layout/MultilineBlockLayout - Offense count: 5 * Layout/MultilineMethodCallBraceLayout - Offense count: 1 * Fix Layout/MultilineOperationIndentation - Offense count: 2 * Fix Layout/SpaceAfterColon and gen new toto * Fix Layout/SpaceAroundOperators - Offense count: 1 * Fix Layout/SpaceInsideBlockBraces - Offense count: 9 * Fix Layout/SpaceInsideBrackets - Offense count: 2 * Fix Layout/SpaceInsideHashLiteralBraces - Offense count: 180 * Fix Layout/SpaceInsideParens - Offense count: 1 * Fix Lint/AmbiguousBlockAssociation - Offense count: 3 * Fix Lint/AmbiguousOperator - Offense count: 1 * Fix Lint/AssignmentInCondition - Offense count: 3 * Fix Lint/BlockAlignment - Offense count: 1 * Fix Lint/DuplicateMethods - Offense count: 1 * Fix Lint/UriEscapeUnescape - Offense count: 1 * Fix Lint/UselessAssignment - Offense count: 8 * Fix # Style/StringLiterals: - Offense count: 1070 * Fix Style/BlockComments - Offense count: 1 * Fix Style/BlockDelimiters - Offense count: 34 * Fix Style/BracesAroundHashParameters - Offense count: 2 * Fix Style/EachWithObject - Offense count: 1 * Fix Style/FrozenStringLiteralComment - Offense count: 133 * Fix Style/HashSyntax - Offense count: 36 * Fix Style/IfUnlessModifier - Offense count: 2 * Fix Style/LineEndConcatenation - Offense count: 1 * Fix Style/MutableConstant - Offense count: 0 * Fix Style/NestedParenthesizedCalls - Offense count: 5 * Fix Style/NumericLiterals - Offense count: 3 * Fix Style/PercentLiteralDelimiters - Offense count: 4 * Fix Style/SignalException - Offense count: 1 * Fix Style/StringLiteralsInInterpolation - Offense count: 1 * Fix Style/SymbolArray - Offense count: 17 * Fix Style/TernaryParentheses - Offense count: 1 * Fix Style/TrailingCommaInLiteral - Offense count: 7 * Fix Style/WordArray - Offense count: 1 * Regenerate .rubocop_todo.yml * Fix Style/GuardClause - Offense count: 3 * Linelength changes and Revert db/* changes * Fix the fixer - a24607e - fix end of line comment alignment - 498d574 - numerical formatting - Fix the human directory ignoring issue * Multi line fix * Rubocop Update: - Moved to rubocop.yml: Style/NumericLiterals, Metrics/BlockLength, Metrics/AbcSize - Updated http_client to call param_hash instead of having in method for length purposes. * Railscop and other fixes - Layout/IndentationWidth - Rails/ApplicationRecord - Rails/Blank - Rails/Delegate - Rails/DynamicFindBy - Rails/FilePath - Style/FrozenStringLiteralComment - Style/StringLiterals * Remove pry-byebug * Rubocop work: - Rubocop version force/upgrade - Cop fixes * Remove factory_girl file. Merge issue * Handle new rubocop violations after merge * Merge fix * Railscop update
1 parent d74569a commit 6b96925

26 files changed

+161
-139
lines changed

.rubocop.yml

+20-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,28 @@ AllCops:
1616
# `-S/--display-style-guide` option.
1717
DisplayStyleGuide: true
1818

19+
# Numbers shouldn't have to be formatted with underscores
1920
Style/NumericLiterals:
2021
Enabled: false
2122

22-
Style/BlockDelimiters:
23+
# The excluded files below can create some pretty big blocks which are needed
24+
Metrics/BlockLength:
25+
CountComments: false
2326
Exclude:
2427
- spec/**/*
28+
- config/**/*
29+
30+
Metrics/MethodLength:
31+
Max: 12
32+
33+
# This gives us some breathing room
34+
Metrics/AbcSize:
35+
Max: 20
36+
37+
# If code isn't self-documenting then we should add documentation, otherwise
38+
# forcing documentation isn't needed.
39+
Style/Documentation:
40+
Enabled: false
41+
42+
Style/MixinUsage:
43+
Enabled: false

.rubocop_todo.yml

+2-30
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2017-10-19 07:48:24 -0700 using RuboCop version 0.50.0.
3+
# on 2017-10-24 20:49:44 -0500 using RuboCop version 0.50.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
Metrics/AbcSize:
11-
Max: 19
12-
13-
# Offense count: 51
14-
# Configuration parameters: CountComments, ExcludedMethods.
15-
Metrics/BlockLength:
16-
Max: 305
17-
18-
# Offense count: 33
9+
# Offense count: 34
1910
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
2011
# URISchemes: http, https
2112
Metrics/LineLength:
2213
Max: 117
23-
24-
# Offense count: 1
25-
# Configuration parameters: CountComments.
26-
Metrics/MethodLength:
27-
Max: 12
28-
29-
# Offense count: 1
30-
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
31-
# NamePrefix: is_, has_, have_
32-
# NamePrefixBlacklist: is_, has_, have_
33-
# NameWhitelist: is_a?
34-
Naming/PredicateName:
35-
Exclude:
36-
- 'spec/**/*'
37-
- 'lib/amazon_product_api/search_item.rb'
38-
39-
# Offense count: 49
40-
Style/Documentation:
41-
Enabled: false

Capfile

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
# Load DSL and set up stages
2-
require "capistrano/setup"
4+
require 'capistrano/setup'
35

46
# Include default deployment tasks
5-
require "capistrano/deploy"
7+
require 'capistrano/deploy'
68

79
require 'capistrano/rbenv'
810
# require 'capistrano/chruby'
@@ -11,12 +13,12 @@ require 'capistrano/rails/assets'
1113
require 'capistrano/rails/migrations'
1214
require 'capistrano/puma'
1315
require 'capistrano/rails/console'
14-
require "capistrano/scm/git"
16+
require 'capistrano/scm/git'
1517

1618
install_plugin Capistrano::SCM::Git
17-
install_plugin Capistrano::Puma # Default puma tasks
18-
install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
19-
install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
19+
install_plugin Capistrano::Puma # Default puma tasks
20+
install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
21+
install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
2022

2123
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
22-
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
24+
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

Gemfile

+12-12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ group :development, :test do
7171
end
7272

7373
group :development do
74+
gem 'better_errors', '~> 2.1'
75+
gem 'binding_of_caller', '~> 0.7'
76+
# Helps detect N+1 queries and unused eager loading
77+
gem 'bullet'
78+
gem 'capistrano-bundler', '~> 1.2'
79+
gem 'capistrano-rails', '~> 1.2'
80+
gem 'capistrano-rails-console', require: false
81+
gem 'capistrano-rbenv', '~> 2.1'
82+
gem 'capistrano3-puma', '~> 3.1'
7483
# Access an IRB console on exception pages or by using <%= console %> anywhere
7584
# in the code.
7685
gem 'web-console', '>= 3.3.0'
@@ -79,25 +88,16 @@ group :development do
7988
# The Listen gem listens to file modifications and notifies you about the
8089
# changes. https://rubygems.org/gems/listen
8190
gem 'listen', '>= 3.0.5', '< 3.2'
91+
# Ruby's style guide enforcer
92+
gem 'rubocop', '~> 0.52.1'
8293
# Spring speeds up development by keeping your application running in the
8394
# background. Read more: https://github.com/rails/spring
8495
gem 'spring'
8596
# This gem makes Spring watch the filesystem for changes using Listen rather
8697
# than by polling the filesystem.
8798
gem 'spring-watcher-listen', '~> 2.0.0'
88-
# Implements the `rspec` command for Spring, allowing for faster test loading
99+
# Implements the `rspec` command for Spring, allowing for faster test loading.
89100
gem 'spring-commands-rspec', '~> 1.0'
90-
# Helps detect N+1 queries and unused eager loading
91-
gem 'bullet'
92-
# Ruby's style guide enforcer
93-
gem 'rubocop'
94-
gem 'binding_of_caller', '~> 0.7'
95-
gem 'better_errors', '~> 2.1'
96-
gem 'capistrano-rails', '~> 1.2'
97-
gem 'capistrano-rbenv', '~> 2.1'
98-
gem 'capistrano-bundler', '~> 1.2'
99-
gem 'capistrano3-puma', '~> 3.1'
100-
gem 'capistrano-rails-console', require: false
101101
end
102102

103103
group :test do

Gemfile.lock

+9-10
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ GEM
181181
omniauth-oauth2 (1.4.0)
182182
oauth2 (~> 1.0)
183183
omniauth (~> 1.2)
184-
parallel (1.12.0)
185-
parser (2.4.0.0)
186-
ast (~> 2.2)
184+
parallel (1.12.1)
185+
parser (2.4.0.2)
186+
ast (~> 2.3)
187187
pg (0.20.0)
188188
powerpack (0.1.1)
189189
pry (0.10.4)
@@ -223,8 +223,7 @@ GEM
223223
method_source
224224
rake (>= 0.8.7)
225225
thor (>= 0.18.1, < 2.0)
226-
rainbow (2.2.2)
227-
rake
226+
rainbow (3.0.0)
228227
rake (12.0.0)
229228
rb-fsevent (0.9.8)
230229
rb-inotify (0.9.8)
@@ -248,11 +247,11 @@ GEM
248247
rspec-mocks (~> 3.6.0)
249248
rspec-support (~> 3.6.0)
250249
rspec-support (3.6.0)
251-
rubocop (0.50.0)
250+
rubocop (0.52.1)
252251
parallel (~> 1.10)
253-
parser (>= 2.3.3.1, < 3.0)
252+
parser (>= 2.4.0.2, < 3.0)
254253
powerpack (~> 0.1)
255-
rainbow (>= 2.2.2, < 3.0)
254+
rainbow (>= 2.2.2, < 4.0)
256255
ruby-progressbar (~> 1.7)
257256
unicode-display_width (~> 1.0, >= 1.0.1)
258257
ruby-progressbar (1.9.0)
@@ -355,7 +354,7 @@ DEPENDENCIES
355354
rails-assets-tether (>= 1.3.3)!
356355
rollbar
357356
rspec-rails (~> 3.5)
358-
rubocop
357+
rubocop (~> 0.52.1)
359358
sass-rails (~> 5.0)
360359
selenium-webdriver
361360
social-share-button (~> 1.0.0)
@@ -372,4 +371,4 @@ RUBY VERSION
372371
ruby 2.4.1p111
373372

374373
BUNDLED WITH
375-
1.15.4
374+
1.16.1

analyze_new_cluster.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
echo 'This script will generate minimal optimizer statistics rapidly'
4+
echo 'so your system is usable, and then gather statistics twice more'
5+
echo 'with increasing accuracy. When it is done, your system will'
6+
echo 'have the default level of optimizer statistics.'
7+
echo
8+
9+
echo 'If you have used ALTER TABLE to modify the statistics target for'
10+
echo 'any tables, you might want to remove them and restore them after'
11+
echo 'running this script because they will delay fast statistics generation.'
12+
echo
13+
14+
echo 'If you would like default statistics as quickly as possible, cancel'
15+
echo 'this script and run:'
16+
echo ' "/usr/local/Cellar/postgresql/10.1/bin/vacuumdb" --all --analyze-only'
17+
echo
18+
19+
"/usr/local/Cellar/postgresql/10.1/bin/vacuumdb" --all --analyze-in-stages
20+
echo
21+
22+
echo 'Done'

app/models/item.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#
1919

2020
class Item < ApplicationRecord
21-
has_many :wishlist_items
21+
has_many :wishlist_items, dependent: :nullify
2222
has_many :wishlists, through: :wishlist_items
2323

2424
validates :name, presence: true
2525

2626
def self.find_or_create_by_asin!(item_params)
2727
asin = item_params[:asin] || item_params['asin']
28-
Item.find_by_asin(asin) || Item.create!(item_params)
28+
Item.find_by(asin: asin) || Item.create!(item_params)
2929
end
3030
end

app/models/site_manager.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# updated_at :datetime not null
1212
#
1313

14-
class SiteManager < ActiveRecord::Base
14+
class SiteManager < ApplicationRecord
1515
belongs_to :user
1616
belongs_to :wishlist
1717
end

app/models/user.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class User < ApplicationRecord
2323
validates :amazon_user_id, uniqueness: true,
2424
allow_blank: true
2525

26-
has_many :pledges
26+
has_many :pledges, dependent: :nullify
2727
has_many :wishlist_items, through: :pledges
2828
has_many :site_managers, dependent: :destroy
2929
has_many :wishlists, through: :site_managers
@@ -73,8 +73,8 @@ def self.generate_csv(csv_generator: ActiveRecordCSVGenerator.new(self))
7373
def self.find_or_create_from_amazon_hash!(hash)
7474
oauth_info = AmazonOAuthInfo.new(hash)
7575

76-
find_by_amazon_user_id(oauth_info.amazon_user_id) ||
77-
find_by_email(oauth_info.email) ||
76+
find_by(amazon_user_id: oauth_info.amazon_user_id) ||
77+
find_by(email: oauth_info.email) ||
7878
create!(
7979
name: oauth_info.name,
8080
email: oauth_info.email,

bin/yarn

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Dir.chdir(VENDOR_PATH) do
66
begin
77
exec "yarnpkg #{ARGV.join(' ')}"
88
rescue Errno::ENOENT
9-
$stderr.puts 'Yarn executable was not detected in the system.'
10-
$stderr.puts 'Download Yarn at https://yarnpkg.com/en/docs/install'
9+
warn 'Yarn executable was not detected in the system.'
10+
warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
1111
exit 1
1212
end
1313
end

config/deploy.rb

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
# frozen_string_literal: true
2+
13
# config valid only for current version of Capistrano
24
lock '3.9.1'
35

4-
set :repo_url, "git@github.com:rubyforgood/playtime.git"
5-
set :application, "playtime"
6-
set :user, "deploy"
6+
set :repo_url, 'git@github.com:rubyforgood/playtime.git'
7+
set :application, 'playtime'
8+
set :user, 'deploy'
79
set :puma_threads, [4, 16]
810
set :puma_workers, 1
9-
set :ssh_options, keys: ["config/deploy_id_rsa"] if File.exist?("config/deploy_id_rsa")
11+
set :ssh_options, keys: ['config/deploy_id_rsa'] if File.exist?('config/deploy_id_rsa')
1012

1113
# Don't change these unless you know what you're doing
1214
set :pty, true
@@ -19,10 +21,13 @@
1921
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
2022
set :puma_access_log, "#{release_path}/log/puma.error.log"
2123
set :puma_error_log, "#{release_path}/log/puma.access.log"
22-
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
24+
# rubocop:disable Style/BracesAroundHashParameters
25+
# The below makes things more readable which is better than being stylistically correct here.
26+
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w[~/.ssh/id_rsa.pub] }
27+
# rubocop:enable Style/BracesAroundHashParameters
2328
set :puma_preload_app, true
2429
set :puma_worker_timeout, nil
25-
set :puma_init_active_record, true # Change to false when not using ActiveRecord
30+
set :puma_init_active_record, true # Change to false when not using ActiveRecord
2631

2732
## Defaults:
2833
# set :scm, :git
@@ -32,8 +37,8 @@
3237
# set :keep_releases, 5
3338

3439
## Linked Files & Directories (Default None):
35-
set :linked_files, %w{config/database.yml}
36-
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
40+
set :linked_files, %w[config/database.yml]
41+
set :linked_dirs, %w[log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system]
3742

3843
namespace :puma do
3944
desc 'Create Directories for Puma Pids and Socket'
@@ -48,27 +53,26 @@
4853
end
4954

5055
namespace :deploy do
51-
desc "Make sure local git is in sync with remote."
56+
desc 'Make sure local git is in sync with remote.'
5257
task :check_revision do
5358
on roles(:app) do
5459
unless `git rev-parse HEAD` == `git rev-parse origin/master`
55-
puts "WARNING: HEAD is not the same as origin/master"
56-
puts "Run `git push` to sync changes."
57-
exit
60+
raise 'WARNING: HEAD is not the same as origin/master\n'\
61+
'Run `git push` to sync changes.'
5862
end
5963
end
6064
end
6165

6266
desc 'Restart application'
63-
task :restart do
64-
on roles(:app), in: :sequence, wait: 5 do
67+
task :restart do
68+
on roles(:app), in: :sequence, wait: 5 do
6569
invoke 'puma:restart'
6670
end
6771
end
6872

6973
desc 'Puma is sometimes not restarting. This ensures it restarts... Nothing happens if restart works'
70-
task :ensure_start do
71-
on roles(:app), in: :sequence, wait: 10 do
74+
task :ensure_start do
75+
on roles(:app), in: :sequence, wait: 10 do
7276
invoke 'puma:stop'
7377
end
7478
end

0 commit comments

Comments
 (0)