Skip to content

Commit e588fa7

Browse files
rhymesbenhalpern
authored andcommitted
Code cleanups (forem#659)
* Initial automatic cleanup with rubocop * Fix syntax error introduced by rubocop * Cleanup seeds file * Cleanup lib folder * Exclude bin folder because it contains auto generated files * Make Rubocop a little bit more chatty * Block length should not include comments in the count * Cleanup config folder * Cleanup specs * Updated Rubocop version and generated a todo file * Fix broken ArticlesApi spec * Fix tests * Restored rubocop pre-commit hook
1 parent 2cae371 commit e588fa7

File tree

321 files changed

+2854
-2393
lines changed

Some content is hidden

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

321 files changed

+2854
-2393
lines changed

Diff for: .rubocop.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
inherit_from: .rubocop_todo.yml
2+
13
require: rubocop-rspec
24

35
# our custom config
@@ -19,7 +21,13 @@ Metrics/LineLength:
1921

2022
AllCops:
2123
Exclude:
24+
- bin/**/*
2225
- db/schema.rb
26+
- db/migrate/*.rb
27+
- node_modules/**/*
28+
DisplayStyleGuide: true
29+
ExtraDetails: true
30+
TargetRubyVersion: 2.5
2331

2432
Naming/AccessorMethodName:
2533
Description: Check the naming of accessor methods for get_/set_.
@@ -110,7 +118,7 @@ Metrics/AbcSize:
110118
Enabled: false
111119

112120
Metrics/BlockLength:
113-
CountComments: true # count full line comments?
121+
CountComments: false # count full line comments?
114122
Max: 25
115123
ExcludedMethods: []
116124
Exclude:

Diff for: .rubocop_todo.yml

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2018-08-05 17:42:25 +0200 using RuboCop version 0.58.2.
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: 9
10+
# Cop supports --auto-correct.
11+
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
12+
# SupportedStylesAlignWith: keyword, variable, start_of_line
13+
Layout/EndAlignment:
14+
Exclude:
15+
- 'app/controllers/api/v0/articles_controller.rb'
16+
- 'app/controllers/articles_controller.rb'
17+
- 'app/controllers/chat_channels_controller.rb'
18+
- 'app/controllers/image_uploads_controller.rb'
19+
- 'app/helpers/application_helper.rb'
20+
- 'app/models/user.rb'
21+
- 'app/services/article_api_index_service.rb'
22+
23+
# Offense count: 1
24+
# Cop supports --auto-correct.
25+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
26+
# SupportedStyles: space, no_space, compact
27+
# SupportedStylesForEmptyBrackets: space, no_space
28+
Layout/SpaceInsideArrayLiteralBrackets:
29+
Exclude:
30+
- 'app/dashboards/email_message_dashboard.rb'
31+
32+
# Offense count: 3
33+
Lint/AmbiguousBlockAssociation:
34+
Exclude:
35+
- 'app/controllers/podcast_episodes_controller.rb'
36+
- 'app/views/api/v0/articles/show.json.jbuilder'
37+
38+
# Offense count: 4
39+
Lint/IneffectiveAccessModifier:
40+
Exclude:
41+
- 'app/black_box/black_box.rb'
42+
- 'app/models/tweet.rb'
43+
44+
# Offense count: 3
45+
Lint/ShadowingOuterLocalVariable:
46+
Exclude:
47+
- 'app/views/api/v0/comments/index.json.jbuilder'
48+
- 'app/views/api/v0/comments/show.json.jbuilder'
49+
50+
# Offense count: 2
51+
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
52+
Lint/UselessAccessModifier:
53+
Exclude:
54+
- 'app/black_box/black_box.rb'
55+
- 'app/models/tweet.rb'
56+
57+
# Offense count: 10
58+
Lint/UselessAssignment:
59+
Exclude:
60+
- 'app/controllers/stories_controller.rb'
61+
- 'app/labor/cache_buster.rb'
62+
- 'app/labor/markdown_parser.rb'
63+
- 'app/labor/rate_limit_checker.rb'
64+
- 'app/liquid_tags/comment_tag.rb'
65+
- 'app/liquid_tags/glitch_tag.rb'
66+
- 'app/liquid_tags/tweet_tag.rb'
67+
68+
# Offense count: 8
69+
# Configuration parameters: CountComments, ExcludedMethods.
70+
# ExcludedMethods: refine
71+
Metrics/BlockLength:
72+
Max: 68
73+
74+
# Offense count: 132
75+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
76+
# URISchemes: http, https
77+
Metrics/LineLength:
78+
Max: 274
79+
80+
# Offense count: 14
81+
Metrics/PerceivedComplexity:
82+
Max: 16
83+
84+
# Offense count: 1
85+
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
86+
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
87+
Naming/MemoizedInstanceVariableName:
88+
Exclude:
89+
- 'app/controllers/admin/application_controller.rb'
90+
91+
# Offense count: 2
92+
# Configuration parameters: EnforcedStyle.
93+
# SupportedStyles: snake_case, camelCase
94+
Naming/MethodName:
95+
Exclude:
96+
- 'app/helpers/articles_helper.rb'
97+
- 'app/liquid_tags/podcast_tag.rb'
98+
99+
# Offense count: 4
100+
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
101+
# NamePrefix: is_, has_, have_
102+
# NamePrefixBlacklist: is_, has_, have_
103+
# NameWhitelist: is_a?
104+
# MethodDefinitionMacros: define_method, define_singleton_method
105+
Naming/PredicateName:
106+
Exclude:
107+
- 'spec/**/*'
108+
- 'app/controllers/application_controller.rb'
109+
- 'app/helpers/articles_helper.rb'
110+
- 'app/models/user.rb'
111+
112+
# Offense count: 9
113+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
114+
# AllowedNames: io, id, to, by, on, in, at, ip
115+
Naming/UncommunicativeMethodParamName:
116+
Exclude:
117+
- 'app/controllers/followed_articles_controller.rb'
118+
- 'app/controllers/internal/dogfood_controller.rb'
119+
- 'app/labor/mailchimp_bot.rb'
120+
- 'app/labor/podcast_feed.rb'
121+
- 'app/models/chat_channel.rb'
122+
- 'app/models/tweet.rb'
123+
124+
# Offense count: 2
125+
# Configuration parameters: EnforcedStyle.
126+
# SupportedStyles: snake_case, camelCase
127+
Naming/VariableName:
128+
Exclude:
129+
- 'app/liquid_tags/github_tag/github_issue_tag.rb'
130+
131+
# Offense count: 3
132+
Security/Open:
133+
Exclude:
134+
- 'app/labor/podcast_feed.rb'
135+
- 'app/labor/rss_reader.rb'
136+
137+
# Offense count: 14
138+
# Cop supports --auto-correct.
139+
# Configuration parameters: AutoCorrect, EnforcedStyle.
140+
# SupportedStyles: nested, compact
141+
Style/ClassAndModuleChildren:
142+
Exclude:
143+
- 'app/controllers/api/v0/api_controller.rb'
144+
- 'app/controllers/internal/application_controller.rb'
145+
- 'app/controllers/internal/articles_controller.rb'
146+
- 'app/controllers/internal/broadcasts_controller.rb'
147+
- 'app/controllers/internal/buffer_updates_controller.rb'
148+
- 'app/controllers/internal/comments_controller.rb'
149+
- 'app/controllers/internal/dogfood_controller.rb'
150+
- 'app/controllers/internal/feedback_messages_controller.rb'
151+
- 'app/controllers/internal/members_controller.rb'
152+
- 'app/controllers/internal/tags_controller.rb'
153+
- 'app/controllers/internal/users_controller.rb'
154+
- 'app/controllers/internal/welcome_controller.rb'
155+
- 'app/controllers/notifications/counts_controller.rb'
156+
- 'app/controllers/notifications/reads_controller.rb'
157+
158+
# Offense count: 1
159+
Style/DateTime:
160+
Exclude:
161+
- 'app/controllers/comments_controller.rb'
162+
163+
# Offense count: 1
164+
Style/EvalWithLocation:
165+
Exclude:
166+
- 'app/controllers/omniauth_callbacks_controller.rb'
167+
168+
# Offense count: 1
169+
# Configuration parameters: EnforcedStyle.
170+
# SupportedStyles: each, for
171+
Style/For:
172+
Exclude:
173+
- 'app/views/articles/feed.rss.builder'
174+
175+
# Offense count: 1
176+
Style/IfInsideElse:
177+
Exclude:
178+
- 'app/models/comment.rb'
179+
180+
# Offense count: 3
181+
Style/MixinUsage:
182+
Exclude:
183+
- 'app/models/organization.rb'
184+
- 'app/models/podcast_episode.rb'
185+
186+
# Offense count: 1
187+
# Cop supports --auto-correct.
188+
# Configuration parameters: AutoCorrect, EnforcedStyle.
189+
# SupportedStyles: predicate, comparison
190+
Style/NumericPredicate:
191+
Exclude:
192+
- 'spec/**/*'
193+
- 'app/liquid_tags/github_tag/github_issue_tag.rb'
194+
195+
# Offense count: 3
196+
# Cop supports --auto-correct.
197+
# Configuration parameters: AllowAsExpressionSeparator.
198+
Style/Semicolon:
199+
Exclude:
200+
- 'app/controllers/stories_controller.rb'

Diff for: Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ git_source(:github) do |repo_name|
1010
end
1111

1212
group :production do
13-
gem 'nakayoshi_fork'
13+
gem "nakayoshi_fork"
1414
end
1515

1616
gem "actionpack-action_caching", "~> 1.2"

Diff for: Gemfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ GEM
617617
parallel (1.12.1)
618618
parallel_tests (2.21.3)
619619
parallel
620-
parser (2.5.1.0)
620+
parser (2.5.1.2)
621621
ast (~> 2.4.0)
622622
pg (0.21.0)
623623
powerpack (0.1.2)
@@ -736,10 +736,10 @@ GEM
736736
rspec-retry (0.6.1)
737737
rspec-core (> 3.3)
738738
rspec-support (3.7.1)
739-
rubocop (0.57.2)
739+
rubocop (0.58.2)
740740
jaro_winkler (~> 1.5.1)
741741
parallel (~> 1.10)
742-
parser (>= 2.5)
742+
parser (>= 2.5, != 2.5.1.1)
743743
powerpack (~> 0.1)
744744
rainbow (>= 2.2.2, < 4.0)
745745
ruby-progressbar (~> 1.7)

Diff for: Guardfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
ignore([%r{^bin/*}, %r{^config/*}, %r{^db/*}, %r{^lib/*}, %r{^log/*}, %r{^public/*}, %r{^tmp/*}, %r{^node_modules/*}])
2828

2929
rspec_options = {
30-
results_file: File.expand_path('tmp/guard_rspec_results.txt'),
30+
results_file: File.expand_path("tmp/guard_rspec_results.txt"),
3131
#############################
3232
# BECAUSE spring doesn't seem to work well with simplecov, choose
3333
# between the following two.
@@ -37,7 +37,7 @@ rspec_options = {
3737
cmd: "bin/spring rspec -p",
3838
#############################
3939
failed_mode: :focus,
40-
bundler_env: :clean_env
40+
bundler_env: :clean_env,
4141
}
4242

4343
guard :rspec, rspec_options do
@@ -65,7 +65,7 @@ guard :rspec, rspec_options do
6565
[
6666
rspec.spec.call("routing/#{m[1]}_routing"),
6767
rspec.spec.call("controllers/#{m[1]}_controller"),
68-
rspec.spec.call("acceptance/#{m[1]}")
68+
rspec.spec.call("acceptance/#{m[1]}"),
6969
]
7070
end
7171

Diff for: Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add your own tasks in files placed in lib/tasks ending in .rake,
22
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
33

4-
require File.expand_path('../config/application', __FILE__)
4+
require File.expand_path("config/application", __dir__)
55

66
Rails.application.load_tasks

Diff for: app/black_box/black_box.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
class BlackBox
22
def self.article_hotness_score(article)
3-
return (article.featured_number|| 10000)/10000 unless Rails.env.production?
3+
return (article.featured_number || 10000) / 10000 unless Rails.env.production?
44
reaction_points = article.reactions.sum(:points)
55
recency_bonus = article.published_at > 12.hours.ago ? 50 : 0
66
today_bonus = article.published_at > 36.hours.ago ? 250 : 0
77
FunctionCaller.new("blackbox-production-articleHotness",
8-
{article: article, user: article.user}.to_json).call +
8+
{ article: article, user: article.user }.to_json).call +
99
reaction_points + recency_bonus + today_bonus
1010
end
1111

1212
def self.comment_quality_score(comment)
13-
descendants_points = (comment.descendants.size/2)
13+
descendants_points = (comment.descendants.size / 2)
1414
rep_points = comment.reactions.sum(:points)
1515
bonus_points = calculate_bonus_score(comment.body_markdown)
1616
spaminess_rating = calculate_spaminess(comment)
1717
(rep_points + descendants_points + bonus_points - spaminess_rating).to_i
1818
end
1919

2020
def self.calculate_spaminess(story)
21-
#accepts comment or article as story
21+
# accepts comment or article as story
2222
return 0 unless Rails.env.production?
2323
return 100 unless story.user
2424
FunctionCaller.new("blackbox-production-spamScore",
25-
{story: story, user: story.user}.to_json).call
25+
{ story: story, user: story.user }.to_json).call
2626
end
2727

2828
private
2929

3030
def self.calculate_bonus_score(body_markdown)
3131
size_bonus = body_markdown.size > 200 ? 2 : 0
32-
code_bonus = body_markdown.include?('`') ? 1 : 0
32+
code_bonus = body_markdown.include?("`") ? 1 : 0
3333
size_bonus + code_bonus
3434
end
3535
end

Diff for: app/controllers/additional_content_boxes_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def index
1414
@boosted_article = Suggester::Articles::Boosted.new(
1515
current_user,
1616
@article,
17-
{not_ids: (article_ids + [@for_user_article&.id]), area: "additional_articles"},
17+
not_ids: (article_ids + [@for_user_article&.id]), area: "additional_articles",
1818
).suggest
1919
else
2020
@alt_classic = Suggester::Articles::Classic.
21-
new(@article, {not_ids: (article_ids + [@for_user_article&.id])}).get
21+
new(@article, not_ids: (article_ids + [@for_user_article&.id])).get
2222
end
2323
set_surrogate_key_header "additional_content_boxes_" + params.to_s unless current_user
2424
render "boxes", layout: false

Diff for: app/controllers/admin/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ApplicationController < Administrate::ApplicationController
1010
before_action :authorize_admin
1111

1212
def order
13-
@_order ||= Administrate::Order.new(params[:order] || "id",params[:direction] || "desc")
13+
@_order ||= Administrate::Order.new(params[:order] || "id", params[:direction] || "desc")
1414
end
1515

1616
def valid_request_origin?

Diff for: app/controllers/api/v0/api_controller.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
class Api::V0::ApiController < ApplicationController
22
def cors_set_access_control_headers
3-
headers['Access-Control-Allow-Origin'] = '*'
4-
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
5-
headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Accept, Authorization, Token'
6-
headers['Access-Control-Max-Age'] = "1728000"
3+
headers["Access-Control-Allow-Origin"] = "*"
4+
headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, DELETE, OPTIONS"
5+
headers["Access-Control-Allow-Headers"] = "Origin, Content-Type, Accept, Authorization, Token"
6+
headers["Access-Control-Max-Age"] = "1728000"
77
end
88

99
def cors_preflight_check
10-
if request.method == 'OPTIONS'
11-
headers['Access-Control-Allow-Origin'] = '*'
12-
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
13-
headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version, Token'
14-
headers['Access-Control-Max-Age'] = '1728000'
10+
if request.method == "OPTIONS"
11+
headers["Access-Control-Allow-Origin"] = "*"
12+
headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, DELETE, OPTIONS"
13+
headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-Prototype-Version, Token"
14+
headers["Access-Control-Max-Age"] = "1728000"
1515

16-
render :text => '', :content_type => 'text/plain'
16+
render text: "", content_type: "text/plain"
1717
end
1818
end
19-
end
19+
end

0 commit comments

Comments
 (0)