Skip to content

Commit

Permalink
Update RuboCop used in CI from 0.54.0 to 0.82.0
Browse files Browse the repository at this point in the history
While here, run an auto-correct. Note: RuboCop 1.0 has been released,
but as we haven't seen any fundamental bug reports yet, it seems safe to
only upgrade to 0.82.0 at this time, largely due to the new
`--disable-pending-cops` flag introduced in this version.
  • Loading branch information
sds committed May 31, 2021
1 parent 919350b commit 942969a
Show file tree
Hide file tree
Showing 105 changed files with 382 additions and 352 deletions.
10 changes: 5 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ Layout/EndOfLine:
Layout/FirstParameterIndentation:
Enabled: false

Layout/IndentArray:
Layout/FirstArrayElementIndentation:
Enabled: false

Layout/IndentHeredoc:
Layout/HeredocIndentation:
Enabled: false

Layout/LineLength:
Max: 100

Layout/MultilineMethodCallIndentation:
Enabled: false

Expand Down Expand Up @@ -48,9 +51,6 @@ Metrics/AbcSize:
Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Max: 100

Metrics/MethodLength:
Max: 20

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## master (unreleased)

* Add `--disable-pending-cops` as default flag to `RuboCop` pre-commit hook to ignore non-existent cops.
* Add `--disable-pending-cops` as default flag to `RuboCop` pre-commit hook to ignore non-existent cops. Requires RuboCop `0.82.0` or newer.

## 0.58.0

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ gem 'rspec', '~> 3.0'
gem 'coveralls', '~> 0.8'

# Pin RuboCop for Travis builds.
gem 'rubocop', '0.54.0'
gem 'rubocop', '0.82.0'

gem 'ffi' if Gem.win_platform?
11 changes: 6 additions & 5 deletions bin/overcommit
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
ensure
$stderr = old_stderr
end
rescue Bundler::BundlerError => ex
puts "Problem loading '#{gemfile}': #{ex.message}"
puts "Try running:\nbundle install --gemfile=#{gemfile}" if ex.is_a?(Bundler::GemNotFound)
rescue Bundler::BundlerError => e
puts "Problem loading '#{gemfile}': #{e.message}"
puts "Try running:\nbundle install --gemfile=#{gemfile}" if e.is_a?(Bundler::GemNotFound)
exit 78 # EX_CONFIG
rescue Gem::LoadError => ex
rescue Gem::LoadError => e
# Handle case where user is executing overcommit without `bundle exec` and
# whose local Gemfile has a gem requirement that does not match a gem
# requirement of the installed version of Overcommit.
raise unless ex.message =~ /already activated/i
raise unless e.message =~ /already activated/i

exec('bundle', 'exec', $0, *ARGV)
end
end
Expand Down
22 changes: 11 additions & 11 deletions lib/overcommit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Overcommit
# Responsible for parsing command-line options and executing appropriate
# application logic based on those options.
class CLI # rubocop:disable ClassLength
class CLI # rubocop:disable Metrics/ClassLength
def initialize(arguments, input, logger)
@arguments = arguments
@input = input
Expand All @@ -29,11 +29,11 @@ def run
when :run_all
run_all
end
rescue Overcommit::Exceptions::ConfigurationSignatureChanged => ex
puts ex
rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e
puts e
exit 78 # EX_CONFIG
rescue Overcommit::Exceptions::HookContextLoadError => ex
puts ex
rescue Overcommit::Exceptions::HookContextLoadError => e
puts e
exit 64 # EX_USAGE
end

Expand All @@ -52,8 +52,8 @@ def parse_arguments

# Unconsumed arguments are our targets
@options[:targets] = @arguments
rescue OptionParser::InvalidOption => ex
print_help @parser.help, ex
rescue OptionParser::InvalidOption => e
print_help @parser.help, e
end
end

Expand Down Expand Up @@ -125,11 +125,11 @@ def install_or_uninstall
@options[:targets].each do |target|
begin
Installer.new(log).run(target, @options)
rescue Overcommit::Exceptions::InvalidGitRepo => error
log.warning "Invalid repo #{target}: #{error}"
rescue Overcommit::Exceptions::InvalidGitRepo => e
log.warning "Invalid repo #{target}: #{e}"
halt 69 # EX_UNAVAILABLE
rescue Overcommit::Exceptions::PreExistingHooks => error
log.warning "Unable to install into #{target}: #{error}"
rescue Overcommit::Exceptions::PreExistingHooks => e
log.warning "Unable to install into #{target}: #{e}"
halt 73 # EX_CANTCREAT
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/overcommit/command_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def arguments_under_limit(splittable_args, start_index, byte_limit)

loop do
break if index > splittable_args.length - 1

total_bytes += splittable_args[index].bytesize
break if total_bytes > byte_limit # Not enough room

index += 1
end

Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module Overcommit
# Stores configuration for Overcommit and the hooks it runs.
class Configuration # rubocop:disable ClassLength
class Configuration # rubocop:disable Metrics/ClassLength
# Creates a configuration from the given hash.
#
# @param hash [Hash] loaded YAML config file as a hash
Expand Down
6 changes: 3 additions & 3 deletions lib/overcommit/configuration_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def load_file(file)
config
rescue Overcommit::Exceptions::ConfigurationSignatureChanged
raise
rescue StandardError => error
rescue StandardError => e
raise Overcommit::Exceptions::ConfigurationError,
"Unable to load configuration from '#{file}': #{error}",
error.backtrace
"Unable to load configuration from '#{file}': #{e}",
e.backtrace
end

private
Expand Down
1 change: 1 addition & 0 deletions lib/overcommit/git_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def comment_character
def hooks_path
path = `git config --get core.hooksPath`.chomp
return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?

File.absolute_path(path, Dir.pwd)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/overcommit/git_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module GitRepo
[^\s]+\s # Ignore old file range
\+(\d+)(?:,(\d+))? # Extract range of hunk containing start line and number of lines
\s@@.*$
/x
/x.freeze

# Regular expression used to extract information from lines of
# `git submodule status` output
SUBMODULE_STATUS_REGEX = /
^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
\s(?<path>[^\s]+?)
(?:\s\((?<describe>.+)\))?$
/x
/x.freeze

# Struct encapsulating submodule information extracted from the
# output of `git submodule status`
Expand Down Expand Up @@ -262,9 +262,9 @@ def submodules(options = {})
end

modules
rescue IniParse::IniParseError => ex
rescue IniParse::IniParseError => e
raise Overcommit::Exceptions::GitSubmoduleError,
"Unable to read submodule information from #{ref}:.gitmodules file: #{ex.message}"
"Unable to read submodule information from #{ref}:.gitmodules file: #{e.message}"
end

# Returns the names of all branches containing the given commit.
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/commit_msg/spell_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Overcommit::Hook::CommitMsg
class SpellCheck < Base
Misspelling = Struct.new(:word, :suggestions)

MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/
MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/.freeze

def run
result = execute(command + [uncommented_commit_msg_file])
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/commit_msg/text_width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def find_errors_in_subject(subject)
min_subject_width = config['min_subject_width']
if subject.length < min_subject_width
@errors << "Commit message subject must be >= #{min_subject_width} characters"
return
nil
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/overcommit/hook/post_checkout/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def skip_file_checkout?

def enabled?
return false if file_checkout? && skip_file_checkout?

super
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/overcommit/hook/post_commit/git_guilt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ module Overcommit::Hook::PostCommit
#
# @see https://www.npmjs.com/package/git-guilt
class GitGuilt < Base
PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))$/
PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))$/.freeze
GREEN = 32
RED = 31

def run
return :pass if initial_commit?

result = execute(command)
return :fail, result.stderr unless result.success?

Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/bundle_audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run
if result.success?
:pass
else
return [:warn, result.stdout]
[:warn, result.stdout]
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/overcommit/hook/pre_commit/chamber_compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def run
next unless second

result = execute(
command,
args: [
"--first=#{first.join(' ')}",
"--second=#{second.join(' ')}",
],
command,
args: [
"--first=#{first.join(' ')}",
"--second=#{second.join(' ')}",
],
)

unless result.stdout.empty?
Expand Down
1 change: 1 addition & 0 deletions lib/overcommit/hook/pre_commit/chamber_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def run
result = execute(command, args: applicable_files)

return :pass if result.stdout.empty?

[:fail, "These settings appear to need to be secured but were not: #{result.stdout}"]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/coffee_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CoffeeLint < Base
,(?<line>\d*),\d*
,(?<type>\w+)
,(?<msg>.+)$
/x
/x.freeze

MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.include?('w') ? :warning : :error
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/css_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CssLint < Base
^(?<file>(?:\w:)?[^:]+):\s
(?:line\s(?<line>\d+)[^EW]+)?
(?<type>Error|Warning)
/x
/x.freeze

def run
result = execute(command, args: applicable_files)
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/dart_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
# Runs `dartanalyzer` against modified Dart files.
# @see https://dart.dev/tools/dartanalyzer
class DartAnalyzer < Base
MESSAGE_REGEX = /(?<type>.*)•\ (?<message>[^•]+)•\ (?<file>[^:]+):(?<line>\d+):(\d+)\.*/
MESSAGE_REGEX = /(?<type>.*)•\ (?<message>[^•]+)•\ (?<file>[^:]+):(?<line>\d+):(\d+)\.*/.freeze

def run
result = execute(command, args: applicable_files)
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/erb_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
#
# @see https://github.com/Shopify/erb-lint
class ErbLint < Base
MESSAGE_REGEX = /(?<message>.+)\nIn file: (?<file>.+):(?<line>\d+)/
MESSAGE_REGEX = /(?<message>.+)\nIn file: (?<file>.+):(?<line>\d+)/.freeze

def run
result = execute(command, args: applicable_files)
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/fasterer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def run
if extract_offense_num(output) == 0
:pass
else
return [:warn, output]
[:warn, output]
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/overcommit/hook/pre_commit/foodcritic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run
if result.success?
:pass
else
return [:warn, result.stderr + result.stdout]
[:warn, result.stderr + result.stdout]
end
end

Expand Down Expand Up @@ -137,12 +137,14 @@ def modified_cookbooks_args

def modified(type)
return [] if !config["#{type}_directory"] || config["#{type}_directory"].empty?

@modified ||= {}
@modified[type] ||= directories_changed(full_directory_path("#{type}_directory"))
end

def full_directory_path(config_option)
return config[config_option] if config[config_option].start_with?(File::SEPARATOR)

File.absolute_path(File.join(Overcommit::Utils.repo_root, config[config_option]))
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/hlint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Hlint < Base
:(?<line>\d+)
:\d+
:\s*(?<type>\w+)
/x
/x.freeze

MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.include?('W') ? :warning : :error
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/html_tidy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class HtmlTidy < Base
line\s(?<line>\d+)\s
column\s(?<col>\d+)\s-\s
(?<type>Error|Warning):\s(?<message>.+)$
/x
/x.freeze

def run
# example message:
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/java_checkstyle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
#
# @see http://checkstyle.sourceforge.net/
class JavaCheckstyle < Base
MESSAGE_REGEX = /^(\[(?<type>[^\]]+)\]\s+)?(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
MESSAGE_REGEX = /^(\[(?<type>[^\]]+)\]\s+)?(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze

MESSAGE_TYPE_CATEGORIZER = lambda do |type|
%w[WARN INFO].include?(type.to_s) ? :warning : :error
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/js_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
#
# @see http://www.jslint.com/
class JsLint < Base
MESSAGE_REGEX = /(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
MESSAGE_REGEX = /(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze

def run
result = execute(command, args: applicable_files)
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/jsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
#
# @see http://www.javascriptlint.com/
class Jsl < Base
MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)/
MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)/.freeze

MESSAGE_TYPE_CATEGORIZER = lambda do |type|
type.match?(/warning/) ? :warning : :error
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/kt_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
# Runs `ktlint` against modified Kotlin files.
# @see https://github.com/shyiko/ktlint
class KtLint < Base
MESSAGE_REGEX = /((?<file>[^:]+):(?<line>\d+):(\d+):(?<message>.+))/
MESSAGE_REGEX = /((?<file>[^:]+):(?<line>\d+):(\d+):(?<message>.+))/.freeze

def run
result = execute(command, args: applicable_files)
Expand Down
1 change: 1 addition & 0 deletions lib/overcommit/hook/pre_commit/license_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class LicenseFinder < Base
def run
result = execute(command)
return :pass if result.success?

output = result.stdout + result.stderr
[:fail, output]
end
Expand Down
Loading

0 comments on commit 942969a

Please sign in to comment.