diff --git a/.rubocop.yml b/.rubocop.yml index 56197f7d..35002594 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 @@ -48,9 +51,6 @@ Metrics/AbcSize: Metrics/BlockLength: Enabled: false -Metrics/LineLength: - Max: 100 - Metrics/MethodLength: Max: 20 diff --git a/CHANGELOG.md b/CHANGELOG.md index b81a9bf3..f27e6208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Gemfile b/Gemfile index 961e5d5a..d1cd3c37 100644 --- a/Gemfile +++ b/Gemfile @@ -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? diff --git a/bin/overcommit b/bin/overcommit index ebcf56a4..d54d179f 100755 --- a/bin/overcommit +++ b/bin/overcommit @@ -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 diff --git a/lib/overcommit/cli.rb b/lib/overcommit/cli.rb index 54a3f9b7..9848c646 100644 --- a/lib/overcommit/cli.rb +++ b/lib/overcommit/cli.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/overcommit/command_splitter.rb b/lib/overcommit/command_splitter.rb index 32c5299c..c334b6f9 100644 --- a/lib/overcommit/command_splitter.rb +++ b/lib/overcommit/command_splitter.rb @@ -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 diff --git a/lib/overcommit/configuration.rb b/lib/overcommit/configuration.rb index ae3efa50..72086457 100644 --- a/lib/overcommit/configuration.rb +++ b/lib/overcommit/configuration.rb @@ -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 diff --git a/lib/overcommit/configuration_loader.rb b/lib/overcommit/configuration_loader.rb index 9ba96fb5..77a08549 100644 --- a/lib/overcommit/configuration_loader.rb +++ b/lib/overcommit/configuration_loader.rb @@ -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 diff --git a/lib/overcommit/git_config.rb b/lib/overcommit/git_config.rb index d2ad2ad6..392dd9da 100644 --- a/lib/overcommit/git_config.rb +++ b/lib/overcommit/git_config.rb @@ -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 diff --git a/lib/overcommit/git_repo.rb b/lib/overcommit/git_repo.rb index 179aebaa..1af73e81 100644 --- a/lib/overcommit/git_repo.rb +++ b/lib/overcommit/git_repo.rb @@ -14,7 +14,7 @@ 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 @@ -22,7 +22,7 @@ module GitRepo ^\s*(?[-+U]?)(?\w+) \s(?[^\s]+?) (?:\s\((?.+)\))?$ - /x + /x.freeze # Struct encapsulating submodule information extracted from the # output of `git submodule status` @@ -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. diff --git a/lib/overcommit/hook/commit_msg/spell_check.rb b/lib/overcommit/hook/commit_msg/spell_check.rb index 241df378..ec6c4d4a 100644 --- a/lib/overcommit/hook/commit_msg/spell_check.rb +++ b/lib/overcommit/hook/commit_msg/spell_check.rb @@ -9,7 +9,7 @@ module Overcommit::Hook::CommitMsg class SpellCheck < Base Misspelling = Struct.new(:word, :suggestions) - MISSPELLING_REGEX = /^[&#]\s(?\w+)(?:.+?:\s(?.*))?/ + MISSPELLING_REGEX = /^[&#]\s(?\w+)(?:.+?:\s(?.*))?/.freeze def run result = execute(command + [uncommented_commit_msg_file]) diff --git a/lib/overcommit/hook/commit_msg/text_width.rb b/lib/overcommit/hook/commit_msg/text_width.rb index 011e7e2a..63addbcf 100644 --- a/lib/overcommit/hook/commit_msg/text_width.rb +++ b/lib/overcommit/hook/commit_msg/text_width.rb @@ -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 diff --git a/lib/overcommit/hook/post_checkout/base.rb b/lib/overcommit/hook/post_checkout/base.rb index 842e3154..78798b9e 100644 --- a/lib/overcommit/hook/post_checkout/base.rb +++ b/lib/overcommit/hook/post_checkout/base.rb @@ -16,6 +16,7 @@ def skip_file_checkout? def enabled? return false if file_checkout? && skip_file_checkout? + super end end diff --git a/lib/overcommit/hook/post_commit/git_guilt.rb b/lib/overcommit/hook/post_commit/git_guilt.rb index 41980425..b4f1ead8 100644 --- a/lib/overcommit/hook/post_commit/git_guilt.rb +++ b/lib/overcommit/hook/post_commit/git_guilt.rb @@ -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? diff --git a/lib/overcommit/hook/pre_commit/bundle_audit.rb b/lib/overcommit/hook/pre_commit/bundle_audit.rb index 465cc3c8..1f9f24c7 100644 --- a/lib/overcommit/hook/pre_commit/bundle_audit.rb +++ b/lib/overcommit/hook/pre_commit/bundle_audit.rb @@ -17,7 +17,7 @@ def run if result.success? :pass else - return [:warn, result.stdout] + [:warn, result.stdout] end end end diff --git a/lib/overcommit/hook/pre_commit/chamber_compare.rb b/lib/overcommit/hook/pre_commit/chamber_compare.rb index f0c4f146..b3e0366c 100644 --- a/lib/overcommit/hook/pre_commit/chamber_compare.rb +++ b/lib/overcommit/hook/pre_commit/chamber_compare.rb @@ -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? diff --git a/lib/overcommit/hook/pre_commit/chamber_security.rb b/lib/overcommit/hook/pre_commit/chamber_security.rb index b47672df..c639fbf8 100644 --- a/lib/overcommit/hook/pre_commit/chamber_security.rb +++ b/lib/overcommit/hook/pre_commit/chamber_security.rb @@ -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 diff --git a/lib/overcommit/hook/pre_commit/coffee_lint.rb b/lib/overcommit/hook/pre_commit/coffee_lint.rb index 7e68b40d..57c80a58 100644 --- a/lib/overcommit/hook/pre_commit/coffee_lint.rb +++ b/lib/overcommit/hook/pre_commit/coffee_lint.rb @@ -10,7 +10,7 @@ class CoffeeLint < Base ,(?\d*),\d* ,(?\w+) ,(?.+)$ - /x + /x.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| type.include?('w') ? :warning : :error diff --git a/lib/overcommit/hook/pre_commit/css_lint.rb b/lib/overcommit/hook/pre_commit/css_lint.rb index 7ca82283..b110d074 100644 --- a/lib/overcommit/hook/pre_commit/css_lint.rb +++ b/lib/overcommit/hook/pre_commit/css_lint.rb @@ -9,7 +9,7 @@ class CssLint < Base ^(?(?:\w:)?[^:]+):\s (?:line\s(?\d+)[^EW]+)? (?Error|Warning) - /x + /x.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/dart_analyzer.rb b/lib/overcommit/hook/pre_commit/dart_analyzer.rb index a1c99448..38002f22 100644 --- a/lib/overcommit/hook/pre_commit/dart_analyzer.rb +++ b/lib/overcommit/hook/pre_commit/dart_analyzer.rb @@ -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 = /(?.*)•\ (?[^•]+)•\ (?[^:]+):(?\d+):(\d+)\.*/ + MESSAGE_REGEX = /(?.*)•\ (?[^•]+)•\ (?[^:]+):(?\d+):(\d+)\.*/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/erb_lint.rb b/lib/overcommit/hook/pre_commit/erb_lint.rb index 2073538c..a903b10b 100644 --- a/lib/overcommit/hook/pre_commit/erb_lint.rb +++ b/lib/overcommit/hook/pre_commit/erb_lint.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://github.com/Shopify/erb-lint class ErbLint < Base - MESSAGE_REGEX = /(?.+)\nIn file: (?.+):(?\d+)/ + MESSAGE_REGEX = /(?.+)\nIn file: (?.+):(?\d+)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/fasterer.rb b/lib/overcommit/hook/pre_commit/fasterer.rb index dc584368..871be80f 100644 --- a/lib/overcommit/hook/pre_commit/fasterer.rb +++ b/lib/overcommit/hook/pre_commit/fasterer.rb @@ -12,7 +12,7 @@ def run if extract_offense_num(output) == 0 :pass else - return [:warn, output] + [:warn, output] end end diff --git a/lib/overcommit/hook/pre_commit/foodcritic.rb b/lib/overcommit/hook/pre_commit/foodcritic.rb index 98ac9873..b40adfbe 100644 --- a/lib/overcommit/hook/pre_commit/foodcritic.rb +++ b/lib/overcommit/hook/pre_commit/foodcritic.rb @@ -102,7 +102,7 @@ def run if result.success? :pass else - return [:warn, result.stderr + result.stdout] + [:warn, result.stderr + result.stdout] end end @@ -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 diff --git a/lib/overcommit/hook/pre_commit/hlint.rb b/lib/overcommit/hook/pre_commit/hlint.rb index 1ac2775c..a52d1b62 100644 --- a/lib/overcommit/hook/pre_commit/hlint.rb +++ b/lib/overcommit/hook/pre_commit/hlint.rb @@ -10,7 +10,7 @@ class Hlint < Base :(?\d+) :\d+ :\s*(?\w+) - /x + /x.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| type.include?('W') ? :warning : :error diff --git a/lib/overcommit/hook/pre_commit/html_tidy.rb b/lib/overcommit/hook/pre_commit/html_tidy.rb index b4a2d89d..2667e2c1 100644 --- a/lib/overcommit/hook/pre_commit/html_tidy.rb +++ b/lib/overcommit/hook/pre_commit/html_tidy.rb @@ -10,7 +10,7 @@ class HtmlTidy < Base line\s(?\d+)\s column\s(?\d+)\s-\s (?Error|Warning):\s(?.+)$ - /x + /x.freeze def run # example message: diff --git a/lib/overcommit/hook/pre_commit/java_checkstyle.rb b/lib/overcommit/hook/pre_commit/java_checkstyle.rb index 4961eb12..5d627a64 100644 --- a/lib/overcommit/hook/pre_commit/java_checkstyle.rb +++ b/lib/overcommit/hook/pre_commit/java_checkstyle.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see http://checkstyle.sourceforge.net/ class JavaCheckstyle < Base - MESSAGE_REGEX = /^(\[(?[^\]]+)\]\s+)?(?(?:\w:)?[^:]+):(?\d+)/ + MESSAGE_REGEX = /^(\[(?[^\]]+)\]\s+)?(?(?:\w:)?[^:]+):(?\d+)/.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| %w[WARN INFO].include?(type.to_s) ? :warning : :error diff --git a/lib/overcommit/hook/pre_commit/js_lint.rb b/lib/overcommit/hook/pre_commit/js_lint.rb index 3b6b8b87..956dfd2c 100644 --- a/lib/overcommit/hook/pre_commit/js_lint.rb +++ b/lib/overcommit/hook/pre_commit/js_lint.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see http://www.jslint.com/ class JsLint < Base - MESSAGE_REGEX = /(?(?:\w:)?[^:]+):(?\d+)/ + MESSAGE_REGEX = /(?(?:\w:)?[^:]+):(?\d+)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/jsl.rb b/lib/overcommit/hook/pre_commit/jsl.rb index 38f8a0cf..98eb7175 100644 --- a/lib/overcommit/hook/pre_commit/jsl.rb +++ b/lib/overcommit/hook/pre_commit/jsl.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see http://www.javascriptlint.com/ class Jsl < Base - MESSAGE_REGEX = /(?(?:\w:)?.+)\((?\d+)\):(?[^:]+)/ + MESSAGE_REGEX = /(?(?:\w:)?.+)\((?\d+)\):(?[^:]+)/.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| type.match?(/warning/) ? :warning : :error diff --git a/lib/overcommit/hook/pre_commit/kt_lint.rb b/lib/overcommit/hook/pre_commit/kt_lint.rb index 8e80a581..4b81ed21 100644 --- a/lib/overcommit/hook/pre_commit/kt_lint.rb +++ b/lib/overcommit/hook/pre_commit/kt_lint.rb @@ -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 = /((?[^:]+):(?\d+):(\d+):(?.+))/ + MESSAGE_REGEX = /((?[^:]+):(?\d+):(\d+):(?.+))/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/license_finder.rb b/lib/overcommit/hook/pre_commit/license_finder.rb index fc3739fe..e2b8611b 100644 --- a/lib/overcommit/hook/pre_commit/license_finder.rb +++ b/lib/overcommit/hook/pre_commit/license_finder.rb @@ -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 diff --git a/lib/overcommit/hook/pre_commit/line_endings.rb b/lib/overcommit/hook/pre_commit/line_endings.rb index 8f8eb9c7..ab66001b 100644 --- a/lib/overcommit/hook/pre_commit/line_endings.rb +++ b/lib/overcommit/hook/pre_commit/line_endings.rb @@ -12,14 +12,14 @@ def run file = File.open(file_name) begin messages += check_file(file, file_name) - rescue ArgumentError => ex + rescue ArgumentError => e # File is likely a binary file which this check should ignore, but # print a warning just in case messages << Overcommit::Hook::Message.new( :warning, file_name, file.lineno, - "#{file_name}:#{file.lineno}:#{ex.message}" + "#{file_name}:#{file.lineno}:#{e.message}" ) end end @@ -59,6 +59,7 @@ def offending_files i = info.split.first next if i == 'l/-text' # ignore binary files next if i == "l/#{eol}" + path end.compact end diff --git a/lib/overcommit/hook/pre_commit/nginx_test.rb b/lib/overcommit/hook/pre_commit/nginx_test.rb index cff43bbe..b681ded0 100644 --- a/lib/overcommit/hook/pre_commit/nginx_test.rb +++ b/lib/overcommit/hook/pre_commit/nginx_test.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/ class NginxTest < Base - MESSAGE_REGEX = /^nginx: .+ in (?.+):(?\d+)$/ + MESSAGE_REGEX = /^nginx: .+ in (?.+):(?\d+)$/.freeze def run messages = [] diff --git a/lib/overcommit/hook/pre_commit/php_cs.rb b/lib/overcommit/hook/pre_commit/php_cs.rb index 8e837406..41d2f2b4 100644 --- a/lib/overcommit/hook/pre_commit/php_cs.rb +++ b/lib/overcommit/hook/pre_commit/php_cs.rb @@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit # Runs `phpcs` against any modified PHP files. class PhpCs < Base # Parse `phpcs` csv mode output - MESSAGE_REGEX = /^\"(?.+)\",(?\d+),\d+,(?.+),\"(?.+)\"/ + MESSAGE_REGEX = /^\"(?.+)\",(?\d+),\d+,(?.+),\"(?.+)\"/.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| 'error'.include?(type) ? :error : :warning end diff --git a/lib/overcommit/hook/pre_commit/php_cs_fixer.rb b/lib/overcommit/hook/pre_commit/php_cs_fixer.rb index 02f8932e..87e63744 100644 --- a/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +++ b/lib/overcommit/hook/pre_commit/php_cs_fixer.rb @@ -3,7 +3,7 @@ module Overcommit::Hook::PreCommit # Runs `php-cs-fixer` against any modified PHP files. class PhpCsFixer < Base - MESSAGE_REGEX = /\s+\d+\)\s+(?.*\.php)(?\s+\(\w+(?:,\s+)?\))?/ + MESSAGE_REGEX = /\s+\d+\)\s+(?.*\.php)(?\s+\(\w+(?:,\s+)?\))?/.freeze def run messages = [] diff --git a/lib/overcommit/hook/pre_commit/php_lint.rb b/lib/overcommit/hook/pre_commit/php_lint.rb index 98582c3c..3f70bfb2 100644 --- a/lib/overcommit/hook/pre_commit/php_lint.rb +++ b/lib/overcommit/hook/pre_commit/php_lint.rb @@ -7,7 +7,7 @@ class PhpLint < Base # rubocop:disable Metrics/LineLength # PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12 # rubocop:enable Metrics/LineLength - MESSAGE_REGEX = /^(?.+)\:\s+(?.+) in (?.+) on line (?\d+)/ + MESSAGE_REGEX = /^(?.+)\:\s+(?.+) in (?.+) on line (?\d+)/.freeze def run # A list of error messages diff --git a/lib/overcommit/hook/pre_commit/php_stan.rb b/lib/overcommit/hook/pre_commit/php_stan.rb index d9971ff0..9b8550f7 100644 --- a/lib/overcommit/hook/pre_commit/php_stan.rb +++ b/lib/overcommit/hook/pre_commit/php_stan.rb @@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit # https://github.com/phpstan/phpstan/issues/239 # https://gist.github.com/edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2 class PhpStan < Base - MESSAGE_REGEX = /^(?.+)\:(?\d+)\:(?.+)/ + MESSAGE_REGEX = /^(?.+)\:(?\d+)\:(?.+)/.freeze def run messages = [] diff --git a/lib/overcommit/hook/pre_commit/puppet_lint.rb b/lib/overcommit/hook/pre_commit/puppet_lint.rb index c67c248a..2ddf3a10 100644 --- a/lib/overcommit/hook/pre_commit/puppet_lint.rb +++ b/lib/overcommit/hook/pre_commit/puppet_lint.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see http://puppet-lint.com/ class PuppetLint < Base - MESSAGE_REGEX = /(?(?:\w:)?.+):(?\d+):\d+:(?\w+)/ + MESSAGE_REGEX = /(?(?:\w:)?.+):(?\d+):\d+:(?\w+)/.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| type == 'ERROR' ? :error : :warning diff --git a/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb b/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb index b020b79c..311a09c3 100644 --- a/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +++ b/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb @@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit # @see https://voxpupuli.org/blog/2014/11/06/linting-metadata-json/ # class PuppetMetadataJsonLint < Base - MESSAGE_REGEX = /\((?.*)\).*/ + MESSAGE_REGEX = /\((?.*)\).*/.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| type == 'WARN' ? :warning : :error diff --git a/lib/overcommit/hook/pre_commit/pyflakes.rb b/lib/overcommit/hook/pre_commit/pyflakes.rb index 871f0594..ff7824c4 100644 --- a/lib/overcommit/hook/pre_commit/pyflakes.rb +++ b/lib/overcommit/hook/pre_commit/pyflakes.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://pypi.python.org/pypi/pyflakes class Pyflakes < Base - MESSAGE_REGEX = /^(?(?:\w:)?[^:]+):(?\d+):/ + MESSAGE_REGEX = /^(?(?:\w:)?[^:]+):(?\d+):/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/pylint.rb b/lib/overcommit/hook/pre_commit/pylint.rb index 1ee92c9a..526bee2d 100644 --- a/lib/overcommit/hook/pre_commit/pylint.rb +++ b/lib/overcommit/hook/pre_commit/pylint.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see http://www.pylint.org/ class Pylint < Base - MESSAGE_REGEX = /^(?(?:\w:)?.+):(?\d+):(?[CEFRW])/ + MESSAGE_REGEX = /^(?(?:\w:)?.+):(?\d+):(?[CEFRW])/.freeze # Classify 'E' and 'F' message codes as errors, # everything else as warnings. diff --git a/lib/overcommit/hook/pre_commit/python_flake8.rb b/lib/overcommit/hook/pre_commit/python_flake8.rb index 0e03bdf9..d506cf62 100644 --- a/lib/overcommit/hook/pre_commit/python_flake8.rb +++ b/lib/overcommit/hook/pre_commit/python_flake8.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://pypi.python.org/pypi/flake8 class PythonFlake8 < Base - MESSAGE_REGEX = /^(?(?:\w:)?.+):(?\d+):\d+:\s(?\w\d+)/ + MESSAGE_REGEX = /^(?(?:\w:)?.+):(?\d+):\d+:\s(?\w\d+)/.freeze # Classify 'Exxx' and 'Fxxx' message codes as errors, # everything else as warnings. diff --git a/lib/overcommit/hook/pre_commit/rails_best_practices.rb b/lib/overcommit/hook/pre_commit/rails_best_practices.rb index bda0101f..7c3ba79a 100644 --- a/lib/overcommit/hook/pre_commit/rails_best_practices.rb +++ b/lib/overcommit/hook/pre_commit/rails_best_practices.rb @@ -7,7 +7,7 @@ module PreCommit # # @see https://github.com/railsbp/rails_best_practices class RailsBestPractices < Base - ERROR_REGEXP = /^(?(?:\w:)?[^:]+):(?\d+)\s-\s(?.+)/ + ERROR_REGEXP = /^(?(?:\w:)?[^:]+):(?\d+)\s-\s(?.+)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb index da0951bf..13d7932f 100644 --- a/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +++ b/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb @@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit # failure. The exception is if the schema is at version 0 (i.e before any # migrations have been run). In this case it is OK if there are no migrations. class RailsSchemaUpToDate < Base - def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity + def run # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity if migration_files.any? && schema_files.none? return :fail, "It looks like you're adding a migration, but did not update the schema file" elsif migration_files.none? && schema_files.any? && non_zero_schema_version? @@ -18,7 +18,7 @@ def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity # their username. latest_version = migration_files.map do |file| File.basename(file)[/\d+/] - end.sort.last + end.max up_to_date = schema.include?(latest_version) diff --git a/lib/overcommit/hook/pre_commit/rst_lint.rb b/lib/overcommit/hook/pre_commit/rst_lint.rb index 15f93584..5647508d 100644 --- a/lib/overcommit/hook/pre_commit/rst_lint.rb +++ b/lib/overcommit/hook/pre_commit/rst_lint.rb @@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit class RstLint < Base MESSAGE_REGEX = / ^(?INFO|WARNING|ERROR|SEVERE)(?(?:\w:)?[^:]+):(?\d+)\s(?.+) - /x + /x.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/scalariform.rb b/lib/overcommit/hook/pre_commit/scalariform.rb index 6b766dd0..63bf5e6c 100644 --- a/lib/overcommit/hook/pre_commit/scalariform.rb +++ b/lib/overcommit/hook/pre_commit/scalariform.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://github.com/mdr/scalariform class Scalariform < Base - MESSAGE_REGEX = /^\[(?FAILED|ERROR)\]\s+(?(?:\w:)?.+)/ + MESSAGE_REGEX = /^\[(?FAILED|ERROR)\]\s+(?(?:\w:)?.+)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/scalastyle.rb b/lib/overcommit/hook/pre_commit/scalastyle.rb index 55c6dc4f..6494521d 100644 --- a/lib/overcommit/hook/pre_commit/scalastyle.rb +++ b/lib/overcommit/hook/pre_commit/scalastyle.rb @@ -10,7 +10,7 @@ class Scalastyle < Base file=(?(?:\w:)?.+)\s message=.+\s* (line=(?\d+))? - /x + /x.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/scss_lint.rb b/lib/overcommit/hook/pre_commit/scss_lint.rb index 6d279cec..1bbaba93 100644 --- a/lib/overcommit/hook/pre_commit/scss_lint.rb +++ b/lib/overcommit/hook/pre_commit/scss_lint.rb @@ -18,9 +18,9 @@ def run begin collect_lint_messages(JSON.parse(result.stdout)) - rescue JSON::ParserError => ex - return :fail, "Unable to parse JSON returned by SCSS-Lint: #{ex.message}\n" \ - "STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}" + rescue JSON::ParserError => e + [:fail, "Unable to parse JSON returned by SCSS-Lint: #{e.message}\n" \ + "STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"] end end diff --git a/lib/overcommit/hook/pre_commit/semi_standard.rb b/lib/overcommit/hook/pre_commit/semi_standard.rb index ce40119b..f6746d2f 100644 --- a/lib/overcommit/hook/pre_commit/semi_standard.rb +++ b/lib/overcommit/hook/pre_commit/semi_standard.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://github.com/Flet/semistandard class SemiStandard < Base - MESSAGE_REGEX = /^\s*(?(?:\w:)?[^:]+):(?\d+)/ + MESSAGE_REGEX = /^\s*(?(?:\w:)?[^:]+):(?\d+)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/sqlint.rb b/lib/overcommit/hook/pre_commit/sqlint.rb index 6568a987..2e5c5a88 100644 --- a/lib/overcommit/hook/pre_commit/sqlint.rb +++ b/lib/overcommit/hook/pre_commit/sqlint.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://github.com/purcell/sqlint class Sqlint < Base - MESSAGE_REGEX = /(?(?:\w:)?.+):(?\d+):\d+:(?\w+)/ + MESSAGE_REGEX = /(?(?:\w:)?.+):(?\d+):\d+:(?\w+)/.freeze MESSAGE_TYPE_CATEGORIZER = lambda do |type| type == 'ERROR' ? :error : :warning diff --git a/lib/overcommit/hook/pre_commit/standard.rb b/lib/overcommit/hook/pre_commit/standard.rb index 4d2ee277..7b70ab2c 100644 --- a/lib/overcommit/hook/pre_commit/standard.rb +++ b/lib/overcommit/hook/pre_commit/standard.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see https://github.com/feross/standard class Standard < Base - MESSAGE_REGEX = /^\s*(?(?:\w:)?[^:]+):(?\d+)/ + MESSAGE_REGEX = /^\s*(?(?:\w:)?[^:]+):(?\d+)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/stylelint.rb b/lib/overcommit/hook/pre_commit/stylelint.rb index 403c5e27..e20bc8df 100644 --- a/lib/overcommit/hook/pre_commit/stylelint.rb +++ b/lib/overcommit/hook/pre_commit/stylelint.rb @@ -8,12 +8,13 @@ class Stylelint < Base # example of output: # index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation) - MESSAGE_REGEX = /^(?.+):\D*(?\d+).*$/ + MESSAGE_REGEX = /^(?.+):\D*(?\d+).*$/.freeze def run result = execute(command, args: applicable_files) output = result.stdout.chomp return :pass if result.success? && output.empty? + extract_messages( output.split("\n"), MESSAGE_REGEX diff --git a/lib/overcommit/hook/pre_commit/swift_lint.rb b/lib/overcommit/hook/pre_commit/swift_lint.rb index 40e4a5eb..a1d8ef09 100644 --- a/lib/overcommit/hook/pre_commit/swift_lint.rb +++ b/lib/overcommit/hook/pre_commit/swift_lint.rb @@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit # Runs `swiftlint lint` against modified Swift files. # @see https://github.com/realm/SwiftLint class SwiftLint < Base - MESSAGE_REGEX = /^(?(?:\w:)?[^:]+):(?\d+)[^ ]* (?[^ ]+):(?.*)/ + MESSAGE_REGEX = /^(?(?:\w:)?[^:]+):(?\d+)[^ ]* (?[^ ]+):(?.*)/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/ts_lint.rb b/lib/overcommit/hook/pre_commit/ts_lint.rb index 7f8cc503..1340cbcf 100644 --- a/lib/overcommit/hook/pre_commit/ts_lint.rb +++ b/lib/overcommit/hook/pre_commit/ts_lint.rb @@ -8,7 +8,7 @@ class TsLint < Base # "src/file/anotherfile.ts[298, 1]: exceeds maximum line length of 140" # or # "ERROR: src/AccountController.ts[4, 28]: expected call-signature to have a typedef" - MESSAGE_REGEX = /^(?.+: )?(?.+?(?=\[))[^\d]+(?\d+).*?/ + MESSAGE_REGEX = /^(?.+: )?(?.+?(?=\[))[^\d]+(?\d+).*?/.freeze def run result = execute(command, args: applicable_files) @@ -19,9 +19,9 @@ def run type_categorizer = ->(type) { type.nil? || type.include?('ERROR') ? :error : :warning } extract_messages( - output_lines, - MESSAGE_REGEX, - type_categorizer + output_lines, + MESSAGE_REGEX, + type_categorizer ) end end diff --git a/lib/overcommit/hook/pre_commit/w3c_css.rb b/lib/overcommit/hook/pre_commit/w3c_css.rb index f36230f6..cb32c109 100644 --- a/lib/overcommit/hook/pre_commit/w3c_css.rb +++ b/lib/overcommit/hook/pre_commit/w3c_css.rb @@ -42,10 +42,10 @@ def validator def opts @opts ||= { validator_uri: config['validator_uri'], - proxy_server: config['proxy_server'], - proxy_port: config['proxy_port'], - proxy_user: config['proxy_user'], - proxy_pass: config['proxy_pass'] + proxy_server: config['proxy_server'], + proxy_port: config['proxy_port'], + proxy_user: config['proxy_user'], + proxy_pass: config['proxy_pass'] } end diff --git a/lib/overcommit/hook/pre_commit/w3c_html.rb b/lib/overcommit/hook/pre_commit/w3c_html.rb index 5330ef4e..945e7997 100644 --- a/lib/overcommit/hook/pre_commit/w3c_html.rb +++ b/lib/overcommit/hook/pre_commit/w3c_html.rb @@ -42,10 +42,10 @@ def validator def opts @opts ||= { validator_uri: config['validator_uri'], - proxy_server: config['proxy_server'], - proxy_port: config['proxy_port'], - proxy_user: config['proxy_user'], - proxy_pass: config['proxy_pass'] + proxy_server: config['proxy_server'], + proxy_port: config['proxy_port'], + proxy_user: config['proxy_user'], + proxy_pass: config['proxy_pass'] } end diff --git a/lib/overcommit/hook/pre_commit/xml_lint.rb b/lib/overcommit/hook/pre_commit/xml_lint.rb index 618f3e74..71cb403f 100644 --- a/lib/overcommit/hook/pre_commit/xml_lint.rb +++ b/lib/overcommit/hook/pre_commit/xml_lint.rb @@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit # # @see http://xmlsoft.org/xmllint.html class XmlLint < Base - MESSAGE_REGEX = /^(?(?:\w:)?[^:]+):(?\d+):/ + MESSAGE_REGEX = /^(?(?:\w:)?[^:]+):(?\d+):/.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/yaml_lint.rb b/lib/overcommit/hook/pre_commit/yaml_lint.rb index 1fd57513..f780725f 100644 --- a/lib/overcommit/hook/pre_commit/yaml_lint.rb +++ b/lib/overcommit/hook/pre_commit/yaml_lint.rb @@ -11,7 +11,7 @@ class YamlLint < Base :(?\d+) :\s\[(?\w+)\] \s(?.+)$ - /x + /x.freeze def run result = execute(command, args: applicable_files) diff --git a/lib/overcommit/hook/pre_commit/yard_coverage.rb b/lib/overcommit/hook/pre_commit/yard_coverage.rb index b9336f0f..c9188edb 100644 --- a/lib/overcommit/hook/pre_commit/yard_coverage.rb +++ b/lib/overcommit/hook/pre_commit/yard_coverage.rb @@ -1,4 +1,3 @@ - # frozen_string_literal: true module Overcommit::Hook::PreCommit diff --git a/lib/overcommit/hook/pre_push/cargo_test.rb b/lib/overcommit/hook/pre_push/cargo_test.rb index 33e5076b..ab782e0c 100644 --- a/lib/overcommit/hook/pre_push/cargo_test.rb +++ b/lib/overcommit/hook/pre_push/cargo_test.rb @@ -6,6 +6,7 @@ class CargoTest < Base def run result = execute(command) return :pass if result.success? + [:fail, result.stdout] end end diff --git a/lib/overcommit/hook/prepare_commit_msg/base.rb b/lib/overcommit/hook/prepare_commit_msg/base.rb index 5c0c68d4..a4fbf31e 100644 --- a/lib/overcommit/hook/prepare_commit_msg/base.rb +++ b/lib/overcommit/hook/prepare_commit_msg/base.rb @@ -12,6 +12,7 @@ class Base < Overcommit::Hook::Base def modify_commit_message raise 'This expects a block!' unless block_given? + # NOTE: this assumes all the hooks of the same type share the context's # memory. If that's not the case, this won't work. lock.synchronize do diff --git a/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb b/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb index 5739d124..7a40ed69 100644 --- a/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +++ b/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb @@ -29,7 +29,7 @@ module Overcommit::Hook::PrepareCommitMsg # - 'squash' - if squashing # class ReplaceBranch < Base - DEFAULT_BRANCH_PATTERN = /\A(\d+)-(\w+).*\z/ + DEFAULT_BRANCH_PATTERN = /\A(\d+)-(\w+).*\z/.freeze def run return :pass if skip? diff --git a/lib/overcommit/hook/shared/bower_install.rb b/lib/overcommit/hook/shared/bower_install.rb index b39d4ada..cfcde92f 100644 --- a/lib/overcommit/hook/shared/bower_install.rb +++ b/lib/overcommit/hook/shared/bower_install.rb @@ -9,6 +9,7 @@ module BowerInstall def run result = execute(command) return :fail, result.stderr unless result.success? + :pass end end diff --git a/lib/overcommit/hook/shared/bundle_install.rb b/lib/overcommit/hook/shared/bundle_install.rb index 060e30c5..01acaa32 100644 --- a/lib/overcommit/hook/shared/bundle_install.rb +++ b/lib/overcommit/hook/shared/bundle_install.rb @@ -9,6 +9,7 @@ module BundleInstall def run result = execute(command) return :fail, result.stdout unless result.success? + :pass end end diff --git a/lib/overcommit/hook/shared/composer_install.rb b/lib/overcommit/hook/shared/composer_install.rb index 839dd65b..2d2ff01d 100644 --- a/lib/overcommit/hook/shared/composer_install.rb +++ b/lib/overcommit/hook/shared/composer_install.rb @@ -9,6 +9,7 @@ module ComposerInstall def run result = execute(command) return :fail, result.stdout unless result.success? + :pass end end diff --git a/lib/overcommit/hook/shared/npm_install.rb b/lib/overcommit/hook/shared/npm_install.rb index 7fa06772..f487c8e7 100644 --- a/lib/overcommit/hook/shared/npm_install.rb +++ b/lib/overcommit/hook/shared/npm_install.rb @@ -9,6 +9,7 @@ module NpmInstall def run result = execute(command) return :fail, result.stderr unless result.success? + :pass end end diff --git a/lib/overcommit/hook/shared/yarn_install.rb b/lib/overcommit/hook/shared/yarn_install.rb index bc3b7869..fd548f07 100644 --- a/lib/overcommit/hook/shared/yarn_install.rb +++ b/lib/overcommit/hook/shared/yarn_install.rb @@ -9,6 +9,7 @@ module YarnInstall def run result = execute(command) return :fail, result.stderr unless result.success? + :pass end end diff --git a/lib/overcommit/hook_context.rb b/lib/overcommit/hook_context.rb index df12b86c..acdff1bb 100644 --- a/lib/overcommit/hook_context.rb +++ b/lib/overcommit/hook_context.rb @@ -9,11 +9,11 @@ def self.create(hook_type, config, args, input) require "overcommit/hook_context/#{underscored_hook_type}" Overcommit::HookContext.const_get(hook_type_class).new(config, args, input) - rescue LoadError, NameError => error + rescue LoadError, NameError => e # Could happen when a symlink was created for a hook type Overcommit does # not yet support. raise Overcommit::Exceptions::HookContextLoadError, - "Unable to load '#{hook_type}' hook context: '#{error}'", - error.backtrace + "Unable to load '#{hook_type}' hook context: '#{e}'", + e.backtrace end end diff --git a/lib/overcommit/hook_context/helpers/file_modifications.rb b/lib/overcommit/hook_context/helpers/file_modifications.rb index 9eade907..00aaccc8 100644 --- a/lib/overcommit/hook_context/helpers/file_modifications.rb +++ b/lib/overcommit/hook_context/helpers/file_modifications.rb @@ -11,6 +11,7 @@ def amendment? cmd = Overcommit::Utils.parent_command return unless cmd + amend_pattern = 'commit(\s.*)?\s--amend(\s|$)' # Since the ps command can return invalid byte sequences for commands diff --git a/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb b/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb index 0d333098..17400539 100644 --- a/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +++ b/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb @@ -26,6 +26,7 @@ def setup_environment # Returns whether the current git branch is empty (has no commits). def initial_commit? return @initial_commit unless @initial_commit.nil? + @initial_commit = Overcommit::GitRepo.initial_commit? end @@ -63,6 +64,7 @@ def store_modified_times (staged_files + unstaged_files).each do |file| next if Overcommit::Utils.broken_symlink?(file) next unless File.exist?(file) # Ignore renamed files (old file no longer exists) + @modified_times[file] = File.mtime(file) end end @@ -101,6 +103,7 @@ def restore_modified_times @modified_times.each do |file, time| next if Overcommit::Utils.broken_symlink?(file) next unless File.exist?(file) + File.utime(time, time, file) end end diff --git a/lib/overcommit/hook_context/post_commit.rb b/lib/overcommit/hook_context/post_commit.rb index 0e780077..8327b0d9 100644 --- a/lib/overcommit/hook_context/post_commit.rb +++ b/lib/overcommit/hook_context/post_commit.rb @@ -27,6 +27,7 @@ def modified_lines_in_file(file) # @return [true,false] def initial_commit? return @initial_commit unless @initial_commit.nil? + @initial_commit = !Overcommit::Utils.execute(%w[git rev-parse HEAD~]).success? end end diff --git a/lib/overcommit/hook_context/pre_push.rb b/lib/overcommit/hook_context/pre_push.rb index 0b2e72a1..39ec19ba 100644 --- a/lib/overcommit/hook_context/pre_push.rb +++ b/lib/overcommit/hook_context/pre_push.rb @@ -76,6 +76,7 @@ def ref_range def overwritten_commits return @overwritten_commits if defined? @overwritten_commits + result = Overcommit::Subprocess.spawn(%W[git rev-list #{remote_sha1} ^#{local_sha1}]) if result.success? result.stdout.split("\n") diff --git a/lib/overcommit/hook_context/run_all.rb b/lib/overcommit/hook_context/run_all.rb index e7acee57..5ed7efa0 100644 --- a/lib/overcommit/hook_context/run_all.rb +++ b/lib/overcommit/hook_context/run_all.rb @@ -36,6 +36,7 @@ def hook_script_name def initial_commit? return @initial_commit unless @initial_commit.nil? + @initial_commit = Overcommit::GitRepo.initial_commit? end diff --git a/lib/overcommit/hook_loader/base.rb b/lib/overcommit/hook_loader/base.rb index 93e83ccc..9173e9f1 100644 --- a/lib/overcommit/hook_loader/base.rb +++ b/lib/overcommit/hook_loader/base.rb @@ -38,10 +38,10 @@ def create_hook(hook_name) Overcommit::Hook.const_get(@context.hook_class_name). const_get(hook_name). new(@config, @context) - rescue LoadError, NameError => error + rescue LoadError, NameError => e raise Overcommit::Exceptions::HookLoadError, - "Unable to load hook '#{hook_name}': #{error}", - error.backtrace + "Unable to load hook '#{hook_name}': #{e}", + e.backtrace end end end diff --git a/lib/overcommit/hook_loader/plugin_hook_loader.rb b/lib/overcommit/hook_loader/plugin_hook_loader.rb index b57d7095..d168a0de 100644 --- a/lib/overcommit/hook_loader/plugin_hook_loader.rb +++ b/lib/overcommit/hook_loader/plugin_hook_loader.rb @@ -93,10 +93,10 @@ def run end hook_module.const_set(hook_name, hook_class).new(@config, @context) - rescue LoadError, NameError => error + rescue LoadError, NameError => e raise Overcommit::Exceptions::HookLoadError, - "Unable to load hook '#{hook_name}': #{error}", - error.backtrace + "Unable to load hook '#{hook_name}': #{e}", + e.backtrace end end end diff --git a/lib/overcommit/hook_runner.rb b/lib/overcommit/hook_runner.rb index 8ac01e99..c7c313ab 100644 --- a/lib/overcommit/hook_runner.rb +++ b/lib/overcommit/hook_runner.rb @@ -94,6 +94,7 @@ def consume loop do hook = @lock.synchronize { @hooks_left.pop } break unless hook + run_hook(hook) end end @@ -159,12 +160,12 @@ def run_hook(hook) # rubocop:disable Metrics/CyclomaticComplexity return if should_skip?(hook) status, output = hook.run_and_transform - rescue Overcommit::Exceptions::MessageProcessingError => ex + rescue Overcommit::Exceptions::MessageProcessingError => e status = :fail - output = ex.message - rescue StandardError => ex + output = e.message + rescue StandardError => e status = :fail - output = "Hook raised unexpected error\n#{ex.message}\n#{ex.backtrace.join("\n")}" + output = "Hook raised unexpected error\n#{e.message}\n#{e.backtrace.join("\n")}" end @failed = true if status == :fail @@ -202,7 +203,7 @@ def load_hooks # Load plugin hooks after so they can subclass existing hooks @hooks += HookLoader::PluginHookLoader.new(@config, @context, @log).load_hooks - rescue LoadError => ex + rescue LoadError => e # Include a more helpful message that will probably save some confusion message = 'A load error occurred. ' + if @config['gemfile'] @@ -212,8 +213,8 @@ def load_hooks end raise Overcommit::Exceptions::HookLoadError, - "#{message}\n#{ex.message}", - ex.backtrace + "#{message}\n#{e.message}", + e.backtrace end end end diff --git a/lib/overcommit/hook_signer.rb b/lib/overcommit/hook_signer.rb index f432ca48..fab99c37 100644 --- a/lib/overcommit/hook_signer.rb +++ b/lib/overcommit/hook_signer.rb @@ -52,6 +52,7 @@ def hook_path def signable_file?(file) return unless file + sep = Overcommit::OS.windows? ? '\\' : File::SEPARATOR file.start_with?(".#{sep}") || file.start_with?(Overcommit::Utils.repo_root) diff --git a/lib/overcommit/installer.rb b/lib/overcommit/installer.rb index 11d598e8..79287b30 100644 --- a/lib/overcommit/installer.rb +++ b/lib/overcommit/installer.rb @@ -4,7 +4,7 @@ module Overcommit # Manages the installation of Overcommit hooks in a git repository. - class Installer # rubocop:disable ClassLength + class Installer # rubocop:disable Metrics/ClassLength TEMPLATE_DIRECTORY = File.join(Overcommit::HOME, 'template-dir') MASTER_HOOK = File.join(TEMPLATE_DIRECTORY, 'hooks', 'overcommit-hook') @@ -174,6 +174,7 @@ def install_starter_config repo_config_file = File.join(@target, Overcommit::CONFIG_FILE_NAME) return if File.exist?(repo_config_file) + FileUtils.cp(File.join(Overcommit::HOME, 'config', 'starter.yml'), repo_config_file) end diff --git a/lib/overcommit/subprocess.rb b/lib/overcommit/subprocess.rb index 47713ff2..07e4fe04 100644 --- a/lib/overcommit/subprocess.rb +++ b/lib/overcommit/subprocess.rb @@ -38,7 +38,7 @@ def spawn(args, options = {}) if options[:input] begin process.io.stdin.puts(options[:input]) - rescue StandardError # rubocop:disable Lint/HandleExceptions + rescue StandardError # Silently ignore if the standard input stream of the spawned # process is closed before we get a chance to write to it. This # happens on JRuby a lot. diff --git a/lib/overcommit/utils/messages_utils.rb b/lib/overcommit/utils/messages_utils.rb index 642e3e22..c92a6010 100644 --- a/lib/overcommit/utils/messages_utils.rb +++ b/lib/overcommit/utils/messages_utils.rb @@ -52,6 +52,7 @@ def extract_file(match, message) def extract_line(match, message) return unless match.names.include?('line') + Integer(match[:line]) rescue ArgumentError, TypeError raise Overcommit::Exceptions::MessageProcessingError, diff --git a/spec/overcommit/git_repo_spec.rb b/spec/overcommit/git_repo_spec.rb index a5f753e1..128737c3 100644 --- a/spec/overcommit/git_repo_spec.rb +++ b/spec/overcommit/git_repo_spec.rb @@ -377,7 +377,7 @@ it 'returns all submodules that were removed' do subject.size.should == 2 - subject.map(&:path).sort.should == ['sub-repo', 'yet-another-sub-repo'] + subject.map(&:path).sort.should == %w[sub-repo yet-another-sub-repo] end end end diff --git a/spec/overcommit/hook/commit_msg/message_format_spec.rb b/spec/overcommit/hook/commit_msg/message_format_spec.rb index d4aaab62..c9dde29b 100644 --- a/spec/overcommit/hook/commit_msg/message_format_spec.rb +++ b/spec/overcommit/hook/commit_msg/message_format_spec.rb @@ -15,11 +15,11 @@ context 'when pattern is empty' do let(:config) do super().merge(Overcommit::Configuration.new( - 'CommitMsg' => { - 'MessageFormat' => { - 'pattern' => nil - } - } + 'CommitMsg' => { + 'MessageFormat' => { + 'pattern' => nil + } + } )) end @@ -43,11 +43,11 @@ context 'when multiline message matches the pattern' do let(:config) do super().merge(Overcommit::Configuration.new( - 'CommitMsg' => { - 'MessageFormat' => { - 'pattern' => '^Some .* Message$' - } - } + 'CommitMsg' => { + 'MessageFormat' => { + 'pattern' => '^Some .* Message$' + } + } )) end diff --git a/spec/overcommit/hook/commit_msg/text_width_spec.rb b/spec/overcommit/hook/commit_msg/text_width_spec.rb index e07d777e..8829668e 100644 --- a/spec/overcommit/hook/commit_msg/text_width_spec.rb +++ b/spec/overcommit/hook/commit_msg/text_width_spec.rb @@ -98,13 +98,13 @@ context 'when custom lengths are specified' do let(:config) do super().merge(Overcommit::Configuration.new( - 'CommitMsg' => { - 'TextWidth' => { - 'max_subject_width' => 70, - 'min_subject_width' => 4, - 'max_body_width' => 80 - } - } + 'CommitMsg' => { + 'TextWidth' => { + 'max_subject_width' => 70, + 'min_subject_width' => 4, + 'max_body_width' => 80 + } + } )) end diff --git a/spec/overcommit/hook/pre_commit/author_email_spec.rb b/spec/overcommit/hook/pre_commit/author_email_spec.rb index 613f114e..8e0dd768 100644 --- a/spec/overcommit/hook/pre_commit/author_email_spec.rb +++ b/spec/overcommit/hook/pre_commit/author_email_spec.rb @@ -30,11 +30,11 @@ context 'when a custom pattern is specified' do let(:config) do super().merge(Overcommit::Configuration.new( - 'PreCommit' => { - 'AuthorEmail' => { - 'pattern' => '^[^@]+@brigade\.com$' - } - } + 'PreCommit' => { + 'AuthorEmail' => { + 'pattern' => '^[^@]+@brigade\.com$' + } + } )) end diff --git a/spec/overcommit/hook/pre_commit/bundle_audit_spec.rb b/spec/overcommit/hook/pre_commit/bundle_audit_spec.rb index 633e14fe..b8360e2e 100644 --- a/spec/overcommit/hook/pre_commit/bundle_audit_spec.rb +++ b/spec/overcommit/hook/pre_commit/bundle_audit_spec.rb @@ -54,7 +54,7 @@ Title: Rest-Client Gem for Ruby logs password information in plaintext Solution: upgrade to >= 1.7.3 Vulnerabilities found! -MSG + MSG ) end @@ -67,7 +67,7 @@ stdout: <<-MSG Insecure Source URI found: git://github.com/xxx/overcommit.git Vulnerabilities found! -MSG + MSG ) end diff --git a/spec/overcommit/hook/pre_commit/bundle_outdated_spec.rb b/spec/overcommit/hook/pre_commit/bundle_outdated_spec.rb index c61e4873..a734b3dc 100644 --- a/spec/overcommit/hook/pre_commit/bundle_outdated_spec.rb +++ b/spec/overcommit/hook/pre_commit/bundle_outdated_spec.rb @@ -49,7 +49,7 @@ aws-sdk-resources (newest 2.3.3, installed 2.3.1) config (newest 1.1.1, installed 1.1.0) ruby_parser (newest 3.8.2, installed 3.8.1) -MSG + MSG ) end @@ -60,7 +60,7 @@ let(:result) do double(stdout: <<-MSG Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. -MSG + MSG ) end diff --git a/spec/overcommit/hook/pre_commit/erb_lint_spec.rb b/spec/overcommit/hook/pre_commit/erb_lint_spec.rb index fcb17199..e9272bfe 100644 --- a/spec/overcommit/hook/pre_commit/erb_lint_spec.rb +++ b/spec/overcommit/hook/pre_commit/erb_lint_spec.rb @@ -36,7 +36,7 @@ erb interpolation with '<%= (...).html_safe %>' in this context is never safe In file: app/views/posts/show.html.erb:10 -MSG + MSG end it { should fail_hook } diff --git a/spec/overcommit/hook/pre_commit/fasterer_spec.rb b/spec/overcommit/hook/pre_commit/fasterer_spec.rb index 405888ab..afb08791 100644 --- a/spec/overcommit/hook/pre_commit/fasterer_spec.rb +++ b/spec/overcommit/hook/pre_commit/fasterer_spec.rb @@ -36,7 +36,7 @@ spec/models/blog_spec.rb Using each_with_index is slower than while loop. Occurred at lines: 12. 2 files inspected, 0 offense detected - MSG + MSG ) end @@ -51,7 +51,7 @@ spec/models/product_spec.rb Using each_with_index is slower than while loop. Occurred at lines: 52. 1 files inspected, 1 offense detected - MSG + MSG ) end diff --git a/spec/overcommit/hook/pre_commit/flay_spec.rb b/spec/overcommit/hook/pre_commit/flay_spec.rb index a64cd2c3..2a5d8140 100644 --- a/spec/overcommit/hook/pre_commit/flay_spec.rb +++ b/spec/overcommit/hook/pre_commit/flay_spec.rb @@ -38,7 +38,7 @@ app/whatever21.rb:105 app/whatever22.rb:76 -MSG + MSG ) end @@ -51,7 +51,7 @@ success?: false, stdout: <<-MSG Total score (lower is better) = 0 -MSG + MSG ) end diff --git a/spec/overcommit/hook/pre_commit/hadolint_spec.rb b/spec/overcommit/hook/pre_commit/hadolint_spec.rb index 4091ca0b..ad756f30 100644 --- a/spec/overcommit/hook/pre_commit/hadolint_spec.rb +++ b/spec/overcommit/hook/pre_commit/hadolint_spec.rb @@ -31,7 +31,7 @@ success?: false, stdout: <<-MSG Dockerfile:5 DL3015 Avoid additional packages by specifying `--no-install-recommends` - MSG + MSG ) end let(:result_dockerfile_web) do @@ -39,7 +39,7 @@ success?: false, stdout: <<-MSG Dockerfile.web:13 DL3020 Use COPY instead of ADD for files and folders - MSG + MSG ) end @@ -52,7 +52,7 @@ success?: false, stdout: <<-MSG Dockerfile:11 SC2086 Double quote to prevent globbing and word splitting. - MSG + MSG ) end let(:result_dockerfile_web) do diff --git a/spec/overcommit/hook/pre_commit/rake_target_spec.rb b/spec/overcommit/hook/pre_commit/rake_target_spec.rb index 4a0cf400..e295e61f 100644 --- a/spec/overcommit/hook/pre_commit/rake_target_spec.rb +++ b/spec/overcommit/hook/pre_commit/rake_target_spec.rb @@ -19,11 +19,11 @@ context 'with targets parameter set' do let(:config) do super().merge(Overcommit::Configuration.new( - 'PreCommit' => { - 'RakeTarget' => { - 'targets' => ['test'], - } - } + 'PreCommit' => { + 'RakeTarget' => { + 'targets' => ['test'], + } + } )) end let(:result) { double('result') } diff --git a/spec/overcommit/hook/pre_commit/yaml_lint_spec.rb b/spec/overcommit/hook/pre_commit/yaml_lint_spec.rb index a69b8122..e5aea475 100644 --- a/spec/overcommit/hook/pre_commit/yaml_lint_spec.rb +++ b/spec/overcommit/hook/pre_commit/yaml_lint_spec.rb @@ -30,7 +30,7 @@ stdout: <<-MSG file1.yaml:3:81: [error] line too long (253 > 80 characters) (line-length) file2.yml:41:81: [error] line too long (261 > 80 characters) (line-length) - MSG + MSG ) end @@ -44,7 +44,7 @@ stdout: <<-MSG file1.yaml:3:81: [error] line too long (253 > 80 characters) (line-length) file2.yml:41:81: [warning] missing document start "---" (document-start) - MSG + MSG ) end @@ -56,7 +56,7 @@ success?: false, stdout: <<-MSG file1.yaml:1:1: [warning] missing document start "---" (document-start) - MSG + MSG ) end diff --git a/spec/overcommit/hook/pre_commit/yard_coverage_spec.rb b/spec/overcommit/hook/pre_commit/yard_coverage_spec.rb index d59779c9..d463d25d 100644 --- a/spec/overcommit/hook/pre_commit/yard_coverage_spec.rb +++ b/spec/overcommit/hook/pre_commit/yard_coverage_spec.rb @@ -76,7 +76,7 @@ context 'and it reports an error' do before do result.stub(:stdout).and_return( - <<-HEREDOC + <<-HEREDOC Files: 72 Modules: 12 ( 3 undocumented) Classes: 63 ( 15 undocumented) diff --git a/spec/overcommit/hook/pre_push/rake_target_spec.rb b/spec/overcommit/hook/pre_push/rake_target_spec.rb index 45c93752..5147d089 100644 --- a/spec/overcommit/hook/pre_push/rake_target_spec.rb +++ b/spec/overcommit/hook/pre_push/rake_target_spec.rb @@ -19,11 +19,11 @@ context 'with targets parameter set' do let(:config) do super().merge(Overcommit::Configuration.new( - 'PrePush' => { - 'RakeTarget' => { - 'targets' => ['test'], - } - } + 'PrePush' => { + 'RakeTarget' => { + 'targets' => ['test'], + } + } )) end let(:result) { double('result') } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f0d93a7f..fe6f82da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,7 +27,7 @@ each { |f| require f } end -Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f } +Dir[File.dirname(__FILE__) + '/support/**/*.rb'].sort.each { |f| require f } RSpec.configure do |config| config.include GitSpecHelpers diff --git a/spec/support/shell_helpers.rb b/spec/support/shell_helpers.rb index d035e13a..786dac63 100644 --- a/spec/support/shell_helpers.rb +++ b/spec/support/shell_helpers.rb @@ -26,6 +26,7 @@ def wait_until(options = {}) Timeout.timeout(options.fetch(:timeout) { 1 }) do loop do return if yield + sleep options.fetch(:check_interval) { 0.1 } end end diff --git a/template-dir/hooks/commit-msg b/template-dir/hooks/commit-msg index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/commit-msg +++ b/template-dir/hooks/commit-msg @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/overcommit-hook b/template-dir/hooks/overcommit-hook index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/overcommit-hook +++ b/template-dir/hooks/overcommit-hook @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/post-checkout b/template-dir/hooks/post-checkout index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/post-checkout +++ b/template-dir/hooks/post-checkout @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/post-commit b/template-dir/hooks/post-commit index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/post-commit +++ b/template-dir/hooks/post-commit @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/post-merge b/template-dir/hooks/post-merge index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/post-merge +++ b/template-dir/hooks/post-merge @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/post-rewrite b/template-dir/hooks/post-rewrite index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/post-rewrite +++ b/template-dir/hooks/post-rewrite @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/pre-commit b/template-dir/hooks/pre-commit index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/pre-commit +++ b/template-dir/hooks/pre-commit @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/pre-push b/template-dir/hooks/pre-push index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/pre-push +++ b/template-dir/hooks/pre-push @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/pre-rebase b/template-dir/hooks/pre-rebase index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/pre-rebase +++ b/template-dir/hooks/pre-rebase @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end diff --git a/template-dir/hooks/prepare-commit-msg b/template-dir/hooks/prepare-commit-msg index 8b8c118c..197dc198 100755 --- a/template-dir/hooks/prepare-commit-msg +++ b/template-dir/hooks/prepare-commit-msg @@ -35,9 +35,9 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil begin Bundler.setup - 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 end end @@ -80,37 +80,37 @@ begin status = runner.run exit(status ? 0 : 65) # 65 = EX_DATAERR -rescue Overcommit::Exceptions::ConfigurationError => error - puts error +rescue Overcommit::Exceptions::ConfigurationError => e + puts e exit 78 # EX_CONFIG -rescue Overcommit::Exceptions::HookContextLoadError => error - puts error +rescue Overcommit::Exceptions::HookContextLoadError => e + puts e puts 'Are you running an old version of Overcommit?' exit 69 # EX_UNAVAILABLE rescue Overcommit::Exceptions::HookLoadError, - Overcommit::Exceptions::InvalidHookDefinition => error - puts error.message - puts error.backtrace + Overcommit::Exceptions::InvalidHookDefinition => e + puts e.message + puts e.backtrace exit 78 # EX_CONFIG rescue Overcommit::Exceptions::HookSetupFailed, - Overcommit::Exceptions::HookCleanupFailed => error - puts error.message + Overcommit::Exceptions::HookCleanupFailed => e + puts e.message exit 74 # EX_IOERR rescue Overcommit::Exceptions::HookCancelled puts 'You cancelled the hook run' exit 130 # Ctrl-C cancel -rescue Overcommit::Exceptions::InvalidGitRepo => error - puts error +rescue Overcommit::Exceptions::InvalidGitRepo => e + puts e exit 64 # EX_USAGE -rescue Overcommit::Exceptions::ConfigurationSignatureChanged => error - puts error +rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e + puts e puts "For more information, see #{Overcommit::REPO_URL}#security" exit 1 rescue Overcommit::Exceptions::InvalidHookSignature exit 1 -rescue StandardError => error - puts error.message - puts error.backtrace +rescue StandardError => e + puts e.message + puts e.backtrace puts "Report this bug at #{Overcommit::BUG_REPORT_URL}" exit 70 # EX_SOFTWARE end