Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6dcdc5c

Browse files
cristianbicaDavid Heinemeier Hansson
authored andcommitted
Added rubocop / codeclimate config and fixed current offenses (#45)
1 parent 14e6386 commit 6dcdc5c

18 files changed

+183
-33
lines changed

.codeclimate.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
engines:
2+
rubocop:
3+
enabled: true
4+
5+
ratings:
6+
paths:
7+
- "**.rb"

.rubocop.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
AllCops:
2+
TargetRubyVersion: 2.3
3+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4+
# to ignore them, so only the ones explicitly set in this file are enabled.
5+
DisabledByDefault: true
6+
Exclude:
7+
- '**/templates/**/*'
8+
- '**/vendor/**/*'
9+
- 'actionpack/lib/action_dispatch/journey/parser.rb'
10+
11+
# Prefer &&/|| over and/or.
12+
Style/AndOr:
13+
Enabled: true
14+
15+
# Do not use braces for hash literals when they are the last argument of a
16+
# method call.
17+
Style/BracesAroundHashParameters:
18+
Enabled: true
19+
EnforcedStyle: context_dependent
20+
21+
# Align `when` with `case`.
22+
Style/CaseIndentation:
23+
Enabled: true
24+
25+
# Align comments with method definitions.
26+
Style/CommentIndentation:
27+
Enabled: true
28+
29+
# No extra empty lines.
30+
Style/EmptyLines:
31+
Enabled: false
32+
33+
# In a regular class definition, no empty lines around the body.
34+
Style/EmptyLinesAroundClassBody:
35+
Enabled: true
36+
37+
# In a regular method definition, no empty lines around the body.
38+
Style/EmptyLinesAroundMethodBody:
39+
Enabled: true
40+
41+
# In a regular module definition, no empty lines around the body.
42+
Style/EmptyLinesAroundModuleBody:
43+
Enabled: true
44+
45+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
46+
Style/HashSyntax:
47+
Enabled: true
48+
49+
# Method definitions after `private` or `protected` isolated calls need one
50+
# extra level of indentation.
51+
Style/IndentationConsistency:
52+
Enabled: true
53+
EnforcedStyle: rails
54+
55+
# Two spaces, no tabs (for indentation).
56+
Style/IndentationWidth:
57+
Enabled: true
58+
59+
Style/SpaceAfterColon:
60+
Enabled: true
61+
62+
Style/SpaceAfterComma:
63+
Enabled: true
64+
65+
Style/SpaceAroundEqualsInParameterDefault:
66+
Enabled: true
67+
68+
Style/SpaceAroundKeyword:
69+
Enabled: true
70+
71+
Style/SpaceAroundOperators:
72+
Enabled: true
73+
74+
Style/SpaceBeforeFirstArg:
75+
Enabled: true
76+
77+
# Defining a method with parameters needs parentheses.
78+
Style/MethodDefParentheses:
79+
Enabled: true
80+
81+
# Use `foo {}` not `foo{}`.
82+
Style/SpaceBeforeBlockBraces:
83+
Enabled: true
84+
85+
# Use `foo { bar }` not `foo {bar}`.
86+
Style/SpaceInsideBlockBraces:
87+
Enabled: true
88+
89+
# Use `{ a: 1 }` not `{a:1}`.
90+
Style/SpaceInsideHashLiteralBraces:
91+
Enabled: true
92+
93+
Style/SpaceInsideParens:
94+
Enabled: true
95+
96+
# Check quotes usage according to lint rule below.
97+
Style/StringLiterals:
98+
Enabled: true
99+
EnforcedStyle: double_quotes
100+
101+
# Detect hard tabs, no hard tabs.
102+
Style/Tab:
103+
Enabled: true
104+
105+
# Blank lines should not have any spaces.
106+
Style/TrailingBlankLines:
107+
Enabled: true
108+
109+
# No trailing whitespace.
110+
Style/TrailingWhitespace:
111+
Enabled: true
112+
113+
# Use quotes for string literals when they are enough.
114+
Style/UnneededPercentQ:
115+
Enabled: true
116+
117+
# Align `end` with the matching keyword or starting expression except for
118+
# assignments, where it should be aligned with the LHS.
119+
Lint/EndAlignment:
120+
Enabled: true
121+
EnforcedStyleAlignWith: variable
122+
123+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
124+
Lint/RequireParentheses:
125+
Enabled: true

Gemfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rake'
6-
gem 'byebug'
5+
gem "rake"
6+
gem "byebug"
77

8-
gem 'sqlite3'
9-
gem 'httparty'
8+
gem "sqlite3"
9+
gem "httparty"
1010

11-
gem 'aws-sdk', '~> 2', require: false
12-
gem 'google-cloud-storage', '~> 1.3', require: false
11+
gem "aws-sdk", "~> 2", require: false
12+
gem "google-cloud-storage", "~> 1.3", require: false
13+
14+
gem "rubocop", require: false

Gemfile.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ GEM
4040
addressable (2.5.1)
4141
public_suffix (~> 2.0, >= 2.0.2)
4242
arel (8.0.0)
43+
ast (2.3.0)
4344
aws-sdk (2.10.7)
4445
aws-sdk-resources (= 2.10.7)
4546
aws-sdk-core (2.10.7)
@@ -107,6 +108,10 @@ GEM
107108
nokogiri (1.7.2)
108109
mini_portile2 (~> 2.1.0)
109110
os (0.9.6)
111+
parallel (1.11.2)
112+
parser (2.4.0.0)
113+
ast (~> 2.2)
114+
powerpack (0.1.1)
110115
public_suffix (2.0.5)
111116
rack (2.0.3)
112117
rack-test (0.6.3)
@@ -116,12 +121,22 @@ GEM
116121
nokogiri (>= 1.6)
117122
rails-html-sanitizer (1.0.3)
118123
loofah (~> 2.0)
124+
rainbow (2.2.2)
125+
rake
119126
rake (12.0.0)
120127
representable (3.0.4)
121128
declarative (< 0.1.0)
122129
declarative-option (< 0.2.0)
123130
uber (< 0.2.0)
124131
retriable (3.0.2)
132+
rubocop (0.49.1)
133+
parallel (~> 1.10)
134+
parser (>= 2.3.3.1, < 3.0)
135+
powerpack (~> 0.1)
136+
rainbow (>= 1.99.1, < 3.0)
137+
ruby-progressbar (~> 1.7)
138+
unicode-display_width (~> 1.0, >= 1.0.1)
139+
ruby-progressbar (1.8.1)
125140
signet (0.7.3)
126141
addressable (~> 2.3)
127142
faraday (~> 0.9)
@@ -132,6 +147,7 @@ GEM
132147
tzinfo (1.2.3)
133148
thread_safe (~> 0.1)
134149
uber (0.1.0)
150+
unicode-display_width (1.3.0)
135151

136152
PLATFORMS
137153
ruby
@@ -144,6 +160,7 @@ DEPENDENCIES
144160
google-cloud-storage (~> 1.3)
145161
httparty
146162
rake
163+
rubocop
147164
sqlite3
148165

149166
BUNDLED WITH

lib/active_storage/disk_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ def decode_verified_key
3333
end
3434

3535
def disposition_param
36-
params[:disposition].presence_in(%w( inline attachment )) || 'inline'
36+
params[:disposition].presence_in(%w( inline attachment )) || "inline"
3737
end
3838
end

lib/active_storage/download.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ class ActiveStorage::Download
1414
application/xhtml+xml
1515
)
1616

17-
BINARY_CONTENT_TYPE = 'application/octet-stream'
17+
BINARY_CONTENT_TYPE = "application/octet-stream"
1818

1919
def initialize(stored_file)
2020
@stored_file = stored_file
2121
end
2222

2323
def headers(force_attachment: false)
2424
{
25-
x_accel_redirect: '/reproxy',
25+
x_accel_redirect: "/reproxy",
2626
x_reproxy_url: reproxy_url,
2727
content_type: content_type,
2828
content_disposition: content_disposition(force_attachment),
29-
x_frame_options: 'SAMEORIGIN'
29+
x_frame_options: "SAMEORIGIN"
3030
}
3131
end
3232

lib/active_storage/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def url_for_direct_upload(key, expires_in:, content_type:, content_length:)
8585
private
8686
def instrument(operation, key, payload = {}, &block)
8787
ActiveSupport::Notifications.instrument(
88-
"service_#{operation}.active_storage",
88+
"service_#{operation}.active_storage",
8989
payload.merge(key: key, service: service_name), &block)
9090
end
9191

lib/active_storage/service/disk_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def upload(key, io, checksum: nil)
2020
def download(key)
2121
if block_given?
2222
instrument :streaming_download, key do
23-
File.open(path_for(key), 'rb') do |file|
23+
File.open(path_for(key), "rb") do |file|
2424
while data = file.read(64.kilobytes)
2525
yield data
2626
end

lib/active_storage/service/s3_service.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def url(key, expires_in:, disposition:, filename:)
4949
instrument :url, key do |payload|
5050
generated_url = object_for(key).presigned_url :get, expires_in: expires_in,
5151
response_content_disposition: "#{disposition}; filename=\"#{filename}\""
52-
52+
5353
payload[:url] = generated_url
54-
54+
5555
generated_url
5656
end
5757
end
@@ -60,9 +60,9 @@ def url_for_direct_upload(key, expires_in:, content_type:, content_length:)
6060
instrument :url, key do |payload|
6161
generated_url = object_for(key).presigned_url :put, expires_in: expires_in,
6262
content_type: content_type, content_length: content_length
63-
63+
6464
payload[:url] = generated_url
65-
65+
6666
generated_url
6767
end
6868
end

lib/active_storage/verified_key_with_expiration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ActiveStorage::VerifiedKeyWithExpiration
2-
class_attribute :verifier, default: defined?(Rails) ? Rails.application.message_verifier('ActiveStorage') : nil
2+
class_attribute :verifier, default: defined?(Rails) ? Rails.application.message_verifier("ActiveStorage") : nil
33

44
class << self
55
def encode(key, expires_in: nil)

0 commit comments

Comments
 (0)