Skip to content

Commit 026d817

Browse files
committed
initial linting for rubocop setup
1 parent b234ea1 commit 026d817

25 files changed

+137
-98
lines changed

.rubocop.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
AllCops:
2+
Exclude:
3+
- 'Guardfile'
4+
- 'bin/**/*'
5+
- 'node_modules/**/*'
6+
- 'db/schema.rb'
7+
- 'db/migrate/**/*'
8+
9+
Style/Documentation:
10+
Enabled: false
11+
12+
Style/SymbolProc:
13+
Enabled: false
14+
15+
Metrics/LineLength:
16+
Enabled: false
17+
18+
Style/AndOr:
19+
Enabled: false
20+
21+
ParameterLists:
22+
CountKeywordArgs: false

Gemfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ gem 'puma'
2424
gem 'bootstrap-sass', '~> 3.3.1'
2525
gem 'devise'
2626
gem 'omniauth'
27-
gem "omniauth-bike-index"
27+
gem 'omniauth-bike-index'
2828
gem 'devise-bootstrap-views'
29-
gem "hashie-forbidden_attributes"
29+
gem 'hashie-forbidden_attributes'
3030

3131
# Store configuration options
3232
gem 'dotenv-rails'
3333

3434

3535
# Authentication
36-
gem 'doorkeeper', '~> 2.2.2'
36+
gem 'doorkeeper', '~> 2.2.2'
3737
gem 'wine_bouncer'
3838

3939
# Things tied in with Grade and swagger
@@ -44,7 +44,7 @@ gem 'active_model_serializers'
4444
gem 'grape-active_model_serializers'
4545
gem 'grape-swagger'
4646
gem 'api-pagination'
47-
gem 'rack-cors', :require => 'rack/cors'
47+
gem 'rack-cors', require: 'rack/cors'
4848

4949
# Temporarily remote branch because updates, for more info look at
5050
# https://github.com/d4be4st/swagger-ui_rails/pull/13
@@ -61,15 +61,16 @@ group :development, :test do
6161
gem 'pry'
6262
gem 'growl'
6363
gem 'guard'
64+
gem 'guard-rubocop'
6465
gem 'guard-rspec', '4.2.8'
6566
gem 'guard-livereload'
6667
end
6768

68-
group :development do
69+
group :development do
6970
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
7071
gem 'spring'
7172
end
7273

73-
group :test do
74+
group :test do
7475
gem 'database_cleaner'
75-
end
76+
end

Gemfile.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ GEM
4646
tzinfo (~> 1.1)
4747
api-pagination (4.1.1)
4848
arel (6.0.3)
49+
ast (2.2.0)
4950
autoprefixer-rails (6.0.3)
5051
execjs
5152
json
@@ -144,6 +145,9 @@ GEM
144145
guard-rspec (4.2.8)
145146
guard (~> 2.1)
146147
rspec (>= 2.14, < 4.0)
148+
guard-rubocop (1.2.0)
149+
guard (~> 2.0)
150+
rubocop (~> 0.20)
147151
haml (4.0.7)
148152
tilt
149153
hashie (3.4.3)
@@ -201,7 +205,10 @@ GEM
201205
oauth2 (~> 1.0)
202206
omniauth (~> 1.2)
203207
orm_adapter (0.5.0)
208+
parser (2.3.0.6)
209+
ast (~> 2.2)
204210
pg (0.18.3)
211+
powerpack (0.1.1)
205212
pry (0.10.2)
206213
coderay (~> 1.1.0)
207214
method_source (~> 0.8.1)
@@ -239,6 +246,7 @@ GEM
239246
activesupport (= 4.2.5)
240247
rake (>= 0.8.7)
241248
thor (>= 0.18.1, < 2.0)
249+
rainbow (2.1.0)
242250
rake (10.5.0)
243251
rb-fsevent (0.9.6)
244252
rb-inotify (0.9.5)
@@ -268,6 +276,13 @@ GEM
268276
rspec-mocks (~> 3.3.0)
269277
rspec-support (~> 3.3.0)
270278
rspec-support (3.3.0)
279+
rubocop (0.37.2)
280+
parser (>= 2.3.0.4, < 3.0)
281+
powerpack (~> 0.1)
282+
rainbow (>= 1.99.1, < 3.0)
283+
ruby-progressbar (~> 1.7)
284+
unicode-display_width (~> 0.3)
285+
ruby-progressbar (1.7.5)
271286
sass (3.4.18)
272287
sass-rails (5.0.4)
273288
railties (>= 4.0.0, < 5.0)
@@ -299,6 +314,7 @@ GEM
299314
uglifier (2.7.2)
300315
execjs (>= 0.3.0)
301316
json (>= 1.8.0)
317+
unicode-display_width (0.3.1)
302318
vcr (2.9.3)
303319
virtus (1.0.5)
304320
axiom-types (~> 0.1)
@@ -333,6 +349,7 @@ DEPENDENCIES
333349
guard
334350
guard-livereload
335351
guard-rspec (= 4.2.8)
352+
guard-rubocop
336353
haml
337354
hashie-forbidden_attributes
338355
jquery-rails (~> 4.0.4)

Guardfile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do
2-
watch(%r{^spec/.+_spec\.rb$})
3-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4-
watch('spec/spec_helper.rb') { "spec" }
5-
watch(%r{^app/controllers/api/v1/(.+)\.rb$}) { |m| "spec/api/v1/#{m[1]}_spec.rb"}
1+
group :red_green_refactor, halt_on_fail: true do
2+
guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do
3+
watch(%r{^spec/.+_spec\.rb$})
4+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5+
watch('spec/spec_helper.rb') { "spec" }
6+
watch(%r{^app/controllers/api/v1/(.+)\.rb$}) { |m| "spec/api/v1/#{m[1]}_spec.rb"}
67

7-
# Rails example
8-
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9-
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
10-
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
11-
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
12-
# watch('config/routes.rb') { "spec/routing" }
13-
watch('app/controllers/application_controller.rb') { "spec/controllers" }
8+
# Rails example
9+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
10+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
11+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
12+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
13+
# watch('config/routes.rb') { "spec/routing" }
14+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
15+
end
16+
17+
guard :rubocop, all_on_start: false do
18+
watch(/.+\.rb$/)
19+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
20+
end
1421
end

app/controllers/api/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Dispatch < Grape::API
33
mount API::V1::Root
44
format :json
55
route :any, '*path' do
6-
Rack::Response.new({message: "Not found"}.to_json, 404).finish
6+
Rack::Response.new({message: 'Not found'}.to_json, 404).finish
77
end
88
end
99

app/controllers/api/logger.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def call(env)
1212
x_organization: env['HTTP_X_ORGANIZATION']
1313
}
1414

15-
ActiveSupport::Notifications.instrument "grape.request", payload do
15+
ActiveSupport::Notifications.instrument 'grape.request', payload do
1616
@app.call(env).tap do |response|
17-
if env["api.endpoint"].params.present?
18-
payload[:params] = env["api.endpoint"].params.to_hash
19-
payload[:params].delete("route_info")
20-
payload[:params].delete("format")
17+
if env['api.endpoint'].params.present?
18+
payload[:params] = env['api.endpoint'].params.to_hash
19+
payload[:params].delete('route_info')
20+
payload[:params].delete('format')
2121
end
2222
payload[:response_status] = response[0]
2323
end

app/controllers/api/v1/defaults.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module API
22
module V1
33
module Defaults
44
extend ActiveSupport::Concern
5-
included do
5+
included do
66
formatter :json, Grape::Formatter::ActiveModelSerializers
7-
7+
88
before do
99
header['Access-Control-Allow-Origin'] = '*'
1010
header['Access-Control-Request-Method'] = '*'
@@ -23,7 +23,6 @@ def current_scopes
2323
current_token.scopes
2424
end
2525
end
26-
2726
end
2827
end
2928
end

app/controllers/api/v1/me.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ module V1
33
class Me < API::V1::Root
44
include API::V1::Defaults
55

6-
resource :me, desc: "Operations about the current user" do
6+
resource :me, desc: 'Operations about the current user' do
77

8-
desc "Current user's information in access token's scope<span class='accstr'>*</span>", {
9-
notes: <<-NOTE
8+
desc "Current user's information in access token's scope<span class='accstr'>*</span>" do
9+
detail <<-NOTE
1010
Current user is the owner of the `access_token` you use in the request.
1111
NOTE
12-
}
12+
end
1313
oauth2 # This endpoint requires authentication
1414
get '/' do
15-
result = {
15+
{
1616
id: current_user.id.to_s,
1717
user: {
1818
email: current_user.email,
@@ -38,7 +38,7 @@ class Me < API::V1::Root
3838
optional :email, type: String, desc: 'User email'
3939
optional :name, type: String, desc: 'User name'
4040
# Demo of value list, displays as select in swagger-ui
41-
optional :demo_value, type: String, values: ['value 1', 'value 2', '3'], default: 'value 1', desc: "Special value list"
41+
optional :demo_value, type: String, values: ['value 1', 'value 2', '3'], default: 'value 1', desc: 'Special value list'
4242
end
4343
oauth2 'write_user'
4444
put '/' do
@@ -48,7 +48,7 @@ class Me < API::V1::Root
4848
demo_value = declared_p.delete(:demo_value)
4949

5050
current_user.update_attributes(declared_p)
51-
result = {
51+
{
5252
id: current_user.id.to_s,
5353
user: {
5454
value: demo_value,

app/controllers/api/v1/root.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class Root < Dispatch
3232
mount API::V1::Me
3333

3434
add_swagger_documentation base_path: "/api",
35-
api_version: 'v1',
36-
hide_format: true, # don't show .json
37-
hide_documentation_path: true,
38-
mount_path: "/swagger_doc",
39-
markdown: GrapeSwagger::Markdown::KramdownAdapter,
40-
info: {
41-
title: "Grape Swagger base app",
42-
description: "This is the base api provided by the awesome sample app - https://github.com/sethherr/grape-doorkeeper",
43-
}
35+
api_version: 'v1',
36+
hide_format: true, # don't show .json
37+
hide_documentation_path: true,
38+
mount_path: '/swagger_doc',
39+
markdown: GrapeSwagger::Markdown::KramdownAdapter,
40+
info: {
41+
title: 'Grape Swagger base app',
42+
description: 'This is the base api provided by the awesome sample app - https://github.com/sethherr/grape-doorkeeper',
43+
}
4444

4545
route :any, '*path' do
46-
raise StandardError, "Unable to find endpoint"
46+
raise StandardError, 'Unable to find endpoint'
4747
end
4848
end
4949
end
50-
end
50+
end

app/controllers/documentation_controller.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class DocumentationController < ApplicationController
2-
32
def index
43
@applications = Doorkeeper::Application.all
54
render layout: false
@@ -14,6 +13,4 @@ def authorize
1413
@access_grant = Doorkeeper::AccessGrant.where(resource_owner_id: current_user.id, token: @access_code).last
1514
@application = @access_grant.application if @access_grant.present?
1615
end
17-
18-
1916
end

0 commit comments

Comments
 (0)