Skip to content

Commit 357140d

Browse files
committed
Implemented RuboCop, ruby style linter.
1 parent 7073ad6 commit 357140d

19 files changed

+166
-93
lines changed

Diff for: .rubocop.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AllCops:
2+
Exclude:
3+
- vendor/**/*
4+
5+
inherit_from: .rubocop_todo.yml

Diff for: .rubocop_todo.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2015-08-19 12:23:54 -0400 using RuboCop version 0.33.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+
Lint/AmbiguousRegexpLiteral:
11+
Exclude:
12+
- 'lib/tasks/swagger_ui.rake'
13+
14+
# Offense count: 1
15+
# Configuration parameters: AllowSafeAssignment.
16+
Lint/AssignmentInCondition:
17+
Exclude:
18+
- 'spec/dummy/bin/spring'
19+
20+
# Offense count: 2
21+
Lint/HandleExceptions:
22+
Exclude:
23+
- 'spec/dummy/bin/rails'
24+
- 'spec/dummy/bin/rake'
25+
26+
# Offense count: 31
27+
# Configuration parameters: AllowURI, URISchemes.
28+
Metrics/LineLength:
29+
Max: 129
30+
31+
# Offense count: 2
32+
# Cop supports --auto-correct.
33+
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
34+
Style/BlockDelimiters:
35+
Enabled: false
36+
37+
# Offense count: 9
38+
Style/Documentation:
39+
Exclude:
40+
- 'app/controllers/grape_swagger_rails/application_controller.rb'
41+
- 'lib/grape-swagger-rails.rb'
42+
- 'lib/grape-swagger-rails/engine.rb'
43+
- 'lib/grape-swagger-rails/version.rb'
44+
- 'spec/dummy/app/api/api.rb'
45+
- 'spec/dummy/app/controllers/application_controller.rb'
46+
- 'spec/dummy/app/controllers/welcome_controller.rb'
47+
- 'spec/dummy/config/application.rb'
48+
49+
# Offense count: 2
50+
# Configuration parameters: Exclude.
51+
Style/FileName:
52+
Exclude:
53+
- 'lib/grape-swagger-rails.rb'
54+
- 'spec/features/grape-swagger-rails_spec.rb'
55+
56+
# Offense count: 1
57+
# Cop supports --auto-correct.
58+
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
59+
Style/RegexpLiteral:
60+
Exclude:
61+
- 'lib/tasks/swagger_ui.rake'

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [#6](https://github.com/ruby-grape/grape-swagger-rails/pull/6): Fix: support multiple predefined headers - [@Tyr0](https://github.com/tyr0).
44
* Upgraded swagger-ui to v2.1.1 - [@dblock](https://github.com/dblock).
55
* Grape-swagger 0.7.2 is no longer supported - [@dblock](https://github.com/dblock).
6+
* Implemented RuboCop, Ruby-style linter - [@dblock](https://github.com/dblock).
67
* Your contribution here.
78

89
### 0.1.0 (February 5, 2015)

Diff for: CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ We definitely appreciate pull requests that highlight or reproduce a problem, ev
4646

4747
Implement your feature or bug fix.
4848

49+
Ruby style is enforced with [RuboCop](https://github.com/bbatsov/rubocop).
50+
Run `bundle exec rubocop` and fix any style issues highlighted.
51+
4952
Make sure that `bundle exec rake` completes without errors.
5053

5154
You might find it useful to iterate on code by running the test project from spec/dummy.

Diff for: Rakefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rescue LoadError
55
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
66
end
77

8-
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
99

1010
load 'rails/tasks/engine.rake'
1111
Bundler::GemHelper.install_tasks
@@ -17,7 +17,10 @@ end
1717
require 'rspec/core'
1818
require 'rspec/core/rake_task'
1919

20-
desc "Run all specs."
20+
desc 'Run all specs.'
2121
RSpec::Core::RakeTask.new(:spec)
2222

23-
task :default => :spec
23+
require 'rubocop/rake_task'
24+
RuboCop::RakeTask.new(:rubocop)
25+
26+
task default: [:rubocop, :spec]

Diff for: config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
GrapeSwaggerRails::Engine.routes.draw do
2-
root :to => "application#index"
2+
root to: 'application#index'
33
end

Diff for: grape-swagger-rails.gemspec

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Gem::Specification.new do |spec|
1212
spec.summary = 'Swagger UI as Rails Engine for grape-swagger gem'
1313
spec.homepage = 'https://github.com/ruby-grape/grape-swagger-rails'
1414
spec.license = 'MIT'
15-
spec.files = `git ls-files`.split($/)
16-
spec.test_files = `git ls-files spec`.split($/)
15+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16+
spec.test_files = `git ls-files spec`.split($INPUT_RECORD_SEPARATOR)
1717
spec.require_paths = %w(lib)
1818

1919
spec.add_dependency 'railties', '>= 3.2.12'
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
3333
spec.add_development_dependency 'grape-swagger-ui'
3434
spec.add_development_dependency 'sprockets'
3535
spec.add_development_dependency 'rack-cors'
36+
spec.add_development_dependency 'rubocop', '0.33.0'
3637
end

Diff for: lib/grape-swagger-rails.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
require "grape-swagger-rails/engine"
1+
require 'grape-swagger-rails/engine'
22

33
module GrapeSwaggerRails
44
class Options < OpenStruct
55
def before_filter(&block)
66
if block_given?
77
self.before_filter_proc = block
88
else
9-
self.before_filter_proc
9+
before_filter_proc
1010
end
1111
end
1212
end
@@ -27,5 +27,4 @@ def before_filter(&block)
2727

2828
before_filter_proc: nil # Proc used as a controller before filter
2929
)
30-
3130
end

Diff for: lib/grape-swagger-rails/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module GrapeSwaggerRails
2-
VERSION = "0.1.1"
2+
VERSION = '0.1.1'
33
end

Diff for: lib/tasks/swagger_ui.rake

+42-42
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require 'git'
22

33
namespace :swagger_ui do
44
namespace :dist do
5-
desc "Update Swagger-UI from wordnik/swagger-ui."
5+
desc 'Update Swagger-UI from wordnik/swagger-ui.'
66
task :update do
77
Dir.mktmpdir 'swagger-ui' do |dir|
88
puts "Cloning into #{dir} ..."
@@ -13,80 +13,80 @@ namespace :swagger_ui do
1313
puts "Removing files from #{root} ..."
1414
repo = Git.open root
1515
# Javascripts
16-
puts "Copying Javascripts ..."
16+
puts 'Copying Javascripts ...'
1717
FileUtils.rm_r "#{root}/app/assets/javascripts/grape_swagger_rails"
1818
FileUtils.cp_r "#{dir}/swagger-ui/dist/lib", "#{root}/app/assets/javascripts"
1919
FileUtils.mv "#{root}/app/assets/javascripts/lib", "#{root}/app/assets/javascripts/grape_swagger_rails"
2020
FileUtils.cp_r Dir.glob("#{dir}/swagger-ui/dist/swagger-ui.min.js"), "#{root}/app/assets/javascripts/grape_swagger_rails"
2121
FileUtils.cp Dir.glob("#{root}/lib/javascripts/*.js"), "#{root}/app/assets/javascripts/grape_swagger_rails"
2222
# Generate application.js
2323
JAVASCRIPT_FILES = [
24-
'jquery-1.8.0.min.js',
25-
'jquery.slideto.min.js',
26-
'jquery.wiggle.min.js',
27-
'jquery.ba-bbq.min.js',
28-
'handlebars-2.0.0.js',
29-
'marked.js',
30-
'underscore-min.js',
31-
'backbone-min.js',
32-
'swagger-ui.min.js',
33-
'highlight.7.3.pack.js',
34-
'swagger-oauth.js',
35-
'base64.js'
24+
'jquery-1.8.0.min.js',
25+
'jquery.slideto.min.js',
26+
'jquery.wiggle.min.js',
27+
'jquery.ba-bbq.min.js',
28+
'handlebars-2.0.0.js',
29+
'marked.js',
30+
'underscore-min.js',
31+
'backbone-min.js',
32+
'swagger-ui.min.js',
33+
'highlight.7.3.pack.js',
34+
'swagger-oauth.js',
35+
'base64.js'
3636
]
3737
javascript_files = Dir["#{root}/app/assets/javascripts/grape_swagger_rails/*.js"].map { |f|
38-
f.split('/').last
38+
f.split('/').last
3939
} - ['application.js']
4040
(javascript_files - JAVASCRIPT_FILES).each do |filename|
41-
puts "WARNING: add #{filename} to swagger_ui.rake"
41+
puts "WARNING: add #{filename} to swagger_ui.rake"
4242
end
4343
(JAVASCRIPT_FILES - javascript_files).each do |filename|
44-
puts "WARNING: remove #{filename} from swagger_ui.rake"
44+
puts "WARNING: remove #{filename} from swagger_ui.rake"
4545
end
46-
File.open "#{root}/app/assets/javascripts/grape_swagger_rails/application.js", "w+" do |file|
47-
JAVASCRIPT_FILES.each do |filename|
48-
file.write "//= require ./#{File.basename(filename, '.*')}\n"
49-
end
46+
File.open "#{root}/app/assets/javascripts/grape_swagger_rails/application.js", 'w+' do |file|
47+
JAVASCRIPT_FILES.each do |filename|
48+
file.write "//= require ./#{File.basename(filename, '.*')}\n"
49+
end
5050
end
5151
# Stylesheets
52-
puts "Copying Stylesheets ..."
52+
puts 'Copying Stylesheets ...'
5353
repo.remove 'app/assets/stylesheets/grape_swagger_rails', recursive: true
5454
FileUtils.mkdir_p "#{root}/app/assets/stylesheets/grape_swagger_rails"
5555
FileUtils.cp_r Dir.glob("#{dir}/swagger-ui/dist/css/**/*"), "#{root}/app/assets/stylesheets/grape_swagger_rails"
5656
repo.add 'app/assets/stylesheets/grape_swagger_rails'
5757
# Generate application.js
5858
CSS_FILES = [
59-
'reset.css',
60-
'screen.css'
59+
'reset.css',
60+
'screen.css'
6161
]
6262
css_files = Dir["#{root}/app/assets/stylesheets/grape_swagger_rails/*.css"].map { |f|
63-
f.split('/').last
63+
f.split('/').last
6464
} - ['application.css']
6565
(css_files - CSS_FILES).each do |filename|
66-
puts "WARNING: add #{filename} to swagger_ui.rake"
66+
puts "WARNING: add #{filename} to swagger_ui.rake"
6767
end
6868
(CSS_FILES - css_files).each do |filename|
69-
puts "WARNING: remove #{filename} from swagger_ui.rake"
69+
puts "WARNING: remove #{filename} from swagger_ui.rake"
7070
end
7171
# rewrite screen.css into screen.css.erb with dynamic image paths
72-
File.open "#{root}/app/assets/stylesheets/grape_swagger_rails/screen.css.erb", "w+" do |file|
73-
contents = File.read "#{root}/app/assets/stylesheets/grape_swagger_rails/screen.css"
74-
contents.gsub! /url\((\'*).*\/(?<filename>[\w\.]*)(\'*)\)/ do |match|
75-
"url(<%= image_path('grape_swagger_rails/#{$~[:filename]}') %>)"
76-
end
77-
file.write contents
78-
FileUtils.rm "#{root}/app/assets/stylesheets/grape_swagger_rails/screen.css"
72+
File.open "#{root}/app/assets/stylesheets/grape_swagger_rails/screen.css.erb", 'w+' do |file|
73+
contents = File.read "#{root}/app/assets/stylesheets/grape_swagger_rails/screen.css"
74+
contents.gsub! /url\((\'*).*\/(?<filename>[\w\.]*)(\'*)\)/ do |_match|
75+
"url(<%= image_path('grape_swagger_rails/#{$LAST_MATCH_INFO[:filename]}') %>)"
76+
end
77+
file.write contents
78+
FileUtils.rm "#{root}/app/assets/stylesheets/grape_swagger_rails/screen.css"
7979
end
80-
File.open "#{root}/app/assets/stylesheets/grape_swagger_rails/application.css", "w+" do |file|
81-
file.write "/*\n"
82-
CSS_FILES.each do |filename|
83-
file.write "*= require ./#{File.basename(filename, '.*')}\n"
84-
end
85-
file.write "*= require_self\n"
86-
file.write "*/\n"
80+
File.open "#{root}/app/assets/stylesheets/grape_swagger_rails/application.css", 'w+' do |file|
81+
file.write "/*\n"
82+
CSS_FILES.each do |filename|
83+
file.write "*= require ./#{File.basename(filename, '.*')}\n"
84+
end
85+
file.write "*= require_self\n"
86+
file.write "*/\n"
8787
end
8888
# Images
89-
puts "Copying Images ..."
89+
puts 'Copying Images ...'
9090
repo.remove 'app/assets/images/grape_swagger_rails', recursive: true
9191
FileUtils.mkdir_p "#{root}/app/assets/images/grape_swagger_rails"
9292
FileUtils.cp_r Dir.glob("#{dir}/swagger-ui/dist/images/**/*"), "#{root}/app/assets/images/grape_swagger_rails"

Diff for: spec/dummy/bin/rails

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env ruby
22
begin
3-
load File.expand_path("../spring", __FILE__)
3+
load File.expand_path('../spring', __FILE__)
44
rescue LoadError
55
end
6-
APP_PATH = File.expand_path('../../config/application', __FILE__)
6+
APP_PATH = File.expand_path('../../config/application', __FILE__)
77
require_relative '../config/boot'
88
require 'rails/commands'

Diff for: spec/dummy/bin/rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22
begin
3-
load File.expand_path("../spring", __FILE__)
3+
load File.expand_path('../spring', __FILE__)
44
rescue LoadError
55
end
66
require_relative '../config/boot'

Diff for: spec/dummy/bin/spring

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# It gets overwritten when you run the `spring binstub` command
55

66
unless defined?(Spring)
7-
require "rubygems"
8-
require "bundler"
7+
require 'rubygems'
8+
require 'bundler'
99

1010
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
11-
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
12-
ENV["GEM_HOME"] = ""
11+
ENV['GEM_PATH'] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
12+
ENV['GEM_HOME'] = ''
1313
Gem.paths = ENV
1414

15-
gem "spring", match[1]
16-
require "spring/binstub"
15+
gem 'spring', match[1]
16+
require 'spring/binstub'
1717
end
1818
end

Diff for: spec/dummy/config.ru

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# This file is used by Rack-based servers to start the application.
22

3-
require ::File.expand_path('../config/environment', __FILE__)
3+
require ::File.expand_path('../config/environment', __FILE__)
44
run Dummy::Application

Diff for: spec/dummy/config/application.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Application < Rails::Application
1616
config.middleware.use Rack::Cors do
1717
allow do
1818
origins '*'
19-
resource '*', :headers => :any, :methods => [:get, :post, :options]
19+
resource '*', headers: :any, methods: [:get, :post, :options]
2020
end
2121
end
2222
end

Diff for: spec/dummy/config/environments/test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
config.eager_load = false
1414

1515
# Configure static asset server for tests with Cache-Control for performance.
16-
config.serve_static_files = true
16+
config.serve_static_files = true
1717
config.static_cache_control = 'public, max-age=3600'
1818

1919
# Show full error reports and disable caching.

Diff for: spec/features/grape-swagger-rails_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe GrapeSwaggerRails do
4-
context "#options" do
4+
context '#options' do
55
subject do
66
GrapeSwaggerRails.options
77
end

0 commit comments

Comments
 (0)