overcommit-jeygeethanmedia 0.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/overcommit +50 -0
- data/config/default.yml +1356 -0
- data/config/starter.yml +33 -0
- data/lib/overcommit.rb +26 -0
- data/lib/overcommit/cli.rb +223 -0
- data/lib/overcommit/command_splitter.rb +146 -0
- data/lib/overcommit/configuration.rb +350 -0
- data/lib/overcommit/configuration_loader.rb +96 -0
- data/lib/overcommit/configuration_validator.rb +186 -0
- data/lib/overcommit/constants.rb +12 -0
- data/lib/overcommit/exceptions.rb +52 -0
- data/lib/overcommit/git_config.rb +22 -0
- data/lib/overcommit/git_repo.rb +286 -0
- data/lib/overcommit/git_version.rb +17 -0
- data/lib/overcommit/hook/base.rb +294 -0
- data/lib/overcommit/hook/commit_msg/base.rb +14 -0
- data/lib/overcommit/hook/commit_msg/capitalized_subject.rb +25 -0
- data/lib/overcommit/hook/commit_msg/empty_message.rb +12 -0
- data/lib/overcommit/hook/commit_msg/gerrit_change_id.rb +22 -0
- data/lib/overcommit/hook/commit_msg/hard_tabs.rb +17 -0
- data/lib/overcommit/hook/commit_msg/message_format.rb +31 -0
- data/lib/overcommit/hook/commit_msg/russian_novel.rb +16 -0
- data/lib/overcommit/hook/commit_msg/single_line_subject.rb +16 -0
- data/lib/overcommit/hook/commit_msg/spell_check.rb +45 -0
- data/lib/overcommit/hook/commit_msg/text_width.rb +56 -0
- data/lib/overcommit/hook/commit_msg/trailing_period.rb +16 -0
- data/lib/overcommit/hook/post_checkout/base.rb +22 -0
- data/lib/overcommit/hook/post_checkout/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_checkout/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_checkout/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_checkout/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/base.rb +12 -0
- data/lib/overcommit/hook/post_commit/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/commitplease.rb +16 -0
- data/lib/overcommit/hook/post_commit/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/git_guilt.rb +43 -0
- data/lib/overcommit/hook/post_commit/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_commit/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_commit/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_commit/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/base.rb +12 -0
- data/lib/overcommit/hook/post_merge/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/index_tags.rb +12 -0
- data/lib/overcommit/hook/post_merge/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_merge/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_merge/yarn_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/base.rb +12 -0
- data/lib/overcommit/hook/post_rewrite/bower_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/bundle_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/composer_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/index_tags.rb +19 -0
- data/lib/overcommit/hook/post_rewrite/npm_install.rb +13 -0
- data/lib/overcommit/hook/post_rewrite/submodule_status.rb +12 -0
- data/lib/overcommit/hook/post_rewrite/yarn_install.rb +13 -0
- data/lib/overcommit/hook/pre_commit/author_email.rb +26 -0
- data/lib/overcommit/hook/pre_commit/author_name.rb +25 -0
- data/lib/overcommit/hook/pre_commit/base.rb +19 -0
- data/lib/overcommit/hook/pre_commit/berksfile_check.rb +24 -0
- data/lib/overcommit/hook/pre_commit/broken_symlinks.rb +17 -0
- data/lib/overcommit/hook/pre_commit/bundle_audit.rb +24 -0
- data/lib/overcommit/hook/pre_commit/bundle_check.rb +32 -0
- data/lib/overcommit/hook/pre_commit/bundle_outdated.rb +25 -0
- data/lib/overcommit/hook/pre_commit/case_conflicts.rb +27 -0
- data/lib/overcommit/hook/pre_commit/chamber_compare.rb +43 -0
- data/lib/overcommit/hook/pre_commit/chamber_security.rb +15 -0
- data/lib/overcommit/hook/pre_commit/chamber_verification.rb +36 -0
- data/lib/overcommit/hook/pre_commit/code_spell_check.rb +36 -0
- data/lib/overcommit/hook/pre_commit/coffee_lint.rb +35 -0
- data/lib/overcommit/hook/pre_commit/cook_style.rb +35 -0
- data/lib/overcommit/hook/pre_commit/credo.rb +27 -0
- data/lib/overcommit/hook/pre_commit/css_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/dogma.rb +33 -0
- data/lib/overcommit/hook/pre_commit/es_lint.rb +38 -0
- data/lib/overcommit/hook/pre_commit/execute_permissions.rb +76 -0
- data/lib/overcommit/hook/pre_commit/fasterer.rb +25 -0
- data/lib/overcommit/hook/pre_commit/file_size.rb +47 -0
- data/lib/overcommit/hook/pre_commit/fix_me.rb +17 -0
- data/lib/overcommit/hook/pre_commit/flay.rb +38 -0
- data/lib/overcommit/hook/pre_commit/foodcritic.rb +149 -0
- data/lib/overcommit/hook/pre_commit/forbidden_branches.rb +26 -0
- data/lib/overcommit/hook/pre_commit/ginkgo_focus.rb +23 -0
- data/lib/overcommit/hook/pre_commit/go_fmt.rb +17 -0
- data/lib/overcommit/hook/pre_commit/go_lint.rb +29 -0
- data/lib/overcommit/hook/pre_commit/go_vet.rb +24 -0
- data/lib/overcommit/hook/pre_commit/golangci_lint.rb +21 -0
- data/lib/overcommit/hook/pre_commit/hadolint.rb +27 -0
- data/lib/overcommit/hook/pre_commit/haml_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/hard_tabs.rb +15 -0
- data/lib/overcommit/hook/pre_commit/hlint.rb +34 -0
- data/lib/overcommit/hook/pre_commit/html_hint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/html_tidy.rb +30 -0
- data/lib/overcommit/hook/pre_commit/image_optim.rb +28 -0
- data/lib/overcommit/hook/pre_commit/java_checkstyle.rb +27 -0
- data/lib/overcommit/hook/pre_commit/js_hint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/js_lint.rb +22 -0
- data/lib/overcommit/hook/pre_commit/jscs.rb +27 -0
- data/lib/overcommit/hook/pre_commit/jsl.rb +28 -0
- data/lib/overcommit/hook/pre_commit/json_syntax.rb +21 -0
- data/lib/overcommit/hook/pre_commit/kt_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/license_finder.rb +14 -0
- data/lib/overcommit/hook/pre_commit/license_header.rb +48 -0
- data/lib/overcommit/hook/pre_commit/line_endings.rb +77 -0
- data/lib/overcommit/hook/pre_commit/local_paths_in_gemfile.rb +16 -0
- data/lib/overcommit/hook/pre_commit/mdl.rb +29 -0
- data/lib/overcommit/hook/pre_commit/merge_conflicts.rb +16 -0
- data/lib/overcommit/hook/pre_commit/nginx_test.rb +26 -0
- data/lib/overcommit/hook/pre_commit/pep257.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pep8.rb +23 -0
- data/lib/overcommit/hook/pre_commit/php_cs.rb +43 -0
- data/lib/overcommit/hook/pre_commit/php_cs_fixer.rb +57 -0
- data/lib/overcommit/hook/pre_commit/php_lint.rb +44 -0
- data/lib/overcommit/hook/pre_commit/php_stan.rb +30 -0
- data/lib/overcommit/hook/pre_commit/pronto.rb +12 -0
- data/lib/overcommit/hook/pre_commit/puppet_lint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/puppet_metadata_json_lint.rb +29 -0
- data/lib/overcommit/hook/pre_commit/pycodestyle.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pydocstyle.rb +23 -0
- data/lib/overcommit/hook/pre_commit/pyflakes.rb +32 -0
- data/lib/overcommit/hook/pre_commit/pylint.rb +32 -0
- data/lib/overcommit/hook/pre_commit/python_flake8.rb +32 -0
- data/lib/overcommit/hook/pre_commit/rails_best_practices.rb +34 -0
- data/lib/overcommit/hook/pre_commit/rails_schema_up_to_date.rb +58 -0
- data/lib/overcommit/hook/pre_commit/rake_target.rb +12 -0
- data/lib/overcommit/hook/pre_commit/reek.rb +26 -0
- data/lib/overcommit/hook/pre_commit/rst_lint.rb +27 -0
- data/lib/overcommit/hook/pre_commit/rubo_cop.rb +35 -0
- data/lib/overcommit/hook/pre_commit/ruby_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/ruby_syntax.rb +27 -0
- data/lib/overcommit/hook/pre_commit/scalariform.rb +22 -0
- data/lib/overcommit/hook/pre_commit/scalastyle.rb +31 -0
- data/lib/overcommit/hook/pre_commit/scss_lint.rb +43 -0
- data/lib/overcommit/hook/pre_commit/semi_standard.rb +23 -0
- data/lib/overcommit/hook/pre_commit/shell_check.rb +23 -0
- data/lib/overcommit/hook/pre_commit/slim_lint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/sqlint.rb +26 -0
- data/lib/overcommit/hook/pre_commit/standard.rb +23 -0
- data/lib/overcommit/hook/pre_commit/stylelint.rb +23 -0
- data/lib/overcommit/hook/pre_commit/swift_lint.rb +19 -0
- data/lib/overcommit/hook/pre_commit/terraform_format.rb +19 -0
- data/lib/overcommit/hook/pre_commit/trailing_whitespace.rb +15 -0
- data/lib/overcommit/hook/pre_commit/travis_lint.rb +15 -0
- data/lib/overcommit/hook/pre_commit/ts_lint.rb +28 -0
- data/lib/overcommit/hook/pre_commit/vint.rb +22 -0
- data/lib/overcommit/hook/pre_commit/w3c_css.rb +67 -0
- data/lib/overcommit/hook/pre_commit/w3c_html.rb +64 -0
- data/lib/overcommit/hook/pre_commit/xml_lint.rb +24 -0
- data/lib/overcommit/hook/pre_commit/xml_syntax.rb +21 -0
- data/lib/overcommit/hook/pre_commit/yaml_lint.rb +18 -0
- data/lib/overcommit/hook/pre_commit/yaml_syntax.rb +20 -0
- data/lib/overcommit/hook/pre_commit/yard_coverage.rb +90 -0
- data/lib/overcommit/hook/pre_commit/yarn_check.rb +37 -0
- data/lib/overcommit/hook/pre_push/base.rb +33 -0
- data/lib/overcommit/hook/pre_push/brakeman.rb +15 -0
- data/lib/overcommit/hook/pre_push/cargo_test.rb +12 -0
- data/lib/overcommit/hook/pre_push/go_test.rb +14 -0
- data/lib/overcommit/hook/pre_push/golangci_lint.rb +16 -0
- data/lib/overcommit/hook/pre_push/minitest.rb +20 -0
- data/lib/overcommit/hook/pre_push/php_unit.rb +16 -0
- data/lib/overcommit/hook/pre_push/pronto.rb +12 -0
- data/lib/overcommit/hook/pre_push/protected_branches.rb +74 -0
- data/lib/overcommit/hook/pre_push/pytest.rb +16 -0
- data/lib/overcommit/hook/pre_push/python_nose.rb +16 -0
- data/lib/overcommit/hook/pre_push/r_spec.rb +16 -0
- data/lib/overcommit/hook/pre_push/rake_target.rb +12 -0
- data/lib/overcommit/hook/pre_push/test_unit.rb +16 -0
- data/lib/overcommit/hook/pre_rebase/base.rb +14 -0
- data/lib/overcommit/hook/pre_rebase/merged_commits.rb +31 -0
- data/lib/overcommit/hook/prepare_commit_msg/base.rb +25 -0
- data/lib/overcommit/hook/prepare_commit_msg/replace_branch.rb +57 -0
- data/lib/overcommit/hook/shared/bower_install.rb +15 -0
- data/lib/overcommit/hook/shared/bundle_install.rb +15 -0
- data/lib/overcommit/hook/shared/composer_install.rb +15 -0
- data/lib/overcommit/hook/shared/index_tags.rb +14 -0
- data/lib/overcommit/hook/shared/npm_install.rb +15 -0
- data/lib/overcommit/hook/shared/pronto.rb +21 -0
- data/lib/overcommit/hook/shared/rake_target.rb +26 -0
- data/lib/overcommit/hook/shared/submodule_status.rb +32 -0
- data/lib/overcommit/hook/shared/yarn_install.rb +15 -0
- data/lib/overcommit/hook_context.rb +19 -0
- data/lib/overcommit/hook_context/base.rb +139 -0
- data/lib/overcommit/hook_context/commit_msg.rb +48 -0
- data/lib/overcommit/hook_context/post_checkout.rb +36 -0
- data/lib/overcommit/hook_context/post_commit.rb +33 -0
- data/lib/overcommit/hook_context/post_merge.rb +37 -0
- data/lib/overcommit/hook_context/post_rewrite.rb +49 -0
- data/lib/overcommit/hook_context/pre_commit.rb +212 -0
- data/lib/overcommit/hook_context/pre_push.rb +89 -0
- data/lib/overcommit/hook_context/pre_rebase.rb +38 -0
- data/lib/overcommit/hook_context/prepare_commit_msg.rb +34 -0
- data/lib/overcommit/hook_context/run_all.rb +48 -0
- data/lib/overcommit/hook_loader/base.rb +48 -0
- data/lib/overcommit/hook_loader/built_in_hook_loader.rb +14 -0
- data/lib/overcommit/hook_loader/plugin_hook_loader.rb +102 -0
- data/lib/overcommit/hook_runner.rb +219 -0
- data/lib/overcommit/hook_signer.rb +123 -0
- data/lib/overcommit/installer.rb +193 -0
- data/lib/overcommit/interrupt_handler.rb +91 -0
- data/lib/overcommit/logger.rb +92 -0
- data/lib/overcommit/message_processor.rb +148 -0
- data/lib/overcommit/os.rb +38 -0
- data/lib/overcommit/printer.rb +145 -0
- data/lib/overcommit/subprocess.rb +98 -0
- data/lib/overcommit/utils.rb +309 -0
- data/lib/overcommit/utils/file_utils.rb +71 -0
- data/lib/overcommit/utils/messages_utils.rb +77 -0
- data/lib/overcommit/version.rb +6 -0
- data/libexec/gerrit-change-id +174 -0
- data/libexec/index-tags +17 -0
- data/template-dir/hooks/commit-msg +116 -0
- data/template-dir/hooks/overcommit-hook +116 -0
- data/template-dir/hooks/post-checkout +116 -0
- data/template-dir/hooks/post-commit +116 -0
- data/template-dir/hooks/post-merge +116 -0
- data/template-dir/hooks/post-rewrite +116 -0
- data/template-dir/hooks/pre-commit +116 -0
- data/template-dir/hooks/pre-push +116 -0
- data/template-dir/hooks/pre-rebase +116 -0
- data/template-dir/hooks/prepare-commit-msg +116 -0
- metadata +303 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Check for "token" strings
|
|
5
|
+
class FixMe < Base
|
|
6
|
+
def run
|
|
7
|
+
keywords = config['keywords']
|
|
8
|
+
result = execute(command, args: [keywords.join('|')] + applicable_files)
|
|
9
|
+
|
|
10
|
+
extract_messages(
|
|
11
|
+
result.stdout.split("\n"),
|
|
12
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
|
13
|
+
lambda { |_type| :warning }
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `flay` against any modified files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/seattlerb/flay
|
|
7
|
+
class Flay < Base
|
|
8
|
+
# Flay prints two kinds of messages:
|
|
9
|
+
#
|
|
10
|
+
# 1) IDENTICAL code found in :defn (mass*2 = MASS)
|
|
11
|
+
# file_path_1.rb:LINE_1
|
|
12
|
+
# file_path_2.rb:LINE_2
|
|
13
|
+
#
|
|
14
|
+
# 2) Similar code found in :defn (mass = MASS)
|
|
15
|
+
# file_path_1.rb:LINE_1
|
|
16
|
+
# file_path_2.rb:LINE_2
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
command = ['flay', '--mass', @config['mass_threshold'].to_s, '--fuzzy', @config['fuzzy'].to_s]
|
|
21
|
+
# Use a more liberal detection method
|
|
22
|
+
command += ['--liberal'] if @config['liberal']
|
|
23
|
+
messages = []
|
|
24
|
+
# Run the command for each file
|
|
25
|
+
applicable_files.each do |file|
|
|
26
|
+
result = execute(command, args: [file])
|
|
27
|
+
results = result.stdout.split("\n\n")
|
|
28
|
+
results.shift
|
|
29
|
+
unless results.empty?
|
|
30
|
+
error_message = results.join("\n").gsub(/^\d+\)\s*/, '')
|
|
31
|
+
message = Overcommit::Hook::Message.new(:error, nil, nil, error_message)
|
|
32
|
+
messages << message
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
messages
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `foodcritic` against any modified Ruby files from Chef directory structure.
|
|
5
|
+
#
|
|
6
|
+
# @see http://www.foodcritic.io/
|
|
7
|
+
#
|
|
8
|
+
# There are two "modes" you can run this hook in based on the repo:
|
|
9
|
+
#
|
|
10
|
+
# SINGLE COOKBOOK REPO MODE
|
|
11
|
+
# -------------------------
|
|
12
|
+
# The default. Use this if your repository contains just a single cookbook,
|
|
13
|
+
# i.e. the top-level repo directory contains directories called `attributes`,
|
|
14
|
+
# `libraries`, `recipes`, etc.
|
|
15
|
+
#
|
|
16
|
+
# To get this to work well, you'll want to set your Overcommit configuration
|
|
17
|
+
# for this hook to something like:
|
|
18
|
+
#
|
|
19
|
+
# PreCommit:
|
|
20
|
+
# Foodcritic:
|
|
21
|
+
# enabled: true
|
|
22
|
+
# include:
|
|
23
|
+
# - 'attributes/**/*'
|
|
24
|
+
# - 'definitions/**/*'
|
|
25
|
+
# - 'files/**/*'
|
|
26
|
+
# - 'libraries/**/*'
|
|
27
|
+
# - 'providers/**/*'
|
|
28
|
+
# - 'recipes/**/*'
|
|
29
|
+
# - 'resources/**/*'
|
|
30
|
+
# - 'templates/**/*'
|
|
31
|
+
#
|
|
32
|
+
# MONOLITHIC REPO MODE
|
|
33
|
+
# --------------------
|
|
34
|
+
# Use this if you store multiple cookbooks, environments, and roles (or any
|
|
35
|
+
# combination thereof) in a single repository.
|
|
36
|
+
#
|
|
37
|
+
# There are three configuration options relevant here:
|
|
38
|
+
#
|
|
39
|
+
# * `cookbooks_directory`
|
|
40
|
+
# When set, hook will treat the path as a directory containing cookbooks.
|
|
41
|
+
# Each subdirectory of this directory will be treated as a separate
|
|
42
|
+
# cookbook.
|
|
43
|
+
#
|
|
44
|
+
# * `environments_directory`
|
|
45
|
+
# When set, hook will treat the path as a directory containing environment
|
|
46
|
+
# files.
|
|
47
|
+
#
|
|
48
|
+
# * `roles_directory`
|
|
49
|
+
# When set, hook will treat the given path as a directory containing role
|
|
50
|
+
# files.
|
|
51
|
+
#
|
|
52
|
+
# In order to run in monolithic repo mode, YOU MUST SET `cookbooks_directory`.
|
|
53
|
+
# The other configuration options are optional, if you happen to store
|
|
54
|
+
# environments/roles in another repo.
|
|
55
|
+
#
|
|
56
|
+
# To get this to work well, you'll want to set your Overcommit configuration
|
|
57
|
+
# for this hook to something like:
|
|
58
|
+
#
|
|
59
|
+
# PreCommit:
|
|
60
|
+
# Foodcritic:
|
|
61
|
+
# enabled: true
|
|
62
|
+
# cookbooks_directory: 'cookbooks'
|
|
63
|
+
# environments_directory: 'environments'
|
|
64
|
+
# roles_directory: 'roles'
|
|
65
|
+
# include:
|
|
66
|
+
# - 'cookbooks/**/*'
|
|
67
|
+
# - 'environments/**/*'
|
|
68
|
+
# - 'roles/**/*'
|
|
69
|
+
#
|
|
70
|
+
# ADDITIONAL CONFIGURATION
|
|
71
|
+
# ------------------------
|
|
72
|
+
# You can disable rules using the `flags` hook option. For example:
|
|
73
|
+
#
|
|
74
|
+
# PreCommit:
|
|
75
|
+
# Foodcritic:
|
|
76
|
+
# enabled: true
|
|
77
|
+
# ...
|
|
78
|
+
# flags:
|
|
79
|
+
# - '--epic-fail=any'
|
|
80
|
+
# - '-t~FC011' # Missing README in markdown format
|
|
81
|
+
# - '-t~FC064' # Ensure issues_url is set in metadata
|
|
82
|
+
#
|
|
83
|
+
# Any other command line flag supported by the `foodcritic` executable can be
|
|
84
|
+
# specified here.
|
|
85
|
+
#
|
|
86
|
+
# If you want the hook run to fail (and not just warn), set the `on_warn`
|
|
87
|
+
# option for the hook to `fail`:
|
|
88
|
+
#
|
|
89
|
+
# PreCommit:
|
|
90
|
+
# Foodcritic:
|
|
91
|
+
# enabled: true
|
|
92
|
+
# on_warn: fail
|
|
93
|
+
# ...
|
|
94
|
+
#
|
|
95
|
+
# This will treat any warnings as failures and cause the hook to exit
|
|
96
|
+
# unsuccessfully.
|
|
97
|
+
class Foodcritic < Base
|
|
98
|
+
def run
|
|
99
|
+
args = modified_cookbooks_args + modified_environments_args + modified_roles_args
|
|
100
|
+
result = execute(command, args: args)
|
|
101
|
+
|
|
102
|
+
if result.success?
|
|
103
|
+
:pass
|
|
104
|
+
else
|
|
105
|
+
return [:warn, result.stderr + result.stdout]
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
def directories_changed(dir_prefix)
|
|
112
|
+
applicable_files.
|
|
113
|
+
select { |path| path.start_with?(dir_prefix) }.
|
|
114
|
+
map { |path| path.gsub(%r{^#{dir_prefix}/}, '') }.
|
|
115
|
+
group_by { |path| path.split('/').first }.
|
|
116
|
+
keys.
|
|
117
|
+
map { |path| File.join(dir_prefix, path) }
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def modified_environments_args
|
|
121
|
+
modified('environments').map { |env| %W[-E #{env}] }.flatten
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def modified_roles_args
|
|
125
|
+
modified('roles').map { |role| %W[-R #{role}] }.flatten
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def modified_cookbooks_args
|
|
129
|
+
# Return the repo root if repository contains a single cookbook
|
|
130
|
+
if !config['cookbooks_directory'] || config['cookbooks_directory'].empty?
|
|
131
|
+
['-B', Overcommit::Utils.repo_root]
|
|
132
|
+
else
|
|
133
|
+
# Otherwise return all modified cookbooks in the cookbook directory
|
|
134
|
+
modified('cookbooks').map { |cookbook| ['-B', cookbook] }.flatten
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def modified(type)
|
|
139
|
+
return [] if !config["#{type}_directory"] || config["#{type}_directory"].empty?
|
|
140
|
+
@modified ||= {}
|
|
141
|
+
@modified[type] ||= directories_changed(full_directory_path("#{type}_directory"))
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def full_directory_path(config_option)
|
|
145
|
+
return config[config_option] if config[config_option].start_with?(File::SEPARATOR)
|
|
146
|
+
File.absolute_path(File.join(Overcommit::Utils.repo_root, config[config_option]))
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Prevents commits to branches matching one of the configured patterns.
|
|
5
|
+
class ForbiddenBranches < Base
|
|
6
|
+
def run
|
|
7
|
+
return :pass unless forbidden_commit?
|
|
8
|
+
|
|
9
|
+
[:fail, "Committing to #{current_branch} is forbidden"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def forbidden_commit?
|
|
15
|
+
forbidden_branch_patterns.any? { |p| File.fnmatch(p, current_branch) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def forbidden_branch_patterns
|
|
19
|
+
@forbidden_branch_patterns ||= Array(config['branch_patterns'])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def current_branch
|
|
23
|
+
@current_branch ||= Overcommit::GitRepo.current_branch
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Check for "focused" tests
|
|
5
|
+
class GinkgoFocus < Base
|
|
6
|
+
def run
|
|
7
|
+
keywords = config['keywords']
|
|
8
|
+
result = execute(command, args: [keywords.join('|')] + applicable_files)
|
|
9
|
+
|
|
10
|
+
extract_messages(
|
|
11
|
+
result.stdout.split("\n"),
|
|
12
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
|
13
|
+
lambda { |_type| :warning }
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def applicable_test_files
|
|
18
|
+
applicable_files.select do |f|
|
|
19
|
+
f if f =~ /_test\.go/
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs go fmt for all modified Go files
|
|
5
|
+
class GoFmt < Base
|
|
6
|
+
def run
|
|
7
|
+
errors = []
|
|
8
|
+
applicable_files.each do |file|
|
|
9
|
+
result = execute(command, args: [file])
|
|
10
|
+
errors << (result.stdout + result.stderr) unless result.success?
|
|
11
|
+
end
|
|
12
|
+
return :pass if errors.empty?
|
|
13
|
+
|
|
14
|
+
[:fail, errors.join("\n")]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `golint` against any modified Golang files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/golang/lint
|
|
7
|
+
class GoLint < Base
|
|
8
|
+
def run
|
|
9
|
+
output = ''
|
|
10
|
+
|
|
11
|
+
# golint doesn't accept multiple file arguments if
|
|
12
|
+
# they belong to different packages
|
|
13
|
+
applicable_files.each do |gofile|
|
|
14
|
+
result = execute(command, args: Array(gofile))
|
|
15
|
+
output += result.stdout + result.stderr
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Unfortunately the exit code is always 0
|
|
19
|
+
return :pass if output.empty?
|
|
20
|
+
|
|
21
|
+
# example message:
|
|
22
|
+
# path/to/file.go:1:1: Error message
|
|
23
|
+
extract_messages(
|
|
24
|
+
output.split("\n"),
|
|
25
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `go vet` against any modified Golang files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://godoc.org/code.google.com/p/go-zh.tools/cmd/vet
|
|
7
|
+
class GoVet < Base
|
|
8
|
+
def run
|
|
9
|
+
result = execute(command, args: applicable_files)
|
|
10
|
+
return :pass if result.success?
|
|
11
|
+
|
|
12
|
+
if result.stderr.match?(/no such tool "vet"/)
|
|
13
|
+
return :fail, "`go tool vet` is not installed#{install_command_prompt}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# example message:
|
|
17
|
+
# path/to/file.go:7: Error message
|
|
18
|
+
extract_messages(
|
|
19
|
+
result.stderr.split("\n"),
|
|
20
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `golangci-lint run` against any modified packages
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/golangci/golangci-lint
|
|
7
|
+
class GolangciLint < Base
|
|
8
|
+
def run
|
|
9
|
+
packages = applicable_files.map { |f| File.dirname(f) }.uniq
|
|
10
|
+
result = execute(command, args: packages)
|
|
11
|
+
return :pass if result.success?
|
|
12
|
+
return [:fail, result.stderr] unless result.stderr.empty?
|
|
13
|
+
|
|
14
|
+
extract_messages(
|
|
15
|
+
result.stdout.split("\n"),
|
|
16
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
|
17
|
+
nil
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `hadolint` against any modified Dockefile files.
|
|
5
|
+
#
|
|
6
|
+
# @see http://hadolint.lukasmartinelli.ch/
|
|
7
|
+
class Hadolint < Base
|
|
8
|
+
def run
|
|
9
|
+
output = ''
|
|
10
|
+
success = true
|
|
11
|
+
|
|
12
|
+
# hadolint doesn't accept multiple arguments
|
|
13
|
+
applicable_files.each do |dockerfile|
|
|
14
|
+
result = execute(command, args: Array(dockerfile))
|
|
15
|
+
output += result.stdout
|
|
16
|
+
success &&= result.success?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
return :pass if success
|
|
20
|
+
|
|
21
|
+
extract_messages(
|
|
22
|
+
output.split("\n"),
|
|
23
|
+
/^(?<file>[^:]+):(?<line>\d+)/,
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `haml-lint` against any modified HAML files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/brigade/haml-lint/
|
|
7
|
+
class HamlLint < Base
|
|
8
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
|
9
|
+
type.include?('W') ? :warning : :error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def run
|
|
13
|
+
result = execute(command, args: applicable_files)
|
|
14
|
+
return :pass if result.success?
|
|
15
|
+
|
|
16
|
+
extract_messages(
|
|
17
|
+
result.stdout.split("\n"),
|
|
18
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)[^ ]* (?<type>[^ ]+)/,
|
|
19
|
+
MESSAGE_TYPE_CATEGORIZER,
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Checks for hard tabs in files.
|
|
5
|
+
class HardTabs < Base
|
|
6
|
+
def run
|
|
7
|
+
result = execute(command, args: applicable_files)
|
|
8
|
+
|
|
9
|
+
extract_messages(
|
|
10
|
+
result.stdout.split("\n"),
|
|
11
|
+
/^(?<file>(?:\w:)?[^:]+):(?<line>\d+)/,
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Overcommit::Hook::PreCommit
|
|
4
|
+
# Runs `hlint` against any modified Haskell files.
|
|
5
|
+
#
|
|
6
|
+
# @see https://github.com/ndmitchell/hlint
|
|
7
|
+
class Hlint < Base
|
|
8
|
+
MESSAGE_REGEX = /
|
|
9
|
+
^(?<file>(?:\w:)?[^:]+)
|
|
10
|
+
:(?<line>\d+)
|
|
11
|
+
:\d+
|
|
12
|
+
:\s*(?<type>\w+)
|
|
13
|
+
/x
|
|
14
|
+
|
|
15
|
+
MESSAGE_TYPE_CATEGORIZER = lambda do |type|
|
|
16
|
+
type.include?('W') ? :warning : :error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
result = execute(command, args: applicable_files)
|
|
21
|
+
return :pass if result.success?
|
|
22
|
+
|
|
23
|
+
raw_messages = result.stdout.split("\n").grep(MESSAGE_REGEX)
|
|
24
|
+
|
|
25
|
+
# example message:
|
|
26
|
+
# path/to/file.hs:1:0: Error: message
|
|
27
|
+
extract_messages(
|
|
28
|
+
raw_messages,
|
|
29
|
+
MESSAGE_REGEX,
|
|
30
|
+
MESSAGE_TYPE_CATEGORIZER
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|