jawshooah-overcommit 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/bin/overcommit +8 -0
  3. data/config/default.yml +275 -0
  4. data/config/starter.yml +31 -0
  5. data/lib/overcommit.rb +20 -0
  6. data/lib/overcommit/cli.rb +205 -0
  7. data/lib/overcommit/configuration.rb +183 -0
  8. data/lib/overcommit/configuration_loader.rb +49 -0
  9. data/lib/overcommit/configuration_validator.rb +40 -0
  10. data/lib/overcommit/constants.rb +8 -0
  11. data/lib/overcommit/exceptions.rb +35 -0
  12. data/lib/overcommit/git_repo.rb +147 -0
  13. data/lib/overcommit/hook/base.rb +174 -0
  14. data/lib/overcommit/hook/commit_msg/base.rb +11 -0
  15. data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +18 -0
  16. data/lib/overcommit/hook/commit_msg/hard_tabs.rb +13 -0
  17. data/lib/overcommit/hook/commit_msg/russian_novel.rb +14 -0
  18. data/lib/overcommit/hook/commit_msg/single_line_subject.rb +12 -0
  19. data/lib/overcommit/hook/commit_msg/text_width.rb +38 -0
  20. data/lib/overcommit/hook/commit_msg/trailing_period.rb +12 -0
  21. data/lib/overcommit/hook/post_checkout/base.rb +11 -0
  22. data/lib/overcommit/hook/post_checkout/index_tags.rb +26 -0
  23. data/lib/overcommit/hook/post_commit/base.rb +11 -0
  24. data/lib/overcommit/hook/post_commit/git_guilt.rb +9 -0
  25. data/lib/overcommit/hook/pre_commit/author_email.rb +18 -0
  26. data/lib/overcommit/hook/pre_commit/author_name.rb +17 -0
  27. data/lib/overcommit/hook/pre_commit/base.rb +70 -0
  28. data/lib/overcommit/hook/pre_commit/berksfile_check.rb +20 -0
  29. data/lib/overcommit/hook/pre_commit/brakeman.rb +12 -0
  30. data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +15 -0
  31. data/lib/overcommit/hook/pre_commit/bundle_check.rb +25 -0
  32. data/lib/overcommit/hook/pre_commit/chamber_security.rb +11 -0
  33. data/lib/overcommit/hook/pre_commit/coffee_lint.rb +11 -0
  34. data/lib/overcommit/hook/pre_commit/css_lint.rb +11 -0
  35. data/lib/overcommit/hook/pre_commit/go_lint.rb +12 -0
  36. data/lib/overcommit/hook/pre_commit/haml_lint.rb +19 -0
  37. data/lib/overcommit/hook/pre_commit/hard_tabs.rb +14 -0
  38. data/lib/overcommit/hook/pre_commit/image_optim.rb +41 -0
  39. data/lib/overcommit/hook/pre_commit/js_hint.rb +13 -0
  40. data/lib/overcommit/hook/pre_commit/jscs.rb +22 -0
  41. data/lib/overcommit/hook/pre_commit/json_syntax.rb +22 -0
  42. data/lib/overcommit/hook/pre_commit/jsx_hint.rb +13 -0
  43. data/lib/overcommit/hook/pre_commit/jsxcs.rb +20 -0
  44. data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +14 -0
  45. data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +14 -0
  46. data/lib/overcommit/hook/pre_commit/pry_binding.rb +14 -0
  47. data/lib/overcommit/hook/pre_commit/python_flake8.rb +11 -0
  48. data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +45 -0
  49. data/lib/overcommit/hook/pre_commit/reek.rb +22 -0
  50. data/lib/overcommit/hook/pre_commit/rubocop.rb +19 -0
  51. data/lib/overcommit/hook/pre_commit/scss_lint.rb +19 -0
  52. data/lib/overcommit/hook/pre_commit/shell_check.rb +19 -0
  53. data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +13 -0
  54. data/lib/overcommit/hook/pre_commit/travis_lint.rb +11 -0
  55. data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +22 -0
  56. data/lib/overcommit/hook_context.rb +17 -0
  57. data/lib/overcommit/hook_context/base.rb +69 -0
  58. data/lib/overcommit/hook_context/commit_msg.rb +32 -0
  59. data/lib/overcommit/hook_context/post_checkout.rb +26 -0
  60. data/lib/overcommit/hook_context/post_commit.rb +19 -0
  61. data/lib/overcommit/hook_context/pre_commit.rb +148 -0
  62. data/lib/overcommit/hook_context/run_all.rb +39 -0
  63. data/lib/overcommit/hook_loader/base.rb +36 -0
  64. data/lib/overcommit/hook_loader/built_in_hook_loader.rb +12 -0
  65. data/lib/overcommit/hook_loader/plugin_hook_loader.rb +61 -0
  66. data/lib/overcommit/hook_runner.rb +129 -0
  67. data/lib/overcommit/hook_signer.rb +79 -0
  68. data/lib/overcommit/installer.rb +148 -0
  69. data/lib/overcommit/interrupt_handler.rb +87 -0
  70. data/lib/overcommit/logger.rb +79 -0
  71. data/lib/overcommit/message_processor.rb +132 -0
  72. data/lib/overcommit/printer.rb +116 -0
  73. data/lib/overcommit/subprocess.rb +46 -0
  74. data/lib/overcommit/utils.rb +163 -0
  75. data/lib/overcommit/version.rb +4 -0
  76. data/libexec/gerrit-change-id +174 -0
  77. data/libexec/index-tags +17 -0
  78. data/template-dir/hooks/commit-msg +81 -0
  79. data/template-dir/hooks/overcommit-hook +81 -0
  80. data/template-dir/hooks/post-checkout +81 -0
  81. data/template-dir/hooks/pre-commit +81 -0
  82. metadata +184 -0
@@ -0,0 +1,20 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Check if local Berksfile.lock matches Berksfile when either changes, unless
3
+ # Berksfile.lock is ignored by git.
4
+ class BerksfileCheck < Base
5
+ LOCK_FILE = 'Berksfile.lock'
6
+
7
+ def run
8
+ # Ignore if Berksfile.lock is not tracked by git
9
+ ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
10
+ return :pass if ignored_files.include?(LOCK_FILE)
11
+
12
+ result = execute(%W[#{executable} list --quiet])
13
+ unless result.success?
14
+ return :fail, result.stderr
15
+ end
16
+
17
+ :pass
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `brakeman` against any modified Ruby/Rails files.
3
+ class Brakeman < Base
4
+ def run
5
+ result = execute(%W[#{executable} --exit-on-warn --quiet --summary --only-files] <<
6
+ applicable_files.join(','))
7
+ return :pass if result.success?
8
+
9
+ [:fail, result.stdout]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for broken symlinks.
3
+ class BrokenSymlinks < Base
4
+ def run
5
+ broken_symlinks = applicable_files.
6
+ select { |file| Overcommit::Utils.broken_symlink?(file) }
7
+
8
+ if broken_symlinks.any?
9
+ return :fail, "Broken symlinks detected:\n#{broken_symlinks.join("\n")}"
10
+ end
11
+
12
+ :pass
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Check if local Gemfile.lock matches Gemfile when either changes, unless
3
+ # Gemfile.lock is ignored by git.
4
+ class BundleCheck < Base
5
+ LOCK_FILE = 'Gemfile.lock'
6
+
7
+ def run
8
+ # Ignore if Gemfile.lock is not tracked by git
9
+ ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
10
+ return :pass if ignored_files.include?(LOCK_FILE)
11
+
12
+ result = execute(%W[#{executable} check])
13
+ unless result.success?
14
+ return :fail, result.stdout
15
+ end
16
+
17
+ result = execute(%w[git diff --quiet --] + [LOCK_FILE])
18
+ unless result.success?
19
+ return :fail, "#{LOCK_FILE} is not up-to-date -- run `#{executable} check`"
20
+ end
21
+
22
+ :pass
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `chamber secure` against any modified Chamber settings files
3
+ class ChamberSecurity < Base
4
+ def run
5
+ result = execute(%W[#{executable} secure --files] + applicable_files)
6
+
7
+ return :pass if result.stdout.empty?
8
+ [:fail, "These settings appear to need to be secured but were not: #{result.stdout}"]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `coffeelint` against any modified CoffeeScript files.
3
+ class CoffeeLint < Base
4
+ def run
5
+ result = execute(%W[#{executable} --quiet] + applicable_files)
6
+ return :pass if result.success?
7
+
8
+ [:fail, result.stdout]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `csslint` against any modified CSS files.
3
+ class CssLint < Base
4
+ def run
5
+ result = execute(%W[#{executable} --quiet --format=compact] + applicable_files)
6
+ return :pass if result.stdout !~ /Error - (?!Unknown @ rule)/
7
+
8
+ [:fail, result.stdout]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `golint` against any modified Golang files.
3
+ class GoLint < Base
4
+ def run
5
+ result = execute([executable] + applicable_files)
6
+ # Unfortunately the exit code is always 0
7
+ return :pass if result.stdout.empty?
8
+
9
+ [:fail, result.stdout]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `haml-lint` against any modified HAML files.
3
+ class HamlLint < Base
4
+ MESSAGE_TYPE_CATEGORIZER = lambda do |type|
5
+ type.include?('W') ? :warning : :error
6
+ end
7
+
8
+ def run
9
+ result = execute([executable] + applicable_files)
10
+ return :pass if result.success?
11
+
12
+ extract_messages(
13
+ result.stdout.split("\n"),
14
+ /^(?<file>[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+)/,
15
+ MESSAGE_TYPE_CATEGORIZER,
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for hard tabs in files.
3
+ class HardTabs < Base
4
+ def run
5
+ # Catches hard tabs
6
+ result = execute(%w[grep -IHn] + ["\t"] + applicable_files)
7
+ unless result.stdout.empty?
8
+ return :fail, "Hard tabs detected:\n#{result.stdout}"
9
+ end
10
+
11
+ :pass
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for images that can be optimized with `image_optim`.
3
+ class ImageOptim < Base
4
+ def run
5
+ begin
6
+ require 'image_optim'
7
+ rescue LoadError
8
+ return :warn, 'image_optim not installed -- run `gem install image_optim`'
9
+ end
10
+
11
+ optimized_images =
12
+ begin
13
+ optimize_images(applicable_files)
14
+ rescue ::ImageOptim::BinResolver::BinNotFound => e
15
+ return :fail, "#{e.message}. The image_optim gem is dependendent on this binary."
16
+ end
17
+
18
+ if optimized_images.any?
19
+ return :fail,
20
+ "The following images are optimizable:\n#{optimized_images.join("\n")}" \
21
+ "\n\nOptimize them by running:\n" \
22
+ " image_optim --skip-missing-workers #{optimized_images.join(' ')}"
23
+ end
24
+
25
+ :pass
26
+ end
27
+
28
+ private
29
+
30
+ def optimize_images(image_paths)
31
+ image_optim = ::ImageOptim.new(skip_missing_workers: true)
32
+
33
+ optimized_images =
34
+ image_optim.optimize_images(image_paths) do |path, optimized|
35
+ path if optimized
36
+ end
37
+
38
+ optimized_images.compact
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `jshint` against any modified JavaScript files.
3
+ class JsHint < Base
4
+ def run
5
+ result = execute([executable] + applicable_files)
6
+ output = result.stdout
7
+
8
+ return :pass if output.empty?
9
+
10
+ [:fail, output]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `jscs` (JavaScript Code Style Checker) against any modified JavaScript
3
+ # files.
4
+ class Jscs < Base
5
+ def run
6
+ result = execute(%W[#{executable} --reporter=inline --verbose] + applicable_files)
7
+ return :pass if result.success?
8
+
9
+ if result.status == 1
10
+ # No configuration was found
11
+ return :warn, result.stderr.chomp
12
+ end
13
+
14
+ # example message:
15
+ # path/to/file.js: line 7, col 0, ruleName: Error message
16
+ extract_messages(
17
+ result.stdout.split("\n"),
18
+ /^(?<file>[^:]+):[^\d]+(?<line>\d+)/,
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ module Overcommit::Hook::PreCommit
4
+ # Checks the syntax of any modified JSON files.
5
+ class JsonSyntax < Base
6
+ def run
7
+ output = []
8
+
9
+ applicable_files.each do |file|
10
+ begin
11
+ JSON.parse(IO.read(file))
12
+ rescue JSON::ParserError => e
13
+ output << "#{e.message} parsing #{file}"
14
+ end
15
+ end
16
+
17
+ return :pass if output.empty?
18
+
19
+ [:fail, output]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `jsxhint` against any modified JSX files.
3
+ class JsxHint < Base
4
+ def run
5
+ result = execute([executable] + applicable_files)
6
+ output = result.stdout
7
+
8
+ return :pass if output.empty?
9
+
10
+ [:fail, output]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `jsxcs` (JSCS (JavaScript Code Style Checker) wrapper for JSX files)
3
+ # against any modified JavaScript files.
4
+ class Jsxcs < Base
5
+ def run
6
+ result = execute(%W[#{executable} --reporter=inline] + applicable_files)
7
+ return :pass if result.success?
8
+
9
+ if result.status == 1
10
+ # No configuration found
11
+ return :warn, result.stderr.chomp
12
+ end
13
+
14
+ extract_messages(
15
+ result.stdout.split("\n"),
16
+ /^(?<file>[^:]+):[^\d]+(?<line>\d+)/,
17
+ )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for local paths in files and issues a warning
3
+ class LocalPathsInGemfile < Base
4
+ def run
5
+ result = execute(%w[grep -IHnE (\s*path:\s*)|(\s*:path\s*=>)] + applicable_files)
6
+
7
+ unless result.stdout.empty?
8
+ return :warn, "Avoid pointing to local paths in Gemfiles:\n#{result.stdout}"
9
+ end
10
+
11
+ :pass
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Checks for unresolved merge conflicts
3
+ class MergeConflicts < Base
4
+ def run
5
+ result = execute(%w[grep -IHn ^<<<<<<<\s] + applicable_files)
6
+
7
+ unless result.stdout.empty?
8
+ return :fail, "Merge conflict markers detected:\n#{result.stdout}"
9
+ end
10
+
11
+ :pass
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Adds a check to make sure no `binding.pry`'s have been left in the code
3
+ class PryBinding < Base
4
+ def run
5
+ result = execute(%w[grep -IHnE ^\s*binding\.pry] + applicable_files)
6
+
7
+ unless result.stdout.empty?
8
+ return :fail, "Found a `binding.pry` call left in:\n#{result.stdout}"
9
+ end
10
+
11
+ :pass
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `flake8` against any modified Python files.
3
+ class PythonFlake8 < Base
4
+ def run
5
+ result = execute([executable] + applicable_files)
6
+ return :pass if result.success?
7
+
8
+ [:fail, result.stdout]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Check to see whether the schema file is in line with the migrations
3
+ class RailsSchemaUpToDate < Base
4
+ def run # rubocop:disable CyclomaticComplexity, PerceivedComplexity
5
+ if migration_files.any? && schema_files.none?
6
+ return :fail, "It looks like you're adding a migration, but did not update the schema file"
7
+ elsif migration_files.none? && schema_files.any?
8
+ return :fail, "You're trying to change the schema without adding a migration file"
9
+ elsif migration_files.any? && schema_files.any?
10
+ # Get the latest version from the migration filename. Use
11
+ # `File.basename` to prevent finding numbers that could appear in
12
+ # directories, such as the home directory of a user with a number in
13
+ # their username.
14
+ latest_version = migration_files.map do |file|
15
+ File.basename(file)[/\d+/]
16
+ end.sort.last
17
+
18
+ schema = schema_files.map { |file| File.read(file) }.join
19
+ up_to_date = schema.include?(latest_version)
20
+
21
+ unless up_to_date
22
+ return :fail, "The latest migration version you're committing is " \
23
+ "#{latest_version}, but your schema file " \
24
+ "#{schema_files.join(' or ')} is on a different version."
25
+ end
26
+ end
27
+
28
+ :pass
29
+ end
30
+
31
+ private
32
+
33
+ def migration_files
34
+ @migration_files ||= applicable_files.select do |file|
35
+ file.match %r{db/migrate/.*\.rb}
36
+ end
37
+ end
38
+
39
+ def schema_files
40
+ @schema_files ||= applicable_files.select do |file|
41
+ file.match %r{db/schema\.rb|db/structure.*\.sql}
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ module Overcommit::Hook::PreCommit
2
+ # Runs `reek` against any modified Ruby files.
3
+ class Reek < Base
4
+ def run
5
+ result = execute(%W[#{executable} --single-line --no-color] + applicable_files)
6
+ return :pass if result.success?
7
+
8
+ output = scrub_output(result.stdout + result.stderr)
9
+
10
+ extract_messages(
11
+ output,
12
+ /^(?<file>[^:]+):(?<line>\d+):/,
13
+ )
14
+ end
15
+
16
+ private
17
+
18
+ def scrub_output(raw_output)
19
+ raw_output.split("\n").grep(/^(.(?!warning))*$/)
20
+ end
21
+ end
22
+ end