Skip to content

Commit

Permalink
Upgrade RuboCop 0.35.1 -> 0.36.0 for Travis builds
Browse files Browse the repository at this point in the history
This required a number of fixes to address new cops introduced in
version 0.36.0.
  • Loading branch information
sds committed Jan 20, 2016
1 parent 37a62b4 commit 9893350
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 40 deletions.
13 changes: 11 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Style/FormatString:
Style/GuardClause:
Enabled: false

Style/IndentArray:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Expand All @@ -63,6 +66,9 @@ Style/IfUnlessModifier:
Style/Lambda:
Enabled: false

Style/MultilineMethodCallIndentation:
Enabled: false

Style/MultilineOperationIndentation:
Enabled: false

Expand Down Expand Up @@ -98,12 +104,15 @@ Style/SignalException:
Style/SingleLineBlockParams:
Enabled: false

Style/SingleSpaceBeforeFirstArg:
Style/SpaceBeforeFirstArg:
Exclude:
- '*.gemspec'

Style/SpecialGlobalVars:
Enabled: false

Style/TrailingComma:
Style/TrailingCommaInArguments:
Enabled: false

Style/TrailingCommaInLiteral:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ source 'https://rubygems.org'
gem 'coveralls'

# Pin RuboCop for Travis builds.
gem 'rubocop', '0.35.1'
gem 'rubocop', '0.36.0'

gemspec
1 change: 0 additions & 1 deletion lib/overcommit/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def initialize(hash, options = {})
def ==(other)
super || @hash == other.hash
end
alias_method :eql?, :==

# Access the configuration as if it were a hash.
#
Expand Down
10 changes: 5 additions & 5 deletions lib/overcommit/constants.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Global application constants.
module Overcommit
HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
CONFIG_FILE_NAME = '.overcommit.yml'
HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
CONFIG_FILE_NAME = '.overcommit.yml'.freeze

HOOK_DIRECTORY = File.join(HOME, 'lib', 'overcommit', 'hook')
HOOK_DIRECTORY = File.join(HOME, 'lib', 'overcommit', 'hook').freeze

REPO_URL = 'https://github.com/brigade/overcommit'
BUG_REPORT_URL = "#{REPO_URL}/issues"
REPO_URL = 'https://github.com/brigade/overcommit'.freeze
BUG_REPORT_URL = "#{REPO_URL}/issues".freeze
end
2 changes: 1 addition & 1 deletion lib/overcommit/hook/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_s
end

# Possible types of messages.
MESSAGE_TYPES = [:error, :warning]
MESSAGE_TYPES = [:error, :warning].freeze

# Functionality common to all hooks.
class Base # rubocop:disable Metrics/ClassLength
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/commit_msg/capitalized_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def run
return :pass if empty_message?

first_letter = commit_message_lines[0].to_s.match(/^[[:punct:]]*(.)/)[1]
unless first_letter.match(/[[:upper:]]/)
unless first_letter =~ /[[:upper:]]/
return :warn, 'Subject should start with a capital letter'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/berksfile_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
#
# @see http://berkshelf.com/
class BerksfileCheck < Base
LOCK_FILE = 'Berksfile.lock'
LOCK_FILE = 'Berksfile.lock'.freeze

def run
# Ignore if Berksfile.lock is not tracked by git
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/bundle_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
#
# @see http://bundler.io/
class BundleCheck < Base
LOCK_FILE = 'Gemfile.lock'
LOCK_FILE = 'Gemfile.lock'.freeze

def run
# Ignore if Gemfile.lock is not tracked by git
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook_signer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class HookSigner

# We don't want to include the skip setting as it is set by Overcommit
# itself
IGNORED_CONFIG_KEYS = %w[skip]
IGNORED_CONFIG_KEYS = %w[skip].freeze

# @param hook_name [String] name of the hook
# @param config [Overcommit::Configuration]
Expand Down
8 changes: 4 additions & 4 deletions lib/overcommit/message_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module Overcommit
# output tuple from an array of {Overcommit::Hook::Message}s, respecting the
# configuration settings for the given hook.
class MessageProcessor
ERRORS_MODIFIED_HEADER = 'Errors on modified lines:'
WARNINGS_MODIFIED_HEADER = 'Warnings on modified lines:'
ERRORS_UNMODIFIED_HEADER = "Errors on lines you didn't modify:"
WARNINGS_UNMODIFIED_HEADER = "Warnings on lines you didn't modify:"
ERRORS_MODIFIED_HEADER = 'Errors on modified lines:'.freeze
WARNINGS_MODIFIED_HEADER = 'Warnings on modified lines:'.freeze
ERRORS_UNMODIFIED_HEADER = "Errors on lines you didn't modify:".freeze
WARNINGS_UNMODIFIED_HEADER = "Warnings on lines you didn't modify:".freeze

# @param hook [Overcommit::Hook::Base]
# @param unmodified_lines_setting [String] how to treat messages on
Expand Down
4 changes: 2 additions & 2 deletions lib/overcommit/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def linux?
private

def host_os
@os ||= ::RbConfig::CONFIG['host_os']
@os ||= ::RbConfig::CONFIG['host_os'].freeze
end
end

SEPARATOR = self.windows? ? '\\' : File::SEPARATOR
SEPARATOR = (windows? ? '\\' : File::SEPARATOR).freeze
end
end
2 changes: 1 addition & 1 deletion lib/overcommit/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Defines the gem version.
module Overcommit
VERSION = '0.30.0'
VERSION = '0.30.0'.freeze
end
2 changes: 1 addition & 1 deletion spec/overcommit/command_splitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
end

context 'with splittable arguments well over the limit' do
let(:splittable_args) { 15.times.map { |i| (i + 1).to_s } }
let(:splittable_args) { Array.new(15) { |i| (i + 1).to_s } }

it 'executes multiple commands with the appropriately split arguments' do
Overcommit::Subprocess.should_receive(:spawn).with(%w[cmd 1 2 3 4 5 6 7],
Expand Down
2 changes: 0 additions & 2 deletions spec/overcommit/hook/pre_commit/scalastyle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@

context 'with a runtime error' do
before do
# rubocop:disable Metrics/LineLength
result.stub(stdout: '', stderr: normalize_indent(<<-ERR))
Exception in thread "main" java.io.FileNotFoundException: scalastyle-config.xml (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
Expand All @@ -103,7 +102,6 @@
at org.scalastyle.Main$.main(Main.scala:95)
at org.scalastyle.Main.main(Main.scala)
ERR
# rubocop:enable Metrics/LineLength
end

it { should fail_hook }
Expand Down
4 changes: 0 additions & 4 deletions spec/overcommit/hook/pre_push/r_spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

context 'with a runtime error' do
before do
# rubocop:disable Metrics/LineLength
result.stub(stdout: '', stderr: <<-EOS)
/home/user/.rbenv/gems/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1226:in `load': /home/user/dev/github/overcommit/spec/overcommit/hook/pre_push/rspec_spec.rb:49: can't find string "EOS" anywhere before EOF (SyntaxError)
/home/user/dev/overcommit/spec/overcommit/hook/pre_push/rspec_spec.rb:29: syntax error, unexpected end-of-input
Expand All @@ -41,15 +40,13 @@
from /home/user/.rbenv/versions/2.2.1/bin/rspec:23:in `load'
from /home/user/.rbenv/versions/2.2.1/bin/rspec:23:in `<main>'
EOS
# rubocop:enable Metrics/LineLength
end

it { should fail_hook }
end

context 'with a test failure' do
before do
# rubocop:disable Metrics/LineLength
result.stub(stderr: '', stdout: <<-EOS)
.FF
Expand All @@ -73,7 +70,6 @@
rspec ./spec/overcommit/hook/pre_push/rspec_spec.rb:45 # Overcommit::Hook::PrePush::RSpec when rspec exits unsuccessfully with a runtime error should fail
rspec ./spec/overcommit/hook/pre_push/rspec_spec.rb:57 # Overcommit::Hook::PrePush::RSpec when rspec exits unsuccessfully with a test failure should fail
EOS
# rubocop:enable Metrics/LineLength
end

it { should fail_hook }
Expand Down
7 changes: 4 additions & 3 deletions spec/overcommit/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@
subject { described_class.execute(arguments, args: splittable_args) }

it 'invokes CommandSplitter.execute' do
Overcommit::CommandSplitter.should_receive(:execute).
with(arguments, args: splittable_args).
and_return(double(status: 0, stdout: '', stderr: ''))
Overcommit::CommandSplitter.
should_receive(:execute).
with(arguments, args: splittable_args).
and_return(double(status: 0, stdout: '', stderr: ''))
subject
end

Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
require 'overcommit'
require 'tempfile'

hook_types = Dir[File.join(Overcommit::HOOK_DIRECTORY, '*')].
hook_types =
Dir[File.join(Overcommit::HOOK_DIRECTORY, '*')].
select { |f| File.directory?(f) }.
reject { |f| File.basename(f) == 'shared' }.
sort
Expand Down
21 changes: 15 additions & 6 deletions spec/support/git_spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
module GitSpecHelpers
module_function

def repo(options = {}, &block)
# Creates an empty git repository, allowing you to execute a block where
# the current working directory is set to that repository's root directory.
#
# @param options [Hash]
# @return [String] path of the repository
def repo(options = {})
directory('some-repo') do
`git init --template="#{options[:template_dir]}"`

Expand All @@ -13,26 +18,30 @@ def repo(options = {}, &block)
`git config --local user.email "[email protected]"`
`git config --local rerere.enabled 0` # Don't record resolutions in tests

block.call if block_given?
yield if block_given?
end
end

# Creates a directory (with an optional specific name) in a temporary
# directory which will automatically be destroyed.
#
# @param name [String] base name of the directory
# @return [String] path of the directory that was created
def directory(name = 'some-dir', &block)
tmpdir = Dir.mktmpdir.tap do |path|
Dir.chdir(path) do
Dir.mkdir(name)
Dir.chdir(name) do
block.call if block_given?
end
Dir.chdir(name, &block) if block_given?
end
end

File.join(tmpdir, name)
end

# Returns a random git object hash.
#
# @return [String]
def random_hash
40.times.map { (65 + rand(26)).chr }.join
Array.new(40) { (65 + rand(26)).chr }.join
end
end
4 changes: 2 additions & 2 deletions spec/support/shell_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def touch(file)
#
# @param options [Hash]
# @raise [Timeout::TimeoutError] timeout has elapsed before condition holds
def wait_until(options = {}, &block)
def wait_until(options = {})
Timeout.timeout(options.fetch(:timeout, 1)) do
loop do
return if block.call
return if yield
sleep options.fetch(:check_interval, 0.1)
end
end
Expand Down

0 comments on commit 9893350

Please sign in to comment.