Skip to content

Commit 6a3b767

Browse files
mxygemseanmarcia
authored andcommitted
Add Rubocop WIP (#126)
* 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
1 parent 8c09cb0 commit 6a3b767

File tree

113 files changed

+1595
-1328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1595
-1328
lines changed

.pryrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
if defined?(PryRails::RAILS_PROMPT)
2-
Pry.config.prompt = PryRails::RAILS_PROMPT
3-
end
1+
# frozen_string_literal: true
2+
3+
Pry.config.prompt = PryRails::RAILS_PROMPT if defined?(PryRails::RAILS_PROMPT)

.rubocop.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
AllCops:
4+
# Use the following Exclude to prevent Rubocop from linting specific
5+
# directories or files.
6+
Exclude:
7+
- db/**/*
8+
TargetRubyVersion: 2.4.1
9+
# Cop names are not displayed in offense messages by default. Change behavior
10+
# by overriding DisplayCopNames, or by giving the `-D/--display-cop-names`
11+
# option.
12+
DisplayCopNames: true
13+
# Style guide URLs are not displayed in offense messages by default. Change
14+
# behavior by overriding `DisplayStyleGuide`, or by giving the
15+
# `-S/--display-style-guide` option.
16+
DisplayStyleGuide: true
17+
18+
Style/NumericLiterals:
19+
Enabled: false

.rubocop_todo.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2017-10-19 07:48:24 -0700 using RuboCop version 0.50.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
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
19+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
20+
# URISchemes: http, https
21+
Metrics/LineLength:
22+
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

Gemfile

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
ruby '2.4.1'
46

57
git_source(:github) do |repo_name|
6-
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
8+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
79
"https://github.com/#{repo_name}.git"
810
end
911

@@ -24,7 +26,8 @@ gem 'newrelic_rpm'
2426
gem 'dotenv-rails'
2527
# Logs production errors to an external service
2628
gem 'rollbar'
27-
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
29+
# Turbolinks makes navigating your web application faster.
30+
# Read more: https://github.com/turbolinks/turbolinks
2831
gem 'turbolinks', '~> 5'
2932
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
3033
gem 'jbuilder', '~> 2.5'
@@ -35,13 +38,15 @@ gem 'jquery-rails', '~> 4.3.1'
3538
source 'https://rails-assets.org' do
3639
gem 'rails-assets-tether', '>= 1.3.3'
3740
end
38-
# The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
41+
# The most popular HTML, CSS, and JavaScript framework for developing
42+
# responsive, mobile first projects on the web.
3943
gem 'bootstrap', '~> 4.0.0.alpha6'
4044
# Login with Amazon OAuth2 strategy for OmniAuth 1.0
4145
gem 'omniauth-amazon'
4246
# Makes http fun again! http://jnunemaker.github.com/httparty
4347
gem 'httparty'
44-
# Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban
48+
# Helper for add social share feature in your Rails app. Twitter, Facebook,
49+
# Weibo, Douban
4550
gem 'social-share-button', '~> 1.0.0'
4651
# most important gem for awesome debugging and awesome consoles
4752
gem 'pry-rails'
@@ -50,11 +55,14 @@ gem 'pundit'
5055

5156
gem 'font-awesome-sass'
5257
group :development, :test do
53-
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
54-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
58+
# Call 'byebug' anywhere in the code to stop execution and get a debugger
59+
# console
60+
gem 'byebug', platforms: %i[mri mingw x64_mingw]
5561
# Adds support for Capybara system testing and selenium driver
5662
gem 'capybara', '~> 2.13'
57-
# WebDriver is a tool for writing automated tests of websites. It aims to mimic the behaviour of a real user, and as such interacts with the HTML of the application.
63+
# WebDriver is a tool for writing automated tests of websites. It aims to
64+
# mimic the behaviour of a real user, and as such interacts with the HTML of
65+
# the application.
5866
gem 'selenium-webdriver'
5967
# rspec-rails is a testing framework for Rails 3+.
6068
gem 'rspec-rails', '~> 3.5'
@@ -63,20 +71,26 @@ group :development, :test do
6371
end
6472

6573
group :development do
66-
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
74+
# Access an IRB console on exception pages or by using <%= console %> anywhere
75+
# in the code.
6776
gem 'web-console', '>= 3.3.0'
6877
# Annotate model/model spec/factory files with the database schema
6978
gem 'annotate', '~> 2.7'
70-
# The Listen gem listens to file modifications and notifies you about the changes. https://rubygems.org/gems/listen
79+
# The Listen gem listens to file modifications and notifies you about the
80+
# changes. https://rubygems.org/gems/listen
7181
gem 'listen', '>= 3.0.5', '< 3.2'
72-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
82+
# Spring speeds up development by keeping your application running in the
83+
# background. Read more: https://github.com/rails/spring
7384
gem 'spring'
74-
# This gem makes Spring watch the filesystem for changes using Listen rather than by polling the filesystem.
85+
# This gem makes Spring watch the filesystem for changes using Listen rather
86+
# than by polling the filesystem.
7587
gem 'spring-watcher-listen', '~> 2.0.0'
7688
# Implements the `rspec` command for Spring, allowing for faster test loading
7789
gem 'spring-commands-rspec', '~> 1.0'
7890
# Helps detect N+1 queries and unused eager loading
7991
gem 'bullet'
92+
# Ruby's style guide enforcer
93+
gem 'rubocop'
8094
gem 'binding_of_caller', '~> 0.7'
8195
gem 'better_errors', '~> 2.1'
8296
gem 'capistrano-rails', '~> 1.2'
@@ -87,13 +101,15 @@ group :development do
87101
end
88102

89103
group :test do
90-
# Allows you to launch a debugging snapshot in your browser during Capybara tests
104+
# Allows you to launch a debugging snapshot in your browser during Capybara
105+
# tests
91106
gem 'launchy', '~> 2.4.3'
92-
# A set of strategies for cleaning your database (ensuring a clean slate during tests)
107+
# A set of strategies for cleaning your database (ensuring a clean slate
108+
# during tests)
93109
gem 'database_cleaner', '~> 1.6.1'
94110
# Library for stubbing and setting expectations on HTTP requests in Ruby.
95111
gem 'webmock', '~> 3.0'
96112
end
97113

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

Gemfile.lock

+17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ GEM
4747
activerecord (>= 3.2, < 6.0)
4848
rake (>= 10.4, < 13.0)
4949
arel (8.0.0)
50+
ast (2.3.0)
5051
autoprefixer-rails (7.1.1)
5152
execjs
5253
better_errors (2.3.0)
@@ -180,7 +181,11 @@ GEM
180181
omniauth-oauth2 (1.4.0)
181182
oauth2 (~> 1.0)
182183
omniauth (~> 1.2)
184+
parallel (1.12.0)
185+
parser (2.4.0.0)
186+
ast (~> 2.2)
183187
pg (0.20.0)
188+
powerpack (0.1.1)
184189
pry (0.10.4)
185190
coderay (~> 1.1.0)
186191
method_source (~> 0.8.1)
@@ -218,6 +223,8 @@ GEM
218223
method_source
219224
rake (>= 0.8.7)
220225
thor (>= 0.18.1, < 2.0)
226+
rainbow (2.2.2)
227+
rake
221228
rake (12.0.0)
222229
rb-fsevent (0.9.8)
223230
rb-inotify (0.9.8)
@@ -241,6 +248,14 @@ GEM
241248
rspec-mocks (~> 3.6.0)
242249
rspec-support (~> 3.6.0)
243250
rspec-support (3.6.0)
251+
rubocop (0.50.0)
252+
parallel (~> 1.10)
253+
parser (>= 2.3.3.1, < 3.0)
254+
powerpack (~> 0.1)
255+
rainbow (>= 2.2.2, < 3.0)
256+
ruby-progressbar (~> 1.7)
257+
unicode-display_width (~> 1.0, >= 1.0.1)
258+
ruby-progressbar (1.9.0)
244259
ruby_dep (1.5.0)
245260
rubyzip (1.2.1)
246261
safe_yaml (1.0.4)
@@ -287,6 +302,7 @@ GEM
287302
thread_safe (~> 0.1)
288303
uglifier (3.2.0)
289304
execjs (>= 0.3.0, < 3)
305+
unicode-display_width (1.3.0)
290306
uniform_notifier (1.10.0)
291307
web-console (3.5.1)
292308
actionview (>= 5.0)
@@ -339,6 +355,7 @@ DEPENDENCIES
339355
rails-assets-tether (>= 1.3.3)!
340356
rollbar
341357
rspec-rails (~> 3.5)
358+
rubocop
342359
sass-rails (~> 5.0)
343360
selenium-webdriver
344361
social-share-button (~> 1.0.0)

Rakefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# frozen_string_literal: true
2+
13
# Add your own tasks in files placed in lib/tasks ending in .rake,
2-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4+
# for example lib/tasks/capistrano.rake, and they will automatically be
5+
# available to Rake.
36

47
require_relative 'config/application'
58

69
Rails.application.load_tasks
710

8-
task default: [:"factory_bot:lint", :spec]
11+
task default: %i[factory_bot:lint spec]

app/channels/application_cable/channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Channel < ActionCable::Channel::Base
35
end

app/channels/application_cable/connection.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Connection < ActionCable::Connection::Base
35
end
+22-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
require "amazon_product_api"
2-
require "nested_wishlist_context"
1+
# frozen_string_literal: true
2+
3+
require 'amazon_product_api'
4+
require 'nested_wishlist_context'
35

46
class AmazonSearchController < ApplicationController
57
before_action :set_wishlist
@@ -15,22 +17,22 @@ def new
1517
end
1618

1719
private
18-
def amazon_client
19-
AmazonProductAPI::HTTPClient.new(query: params[:query],
20-
page_num: params[:page_num] || 1)
21-
end
22-
23-
def set_wishlist
24-
@wishlist = Wishlist.find(params[:wishlist_id])
25-
end
26-
27-
def pundit_user
28-
NestedWishlistContext.new(current_user, @wishlist)
29-
end
30-
31-
def filter_search
32-
if params[:query].blank?
33-
redirect_to new_wishlist_amazon_search_path, notice: "query can't be blank"
34-
end
35-
end
20+
21+
def amazon_client
22+
AmazonProductAPI::HTTPClient.new(query: params[:query],
23+
page_num: params[:page_num] || 1)
24+
end
25+
26+
def set_wishlist
27+
@wishlist = Wishlist.find(params[:wishlist_id])
28+
end
29+
30+
def pundit_user
31+
NestedWishlistContext.new(current_user, @wishlist)
32+
end
33+
34+
def filter_search
35+
params[:query].blank? && redirect_to(new_wishlist_amazon_search_path,
36+
notice: "query can't be blank")
37+
end
3638
end
+13-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::Base
24
include Pundit
35
protect_from_forgery with: :exception
@@ -9,16 +11,17 @@ class ApplicationController < ActionController::Base
911
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
1012

1113
private
12-
def current_user
13-
return @current_user if @current_user
14-
@current_user = User.find_by(id: session[:user_id]) || GuestUser.new
15-
end
1614

17-
def set_wishlists
18-
@wishlists = Wishlist.all
19-
end
15+
def current_user
16+
return @current_user if @current_user
17+
@current_user = User.find_by(id: session[:user_id]) || GuestUser.new
18+
end
19+
20+
def set_wishlists
21+
@wishlists = Wishlist.all
22+
end
2023

21-
def user_not_authorized
22-
redirect_to root_url, alert: "You are not authorized to view that page."
23-
end
24+
def user_not_authorized
25+
redirect_to root_url, alert: 'You are not authorized to view that page.'
26+
end
2427
end

0 commit comments

Comments
 (0)