Skip to content

Commit

Permalink
Add rubocop to CI process
Browse files Browse the repository at this point in the history
Rubocop config
Fix some rubocop offenses
  • Loading branch information
ggiamarchi committed Jun 20, 2014
1 parent ae2db14 commit 982a1c9
Show file tree
Hide file tree
Showing 28 changed files with 358 additions and 301 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ before_install:
- cd source

install:
- "travis_retry bundle install"
- "travis_retry appraisal install"
- travis_retry bundle install
- travis_retry appraisal install

script: "appraisal rake"
script:
- bundle exec rubocop
- appraisal rake

gemfile:
- Gemfile
Expand Down
28 changes: 28 additions & 0 deletions source/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- 'out/**/*'

Style/FileName:
Enabled: false

Style/Encoding:
Enabled: false

Style/Documentation:
Enabled: false

Style/ClassLength:
Max: 300

Style/CyclomaticComplexity:
Severity: warning
Max: 15

Style/MethodLength:
Max: 50

Style/LineLength:
Max: 150
33 changes: 33 additions & 0 deletions source/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-06-20 02:04:44 +0200 using RuboCop version 0.23.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 8
# Cop supports --auto-correct.
Style/Blocks:
Enabled: false

# Offense count: 10
# Cop supports --auto-correct.
Style/NegatedIf:
Enabled: false

# Offense count: 3
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/Next:
Enabled: false

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/SignalException:
Enabled: false

# Offense count: 265
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StringLiterals:
Enabled: false
1 change: 1 addition & 0 deletions source/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gemspec
gem "appraisal", "1.0.0"
gem "restclient", "0.10.0"
gem 'webmock', '~> 1.18.0', :group => [:test]
gem "rubocop", '0.23.0', require: false
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"


Expand Down
2 changes: 1 addition & 1 deletion source/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new

# Default task is to run the unit tests
task :default => "spec"
task default: "spec"
1 change: 1 addition & 0 deletions source/gemfiles/latest_stable.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "https://rubygems.org"
gem "appraisal", "1.0.0"
gem "restclient", "0.10.0"
gem "webmock", "~> 1.18.0", :group => [:test]
gem "rubocop", "0.23.0", :require => false
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"

group :development do
Expand Down
1 change: 1 addition & 0 deletions source/gemfiles/oldest_current.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "https://rubygems.org"
gem "appraisal", "1.0.0"
gem "restclient", "0.10.0"
gem "webmock", "~> 1.18.0", :group => [:test]
gem "rubocop", "0.23.0", :require => false
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"

group :development do
Expand Down
1 change: 1 addition & 0 deletions source/gemfiles/previous_release.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "https://rubygems.org"
gem "appraisal", "1.0.0"
gem "restclient", "0.10.0"
gem "webmock", "~> 1.18.0", :group => [:test]
gem "rubocop", "0.23.0", :require => false
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.4.3"

group :development do
Expand Down
1 change: 0 additions & 1 deletion source/lib/vagrant-openstack-provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def self.init_logging
logger = Log4r::Logger.new("vagrant_openstack")
logger.outputters = Log4r::Outputter.stderr
logger.level = level
logger = nil
end
end

Expand Down
20 changes: 10 additions & 10 deletions source/lib/vagrant-openstack-provider/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.action_destroy
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use DeleteServer
Expand All @@ -29,7 +29,7 @@ def self.action_provision
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use Provision
Expand Down Expand Up @@ -66,7 +66,7 @@ def self.action_ssh
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use SSHExec
Expand All @@ -80,7 +80,7 @@ def self.action_ssh_run
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use SSHRun
Expand All @@ -95,7 +95,7 @@ def self.action_up
b.use ConnectOpenstack

b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Provision
b2.use SyncFolders
b2.use CreateServer
Expand All @@ -111,7 +111,7 @@ def self.action_halt
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use StopServer
Expand All @@ -127,9 +127,9 @@ def self.action_suspend
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
elsif env[:machine_state_id] === :suspended
elsif env[:machine_state_id] == :suspended
b2.use Message, I18n.t("vagrant_openstack.already_suspended")
else
b2.use Suspend
Expand All @@ -145,7 +145,7 @@ def self.action_resume
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use Resume
Expand All @@ -159,7 +159,7 @@ def self.action_reload
b.use ConfigValidate
b.use ConnectOpenstack
b.use Call, ReadState do |env, b2|
if env[:machine_state_id] === :not_created
if env[:machine_state_id] == :not_created
b2.use Message, I18n.t("vagrant_openstack.not_created")
else
b2.use StopServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ module Action
# puts the Openstack connection object into the `:openstack_compute` key
# in the environment.
class ConnectOpenstack
def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::connect_openstack")
end

def call(env)
# Get the configs
config = env[:machine].provider_config
client = OpenstackClient::new()
client = OpenstackClient.new
env[:openstack_client] = client
client.authenticate(env)
@app.call(env)
Expand Down
10 changes: 4 additions & 6 deletions source/lib/vagrant-openstack-provider/action/create_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Action
class CreateServer
include Vagrant::Util::Retryable

def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::create_server")
end
Expand Down Expand Up @@ -52,7 +52,7 @@ def call(env)
# Wait for the server to finish building
env[:ui].info(I18n.t("vagrant_openstack.waiting_for_build"))
timeout(200) do
while client.get_server_details(env, server_id)['status'] != 'ACTIVE' do
while client.get_server_details(env, server_id)['status'] != 'ACTIVE'
sleep 3
@logger.debug("Waiting for server to be ACTIVE")
end
Expand All @@ -72,9 +72,7 @@ def call(env)
ssh_timeout = env[:machine].provider_config.ssh_timeout
if !port_open?(env, host, 22, ssh_timeout)
env[:ui].error(I18n.t("vagrant_openstack.timeout"))
raise Errors::SshUnavailable,
:host => host,
:timeout => ssh_timeout
raise Errors::SshUnavailable, host: host, timeou: ssh_timeout
end

env[:ui].info(I18n.t("vagrant_openstack.ready"))
Expand All @@ -98,7 +96,7 @@ def port_open?(env, ip, port, timeout)
end
current_time = Time.now
end
return false
false
end

# This method finds a matching _thing_ in a collection of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Openstack
module Action
# This deletes the running server, if there is one.
class DeleteServer
def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::delete_server")
end
Expand Down
10 changes: 5 additions & 5 deletions source/lib/vagrant-openstack-provider/action/read_ssh_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Action
# This action reads the SSH info for the machine and puts it into the
# `:machine_ssh_info` key in the environment.
class ReadSSHInfo
def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::read_ssh_info")
end
Expand All @@ -19,11 +19,11 @@ def call(env)

def read_ssh_info(env)
config = env[:machine].provider_config
return {
{
# Usually there should only be one public IP
:host => config.floating_ip,
:port => 22,
:username => config.ssh_username
host: config.floating_ip,
port: 22,
username: config.ssh_username
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions source/lib/vagrant-openstack-provider/action/read_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Action
# This action reads the state of the machine and puts it in the
# `:machine_state_id` key in the environment.
class ReadState
def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::read_state")
end
Expand All @@ -31,7 +31,7 @@ def read_state(env)
end

# Return the state
return server['status'].downcase.to_sym
server['status'].downcase.to_sym
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion source/lib/vagrant-openstack-provider/action/resume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module VagrantPlugins
module Openstack
module Action
class Resume
def initialize(app, env)
def initialize(app, _env)
@app = app
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module VagrantPlugins
module Openstack
module Action
class StartServer
def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::start_server")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module VagrantPlugins
module Openstack
module Action
class StopServer
def initialize(app, env)
def initialize(app, _env)
@app = app
@logger = Log4r::Logger.new("vagrant_openstack::action::stop_server")
end
Expand Down
2 changes: 1 addition & 1 deletion source/lib/vagrant-openstack-provider/action/suspend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module VagrantPlugins
module Openstack
module Action
class Suspend
def initialize(app, env)
def initialize(app, _env)
@app = app
end

Expand Down
Loading

0 comments on commit 982a1c9

Please sign in to comment.