Skip to content

Commit 90ed4f7

Browse files
committed
Added Rubocop and did some auto-formatting of the code
1 parent e81bf45 commit 90ed4f7

File tree

412 files changed

+3326
-3519
lines changed

Some content is hidden

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

412 files changed

+3326
-3519
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ group :development do
140140
gem 'better_errors'
141141
gem 'flog'
142142
gem 'fukuzatsu'
143+
gem 'git_stats', require: false
143144
gem 'guard-rspec'
144145
gem 'rails-erd'
146+
gem 'rubocop'
145147
gem 'spring'
146148
gem 'spring-commands-rspec'
147-
gem 'git_stats', require: false
148149
end
149150

150151
group :development, :test do

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ GEM
434434
polyglot (0.3.5)
435435
poro_plus (1.0.2)
436436
posix-spawn (0.3.8)
437+
powerpack (0.0.9)
437438
pry (0.9.12.6)
438439
coderay (~> 1.0)
439440
method_source (~> 0.8)
@@ -505,6 +506,7 @@ GEM
505506
rake (>= 0.8.7)
506507
rdoc (~> 3.4)
507508
thor (>= 0.14.6, < 2.0)
509+
rainbow (2.0.0)
508510
rake (10.3.2)
509511
rakismet (1.5.0)
510512
rb-fsevent (0.9.4)
@@ -560,6 +562,12 @@ GEM
560562
rspec-mocks (~> 3.0.0)
561563
rspec-support (~> 3.0.0)
562564
rspec-support (3.0.2)
565+
rubocop (0.23.0)
566+
json (>= 1.7.7, < 2)
567+
parser (~> 2.1.9)
568+
powerpack (~> 0.0.6)
569+
rainbow (>= 1.99.1, < 3.0)
570+
ruby-progressbar (~> 1.4)
563571
ruby-graphviz (1.0.9)
564572
ruby-progressbar (1.5.1)
565573
ruby_parser (3.6.1)
@@ -752,6 +760,7 @@ DEPENDENCIES
752760
rest-client
753761
rocket_tag
754762
rspec-rails
763+
rubocop
755764
ruby-progressbar
756765
sanitize
757766
sass (~> 3.2.9)

app/controllers/accounts_controller.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def update
4848

4949
def webhook
5050
data = JSON.parse request.body.read
51-
if data[:type] == "invoice.payment_succeeded"
51+
if data[:type] == 'invoice.payment_succeeded'
5252
invoice_id = data['data']['object']['id']
5353
customer_id = data['data']['object']['customer']
5454
team = Team.where('account.stripe_customer_token' => customer_id).first
@@ -64,7 +64,7 @@ def webhook
6464
def send_invoice
6565
@team = Team.find(params[:team_id])
6666
@team.account.send_invoice_for(1.month.ago)
67-
redirect_to teamname_path(slug: @team.slug), notice: "sent invoice for #{1.month.ago.strftime("%B")} to #{@team.account.admin.email}"
67+
redirect_to teamname_path(slug: @team.slug), notice: "sent invoice for #{1.month.ago.strftime('%B')} to #{@team.account.admin.email}"
6868
end
6969

7070
private
@@ -84,21 +84,20 @@ def determine_plan
8484
end
8585

8686
def ensure_eligibility
87-
return redirect_to(teamname_path(@team.slug), notice: "you must complete at least 6 sections of the team profile before posting jobs") unless @team.has_specified_enough_info?
87+
return redirect_to(teamname_path(@team.slug), notice: 'you must complete at least 6 sections of the team profile before posting jobs') unless @team.has_specified_enough_info?
8888
end
8989

9090
def plan_capability(plan, team)
91-
message = ""
91+
message = ''
9292
if plan.subscription?
9393
message = "You can now post up to #{team.number_of_jobs_to_show} jobs at any time"
9494
elsif plan.one_time?
95-
message = "You can now post one job for 30 days"
95+
message = 'You can now post one job for 30 days'
9696
end
9797
message
9898
end
9999

100100
def paying_user_context
101101
Honeybadger.context(user_email: current_user.try(:email)) if current_user
102102
end
103-
104103
end

app/controllers/achievements_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def show
1414
end
1515

1616
def award
17-
1817
award_params = params.permit(:badge, :twitter, :linkedin, :github, :date)
1918

2019
provider = pick_a_provider(award_params)
@@ -35,23 +34,23 @@ def award
3534
return render json: { message: "don't have permission to do that. contact support@coderwall.com", status: 403 }.to_json
3635
end
3736
end
38-
rescue Exception => e
39-
return render json: { message: "something went wrong with your request or the end point may not be ready. contact support@coderwall.com" }.to_json
37+
rescue => e
38+
return render json: { message: 'something went wrong with your request or the end point may not be ready. contact support@coderwall.com' }.to_json
4039
end
4140

4241
private
4342

4443
def ensure_valid_api_key
4544
@api_key = params.permit(:api_key)[:api_key]
4645
@api_access = ApiAccess.for(@api_key) unless @api_key.nil?
47-
return render json: { message: "no/invalid api_key provided. get your api_key from coderwall.com/settings" }.to_json if @api_access.nil?
46+
return render json: { message: 'no/invalid api_key provided. get your api_key from coderwall.com/settings' }.to_json if @api_access.nil?
4847
end
4948

5049
def badge_class_factory(requested_badge_name)
5150
BADGES_LIST.select { |badge_name| badge_name == requested_badge_name }.first.constantize
5251
end
5352

5453
def pick_a_provider(award_params)
55-
(User::LINKABLE_PROVIDERS & award_params.keys.select { |key| %w{twitter linkedin github}.include?(key) }).first
54+
(User::LINKABLE_PROVIDERS & award_params.keys.select { |key| %w(twitter linkedin github).include?(key) }).first
5655
end
5756
end

app/controllers/admin_controller.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class AdminController < BaseAdminController
2-
32
def index
43
end
54

@@ -12,14 +11,14 @@ def failed_jobs
1211
@per_page = params[:per_page].try(:to_i) || 10
1312

1413
@total_failed = Delayed::Job.
15-
where("last_error IS NOT NULL").
14+
where('last_error IS NOT NULL').
1615
count
1716

1817
@jobs = Delayed::Job.
19-
where("last_error IS NOT NULL").
18+
where('last_error IS NOT NULL').
2019
offset((@page - 1) * @per_page).
2120
limit(@per_page).
22-
order("updated_at DESC")
21+
order('updated_at DESC')
2322
end
2423

2524
if Rails.env.development?
@@ -32,13 +31,12 @@ def toggle_premium_team
3231
end
3332
team.premium = !team.premium
3433
team.save!
35-
return redirect_to('/')
34+
redirect_to('/')
3635
end
3736

3837
end
3938

4039
def teams
41-
4240
end
4341

4442
def sections_teams

app/controllers/alerts_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def authenticate_caller
3434

3535
case @alert[:type].to_sym
3636
when :traction, :google_analytics
37-
valid = (@alert[:key] == "3fEtu89_W13k1")
37+
valid = (@alert[:key] == '3fEtu89_W13k1')
3838
else
3939
valid = false
4040
end
@@ -78,7 +78,7 @@ def can_report_traction?(url)
7878
Time.at(REDIS.get(last_sent_key(:traction, url)).to_i) < TRACTION_ALERT_INTERVAL.ago
7979
end
8080

81-
def last_sent_key(type, subkey=nil)
81+
def last_sent_key(type, subkey = nil)
8282
key = "alert:#{type}:last_sent"
8383
key += ":#{subkey}" unless subkey.nil?
8484
key
@@ -99,4 +99,4 @@ def update_stats
9999
def update_history
100100
REDIS.zadd(history_key(@alert[:type]), Time.now.to_i, @alert[:data])
101101
end
102-
end
102+
end

app/controllers/application_controller.rb

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def apply_flash_message
2828
end
2929

3030
def apply_cache_buster
31-
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
32-
response.headers["Pragma"] = "no-cache"
33-
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
31+
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
32+
response.headers['Pragma'] = 'no-cache'
33+
response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
3434
end
3535

3636
def clear_expired_cookie_if_session_is_empty
37-
if !signed_in?
37+
unless signed_in?
3838
cookies.delete(:signedin)
3939
end
4040
end
@@ -67,7 +67,7 @@ def sign_in(user)
6767
current_user.last_ip = request.remote_ip
6868
current_user.last_ua = request.user_agent
6969
current_user.save
70-
ensure_and_reconcile_tracking_code #updated tracking code if appropriate.
70+
ensure_and_reconcile_tracking_code # updated tracking code if appropriate.
7171
current_user
7272
end
7373

@@ -97,7 +97,7 @@ def ensure_and_reconcile_tracking_code
9797
end
9898

9999
def sign_out
100-
record_event("signed out")
100+
record_event('signed out')
101101
@current_user = nil
102102
session[:current_user] = nil
103103
cookies.delete(:signedin)
@@ -110,7 +110,7 @@ def store_location!(url = nil)
110110

111111
def require_registration
112112
if signed_in? && not_on_pages?
113-
redirect_to(edit_user_url(current_user)) if !current_user.valid?
113+
redirect_to(edit_user_url(current_user)) unless current_user.valid?
114114
end
115115
end
116116

@@ -137,7 +137,7 @@ def record_location
137137
end
138138

139139
def deployment_environment?
140-
Rails.env.production? or Rails.env.staging?
140+
Rails.env.production? || Rails.env.staging?
141141
end
142142

143143
def destination_url
@@ -158,7 +158,7 @@ def destination_url
158158
end
159159

160160
def access_required
161-
redirect_to(root_url) if !signed_in?
161+
redirect_to(root_url) unless signed_in?
162162
end
163163

164164
def viewing_self?
@@ -174,8 +174,8 @@ def not_on_achievements?
174174
end
175175

176176
unless Rails.env.development? || Rails.env.test?
177-
rescue_from(ActiveRecord::RecordNotFound) { |e| render_404 }
178-
rescue_from(ActionController::RoutingError) { |e| render_404 }
177+
rescue_from(ActiveRecord::RecordNotFound) { |_e| render_404 }
178+
rescue_from(ActionController::RoutingError) { |_e| render_404 }
179179
# rescue_from(RuntimeError) { |e| render_500 }
180180
end
181181

@@ -206,7 +206,7 @@ def require_beta_access!
206206
end
207207

208208
def iphone_user_agent?
209-
request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Mobile\/.+Safari)/]
209+
request.env['HTTP_USER_AGENT'] && request.env['HTTP_USER_AGENT'][/(Mobile\/.+Safari)/]
210210
end
211211

212212
def round(number)
@@ -216,7 +216,7 @@ def round(number)
216216
number.round(-1)
217217
elsif number < 1000
218218
number.round(-2)
219-
elsif number < 10000
219+
elsif number < 10_000
220220
number.round(-3)
221221
else
222222
number.round(-Math.log(number, 10))
@@ -228,28 +228,28 @@ def record_event(action_name, options = {})
228228
options.merge!('mp_name_tag' => cookies[:identity]) unless cookies[:identity].blank?
229229
options.merge!('distinct_id' => cookies[:trc]) unless cookies[:trc].blank?
230230
unless current_user.nil?
231-
options.merge!({ 'score' => current_user.score.round(-1),
232-
'followers' => round(current_user.followers_count),
233-
'achievements' => current_user.badges_count,
234-
'on team' => current_user.on_team?,
235-
'premium team' => (current_user.team && current_user.team.premium?) || false,
236-
'signed in' => true,
237-
'member' => true,
238-
'first visit' => false,
239-
'visit frequency' => current_user.visit_frequency })
231+
options.merge!('score' => current_user.score.round(-1),
232+
'followers' => round(current_user.followers_count),
233+
'achievements' => current_user.badges_count,
234+
'on team' => current_user.on_team?,
235+
'premium team' => (current_user.team && current_user.team.premium?) || false,
236+
'signed in' => true,
237+
'member' => true,
238+
'first visit' => false,
239+
'visit frequency' => current_user.visit_frequency)
240240
else
241-
options.merge!({ 'signed in' => false,
242-
'member' => cookies[:identity] && User.exists?(username: cookies[:identity]),
243-
'first visit' => session[:new_visit]
244-
})
241+
options.merge!('signed in' => false,
242+
'member' => cookies[:identity] && User.exists?(username: cookies[:identity]),
243+
'first visit' => session[:new_visit]
244+
)
245245
end
246246

247-
#options.merge!('signed up on' => current_user.created_at.to_formatted_s(:mixpanel),
247+
# options.merge!('signed up on' => current_user.created_at.to_formatted_s(:mixpanel),
248248
# 'achievements' => current_user.badges_count) if signed_in?
249249

250250
Resque.enqueue(MixpanelTracker::TrackEventJob, action_name, options, request.ip) if ENABLE_TRACKING
251251
end
252-
rescue Exception => ex
252+
rescue => ex
253253
Rails.logger.error("MIXPANEL: Swallowing error when trying to record #{action_name}, #{ex.message}")
254254
end
255255

@@ -260,7 +260,7 @@ def session_id
260260
def ensure_domain
261261
if Rails.env.production?
262262
if request.env['HTTP_HOST'] != APP_DOMAIN
263-
redirect_to request.url.sub("//www.", "//"), status: 301
263+
redirect_to request.url.sub('//www.', '//'), status: 301
264264
end
265265
end
266266
end
@@ -288,12 +288,12 @@ def redirect_to_path(path)
288288
end
289289
end
290290

291-
def redirect_to_signup_if_unauthenticated(return_to=request.referer, message = "You must be signed in to do that", &block)
291+
def redirect_to_signup_if_unauthenticated(return_to = request.referer, message = 'You must be signed in to do that', &_block)
292292
if signed_in?
293293
yield
294294
else
295295
flash[:notice] = message
296-
#This is called when someone tries to do an action while unauthenticated
296+
# This is called when someone tries to do an action while unauthenticated
297297
Rails.logger.info "WILL RETURN TO #{return_to}"
298298
store_location!(return_to)
299299
redirect_to_path(signin_path)
@@ -309,5 +309,4 @@ def require_http_basic
309309
end
310310
end
311311
end
312-
313312
end

app/controllers/bans_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class BansController < BaseAdminController
2-
32
def create
43
ban_params = params.permit(:user_id)
54
user = User.find(ban_params[:user_id])
@@ -13,5 +12,4 @@ def create
1312
end
1413
redirect_to(badge_url(username: user.username), notice: flash_notice)
1514
end
16-
1715
end

app/controllers/blog_posts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def show
1414
rescue BlogPost::PostNotFound => e
1515
return head(:not_found)
1616
end
17-
end
17+
end

0 commit comments

Comments
 (0)