overcommit 0.58.0 → 0.59.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/bin/overcommit +6 -5
  3. data/config/default.yml +1 -1
  4. data/lib/overcommit/cli.rb +14 -13
  5. data/lib/overcommit/command_splitter.rb +2 -0
  6. data/lib/overcommit/configuration.rb +1 -1
  7. data/lib/overcommit/configuration_loader.rb +3 -3
  8. data/lib/overcommit/git_config.rb +1 -0
  9. data/lib/overcommit/git_repo.rb +4 -4
  10. data/lib/overcommit/hook/commit_msg/spell_check.rb +1 -1
  11. data/lib/overcommit/hook/commit_msg/text_width.rb +1 -1
  12. data/lib/overcommit/hook/post_checkout/base.rb +1 -0
  13. data/lib/overcommit/hook/post_commit/git_guilt.rb +2 -1
  14. data/lib/overcommit/hook/pre_commit/bundle_audit.rb +1 -1
  15. data/lib/overcommit/hook/pre_commit/chamber_compare.rb +5 -5
  16. data/lib/overcommit/hook/pre_commit/chamber_security.rb +1 -0
  17. data/lib/overcommit/hook/pre_commit/coffee_lint.rb +1 -1
  18. data/lib/overcommit/hook/pre_commit/css_lint.rb +1 -1
  19. data/lib/overcommit/hook/pre_commit/dart_analyzer.rb +1 -1
  20. data/lib/overcommit/hook/pre_commit/erb_lint.rb +1 -1
  21. data/lib/overcommit/hook/pre_commit/fasterer.rb +1 -1
  22. data/lib/overcommit/hook/pre_commit/foodcritic.rb +3 -1
  23. data/lib/overcommit/hook/pre_commit/hlint.rb +1 -1
  24. data/lib/overcommit/hook/pre_commit/html_tidy.rb +1 -1
  25. data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +1 -1
  26. data/lib/overcommit/hook/pre_commit/js_lint.rb +1 -1
  27. data/lib/overcommit/hook/pre_commit/jsl.rb +1 -1
  28. data/lib/overcommit/hook/pre_commit/kt_lint.rb +1 -1
  29. data/lib/overcommit/hook/pre_commit/license_finder.rb +1 -0
  30. data/lib/overcommit/hook/pre_commit/line_endings.rb +3 -2
  31. data/lib/overcommit/hook/pre_commit/nginx_test.rb +1 -1
  32. data/lib/overcommit/hook/pre_commit/php_cs.rb +1 -1
  33. data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +1 -1
  34. data/lib/overcommit/hook/pre_commit/php_lint.rb +3 -3
  35. data/lib/overcommit/hook/pre_commit/php_stan.rb +1 -1
  36. data/lib/overcommit/hook/pre_commit/puppet_lint.rb +1 -1
  37. data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +1 -1
  38. data/lib/overcommit/hook/pre_commit/pyflakes.rb +1 -1
  39. data/lib/overcommit/hook/pre_commit/pylint.rb +1 -1
  40. data/lib/overcommit/hook/pre_commit/python_flake8.rb +1 -1
  41. data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +1 -1
  42. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +2 -2
  43. data/lib/overcommit/hook/pre_commit/rst_lint.rb +1 -1
  44. data/lib/overcommit/hook/pre_commit/scalariform.rb +1 -1
  45. data/lib/overcommit/hook/pre_commit/scalastyle.rb +1 -1
  46. data/lib/overcommit/hook/pre_commit/scss_lint.rb +3 -3
  47. data/lib/overcommit/hook/pre_commit/semi_standard.rb +1 -1
  48. data/lib/overcommit/hook/pre_commit/sqlint.rb +1 -1
  49. data/lib/overcommit/hook/pre_commit/standard.rb +1 -1
  50. data/lib/overcommit/hook/pre_commit/stylelint.rb +2 -1
  51. data/lib/overcommit/hook/pre_commit/swift_lint.rb +1 -1
  52. data/lib/overcommit/hook/pre_commit/ts_lint.rb +4 -4
  53. data/lib/overcommit/hook/pre_commit/w3c_css.rb +4 -4
  54. data/lib/overcommit/hook/pre_commit/w3c_html.rb +4 -4
  55. data/lib/overcommit/hook/pre_commit/xml_lint.rb +1 -1
  56. data/lib/overcommit/hook/pre_commit/yaml_lint.rb +1 -1
  57. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +7 -3
  58. data/lib/overcommit/hook/pre_commit/yard_coverage.rb +0 -1
  59. data/lib/overcommit/hook/pre_push/cargo_test.rb +1 -0
  60. data/lib/overcommit/hook/prepare_commit_msg/base.rb +1 -0
  61. data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +1 -1
  62. data/lib/overcommit/hook/shared/bower_install.rb +1 -0
  63. data/lib/overcommit/hook/shared/bundle_install.rb +1 -0
  64. data/lib/overcommit/hook/shared/composer_install.rb +1 -0
  65. data/lib/overcommit/hook/shared/npm_install.rb +1 -0
  66. data/lib/overcommit/hook/shared/pronto.rb +16 -4
  67. data/lib/overcommit/hook/shared/yarn_install.rb +1 -0
  68. data/lib/overcommit/hook_context/helpers/file_modifications.rb +1 -0
  69. data/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb +3 -0
  70. data/lib/overcommit/hook_context/post_commit.rb +1 -0
  71. data/lib/overcommit/hook_context/pre_push.rb +1 -0
  72. data/lib/overcommit/hook_context/run_all.rb +1 -0
  73. data/lib/overcommit/hook_context.rb +3 -3
  74. data/lib/overcommit/hook_loader/base.rb +3 -3
  75. data/lib/overcommit/hook_loader/plugin_hook_loader.rb +3 -3
  76. data/lib/overcommit/hook_runner.rb +8 -7
  77. data/lib/overcommit/hook_signer.rb +1 -0
  78. data/lib/overcommit/installer.rb +2 -1
  79. data/lib/overcommit/logger.rb +5 -0
  80. data/lib/overcommit/printer.rb +3 -4
  81. data/lib/overcommit/subprocess.rb +24 -2
  82. data/lib/overcommit/utils/messages_utils.rb +1 -0
  83. data/lib/overcommit/version.rb +1 -1
  84. data/template-dir/hooks/commit-msg +27 -20
  85. data/template-dir/hooks/overcommit-hook +27 -20
  86. data/template-dir/hooks/post-checkout +27 -20
  87. data/template-dir/hooks/post-commit +27 -20
  88. data/template-dir/hooks/post-merge +27 -20
  89. data/template-dir/hooks/post-rewrite +27 -20
  90. data/template-dir/hooks/pre-commit +27 -20
  91. data/template-dir/hooks/pre-push +27 -20
  92. data/template-dir/hooks/pre-rebase +27 -20
  93. data/template-dir/hooks/prepare-commit-msg +27 -20
  94. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0d6feac2b1b10b983db054fa8931f302ff8eb8105c6d8788ad965ce986c990c
4
- data.tar.gz: bf03cf18734e6139e5d7885ea1dcffb5d2aa0dcbad07ac8ec4d3cceff53d62e1
3
+ metadata.gz: 61c2ae9a910dd7a508c79a08564313b751646bb5bcdfdd1776b8eb5d58836f98
4
+ data.tar.gz: c3c3d555ee1919b68a5fba95f7e0b8a614c97459e71be94501fd822f94cc75e0
5
5
  SHA512:
6
- metadata.gz: 915b83736de391fe61565da7bd5caca5bf427cca3bf8f6f6aa4d6a639bf151e55d3fc61578b06eab6ffda215abe8e77e209b34d95a0ad4f6988b66fea4773a67
7
- data.tar.gz: 445041c3c00b3d5cfa34c65aae868459f515c24ed4bc40017dd6bfdb91a3a6060c305a24eb03537a3ab0be401241f480fe12c42f3b70cf8fb6835f2d65f8dc6c
6
+ metadata.gz: 3558b41b1158d11ee7d152119bfbd76cb3b205f4221f379d009e9e823c343cd56ceb109d04af2a464e4f4713d577fd1223572fdb8ddacd8641014f99cfa1dfa0
7
+ data.tar.gz: 110d94b41040610061815119882b0ec4ddf67ebe218a410de3d91c3bf6a47a2f5f689828b5a1d477f5b4b2cd3f70f2057c49f6674afaf6c2d0cbedf6bae4bdc1
data/bin/overcommit CHANGED
@@ -18,15 +18,16 @@ if gemfile = YAML.load_file('.overcommit.yml')['gemfile'] rescue nil
18
18
  ensure
19
19
  $stderr = old_stderr
20
20
  end
21
- rescue Bundler::BundlerError => ex
22
- puts "Problem loading '#{gemfile}': #{ex.message}"
23
- puts "Try running:\nbundle install --gemfile=#{gemfile}" if ex.is_a?(Bundler::GemNotFound)
21
+ rescue Bundler::BundlerError => e
22
+ puts "Problem loading '#{gemfile}': #{e.message}"
23
+ puts "Try running:\nbundle install --gemfile=#{gemfile}" if e.is_a?(Bundler::GemNotFound)
24
24
  exit 78 # EX_CONFIG
25
- rescue Gem::LoadError => ex
25
+ rescue Gem::LoadError => e
26
26
  # Handle case where user is executing overcommit without `bundle exec` and
27
27
  # whose local Gemfile has a gem requirement that does not match a gem
28
28
  # requirement of the installed version of Overcommit.
29
- raise unless ex.message =~ /already activated/i
29
+ raise unless e.message =~ /already activated/i
30
+
30
31
  exec('bundle', 'exec', $0, *ARGV)
31
32
  end
32
33
  end
data/config/default.yml CHANGED
@@ -703,7 +703,7 @@ PreCommit:
703
703
  enabled: false
704
704
  description: 'Analyze with RuboCop'
705
705
  required_executable: 'rubocop'
706
- flags: ['--format=emacs', '--force-exclusion', '--display-cop-names']
706
+ flags: ['--format=emacs', '--force-exclusion', '--display-cop-names', '--disable-pending-cops']
707
707
  install_command: 'gem install rubocop'
708
708
  include:
709
709
  - '**/*.gemspec'
@@ -6,7 +6,7 @@ require 'optparse'
6
6
  module Overcommit
7
7
  # Responsible for parsing command-line options and executing appropriate
8
8
  # application logic based on those options.
9
- class CLI # rubocop:disable ClassLength
9
+ class CLI # rubocop:disable Metrics/ClassLength
10
10
  def initialize(arguments, input, logger)
11
11
  @arguments = arguments
12
12
  @input = input
@@ -29,11 +29,11 @@ module Overcommit
29
29
  when :run_all
30
30
  run_all
31
31
  end
32
- rescue Overcommit::Exceptions::ConfigurationSignatureChanged => ex
33
- puts ex
32
+ rescue Overcommit::Exceptions::ConfigurationSignatureChanged => e
33
+ puts e
34
34
  exit 78 # EX_CONFIG
35
- rescue Overcommit::Exceptions::HookContextLoadError => ex
36
- puts ex
35
+ rescue Overcommit::Exceptions::HookContextLoadError => e
36
+ puts e
37
37
  exit 64 # EX_USAGE
38
38
  end
39
39
 
@@ -52,8 +52,8 @@ module Overcommit
52
52
 
53
53
  # Unconsumed arguments are our targets
54
54
  @options[:targets] = @arguments
55
- rescue OptionParser::InvalidOption => ex
56
- print_help @parser.help, ex
55
+ rescue OptionParser::InvalidOption => e
56
+ print_help @parser.help, e
57
57
  end
58
58
  end
59
59
 
@@ -94,8 +94,9 @@ module Overcommit
94
94
  @options[:force] = true
95
95
  end
96
96
 
97
- opts.on('-r', '--run', 'Run pre-commit hook against all git tracked files') do
97
+ opts.on('-r [hook]', '--run [hook]', 'Run specified hook against all git tracked files. Defaults to `pre_commit`.') do |arg| # rubocop:disable Layout/LineLength
98
98
  @options[:action] = :run_all
99
+ @options[:hook_to_run] = arg ? arg.to_s : 'run-all'
99
100
  end
100
101
  end
101
102
 
@@ -125,11 +126,11 @@ module Overcommit
125
126
  @options[:targets].each do |target|
126
127
  begin
127
128
  Installer.new(log).run(target, @options)
128
- rescue Overcommit::Exceptions::InvalidGitRepo => error
129
- log.warning "Invalid repo #{target}: #{error}"
129
+ rescue Overcommit::Exceptions::InvalidGitRepo => e
130
+ log.warning "Invalid repo #{target}: #{e}"
130
131
  halt 69 # EX_UNAVAILABLE
131
- rescue Overcommit::Exceptions::PreExistingHooks => error
132
- log.warning "Unable to install into #{target}: #{error}"
132
+ rescue Overcommit::Exceptions::PreExistingHooks => e
133
+ log.warning "Unable to install into #{target}: #{e}"
133
134
  halt 73 # EX_CANTCREAT
134
135
  end
135
136
  end
@@ -199,7 +200,7 @@ module Overcommit
199
200
 
200
201
  def run_all
201
202
  empty_stdin = File.open(File::NULL) # pre-commit hooks don't take input
202
- context = Overcommit::HookContext.create('run-all', config, @arguments, empty_stdin)
203
+ context = Overcommit::HookContext.create(@options[:hook_to_run], config, @arguments, empty_stdin) # rubocop:disable Layout/LineLength
203
204
  config.apply_environment!(context, ENV)
204
205
 
205
206
  printer = Overcommit::Printer.new(config, log, context)
@@ -107,8 +107,10 @@ module Overcommit
107
107
 
108
108
  loop do
109
109
  break if index > splittable_args.length - 1
110
+
110
111
  total_bytes += splittable_args[index].bytesize
111
112
  break if total_bytes > byte_limit # Not enough room
113
+
112
114
  index += 1
113
115
  end
114
116
 
@@ -5,7 +5,7 @@ require 'json'
5
5
 
6
6
  module Overcommit
7
7
  # Stores configuration for Overcommit and the hooks it runs.
8
- class Configuration # rubocop:disable ClassLength
8
+ class Configuration # rubocop:disable Metrics/ClassLength
9
9
  # Creates a configuration from the given hash.
10
10
  #
11
11
  # @param hash [Hash] loaded YAML config file as a hash
@@ -75,10 +75,10 @@ module Overcommit
75
75
  config
76
76
  rescue Overcommit::Exceptions::ConfigurationSignatureChanged
77
77
  raise
78
- rescue StandardError => error
78
+ rescue StandardError => e
79
79
  raise Overcommit::Exceptions::ConfigurationError,
80
- "Unable to load configuration from '#{file}': #{error}",
81
- error.backtrace
80
+ "Unable to load configuration from '#{file}': #{e}",
81
+ e.backtrace
82
82
  end
83
83
 
84
84
  private
@@ -16,6 +16,7 @@ module Overcommit
16
16
  def hooks_path
17
17
  path = `git config --get core.hooksPath`.chomp
18
18
  return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?
19
+
19
20
  File.absolute_path(path, Dir.pwd)
20
21
  end
21
22
  end
@@ -14,7 +14,7 @@ module Overcommit
14
14
  [^\s]+\s # Ignore old file range
15
15
  \+(\d+)(?:,(\d+))? # Extract range of hunk containing start line and number of lines
16
16
  \s@@.*$
17
- /x
17
+ /x.freeze
18
18
 
19
19
  # Regular expression used to extract information from lines of
20
20
  # `git submodule status` output
@@ -22,7 +22,7 @@ module Overcommit
22
22
  ^\s*(?<prefix>[-+U]?)(?<sha1>\w+)
23
23
  \s(?<path>[^\s]+?)
24
24
  (?:\s\((?<describe>.+)\))?$
25
- /x
25
+ /x.freeze
26
26
 
27
27
  # Struct encapsulating submodule information extracted from the
28
28
  # output of `git submodule status`
@@ -262,9 +262,9 @@ module Overcommit
262
262
  end
263
263
 
264
264
  modules
265
- rescue IniParse::IniParseError => ex
265
+ rescue IniParse::IniParseError => e
266
266
  raise Overcommit::Exceptions::GitSubmoduleError,
267
- "Unable to read submodule information from #{ref}:.gitmodules file: #{ex.message}"
267
+ "Unable to read submodule information from #{ref}:.gitmodules file: #{e.message}"
268
268
  end
269
269
 
270
270
  # Returns the names of all branches containing the given commit.
@@ -9,7 +9,7 @@ module Overcommit::Hook::CommitMsg
9
9
  class SpellCheck < Base
10
10
  Misspelling = Struct.new(:word, :suggestions)
11
11
 
12
- MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/
12
+ MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/.freeze
13
13
 
14
14
  def run
15
15
  result = execute(command + [uncommented_commit_msg_file])
@@ -32,7 +32,7 @@ module Overcommit::Hook::CommitMsg
32
32
  min_subject_width = config['min_subject_width']
33
33
  if subject.length < min_subject_width
34
34
  @errors << "Commit message subject must be >= #{min_subject_width} characters"
35
- return
35
+ nil
36
36
  end
37
37
  end
38
38
 
@@ -16,6 +16,7 @@ module Overcommit::Hook::PostCheckout
16
16
 
17
17
  def enabled?
18
18
  return false if file_checkout? && skip_file_checkout?
19
+
19
20
  super
20
21
  end
21
22
  end
@@ -5,12 +5,13 @@ module Overcommit::Hook::PostCommit
5
5
  #
6
6
  # @see https://www.npmjs.com/package/git-guilt
7
7
  class GitGuilt < Base
8
- PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))$/
8
+ PLUS_MINUS_REGEX = /^(.*?)(?:(\++)|(-+))$/.freeze
9
9
  GREEN = 32
10
10
  RED = 31
11
11
 
12
12
  def run
13
13
  return :pass if initial_commit?
14
+
14
15
  result = execute(command)
15
16
  return :fail, result.stderr unless result.success?
16
17
 
@@ -17,7 +17,7 @@ module Overcommit::Hook::PreCommit
17
17
  if result.success?
18
18
  :pass
19
19
  else
20
- return [:warn, result.stdout]
20
+ [:warn, result.stdout]
21
21
  end
22
22
  end
23
23
  end
@@ -14,11 +14,11 @@ module Overcommit::Hook::PreCommit
14
14
  next unless second
15
15
 
16
16
  result = execute(
17
- command,
18
- args: [
19
- "--first=#{first.join(' ')}",
20
- "--second=#{second.join(' ')}",
21
- ],
17
+ command,
18
+ args: [
19
+ "--first=#{first.join(' ')}",
20
+ "--second=#{second.join(' ')}",
21
+ ],
22
22
  )
23
23
 
24
24
  unless result.stdout.empty?
@@ -9,6 +9,7 @@ module Overcommit::Hook::PreCommit
9
9
  result = execute(command, args: applicable_files)
10
10
 
11
11
  return :pass if result.stdout.empty?
12
+
12
13
  [:fail, "These settings appear to need to be secured but were not: #{result.stdout}"]
13
14
  end
14
15
  end
@@ -10,7 +10,7 @@ module Overcommit::Hook::PreCommit
10
10
  ,(?<line>\d*),\d*
11
11
  ,(?<type>\w+)
12
12
  ,(?<msg>.+)$
13
- /x
13
+ /x.freeze
14
14
 
15
15
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
16
16
  type.include?('w') ? :warning : :error
@@ -9,7 +9,7 @@ module Overcommit::Hook::PreCommit
9
9
  ^(?<file>(?:\w:)?[^:]+):\s
10
10
  (?:line\s(?<line>\d+)[^EW]+)?
11
11
  (?<type>Error|Warning)
12
- /x
12
+ /x.freeze
13
13
 
14
14
  def run
15
15
  result = execute(command, args: applicable_files)
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
4
4
  # Runs `dartanalyzer` against modified Dart files.
5
5
  # @see https://dart.dev/tools/dartanalyzer
6
6
  class DartAnalyzer < Base
7
- MESSAGE_REGEX = /(?<type>.*)•\ (?<message>[^•]+)•\ (?<file>[^:]+):(?<line>\d+):(\d+)\.*/
7
+ MESSAGE_REGEX = /(?<type>.*)•\ (?<message>[^•]+)•\ (?<file>[^:]+):(?<line>\d+):(\d+)\.*/.freeze
8
8
 
9
9
  def run
10
10
  result = execute(command, args: applicable_files)
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://github.com/Shopify/erb-lint
7
7
  class ErbLint < Base
8
- MESSAGE_REGEX = /(?<message>.+)\nIn file: (?<file>.+):(?<line>\d+)/
8
+ MESSAGE_REGEX = /(?<message>.+)\nIn file: (?<file>.+):(?<line>\d+)/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)
@@ -12,7 +12,7 @@ module Overcommit::Hook::PreCommit
12
12
  if extract_offense_num(output) == 0
13
13
  :pass
14
14
  else
15
- return [:warn, output]
15
+ [:warn, output]
16
16
  end
17
17
  end
18
18
 
@@ -102,7 +102,7 @@ module Overcommit::Hook::PreCommit
102
102
  if result.success?
103
103
  :pass
104
104
  else
105
- return [:warn, result.stderr + result.stdout]
105
+ [:warn, result.stderr + result.stdout]
106
106
  end
107
107
  end
108
108
 
@@ -137,12 +137,14 @@ module Overcommit::Hook::PreCommit
137
137
 
138
138
  def modified(type)
139
139
  return [] if !config["#{type}_directory"] || config["#{type}_directory"].empty?
140
+
140
141
  @modified ||= {}
141
142
  @modified[type] ||= directories_changed(full_directory_path("#{type}_directory"))
142
143
  end
143
144
 
144
145
  def full_directory_path(config_option)
145
146
  return config[config_option] if config[config_option].start_with?(File::SEPARATOR)
147
+
146
148
  File.absolute_path(File.join(Overcommit::Utils.repo_root, config[config_option]))
147
149
  end
148
150
  end
@@ -10,7 +10,7 @@ module Overcommit::Hook::PreCommit
10
10
  :(?<line>\d+)
11
11
  :\d+
12
12
  :\s*(?<type>\w+)
13
- /x
13
+ /x.freeze
14
14
 
15
15
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
16
16
  type.include?('W') ? :warning : :error
@@ -10,7 +10,7 @@ module Overcommit::Hook::PreCommit
10
10
  line\s(?<line>\d+)\s
11
11
  column\s(?<col>\d+)\s-\s
12
12
  (?<type>Error|Warning):\s(?<message>.+)$
13
- /x
13
+ /x.freeze
14
14
 
15
15
  def run
16
16
  # example message:
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see http://checkstyle.sourceforge.net/
7
7
  class JavaCheckstyle < Base
8
- MESSAGE_REGEX = /^(\[(?<type>[^\]]+)\]\s+)?(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
8
+ MESSAGE_REGEX = /^(\[(?<type>[^\]]+)\]\s+)?(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
9
9
 
10
10
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
11
11
  %w[WARN INFO].include?(type.to_s) ? :warning : :error
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see http://www.jslint.com/
7
7
  class JsLint < Base
8
- MESSAGE_REGEX = /(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
8
+ MESSAGE_REGEX = /(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see http://www.javascriptlint.com/
7
7
  class Jsl < Base
8
- MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)/
8
+ MESSAGE_REGEX = /(?<file>(?:\w:)?.+)\((?<line>\d+)\):(?<type>[^:]+)/.freeze
9
9
 
10
10
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
11
11
  type.match?(/warning/) ? :warning : :error
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
4
4
  # Runs `ktlint` against modified Kotlin files.
5
5
  # @see https://github.com/shyiko/ktlint
6
6
  class KtLint < Base
7
- MESSAGE_REGEX = /((?<file>[^:]+):(?<line>\d+):(\d+):(?<message>.+))/
7
+ MESSAGE_REGEX = /((?<file>[^:]+):(?<line>\d+):(\d+):(?<message>.+))/.freeze
8
8
 
9
9
  def run
10
10
  result = execute(command, args: applicable_files)
@@ -7,6 +7,7 @@ module Overcommit::Hook::PreCommit
7
7
  def run
8
8
  result = execute(command)
9
9
  return :pass if result.success?
10
+
10
11
  output = result.stdout + result.stderr
11
12
  [:fail, output]
12
13
  end
@@ -12,14 +12,14 @@ module Overcommit::Hook::PreCommit
12
12
  file = File.open(file_name)
13
13
  begin
14
14
  messages += check_file(file, file_name)
15
- rescue ArgumentError => ex
15
+ rescue ArgumentError => e
16
16
  # File is likely a binary file which this check should ignore, but
17
17
  # print a warning just in case
18
18
  messages << Overcommit::Hook::Message.new(
19
19
  :warning,
20
20
  file_name,
21
21
  file.lineno,
22
- "#{file_name}:#{file.lineno}:#{ex.message}"
22
+ "#{file_name}:#{file.lineno}:#{e.message}"
23
23
  )
24
24
  end
25
25
  end
@@ -59,6 +59,7 @@ module Overcommit::Hook::PreCommit
59
59
  i = info.split.first
60
60
  next if i == 'l/-text' # ignore binary files
61
61
  next if i == "l/#{eol}"
62
+
62
63
  path
63
64
  end.compact
64
65
  end
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
7
7
  class NginxTest < Base
8
- MESSAGE_REGEX = /^nginx: .+ in (?<file>.+):(?<line>\d+)$/
8
+ MESSAGE_REGEX = /^nginx: .+ in (?<file>.+):(?<line>\d+)$/.freeze
9
9
 
10
10
  def run
11
11
  messages = []
@@ -4,7 +4,7 @@ module Overcommit::Hook::PreCommit
4
4
  # Runs `phpcs` against any modified PHP files.
5
5
  class PhpCs < Base
6
6
  # Parse `phpcs` csv mode output
7
- MESSAGE_REGEX = /^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"/
7
+ MESSAGE_REGEX = /^\"(?<file>.+)\",(?<line>\d+),\d+,(?<type>.+),\"(?<msg>.+)\"/.freeze
8
8
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
9
9
  'error'.include?(type) ? :error : :warning
10
10
  end
@@ -3,7 +3,7 @@
3
3
  module Overcommit::Hook::PreCommit
4
4
  # Runs `php-cs-fixer` against any modified PHP files.
5
5
  class PhpCsFixer < Base
6
- MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))?/
6
+ MESSAGE_REGEX = /\s+\d+\)\s+(?<file>.*\.php)(?<violated_rules>\s+\(\w+(?:,\s+)?\))?/.freeze
7
7
 
8
8
  def run
9
9
  messages = []
@@ -4,10 +4,10 @@ module Overcommit::Hook::PreCommit
4
4
  # Runs `php -l` against any modified PHP files.
5
5
  class PhpLint < Base
6
6
  # Sample String
7
- # rubocop:disable Metrics/LineLength
7
+ # rubocop:disable Layout/LineLength
8
8
  # PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in site/sumo.php on line 12
9
- # rubocop:enable Metrics/LineLength
10
- MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/
9
+ # rubocop:enable Layout/LineLength
10
+ MESSAGE_REGEX = /^(?<type>.+)\:\s+(?<message>.+) in (?<file>.+) on line (?<line>\d+)/.freeze
11
11
 
12
12
  def run
13
13
  # A list of error messages
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
8
8
  # https://github.com/phpstan/phpstan/issues/239
9
9
  # https://gist.github.com/edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2
10
10
  class PhpStan < Base
11
- MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)/
11
+ MESSAGE_REGEX = /^(?<file>.+)\:(?<line>\d+)\:(?<message>.+)/.freeze
12
12
 
13
13
  def run
14
14
  messages = []
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see http://puppet-lint.com/
7
7
  class PuppetLint < Base
8
- MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/
8
+ MESSAGE_REGEX = /(?<file>(?:\w:)?.+):(?<line>\d+):\d+:(?<type>\w+)/.freeze
9
9
 
10
10
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
11
11
  type == 'ERROR' ? :error : :warning
@@ -8,7 +8,7 @@ module Overcommit::Hook::PreCommit
8
8
  # @see https://voxpupuli.org/blog/2014/11/06/linting-metadata-json/
9
9
  #
10
10
  class PuppetMetadataJsonLint < Base
11
- MESSAGE_REGEX = /\((?<type>.*)\).*/
11
+ MESSAGE_REGEX = /\((?<type>.*)\).*/.freeze
12
12
 
13
13
  MESSAGE_TYPE_CATEGORIZER = lambda do |type|
14
14
  type == 'WARN' ? :warning : :error
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://pypi.python.org/pypi/pyflakes
7
7
  class Pyflakes < Base
8
- MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/
8
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see http://www.pylint.org/
7
7
  class Pylint < Base
8
- MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])/
8
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):(?<type>[CEFRW])/.freeze
9
9
 
10
10
  # Classify 'E' and 'F' message codes as errors,
11
11
  # everything else as warnings.
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://pypi.python.org/pypi/flake8
7
7
  class PythonFlake8 < Base
8
- MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)/
8
+ MESSAGE_REGEX = /^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)/.freeze
9
9
 
10
10
  # Classify 'Exxx' and 'Fxxx' message codes as errors,
11
11
  # everything else as warnings.
@@ -7,7 +7,7 @@ module Overcommit
7
7
  #
8
8
  # @see https://github.com/railsbp/rails_best_practices
9
9
  class RailsBestPractices < Base
10
- ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/
10
+ ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/.freeze
11
11
 
12
12
  def run
13
13
  result = execute(command, args: applicable_files)
@@ -6,7 +6,7 @@ module Overcommit::Hook::PreCommit
6
6
  # failure. The exception is if the schema is at version 0 (i.e before any
7
7
  # migrations have been run). In this case it is OK if there are no migrations.
8
8
  class RailsSchemaUpToDate < Base
9
- def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity
9
+ def run # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
10
10
  if migration_files.any? && schema_files.none?
11
11
  return :fail, "It looks like you're adding a migration, but did not update the schema file"
12
12
  elsif migration_files.none? && schema_files.any? && non_zero_schema_version?
@@ -18,7 +18,7 @@ module Overcommit::Hook::PreCommit
18
18
  # their username.
19
19
  latest_version = migration_files.map do |file|
20
20
  File.basename(file)[/\d+/]
21
- end.sort.last
21
+ end.max
22
22
 
23
23
  up_to_date = schema.include?(latest_version)
24
24
 
@@ -7,7 +7,7 @@ module Overcommit::Hook::PreCommit
7
7
  class RstLint < Base
8
8
  MESSAGE_REGEX = /
9
9
  ^(?<type>INFO|WARNING|ERROR|SEVERE)(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s(?<msg>.+)
10
- /x
10
+ /x.freeze
11
11
 
12
12
  def run
13
13
  result = execute(command, args: applicable_files)
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://github.com/mdr/scalariform
7
7
  class Scalariform < Base
8
- MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)/
8
+ MESSAGE_REGEX = /^\[(?<type>FAILED|ERROR)\]\s+(?<file>(?:\w:)?.+)/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)
@@ -10,7 +10,7 @@ module Overcommit::Hook::PreCommit
10
10
  file=(?<file>(?:\w:)?.+)\s
11
11
  message=.+\s*
12
12
  (line=(?<line>\d+))?
13
- /x
13
+ /x.freeze
14
14
 
15
15
  def run
16
16
  result = execute(command, args: applicable_files)
@@ -18,9 +18,9 @@ module Overcommit::Hook::PreCommit
18
18
 
19
19
  begin
20
20
  collect_lint_messages(JSON.parse(result.stdout))
21
- rescue JSON::ParserError => ex
22
- return :fail, "Unable to parse JSON returned by SCSS-Lint: #{ex.message}\n" \
23
- "STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"
21
+ rescue JSON::ParserError => e
22
+ [:fail, "Unable to parse JSON returned by SCSS-Lint: #{e.message}\n" \
23
+ "STDOUT: #{result.stdout}\nSTDERR: #{result.stderr}"]
24
24
  end
25
25
  end
26
26
 
@@ -5,7 +5,7 @@ module Overcommit::Hook::PreCommit
5
5
  #
6
6
  # @see https://github.com/Flet/semistandard
7
7
  class SemiStandard < Base
8
- MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
8
+ MESSAGE_REGEX = /^\s*(?<file>(?:\w:)?[^:]+):(?<line>\d+)/.freeze
9
9
 
10
10
  def run
11
11
  result = execute(command, args: applicable_files)